Miden VM decoder AIR constraints
In this section we describe AIR constraints for Miden VM program decoder. These constraints enforce that the execution trace generated by the prover when executing a particular program complies with the rules described in the previous section.
To refer to decoder execution trace columns, we use the names shown on the diagram below (these are the same names as in the previous section). Additionally, we denote the register containing the value at the top of the stack as .

We assume that the VM exposes a flag per operation which is set to when the operation is executed, and to otherwise. The notation for such flags is . For example, when the VM executes a PUSH operation, flag . All flags are mutually exclusive - i.e., when one flag is set to all other flags are set to . The flags are computed based on values in op_bits columns.
AIR constraints for the decoder involve operations listed in the table below. For each operation we also provide the degree of the corresponding flag and the effect that the operation has on the operand stack (however, in this section we do not cover the constraints needed to enforce the correct transition of the operand stack).
| Operation | Flag | Degree | Effect on stack |
|---|---|---|---|
JOIN | 5 | Stack remains unchanged. | |
SPLIT | 5 | Top stack element is dropped. | |
LOOP | 5 | Stack remains unchanged. | |
REPEAT | 4 | Top stack element is dropped. | |
SPAN | 5 | Stack remains unchanged. | |
RESPAN | 4 | Stack remains unchanged. | |
DYN | 5 | Top stack element is dropped. | |
DYNCALL | 5 | Top stack element is dropped. | |
CALL | 4 | Stack remains unchanged. | |
SYSCALL | 4 | Stack remains unchanged. | |
END | 4 | When exiting a loop block, top stack element is dropped; otherwise, the stack remains unchanged. | |
HALT | 4 | Stack remains unchanged. | |
PUSH | 5 | An immediate value is pushed onto the stack. | |
EMIT | 7 | Stack remains unchanged. |
We also use the control flow flag
exposed by the VM, which is set to for the control-flow operations
SPAN, JOIN, SPLIT, LOOP, END, REPEAT, RESPAN, HALT, DYN, DYNCALL, CALL,
and SYSCALL (and otherwise). It has degree .
As described previously, the general idea of the decoder is that the prover provides the program to the VM by populating some of cells in the trace non-deterministically. Values in these are then used to update virtual tables (represented via multiset checks) such as block hash table, block stack table etc. Transition constraints are used to ensure that the tables are updates correctly, and we also apply boundary constraints to enforce the correct initial and final states of these tables. One of these boundary constraints binds the execution trace to the hash of the program being executed. Thus, if the virtual tables were updated correctly and boundary constraints hold, we can be convinced that the prover executed the claimed program on the VM.
In the sections below, we describe constraints according to their logical grouping. However, we start out with a set of general constraints which are applicable to multiple parts of the decoder.
General constraints
When SPLIT operation is executed, the top of the operand stack must contain a binary value:
When a DYN operation is executed, the second half of the hasher registers
() must be set to (the first half holds the callee digest):
A REPEAT operation requires at the top of the operand stack:
On each transition, REPEAT must follow an END whose marks the completed node as a loop
body. The block-hash relation authenticates this flag on the END row:
LOOP cannot transition directly to END; that would skip the body if its body-hash
multiplicity were zero:
The first row has no predecessor, so it cannot be a REPEAT operation:
When RESPAN operation is executed, we need to make sure that the block ID is incremented by :
When END operation is executed and we are exiting a loop block (i.e., is_loop, value which is stored in , is ), the value at the top of the operand stack must be :
A HALT instruction can be followed only by another HALT instruction:
When a HALT operation is executed, block address column must be :
Values in op_bits columns must be binary (i.e., either or ):
We also use two extra columns (, ) for degree reduction in the operation flag computation:
Since selects prefix 101, selects prefixes 100 and 11. The two terms below
select disjoint opcode groups: the first forces for prefixes 100 and 11, and the
second rejects opcode under prefix 101:
Prefix 11 also requires :
When the value in in_span column is set to , control flow operations cannot be executed on the VM, but when in_span flag is , only control flow operations can be executed on the VM:
Block hash computation constraints
As described previously, when the VM starts executing a new block, it also initiates computation of the block's hash. There are two separate methodologies for computing block hashes.
For join and split blocks, the hash is computed directly from the hashes of the block's children. The prover provides these child hashes non-deterministically by populating registers . For loop blocks, only the loop body hash is provided in and the remaining registers are set to (padding to a full 8-element rate). For dyn, only the second half of the hasher registers () are forced to , while the first half holds the callee digest read from memory; thus the input is not all zeros. The hasher is initialized using the hash chiplet, and we use the address of the controller input row as the block's ID. The result of the hash is then available in the paired controller output row at block ID plus , and we read that result when the END operation is executed for the block.
For basic blocks, the hash is computed by absorbing a linear sequence of instructions (organized into operation groups and batches) into the hasher and then returning the result. The prover provides operation batches non-deterministically by populating registers . Similarly to other blocks, the hasher is initialized using the hash chiplet at the start of the block, and we use the address of the first controller input row as the ID of the first operation batch in the block. As we absorb additional operation batches into the hasher (by executing RESPAN), the next batch starts at the next controller input row, so the batch address is incremented by . We read the result from the controller output row corresponding to the final batch when the END operation is executed for the block.
Chiplets bus constraints
The decoder communicates with the hash chiplet via the chiplets bus. This works by dividing values of the multiset check column by the values of operations providing inputs to or reading outputs from the hash chiplet. A constraint to enforce this would look as , where is the value which defines the operation.
In constructing values for decoder bus requests, we use the hasher message format described in the hasher chiplet. For decoder requests, the node index is always , so the message reduces to:
We use the following labels:
Let denote the opcode value, which is placed in the capacity domain lane (state index ).
To simplify constraint description, we define the following values:
In the above, is set to when a control flow operation that signifies the initialization of a control block is being executed on the VM (only those control blocks that don't do any concurrent requests to the chiplets bus). Otherwise, it is set to . An exception is made for the DYN, DYNCALL, CALL and SYSCALL operations, since although they initialize a control block, they also run another concurrent bus request, and so are handled separately.
Using the above variables, we define operation values as described below.
When a control block initializer operation (JOIN, SPLIT, LOOP) is executed,
a new hasher is initialized and the contents of are absorbed into
the hasher, with the opcode value placed in the capacity domain lane.
As mentioned previously, the value sent by the SYSCALL operation is defined separately, since in addition to communicating with the hash chiplet it must also send a kernel procedure access request to the kernel ROM chiplet. This value of this kernel procedure request is described by .
In the above, is the unique operation label of the kernel procedure call operation. The values contain the root hash of the procedure being called, which is the procedure that must be requested from the kernel ROM chiplet.
The above value sends both the hash initialization request and the kernel procedure access request to the chiplets bus when the SYSCALL operation is executed.
Similar to SYSCALL, CALL is handled separately, since in addition to communicating with the hash chiplet, it must also initialize the frame memory pointer (stored in memory at constant address fmpaddr with constant value fmpinit):
In the above, represents a "write element" memory request equivalent to mem[fmpaddr] = fmpinit (in pseudo-code) in the new memory context (i.e. the memory context of the callee). Currently , and .
Similar to SYSCALL and CALL, DYN and DYNCALL are handled separately, since in addition to communicating with the hash chiplet they must also issue a memory read operation for the hash of the procedure being called.
In the above, is the control-block request with a zeroed hasher
state, and represents a memory word read request from address
, where the result is placed in the first half of the decoder hasher trace.
Note that similar to CALL, DYNCALL also creates a new memory context, and hence
must also initialize the fmp.
When SPAN operation is executed, a new hasher is initialized and contents of are absorbed into the hasher. The chiplets-bus message uses only the rate lanes; capacity lanes (state indices ) are zeroed for this request:
When RESPAN operation is executed, contents of (which contain the new operation batch) are absorbed into the hasher:
When END operation is executed, the hash result is copied into registers :
Using the above definitions, we can describe the constraint for computing block hashes as follows:
We need to add and subtract the sum of the relevant operation flags to ensure that when none of the flags is set to , the above constraint reduces to .
The degree of this constraint is .
Block stack table constraints
As described previously, block stack table keeps track of program blocks currently executing on the VM. Thus, whenever the VM starts executing a new block, an entry for this block is added to the block stack table. And when execution of a block completes, it is removed from the block stack table.
Adding and removing entries uses one logical block-stack relation with two authenticated entry kinds:
- A continuation carries
(blk, prnt, is_loop). - A caller frame carries
(blk, prnt, caller_ctx, caller_stack_depth, caller_overflow_addr, caller_fn_hash). In the common encoded layout its loop-marker slot is a constant zero; a caller frame cannot also be a LOOP continuation.
Both kinds use the same block-stack bus prefix . Payload slot contributes
. Slot 10 is an explicit entry-kind tag: zero for a continuation and one for a caller
frame, contributing only to the latter. Thus a continuation is not a zero-padded
caller frame, and the two cannot collide when all saved caller-state fields are zero. JOIN,
SPLIT, LOOP, SPAN,
RESPAN, and DYN use continuation entries. CALL, DYNCALL, and SYSCALL use caller-frame
entries. The matching END must consume the same authenticated kind.
Before describing the constraints, we describe the messages added to and removed from the relation. For compactness, throughout this block-stack section we write for . The formulas display each opcode gate multiplied by its encoded denominator to make polynomial degrees visible. The lookup argument supplies the gate and denominator separately and contributes for an addition or for a removal.
For block-start operations (JOIN, SPLIT, LOOP, SPAN), is the parent block ID and
is the starting block ID. For END, is the ending block ID and is its parent. For
RESPAN, is the current operation-batch ID, is the next batch ID, and supplies
their common parent ID.
When JOIN operation is executed, row is added to the block stack table:
When SPLIT operation is executed, row is added to the block stack table:
When LOOP operation is executed, row is added to the block stack table. Because LOOP has do-while semantics, the body is always entered, so the is_loop slot is unconditionally :
When SPAN operation is executed, row is added to the block stack table:
When RESPAN operation is executed, row is removed from the block stack table, and row is added to the table. The prover sets the value of register at the next row to the ID of the parent block:
When a DYN operation is executed, row is added to the block stack table:
When a DYNCALL operation is executed, caller frame
is added to the block stack table. Here
is constrained to the caller's post-shift stack depth . The overflow relation pins
to the post-shift overflow address when overflow is non-empty, and a direct constraint pins
it to zero when overflow is empty:
When a CALL or SYSCALL operation is executed, caller frame
is added to the block stack table:
When END executes, indicates a LOOP continuation and indicates that the
operation restores a caller frame. Both selectors are constrained to be boolean and mutually
exclusive, while is fixed to zero. If , the operation removes continuation
. If , it removes caller frame
.
The booleanity and mutual-exclusion constraints have degree ; the zeroing constraint has degree .
The lookup argument contributes for every add and for every remove. It groups the mutually exclusive opcode branches and cross-multiplies their denominators. Summed across the trace, the block-stack contributions must be zero, proving multiset equality between inserted and removed tagged messages. The compiled constraint has degree .
Block hash table constraints
As described previously, when the VM starts executing a new program block, it adds hashes of the block's children to the block hash table. And when the VM finishes executing a block, it removes the block's hash from the block hash table. This means that the block hash table gets updated when we execute the JOIN, SPLIT, LOOP, DYN, DYNCALL, CALL, SYSCALL, and END operations (executing SPAN operation does not affect the block hash table because a basic block has no children). REPEAT re-enters a loop body that the LOOP operation already accounted for, so it does not add an entry of its own.
The block-hash relation is part of a LogUp lookup column. Each insertion contributes and each removal contributes , where is the operation flag and encodes the entry. Define the denominator for one block-hash entry as:
Using this, we define the left and right child messages for a JOIN as:
Graphically, this looks like so:

When JOIN operation is executed, hashes of both child nodes are added to the block hash table:
When SPLIT operation is executed and the top of the stack is , hash of the true branch is added to the block hash table; when the top of the stack is , hash of the false branch is added:
When LOOP operation is executed, its row contributes the loop-body hash with
is_loop_body = 1 and multiplicity , the value of the group_count column. The lookup
balance equates with the number of body END rows that return to this loop instance. For an
honestly executed do-while loop this count is at least one; the LOOP-to-END adjacency constraint
prevents a malicious trace from skipping the body with a zero count. A single LOOP row therefore
accounts for every iteration:
REPEAT does not add anything to the block hash table. Were it to add the digest supplied on its
own row, a forged body END could be cancelled by the REPEAT that follows it, and the loop body
executed by an iteration would no longer have to be the body that LOOP committed to.
Note that group_count is reused here: on LOOP rows it carries this multiplicity rather than a
number of operation groups. The op group table is unaffected because control-flow rows have
in_span = 0.
When DYN, DYNCALL, CALL or SYSCALL operation is executed, the hash of the child is
added to the block hash table. In all cases, this child is found in the first half
of the decoder hasher state.
When END operation is executed, the hash of the completed block is removed from the block
hash table. We differentiate between the first and second child of a JOIN by looking at
the next opcode: if the next operation is not END, REPEAT, RESPAN, or HALT, then this
block is the first child and is_first_child = 1. RESPAN is included defensively — no single
constraint forbids END → RESPAN, so excluding it would let an adversarial trace inject a
false-positive is_first_child = 1. The is_loop_body flag is read from .
The lookup builder combines these terms with the op-group interactions that share the column and
cross-multiplies the active denominators. The resulting transition constraint has degree . A
boundary contribution inserts , which balances the
root block's END removal and binds the relation to the claimed program hash.
Basic block
Basic block constraints ensure proper decoding of basic blocks. In addition to the block stack table constraints and block hash table constraints described previously, decoding of basic blocks requires constraints described below.
In-span column constraints
The in_span column (denoted as ) marks rows which execute non-control flow
operations. This is enforced by the control-flow constraint
, so for non-control flow operations and
otherwise. Semantically, this means is 1 throughout basic blocks and 0 on
control-flow rows. The transition constraints below enforce the legal state
transitions into and out of basic blocks.
Here includes SPAN, JOIN, SPLIT, LOOP, END, REPEAT, RESPAN, HALT,
DYN, DYNCALL, CALL, and SYSCALL.
We require that the VM starts outside a basic block. Since and is binary, is also binary.
On each transition, SPAN and RESPAN are followed by an in-span row. An
in-span row remains inside unless the next operation is END or RESPAN:
The first-row constraint above handles the start of the trace separately from this transition rule.
Block address constraints
When we are inside a basic block, values in block address columns (denoted as ) must remain the same. The same is true when executing REPEAT, which re-enters the same loop parent for another body iteration. This can be enforced with the following constraint:
Notice that this constraint does not apply when we execute most control flow operations. For such operations, the prover sets the value of the column non-deterministically, except for the RESPAN and REPEAT operations. For the RESPAN operation the value in the column is incremented by , which is enforced by a constraint described previously.
Notice also that this constraint implies that when the next operation is the END operation, the value in the column must also be copied over to the next row. This is exactly the behavior we want to enforce so that when the END operation is executed, the block address is set to the address of the current span batch.
Group count constraints
The group_count column (denoted as ) is used to keep track of the number of operation groups which remains to be executed in a basic block.
In the beginning of a basic block (i.e., when SPAN operation is executed), the prover sets the value of non-deterministically. This value is subsequently decremented according to the rules described below. By the time we exit the basic block (i.e., when END operation is executed), the value in must be .
The rules for decrementing values in the column are as follows:
- The count cannot be decremented by more than in a single row.
- When an operation group is fully executed (which happens when inside a basic block), the count is decremented by .
- When
SPAN,RESPAN, orPUSHoperations are executed, the count is decremented by .
Note that these rules imply that the PUSH operation (or any operation with an immediate value) cannot be the last operation in an operation group (otherwise the count would have to be decremented by ).
To simplify the description of the constraints, we will define the following variable:
Using this variable, we can describe the constraints against the column as follows:
Inside a basic block, group count can either stay the same or decrease by one:
When group count is decremented inside a basic block, either must be (we consumed all operations in a group) or we must be executing an operation with an immediate value:
Notice that the above constraint does not preclude and from being true at the same time. If this happens, op group decoding constraints (described here) will force that the operation following the operation with an immediate value is a NOOP.
When executing a SPAN, a RESPAN, or an operation with an immediate value, group count must be decremented by :
If the next operation is either an END or a RESPAN, group count must remain the same:
When an END operation is executed, group count must be :
Op group decoding constraints
Inside a basic block, register is used to keep track of operations to be executed in the current operation group. The value of this register is set by the prover non-deterministically at the time when the prover executes a SPAN or a RESPAN operation, or when processing of a new operation group within a batch starts. The picture below illustrates this.

In the above:
- The prover sets the value of non-deterministically at row . The value is set to an operation group containing operations
op0throughop8. - As we start executing the group, at every row we "remove" the least significant operation from the group. This can be done by subtracting opcode of the operation from the group, and then dividing the result by .
- By row the group is fully executed. This decrements the group count and set
op_indexto (constraints againstop_indexcolumn are described in the next section). - At row we start executing the next group with operations
op9throughop11. In this case, the prover populates with the group having its first operation (op9) already removed, and sets theop_bitsregisters to the value encodingop9. - By row this group is also fully executed.
To simplify the description of the constraints, we define the following variables:
is just an opcode value implied by the values in op_bits registers. is a flag which is set to when the group count within a basic block does not change. We multiply it by to make sure the flag is when we are about to end decoding of an operation batch. Note that flag is mutually exclusive with , , and flags as these three operations decrement the group count.
Using these variables, we can describe operation group decoding constraints as follows:
When a SPAN, a RESPAN, or an operation with an immediate value is executed or when the group count does not change, the value in should be decremented by the value of the opcode in the next row.
Notice that when the group count does change, and we are not executing , , or operations, no constraints are placed against , and thus, the prover can populate this register non-deterministically.
When we are in a basic block and the next operation is END or RESPAN, the current value in column must be .
Op index constraints
The op_index column (denoted as ) tracks index of an operation within its operation group. It is used to ensure that the number of operations executed per group never exceeds . The index is zero-based, and thus, the possible set of values for is between and (both inclusive).
To simplify the description of the constraints, we will define the following variables:
The value of is set to when we are about to start executing a new operation group (i.e., group count is decremented but we did not execute an operation with an immediate value). Using these variables, we can describe the constraints against the column as follows.
When executing SPAN or RESPAN operations the next value of op_index must be set to :
When starting a new operation group inside a basic block, the next value of op_index must be set to . Note that we multiply by to exclude the cases when the group count is decremented because of SPAN or RESPAN operations:
When inside a basic block but not starting a new operation group, op_index must be incremented by . Note that we multiply by to exclude the cases when we are about to exit processing of an operation batch (i.e., the next operation is either END or RESPAN):
Values of op_index must be in the range .
Op batch flags constraints
Operation batch flag columns (denoted , , and ) are used to specify how many operation groups are present in an operation batch. This is relevant for the last batch in a basic block (or the first batch if there is only one batch in a block) as all other batches should be completely full (i.e., contain 8 operation groups).
These columns are used to define the following 4 flags:
- : there are 8 operation groups in the batch.
- : there are 4 operation groups in the batch.
- : there are 2 operation groups in the batch.
- : there is only 1 operation groups in the batch.
Notice that the degree of is , while the degree of the remaining flags is .
These flags can be set to only when we are executing SPAN or RESPAN operations as this is when the VM starts processing new operation batches. Also, for a given flag we need to ensure that only the specified number of operations groups are present in a batch. This can be done with the following constraints.
All batch flags must be binary:
When SPAN or RESPAN operations is executed, one of the batch flags must be set to .
When neither SPAN nor RESPAN is executed, all batch flags must be set to .
When we have at most 4 groups in a batch, registers should be set to 's.
When we have at most 2 groups in a batch, registers and should also be set to 's.
When we have at most 1 groups in a batch, register should also be set to .
Op group table constraints
Op group table is used to ensure that all operation groups in a given batch are consumed before a new batch is started (i.e., via a RESPAN operation) or the execution of a basic block is complete (i.e., via an END operation). The op group table is updated according to the following rules:
- When a new operation batch is started, we add groups from this batch to the table. To add a group to the table, we multiply the value in column by a value representing a tuple
(batch_id, group_pos, group). A constraint to enforce this would look as , where is the value representing the row to be added. Depending on the batch, we may need to add multiple groups to the table (i.e., ). Flags , , , and are used to define how many groups to add. - When a new operation group starts executing or when an immediate value is consumed, we remove the corresponding group from the table. To do this, we divide the value in column by a value representing a tuple
(batch_id, group_pos, group). A constraint to enforce this would look as , where is the value representing the row to be removed.
To simplify constraint descriptions, we first define variables representing the rows to be added to and removed from the op group table.
When a SPAN or a RESPAN operation is executed, we compute the values of the rows to be added to the op group table as follows:
Where . Thus, defines row value for group in , defines row value for group etc. Note that batch address column comes from the next row of the block address column ().
We compute the value of the row to be removed from the op group table as follows:
In the above, the value of the group is computed as . This basically says that when we execute a PUSH operation we need to remove the immediate value from the table. This value is at the top of the stack (column ) in the next row. However, when we are not executing a PUSH operation, the value to be removed is an op group value which is a combination of values in and op_bits columns (also in the next row). Note also that value for batch address comes from the current value in the block address column (), and the group position comes from the current value of the group count column ().
We also define a flag which is set to when a group needs to be removed from the op group table.
The above says that we remove groups from the op group table whenever group count is decremented. We multiply by to exclude the cases when the group count is decremented due to SPAN or RESPAN operations.
Using the above variables together with flags , , , defined in the previous section, we describe the constraint for updating op group table as follows:
The above constraint specifies that:
- When
SPANorRESPANoperations are executed, we add between and groups to the op group table; else, leave untouched. - When group count is decremented inside a basic block, we remove a group from the op group table; else, leave untouched.
The degree of this constraint is .
In addition to the above transition constraint, we also need to impose boundary constraints against the column to make sure the first and the last value in the column is set to . This enforces that the op group table table starts and ends in an empty state.