Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Memory Consistency Checking

Offline memory checking lets a prover show that a read/write memory was used correctly: every read returns the value most recently written to that address. Unlike online checking with Merkle paths, it checks nothing per access. Each access adds tuples to two multisets, and one equality check between the multisets at the end covers all accesses. Ziren uses it for registers and memory alike, within a shard through the lookup argument and across shards through a global challenge drawn from a hash chain over the shards' cross-shard rows.

Read set and write set

The read set \( RS \) and write set \( WS \) are multisets of tuples \( (a, v, c) \): an address, a value and a timestamp.

  • Initialization. \( RS = WS = \emptyset \). For every address \( a_i \) with initial value \( v_i \), add \( (a_i, v_i, 0) \) to \( WS \).
  • Access. To access address \( a \) at time \( c_{now} \), take the last tuple \( (a, v, c) \) written for \( a \), add it to \( RS \), and add \( (a, v^{\prime}, c_{now}) \) to \( WS \). For a read \( v^{\prime} = v \); for a write \( v^{\prime} \) is the new value.
  • Post-processing. For every address, add its last tuple in \( WS \) to \( RS \).

The memory was used correctly if:

  1. the sets were initialized correctly;
  2. at every access \( c < c_{now} \), so the timestamps of an address strictly increase;
  3. a read adds the same value to \( RS \) and \( WS \);
  4. after post-processing, \( RS = WS \).

Suppose the first incorrect read of address \( a \) returns \( (a, v^{\prime}, c^{\prime}) \) instead of the last written \( (a, v, c) \). All tuples in \( WS \) are distinct because timestamps strictly increase, and \( (a, v^{\prime}, c^{\prime}) \) was never written. So \( RS \) contains a tuple that \( WS \) does not contain, and no later step can remove it. Then \( RS \neq WS \).

Within a shard

A shard's accesses are tuples (shard, clk, addr, value) on the Memory bus. The timestamp is the pair (shard, clk).

  • An access sends its previous tuple (prev_shard, prev_clk, addr, prev_value) (the read) and receives its new tuple (the write). It asserts that (shard, clk) is strictly larger than (prev_shard, prev_clk). When the shards are equal, the difference clk - prev_clk - 1 is split into a 16-bit and a 10-bit limb and both are range-checked, which proves clk > prev_clk because both clocks are below \( 2^{26} \). Otherwise the same check is applied to the shards.
  • MemoryLocal has one row per address the shard touches. The row supplies the address's first tuple in the shard and consumes its last one.
  • Registers are addresses 0 to 35. MemoryBump inserts a read of every touched register at (shard, 0), and another before any access that comes \( 2^{16} \) or more clock ticks after the previous one. Every other register access therefore compares clocks only, and its difference fits one 16-bit range check (see Memory).

The Memory bus balances when the sends equal the receives, which is condition 4 for the shard. The LogUp-GKR argument proves it together with all other buses (see Lookup Arguments).

Across shards

The first and last tuple of each address in a shard must also match the neighbouring shards. These tuples are global lookups: lookups whose two sides may lie in different shards.

  • MemoryLocal receives the address's initial tuple and sends its final tuple, on the local Memory bus and again as global lookups.
  • MemoryGlobalInit sends the initial value of each address outside the program image, at timestamp (0, 0).
  • MemoryGlobalFinal receives the final value of each touched address.
  • MemoryProgram is a preprocessed table of the program image, part of the verifying key. Every shard includes it; its multiplicity is 1 on the image's rows in the first shard and 0 in every other shard, so the first shard sends every image word to MemoryImage over a lookup inside the shard.
  • MemoryImage is the first shard's copy of the image in main columns: it receives each word from MemoryProgram and sends its initial value as a global lookup. A global lookup reads committed main columns only, which is why the preprocessed table does not send it itself.

The same mechanism carries syscalls from an execution shard to the precompile shard that proves them (SyscallCore and SyscallPrecompile).

Global challenge

