# program

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

Canonical HTML: <https://determica.com/docs/functions/program>

- Kind: scalar function
- Category: [Simulation](/docs/category/simulation.md)
- Tags: Program Compiler, Simulate

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

## Overload 1: program(STEP\[\])

```sql
program(STEP[])
```

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

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `steps` (STEP[]; required; positional) — Non-NULL list containing at least one non-NULL STEP, executed in list order.

### Returns

Executable PROGRAM

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

- `program` (PROGRAM)

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

### Examples

_Local SQL · Local_

```sql
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"}]
```

## Overload 2: program(ASSUMPTION\[\], STEP\[\])

```sql
program(ASSUMPTION[], STEP[])
```

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

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `assumptions` (ASSUMPTION[]; required; positional) — Non-NULL list of non-NULL ASSUMPTION values; each balance, nonce, code, or address-and-slot coordinate must be unique.
- `steps` (STEP[]; required; positional) — Non-NULL list containing at least one non-NULL STEP, executed in list order.

### Returns

Executable PROGRAM with assumptions

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

- `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 · 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"}]
```

## 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.

## Related functions

- [assume_native_balance](/docs/functions/assume_native_balance.md) — See Also
- [call_context](/docs/functions/call_context.md) — See Also
- [execute_call](/docs/functions/execute_call.md) — See Also
- [observe](/docs/functions/observe.md) — See Also
- [run](/docs/functions/run.md) — See Also
