View this page as Markdown

program

Builds an ordered, non-atomic EVM PROGRAM that stops execution after its first unsuccessful step.

Example

Local

WITH actors AS (
  SELECT
    '0x1000000000000000000000000000000000000001'::ADDRESS AS sender,
    '0x2000000000000000000000000000000000000002'::ADDRESS AS writer,
    '0x3000000000000000000000000000000000000003'::ADDRESS AS second_target
),
step_values AS (
  SELECT [
    execute_call(
      sender,
      writer,
      '0x000000000000000000000000000000000000000000000000000000000000002a'::BYTES,
      1::UINT256,
      100000::UBIGINT
    ),
    execute_contract(
      sender,
      second_target,
      0::UINT256,
      100000::UBIGINT,
      '[{"type":"function","name":"set","inputs":[{"name":"value","type":"uint256"}],"outputs":[]}]'::JSON,
      'set'::VARCHAR,
      7::UINT256
    )
  ] AS steps
  FROM actors
),
authored AS (
  SELECT steps, program(steps) AS program
  FROM step_values
)
SELECT
  len(steps)::INTEGER AS step_count,
  'raw,abi'::VARCHAR AS step_order,
  program IS NOT NULL AS runnable
FROM authored;
-- => [{"step_count":2,"step_order":"raw,abi","runnable":"true"}]

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

program(STEP[]) #

Builds an ordered, non-atomic EVM PROGRAM that stops execution after its first unsuccessful step.

Inputs

Name Type Use
steps STEP[]

Non-NULL list containing at least one non-NULL STEP, executed in list order.

required positional

Returns

Name Type
program PROGRAM

Executable PROGRAM. Returns a PROGRAM with no state assumptions and the fixed stop-on-first-failure execution policy.

Guidance

Execution policy

Steps execute in order and are not atomic as a group. After the first unsuccessful step, later steps are not executed.

Construction validation

Construction rejects an empty step list, NULL list elements, and duplicate assumption coordinates.

Additional overloads

program(ASSUMPTION[], STEP[]) #

Builds an ordered, non-atomic EVM PROGRAM that stops execution after its first unsuccessful step.

Inputs

Name Type Use
assumptions ASSUMPTION[]

Non-NULL list of non-NULL ASSUMPTION values; each balance, nonce, code, or address-and-slot coordinate must be unique.

required positional
steps STEP[]

Non-NULL list containing at least one non-NULL STEP, executed in list order.

required positional

Returns

Name Type
program PROGRAM

Executable PROGRAM with assumptions. Returns a PROGRAM with exact initial-state assumptions and the fixed stop-on-first-failure execution policy.

Examples

Local SQL

WITH actors AS (
  SELECT
    '0x1000000000000000000000000000000000000001'::ADDRESS AS sender,
    '0x2000000000000000000000000000000000000002'::ADDRESS AS writer
),
inputs AS (
  SELECT
    [
      -- Funds the value consumed by the step.
      assume_native_balance(sender, 1000000::UINT256, 'funds step value transfer'::VARCHAR),
      assume_nonce(sender, 0::UBIGINT, 'step sender nonce'::VARCHAR),
      assume_no_code(sender, 'step sender is an EOA'::VARCHAR),
      assume_native_balance(writer, 0::UINT256, 'receives step value'::VARCHAR),
      assume_nonce(writer, 0::UBIGINT, 'call target nonce'::VARCHAR),
      -- The step consumes this runtime and initial slot.
      assume_code(writer, '0x60003560005500'::BYTES, 'step code stores calldata word'::VARCHAR),
      assume_storage(
        writer,
        '0x0000000000000000000000000000000000000000000000000000000000000000'::BYTES32,
        '0x0000000000000000000000000000000000000000000000000000000000000000'::BYTES32,
        'step writes slot zero'::VARCHAR
      )
    ] AS assumptions,
    [execute_call(
      sender,
      writer,
      '0x000000000000000000000000000000000000000000000000000000000000002a'::BYTES,
      1::UINT256,
      100000::UBIGINT
    )] AS steps
  FROM actors
),
authored AS (
  SELECT assumptions, steps, program(assumptions, steps) AS program
  FROM inputs
)
SELECT
  len(assumptions)::INTEGER AS assumption_count,
  len(steps)::INTEGER AS step_count,
  program IS NOT NULL AS runnable
FROM authored;
-- => [{"assumption_count":7,"step_count":1,"runnable":"true"}]

Related functions

Category and tags

Category
Simulation
Tag
Simulate