Within a shard, LogUp balances a bus with challenges \( (\alpha, \beta) \) drawn after the shard's trace is committed. A global lookup cannot be balanced that way, since its other side is in another shard, proved with other challenges. Ziren instead proves every shard's global lookups, outside the shard's proof, under one challenge pair \( (\alpha_g, \beta_g) \) for the whole execution, drawn only after every shard has committed the rows that carry global lookups.

  1. Global round. The chips with global lookups (MemoryLocal, MemoryGlobalInit, MemoryGlobalFinal, SyscallCore, SyscallPrecompile and MemoryImage) are committed in a round of their own, between the preprocessed round and the main round.
  2. Hash chain. The chain runs in 8 chain lanes, each a hash chain of its own. Every lane starts at \( g_0 \), sampled from a challenger that has observed the verifying key. Shard \( i \) extends the lane its prover chooses for it, \( g \leftarrow H(g, C_i, \mathit{shape}_i) \), with its global round's commitment \( C_i \) and the name and height of each chip in the round; a shard without a global round leaves every lane unchanged, so only a shard with a global round needs a global proof. The chain's value is the digest of its 8 chain heads, and its end is \( g^\star \).
  3. Challenge. The prover grinds a proof-of-work witness \( w \) that, observed after \( g^\star \), makes the challenger emit 22 zero bits (ZIREN_GLOBAL_GRINDING_BITS). \( (\alpha_g, \beta_g) \) is then sampled from \( g^\star \) and \( w \) alone, and every global proof is verified with the same \( w \). \( \beta_g \) is the eq table of a seed of dimension \( d \), the log of the widest global message (its values plus the lookup kind), so a message is fingerprinted alike in every shard.
  4. Shard proof. A shard proof does not wait for the challenge. It commits the shard's global round, proves the shard's other lookups under the shard's own \( (\alpha, \beta) \), and leaves the global lookups out of its LogUp-GKR circuit.
  5. Global proof. Once \( g^\star \) is known, the global rounds are proved in global proofs: proofs over the tables of global rounds in which each chip keeps its global lookups and has no constraints. A global proof opens consecutive rounds of one lane and one shape, each in a table slot of its own; it commits the tables of each slot again, and each commitment must equal the \( C_i \) of the round it opens. Its transcript observes \( g^\star \) first, one LogUp-GKR circuit evaluates the lookups of all its rounds under \( (\alpha_g, \beta_g) \), and it outputs the sum of their global fractions. A global round's shape is canonical: it commits every table of its family, those the shard lacks at height 0, in the smallest power of two of stacking blocks that holds it (its size class). The programs that verify global proofs then depend on the family, the class and the number of rounds alone, and are enumerated with the other recursion shapes. A memory initialization or finalization round, with 18-column rows, falls in the 32-block class.
  6. Recursion. A shard's leaf extends its chain lane's head by the shard's global round and publishes the chain before and after it; the first shard's leaf checks that every lane head starts at \( g_0 \) of the verifying key. A global proof opens consecutive rounds of one chain lane and one shape. The circuit accepts at most 32 (MAX_GLOBAL_ROUNDS_PER_PROOF), no more than keep every table of the program that verifies it within the recursion machine's row cube of \( 2^{20} \) rows (26 rounds at the class of 8 blocks), and requires the proof's committed cells to sum to fewer than \( 2^{30} \); the GPU prover puts at most 8 rounds in one proof. The prover proves all memory shards of a block on one worker, so that their rounds share a lane and group; this is a prover choice that the verifier neither sees nor needs. The compress, deferred and wrap programs assert that their witness has no preceding global rounds. A global leaf verifies one global proof: it checks the proof of work, steps the proof's chain lane over the commitments it opens, and publishes the chain after and before those rounds, \( g^\star \), \( w \), the sum of the \( S_i \) and the count of the rounds' lookups. In the compress tree the global leaves come before the shards, the latest round first, so the chain runs from \( g^\star \) back to \( g_0 \) through the global leaves and forward again to \( g^\star \) through the shards. Compress nodes check that their children's chains meet, take \( g^\star \) and \( w \) from the global leaves (a shard's leaf carries neither), and add the sums. The root checks that the chain starts and ends at \( g^\star \) and that \( \sum_i S_i = 0 \). The chain is a hash chain, so the rounds the global proofs open are exactly the rounds the shards committed.

A matching send and receive give opposite fractions and cancel. Because \( g^\star \) binds every global row of every shard before \( (\alpha_g, \beta_g) \) is drawn, an unbalanced set of global lookups sums to zero only with probability about \( (d + 1) N_g / |\mathbb{F}_{p^5}| \), where \( N_g \) is the number of global lookups in the execution; the 22 bits of grinding count against that term as the lookup argument's grinding does. This requires fewer than \( p \) sends and fewer than \( p \) receives, so that the count of one message cannot wrap around the field's characteristic. The verifiers enforce it. A global round holds at most \( m = \sum_c h_c \max(s_c, r_c) \) lookups either way, for chips of height \( h_c \) with \( s_c \) global sends and \( r_c \) global receives a row (every multiplicity is a bit). A global leaf counts each round it opens as \( \lfloor m / 2^{10} \rfloor + 1 \) units, compress nodes add the units, and every program rejects more than \( (p - 1) / 2^{10} \) of them; the host verifier makes the same count. An execution is therefore limited to about \( 2^{31} \) cross-shard lookups in either direction. Both verifiers also reject a proof whose output fractions have a zero denominator; the recursion programs assert this before dividing, since the recursion machine accepts any quotient of zero by zero.

The prover makes one pass over the execution: it proves each shard as soon as the shard is executed, and proves the global proofs after the last shard has committed its global round. The price is a few small global proofs per execution, each covering several rounds of one lane.