Equivalence Statements And Assumptions

By Ari Published Last updated

The Jolt-qed project verifies, in Lean, that each Jolt bytecode expansion has the same effect as the RISC-V instruction it replaces. These equivalence theorems are not unconditional: they rely on explicit hypotheses about the RISC-V/Jolt state, plus a small number of trusted edits to the generated RISC-V model so that it matches the Jolt CPU. This post records those proof assumptions and trusted-code changes.

Changes to the Trusted RISC-V Model

The Lean RISC-V model lives in LeanRV64D/, with the top-level entry point in LeanRV64D.lean. It was generated by automatically transpiling the Sail specification of a RISC-V CPU to Lean[1]. The Sail-to-Lean post explains how we obtained this generated code. We treat that generated model as trusted throughout the project, except for the two changes below.

  1. We say that the RISC-V CPU should not support misaligned memory addressing. We do this because Jolt does not support misaligned addressing, and it would be impossible to prove equivalence otherwise. The Ethereum zkVM Standards v0 recommend that zk-VMs use RV64IM+Zicclsm as the target baseline, where Zicclsm is included to support misaligned loads and stores. We highlight this drawback off the bat.
-- WARNING: CHANGE IN TRANSPILED CODE
def plat_enable_misaligned_access : Bool := false
  1. Jolt does not support the Zicfiss and Zicfilp extensions. Leaving them on makes it impossible to prove equivalences about writing to control status registers.
-- WARNING: (change to sail, Jolt does not support Zicfilp extension).
| Ext_Zicfilp => false
-- WARNING: (change to sail, Jolt does not support Zicfiss extension).
| Ext_Zicfiss => false

These are the only changes we make to the generated RISC-V model.

Equivalence Statement Structure

Shown below is the equivalence statement for the sra instruction. It says that running the Jolt instruction sraProgram with arguments rd rs2 rs1 on the current Jolt state js, and then projecting down to the RISC-V state, is identical to running sra rd rs2 rs1 on the RISC-V state of the current Jolt CPU. In simple words, we could either run the original RISC-V instruction or run the Jolt expansion on the same starting state, and the effect is the same. If we showed this for all RISC-V instructions, then we would show that Jolt faithfully simulates RISC-V. Now, to prove this theorem, we use an assumption bundle. The goal of this post is to explain what an assumption bundle is.

/-- Main program-level equivalence for `SRA`. -/
def sraProgramEqSailStatement
    (rs2 : regidx)
    (rs1 : regidx)
    (rd : regidx)
    (js : SailJoltState)
    (_h : BinarySourceReadWithLinkedCSRs rs2 rs1 js) -- <--- Assumption bundle
  : Prop :=
  System.systemProjectResult
      ((JoltISA.execProgram (JoltISA.sraProgram rs2 rs1 rd)).run js) =
    (execute_RTYPE rs2 rs1 rd rop.SRA).run js.sail

Assumption bundles are conjunctions of assumptions defined in JoltBytecode/Assumptions.lean and collected in JoltBytecode/Bundles.lean. Each equivalence statement in Jolt-qed uses an assumption bundle. Bundles describe exactly which assumptions were used to prove equivalence for a given instruction. An assumption bundle is always made up of a list of assumptions[2].

This specific assumption bundle is made up of the two groups of assumptions shown below.

abbrev BinarySourceReadAssumptions
    (rs2 rs1 : regidx) (js : SailJoltState) :=
  Assumptions.BinarySourceReadAssumptions rs2 rs1 js.sail

private structure LinkedCSRRegisterAssumptions (js : SailJoltState) where
  mstatus_matches : Assumptions.MstatusVRegMatchesSail js
  mtvec_matches : Assumptions.MtvecVRegMatchesSail js
  mscratch_matches : Assumptions.MscratchVRegMatchesSail js
  mepc_matches : Assumptions.MepcVRegMatchesSail js
  mcause_matches : Assumptions.McauseVRegMatchesSail js
  mtval_matches : Assumptions.MtvalVRegMatchesSail js

We will explain what these mean below, but the takeaway message is that every equivalence theorem uses an assumption bundle. Any assumption bundle can only be made up of core assumptions listed in Assumptions.lean.

Bytecode Expansion Assumptions

For the rest of the document, we list every assumption used in Jolt. If any assumption that is not listed here, or in Assumptions.lean, is used in a proof bundle, then that should be remedied immediately, and we should check whether the assumption is justified.

Privilege Is Always Machine

structure CurPrivilegeMachine (s : SailState) : Prop where
  value : s.regs.get? Register.cur_privilege =
    some (Privilege.Machine : RegisterType Register.cur_privilege)

In simple English, the value in cur_privilege indicates that the Jolt CPU runs in machine mode all the time. According to the Jolt Rust code base, Jolt always runs in machine mode. The above Lean code simply states that the value in the cur_privilege register is Privilege.Machine.

MPP Bit Set To Machine

structure MstatusMppMachine (js : SailJoltState) : Prop where
  value_eq :
    _get_Mstatus_MPP (js.vregs JoltISA.mstatusVReg) =
      privLevel_to_bits Privilege.Machine

Jolt uses virtual register 39 to model the mstatus control status register of the Jolt CPU. Based on the Jolt source code, Jolt always runs in machine mode, and the MPP bit of the status register is always set to Machine.

MISA User Enabled

structure MisaUserEnabled (s : SailState) : Prop where
  exists_value : ∃ misa : BitVec 64,
    s.regs.get? Register.misa = some (misa : RegisterType Register.misa) ∧
    _get_Misa_U misa = 1#1

Jolt initialises misa to 0x800000008014312f based on jolt/tracer/src/emulator/cpu.rs:399. The function _get_Misa_U reads bit 20 of the misa CSR, which, based on the written value, is 1. According to the RISC-V ISA, having bit 20 set to 1 implies user mode is enabled.

MPRV Bit

structure MstatusMprvZero (s : SailState) : Prop where
  value : ∃ mval : RegisterType Register.mstatus,
    s.regs.get? Register.mstatus = some mval ∧
    _get_Mstatus_MPRV mval = 0#1

According to Jolt, the MPRV bit of the mstatus register is set to 0 in Jolt. As a direct consequence of this, we get bare translation: virtual addresses are the same as physical addresses, which is also true in the Jolt code base. In Lean, this is captured by the following three bare-translation theorems for loads, stores, and atomics. We only show the theorem statements here; the proofs are in JoltBytecode/InstructionEquivalence/ProofSupport/BundleLemmas.lean.

theorem translateAddr_load_data_of_machine_mprv_zero
    (addr : BitVec 64) (s : SailState)
    (hpriv : Assumptions.CurPrivilegeMachine s)
    (hmprv : Assumptions.MstatusMprvZero s) :
    translateAddr (Virtaddr addr) (Load Data) s =
      .ok (Ok (physaddr.Physaddr addr, init_ext_ptw)) s
theorem translateAddr_store_data_of_machine_mprv_zero
    (addr : BitVec 64) (s : SailState)
    (hpriv : Assumptions.CurPrivilegeMachine s)
    (hmprv : Assumptions.MstatusMprvZero s) :
    translateAddr (Virtaddr addr) (Store Data) s =
      .ok (Ok (physaddr.Physaddr addr, init_ext_ptw)) s
theorem translateAddr_atomic_data_of_machine_mprv_zero
    (op : amoop) (addr : BitVec 64) (s : SailState)
    (hpriv : Assumptions.CurPrivilegeMachine s)
    (hmprv : Assumptions.MstatusMprvZero s) :
    translateAddr (Virtaddr addr) (Atomic (op, Data, Data)) s =
      .ok (Ok (physaddr.Physaddr addr, init_ext_ptw)) s

Zicfilp Extension

structure ZicfilpDisabled (s : SailState) : Prop where
  value : currentlyEnabled extension.Ext_Zicfilp s = .ok false s

Jolt does not support the Zicfilp extension.

Mtvec

structure MtvecWriteDirectMode (value : BitVec 64) : Prop where
  mode_eq : _get_Mtvec_Mode value = 0b00#2

The RISC-V ISA requires that we legalise values before writing to control and status registers. See this post for more details. When writing the contents of rs1 into the mtvec control and status register, if the value in rs1 has the two least significant bits set to 00, then we write rs1’s contents directly into mtvec. Otherwise, we need to legalise the value. The above assumption says the value in rs1 will always have the lower two bits set to 00.

The ZeroOS/Jolt boot path writes _trap_handler to mtvec with

csrw mtvec, t0

ZeroOS defines _trap_handler under .align 2, which gives 4-byte alignment, so the lower two bits are 00. Evidence from ZeroOS source code is given below.

The ZeroOS boot code writes to mtvec, and the trap handler definition is aligned.

Align PC

Jolt supports compressed instructions (+c / RV64IMAC), as seen here, so we can only guarantee that the least significant bit of PC is 0. The relevant assumption is that mepc[0] = 0. Thus, the legalisation operation according to the specification is a no-op because the lowest bit is already cleared.

structure MepcReadAligned (value : BitVec 64) (s : SailState) : Prop where
  value_eq : align_pc value s = .ok value s

This is the write-side counterpart of MepcReadAligned: CSRRW writes the new rs1 value, so the assumption must be about that source value rather than only the old stored mepc.

structure MepcWriteLegalized (value : BitVec 64) : Prop where
  value_eq : legalize_xepc value = value

Legalise MStatus

structure MstatusWriteLegalized
    (old value : BitVec 64) (s : SailState) : Prop where
  value_eq : legalize_mstatus old value s = .ok value s

Jolt does not legalise before writing to mstatus. The evidence is in the Jolt CSR expansions: CSRRW writes rs1 directly into the CSR virtual register, and CSRRS writes the OR of the old CSR value and rs1. See csrrw.rs and csrrs.rs.

Virtual Register Modelling

Here we are saying that certain virtual registers in Jolt correspond to the control status registers in the Sail state. We could have written directly to the Sail registers in our Jolt semantics, but to be faithful to the Jolt expansion, we write the virtual registers and record that correspondence as an assumption. The Jolt code confirms this.

/-- Sail `mstatus` agrees with Jolt's persistent `mstatus` virtual register. -/
structure MstatusVRegMatchesSail (js : SailJoltState) : Prop where
  value_eq :
    js.sail.regs.get? Register.mstatus =
      some (js.vregs JoltISA.mstatusVReg)

/-- Sail `mtvec` agrees with Jolt's persistent trap-handler virtual register. -/
structure MtvecVRegMatchesSail (js : SailJoltState) : Prop where
  value_eq :
    js.sail.regs.get? Register.mtvec =
      some (js.vregs JoltISA.trapHandlerVReg)

/-- Sail `mscratch` agrees with Jolt's persistent `mscratch` virtual register. -/
structure MscratchVRegMatchesSail (js : SailJoltState) : Prop where
  value_eq :
    js.sail.regs.get? Register.mscratch =
      some (js.vregs JoltISA.mscratchVReg)

/-- Sail `mepc` agrees with Jolt's persistent `mepc` virtual register. -/
structure MepcVRegMatchesSail (js : SailJoltState) : Prop where
  value_eq :
    js.sail.regs.get? Register.mepc =
      some (js.vregs JoltISA.mepcVReg)

/-- Sail `mcause` agrees with Jolt's persistent `mcause` virtual register. -/
structure McauseVRegMatchesSail (js : SailJoltState) : Prop where
  value_eq :
    js.sail.regs.get? Register.mcause =
      some (js.vregs JoltISA.mcauseVReg)

/-- Sail `mtval` agrees with Jolt's persistent `mtval` virtual register. -/
structure MtvalVRegMatchesSail (js : SailJoltState) : Prop where
  value_eq :
    js.sail.regs.get? Register.mtval =
      some (js.vregs JoltISA.mtvalVReg)

Memory Assumptions

structure DwordPresent (addr : BitVec 64) (s : SailState) : Prop where
  bytes :
    ∃ bytes : Fin 8 → BitVec 8,
      ∀ k : Fin 8, s.mem.get? (addr.toNat + k.val) = some (bytes k)

Lean models memory as a hash map from natural numbers to 8-bit bitstrings. The natural numbers are countably infinite, while the address space of any CPU is not. Additionally, because memory is modelled as a hash map, Lean needs a hypothesis that the key already exists before it can retrieve the value. This is a proof-engineering issue: the generated model represents memory as a partial map, so we must state that the relevant bytes are present. Thus, the following assumption says that addresses can be read from memory and that they return valid bytes across the entire doubleword window.

abbrev LoadPmpOk (addr : BitVec 64) (width : Nat) (s : SailState) : Prop :=
  phys_access_check (Load Data) Privilege.Machine
    (physaddr.Physaddr addr) width false s = .ok none s

/-- Machine-mode PMP accepts every explicit sub-load inside a memory window. -/
structure LoadPmpOkWindow
    (base : BitVec 64) (width : Nat) (s : SailState) : Prop where
  ok :
    ∀ offset accessWidth : Nat, offset + accessWidth ≤ width →
      LoadPmpOk (base + BitVec.ofNat 64 offset) accessWidth s

abbrev StorePmpOk (addr : BitVec 64) (width : Nat) (s : SailState) : Prop :=
  phys_access_check (Store Data) Privilege.Machine
    (physaddr.Physaddr addr) width false s = .ok none s

/-- Machine-mode PMP accepts every explicit sub-store inside a memory window. -/
structure StorePmpOkWindow
    (base : BitVec 64) (width : Nat) (s : SailState) : Prop where
  ok :
    ∀ offset accessWidth : Nat, offset + accessWidth ≤ width →
      StorePmpOk (base + BitVec.ofNat 64 offset) accessWidth s

abbrev AtomicPmpOk
    (op : amoop) (addr : BitVec 64) (width : Nat) (s : SailState) : Prop :=
  phys_access_check (Atomic (op, Data, Data)) Privilege.Machine
    (physaddr.Physaddr addr) width true s = .ok none s

/-- Machine-mode PMP accepts every explicit sub-AMO inside a memory window. -/
structure AtomicPmpOkWindow
    (op : amoop) (base : BitVec 64) (width : Nat) (s : SailState) : Prop where
  ok :
    ∀ offset accessWidth : Nat, offset + accessWidth ≤ width →
      AtomicPmpOk op (base + BitVec.ofNat 64 offset) accessWidth s

Jolt’s Rust MMU explicitly says memory protection is not implemented. These predicates constrain the generated RISC-V model to the corresponding no-PMP-fault path.

Rust source: https://github.com/abiswas3/jolt/blob/main/tracer/src/emulator/mmu.rs#L17.

The above assumption says the entire doubleword block read by LD at physical address addr is not protected and can be read. The same applies to writing to memory. To prove equivalence, we need to tell the generated RISC-V model that the address is safe to read from or write to. The generated RISC-V model uses different checks for LD, SD, and atomic operations, so we need three sets of assumptions that say the same thing.

abbrev NotReadableMmio (addr : BitVec 64) (width : Nat) (s : SailState) : Prop :=
  within_mmio_readable (physaddr.Physaddr addr) width s = .ok false s

structure NotReadableMmioWindow
    (base : BitVec 64) (width : Nat) (s : SailState) : Prop where
  ok :
    ∀ offset accessWidth : Nat, offset + accessWidth ≤ width →
      NotReadableMmio (base + BitVec.ofNat 64 offset) accessWidth s

abbrev NotWritableMmio (addr : BitVec 64) (width : Nat) (s : SailState) : Prop :=
  within_mmio_writable (physaddr.Physaddr addr) width s = .ok false s

/-- Every explicit sub-store inside a memory window avoids writable MMIO. -/
structure NotWritableMmioWindow
    (base : BitVec 64) (width : Nat) (s : SailState) : Prop where
  ok :
    ∀ offset accessWidth : Nat, offset + accessWidth ≤ width →
      NotWritableMmio (base + BitVec.ofNat 64 offset) accessWidth s

Rust source: tracer/src/emulator/mmu.rs:139-213.

Jolt splits VM memory into reserved low-memory regions for advice, inputs, outputs, panic, and termination, followed by ordinary RAM. These regions share one VM address space and are mapped into the memory witness layout. Ordinary RAM is backed by the emulator memory map, while advice/input/output are modelled by JoltDevice.

Jolt does not support device MMIO such as UART, CLINT, PLIC, or disk; accesses to those ranges panic in the tracer. On the generated RISC-V side, memory operations can branch on memory-mapped device addresses, so the proof needs assumptions such as NotReadableMmio and NotWritableMmio to keep execution on the ordinary/Jolt-supported memory path.

Register Assumptions

structure XRegReadable (r : regidx) (s : SailState) : Prop where
  exists_value : ∃ value : BitVec 64, rX_bits r s = .ok value s

structure SailRegReadable (r : Register) (s : SailState) : Prop where
  exists_value : ∃ value : RegisterType r, s.regs.get? r = some value

/-- Assumptions for an instruction that reads one architectural source register. -/
structure UnarySourceReadAssumptions (rs1 : regidx) (s : SailState) where
  rs1_val : BitVec 64
  rs1_read : rX_bits rs1 s = .ok rs1_val s

/-- Assumptions for an instruction that reads two architectural source registers. -/
structure BinarySourceReadAssumptions
    (rs2 rs1 : regidx) (s : SailState) where
  rs1_val : BitVec 64
  rs1_read : rX_bits rs1 s = .ok rs1_val s
  rs2_val : BitVec 64
  rs2_read : rX_bits rs2 s = .ok rs2_val s

These assumptions say that the Sail register file is readable.

Jolt Constraint Assumptions

The assumptions below are the assumptions used for proving completeness and soundness of the Jolt constraint system. Note that all the above assumptions described in the bytecode expansion process still apply. Without them, we do not get the RISC-V simulation claim.

Completeness Assumptions

We only have a single assumption that the completeness statement currently takes. It simply says the guest program is not empty. In the Jolt Rust code, the guest program is internally stored with the following struct.

pub struct Rv64ProgramImage {
    /// Source instructions decoded from executable text sections.
    pub instructions: Vec<SourceInstruction>,
    /// Initial byte values for memory-backed ELF sections.
    pub memory_init: Vec<(u64, u8)>,
    /// End address of the loaded program image.
    pub program_end: u64,
    /// ELF entry point.
    pub entry_address: u64,
}

In Lean, the corresponding types are defined in JoltConstraints/program.lean. You will note that in Lean we have two extra fields, which are propositions. The first one simply says that the memory addresses in memory_init are at least the lowest address in Jolt address space, and at most one minus the highest value in the address space. The second one states that no guest bytecode PC wraps around. Both of these assumptions were confirmed with Jolt authors.

structure SourceInstructionRow (Source : Type) where
  address : BitVec 64
  instruction : Source
  is_compressed : Bool

structure Rv64ProgramImage (Source : Type) where
  instructions : Array (SourceInstructionRow Source)
  memory_init : List (BitVec 64 × BitVec 8)
  program_end : BitVec 64
  entry_address : BitVec 64

  -- Facts that the fields above must satisfy.
  -- Provide proofs of these facts when constructing the image.
  program_end_ge_ram_start : JoltISA.RAM_START_ADDRESS ≤ program_end.toNat
  memory_init_in_program : ∀ entry ∈ memory_init,
    (JoltISA.RAM_START_ADDRESS ≤ entry.1.toNat) ∧ (entry.1.toNat < program_end.toNat)
  next_pc_no_wrap : ∀ row ∈ instructions,
    row.address.toNat + (if row.is_compressed then 2 else 4) < 2 ^ 64

The assumption states that the program’s memory_init is not empty: the ELF loads at least one byte into memory.

-- The program is not empty: its memory image loads at least one byte.
def Rv64ProgramImage.ImageNonempty {Source : Type} (image : Rv64ProgramImage Source) : Prop :=
  image.memory_init ≠ []

Soundness Assumptions

Soundness is trickier. It uses one assumption and six temporary assumptions. We say temporary because they are currently used to show that the Jolt constraint system is sound, but these assumptions are not as easily justified. We will start with the main soundness assumption, which is mild and harmless, and then we will get into the temporary restrictions.

Main Soundness Assumption

The assumption says that every load or store used in the program reads/writes to an effective address that fits in the address space. In Jolt, the memory layout is given by the following Rust structure.

pub struct MemoryLayout {
    /// The total size of the elf's sections, including the .text, .data, .rodata, and .bss sections.
    pub program_size: u64,
    pub max_trusted_advice_size: u64,
    pub trusted_advice_start: u64,
    pub trusted_advice_end: u64,
    pub max_untrusted_advice_size: u64,
    pub untrusted_advice_start: u64,
    pub untrusted_advice_end: u64,
    pub max_input_size: u64,
    pub max_output_size: u64,
    pub input_start: u64,
    pub input_end: u64,
    pub output_start: u64,
    pub output_end: u64,
    pub stack_size: u64,
    pub stack_end: u64,
    pub heap_size: u64,
    pub heap_end: u64,
    pub panic: u64,
    pub termination: u64,
    /// End of the memory region containing inputs, outputs, the panic bit,
    /// and the termination bit.
    pub io_end: u64,
}

impl MemoryLayout {
    pub fn get_lowest_address(&self) -> u64 {
        self.trusted_advice_start.min(self.untrusted_advice_start)
    }
}

pub fn compute_max_ram_k(memory_layout: &MemoryLayout) -> Result<usize, RamDomainError> {
    let lowest_address = memory_layout.get_lowest_address();
    let total_bytes = memory_layout.heap_end.checked_sub(lowest_address).ok_or(
        RamDomainError::HeapBelowLowest {
            heap_end: memory_layout.heap_end,
            lowest_address,
        },
    )?;
    let total_words =
        usize::try_from(total_bytes.div_ceil(8)).map_err(|_| RamDomainError::DomainTooLarge)?;
    total_words
        .checked_next_power_of_two()
        .ok_or(RamDomainError::DomainTooLarge)
}

The verifier has access to this layout, and computes the largest legal address that can be read or written to. The verifier performs this computation using compute_max_ram_k(layout) shown above.

The same theorem expressed in Lean. We have not defined every type in the theorem, and that will be done in another post.

def JoltInstance.RamRegionFits {Source : Type} (joltInstance : JoltInstance Source) : Prop :=
  ∀ (layout : MemoryLayout) (maximum : Nat),
    joltInstance.memory_layout = some layout →
    JoltConstraints.VerifierSizes.maxRamSize layout = some maximum →
      layout.get_lowest_address.toNat + 8 * maximum ≤ 2 ^ 64

Loosely, we are saying, given a problem instance JoltInstance (loosely read as public info to prover and verifier), for all memory layouts of the form given above with maximum computed by compute_max_ram_k, we show that the layout’s lowest address plus 8 times the maximum is less than $2^{64}$. This is the same thing as saying that every address fits in the 64-bit address space without overflowing. Note that unless our program was using millions of gigabytes of memory, we are fine with this assumption. Nearly every program encountered in practice satisfies this assumption, and it can be checked statically.

Temporary Soundness Restrictions

If we removed these assumptions today, there would be prover strategies that deceive the verifier and make Jolt unsound. Hence, these are marked as temporary, and there is ongoing discussion about how reasonable these assumptions are. Before we begin, we review the Jolt memory model again. Jolt partitions its memory into regions: (1) the device, and (2) ordinary RAM, where the stack, bytecode, heap and usable memory live.

The device is further partitioned into regions, where each region has special meaning. The following picture illustrates a subset of the regions in the Jolt device. It shows the termination and panic regions. When a program panics, the Jolt tracer writes 1 to the panic region. When a program terminates, it also writes 1 to the termination region before exiting.

The core source of the grief is the following issue.

In more detail, if the guest program has a store that writes to the panic region or the termination region, the store never updates memory, as depicted by the code snippet in Jolt. If the address being written is the first byte of the panic region, then a flag is set to true, and no bytes are written to memory. If the address is the termination region or the other panic region, the write is just ignored[3]. Furthermore, loading from that region does not return contents of memory, but rather returns the contents of the tracer’s panic flag. For termination, it always returns 0, regardless of what was written there.

impl JoltDevice {
    pub fn store(&mut self, address: u64, value: u8) {
        if address == self.memory_layout.panic {
            self.panic = true;
            return;
        } else if self.is_panic(address) || self.is_termination(address) {
            return;
        }
        // ...
    }

    pub fn load(&self, address: u64) -> u8 {
        if self.is_panic(address) {
            self.panic as u8
        } else if self.is_termination(address) {
            0
        }
        // ...
    }


}

But something very different happens in the witness polynomials.

There is a witness polynomial called RamWriteValue that has an evaluation for every cycle. If the panic flag is initially clear and the guest program writes 5 to the first byte of the panic region at time step t, the witness records RamWriteValue[t] = 5, as recorded by trace_store. Note that this witness is saying the write to memory was 5, but as we just discussed above, this write never actually goes through. A later byte load from panic at time step t' > t returns the value of the panic flag. For the witness, trace_load records the whole doubleword, reading the flag for each of its eight bytes, so RamReadValue[t'] = 0x0101_0101_0101_0101. As we will show later, this will cause all sorts of havoc when we do memory checking.

Stores to the Panic Region Write 1

This brings us to our first assumption. Our assumption in plain English says,

If our program ever stores to the panic region, it MUST write 1, and no other value. Once you write to the panic region, the program should never load from that region again.

Note that this condition cannot be statically checked. We are trusting the ELF program author to handle this. Our theorems say all soundness guarantees are off if this condition is violated.

This condition, when expressed in Lean, is kind of annoying to write. We describe it below, and every line might not make sense immediately. When we write our post about how we wrote theorem statements, this proposition should be more approachable.

def JoltInstance.PanicStoresOne (joltInstance : JoltInstance SourceInstruction) : Prop :=
  ∀ (privateInputs : JoltPrivateInputs)
    (run : JoltConstraints.Soundness.UntrustedAnswerRun joltInstance privateInputs)
    (next : Fin run.bytecode.size) (pre : SailJoltState),
    run.NextStep next pre →
      match run.bytecode[next].instruction with
      | .SD base value imm =>
          JoltConstraints.Soundness.TouchesPanic pre.jolt_device
              (JoltISA.sourceValue base pre + imm) →
            JoltISA.sourceValue value pre = 1
      | .LD _ _ base imm =>
          (∃ i, run.StoresPanicAt i) →
            ¬ JoltConstraints.Soundness.TouchesPanic pre.jolt_device
              (JoltISA.sourceValue base pre + imm)
      | .VirtualStoreB base value imm _ | .VirtualStoreH base value imm _
      | .VirtualStoreW base value imm _ =>
          JoltConstraints.Soundness.TouchesPanic pre.jolt_device
              ((JoltISA.sourceValue base pre + imm) &&& ~~~7) →
            JoltISA.sourceValue value pre = 1
      | .VirtualLoadB _ _ base imm _ | .VirtualLoadH _ _ base imm _ | .VirtualLoadW _ _ base imm _ =>
          (∃ i, run.StoresPanicAt i) →
            ¬ JoltConstraints.Soundness.TouchesPanic pre.jolt_device
              ((JoltISA.sourceValue base pre + imm) &&& ~~~7)
      | _ => True

We have already outlined the major issues. As we load after a store, the constraints disagree with what is in memory. Without the ban on loads, a false “panicked” claim could pass when the program reads the panic region back and acts on the value:

        sb   t0, 0(s0)     # panic := 1        (t0 = 1)
        ld   t1, 0(s0)     # read the panic doubleword back
        beq  t1, t0, one   # branch on what was read
        ...                # output := 9
one:    ...                # output := 7
The load returnsBranchFinal output
Witness, from its RAM cell1taken7
Jolt’s tracer, from the panic flag0x0101_0101_0101_0101not taken9

The witness satisfies every constraint, so the verifier accepts “panicked, output 7”, but the real run ends with output 9.

Termination Then Stall

Now we get to the next assumption. First, in plain English.

The same thing in Lean looks terribly complicated, but it’s just saying the same thing. We will go over the theorem statements and translation at a different date.

def JoltInstance.TerminationThenStall (joltInstance : JoltInstance SourceInstruction) : Prop :=
  ∀ (privateInputs : JoltPrivateInputs)
    (run : JoltConstraints.Soundness.UntrustedAnswerRun joltInstance privateInputs)
    (next : Fin run.bytecode.size) (pre : SailJoltState),
    run.NextStep next pre →
    (∃ i, run.StoresTerminationAt i) →
      match run.bytecode[next].instruction with
      | .JAL _ imm => imm = 0
      | .JALR _ _ _ => False
      | .LD _ _ base imm => ¬ JoltConstraints.Soundness.TouchesTermination
          pre.jolt_device (JoltISA.sourceValue base pre + imm)
      | .VirtualLoadB _ _ base imm _ | .VirtualLoadH _ _ base imm _ | .VirtualLoadW _ _ base imm _ =>
          ¬ JoltConstraints.Soundness.TouchesTermination pre.jolt_device
            ((JoltISA.sourceValue base pre + imm) &&& ~~~7)
      | _ => True

Without this assumption, we have one major issue. The constraints do not tell us when the program ends. In Jolt, a program ends when the PC jumps to the same address. That is, at times t and t+1 we have the same PC. Now assume we can write to the termination region as we please, many times. See the following program.

        # s0 = termination address; s1 = address of an output word
        li   t0, 1
        li   t1, 7
        sd   t1, 0(s1)     # output := 7
        sd   t0, 0(s0)     # termination := 1
        j    more         # a cheating prover can end its real rows here
more:
        li   t1, 9
        sd   t1, 0(s1)     # the real execution changes output to 9
        j    done
done:
        j    done         # the real tracer stops here

After we write to termination, we also have many jump statements. A cheating prover could just pretend any of the jumps is where the program ends. There is nothing in the constraints that stops this. Why? Cos the constraints simply ask the following.

For a claim that says the program did not panic, the final RAM witness must contain 0 at panic, 1 at termination, and the claimed output in the output region. The relevant jump constraints are:

ShouldJump[t] = Jump[t] · (1 − NextIsNoop[t])
ShouldJump[t] · (NextUnexpandedPC[t] − LookupOutput[t]) = 0

Here LookupOutput[t] is the address the PC must jump to. If a cheating prover puts padding immediately after j more, then NextIsNoop[t] = 1, so ShouldJump[t] = 0 and the second equation becomes 0 = 0.

The cheating prover’s padded witness is proving the run of this program instead.

        li   t0, 1
        li   t1, 7
        sd   t1, 0(s1)     # output := 7
        sd   t0, 0(s0)     # termination := 1
        j    more         # last real row; the code at more is never executed
        NoOp              # padding row: IsNoop = 1
        NoOp              # padding row: IsNoop = 1
        ...               # padding continues to the chosen trace length

At j more, Jump[t] = 1, NextIsNoop[t] = 1, NextUnexpandedPC[t] = 0, and the cheating prover sets ShouldJump[t] = 0. Substituting into the two constraints:

ShouldJump[t] = Jump[t] · (1 − NextIsNoop[t])
           0 = 1 · (1 − 1) = 0

ShouldJump[t] · (NextUnexpandedPC[t] − LookupOutput[t]) = 0
           0 · (0 − address(more)) = 0

If we assume that after termination the program is over as Jolt expects and the next jump signals the tracer we are done, these constraints are sufficient. For a claim that says the program did not panic, the witness must finish with termination = 1, so it must include a store to that region. The last real row must be a jump, and our assumption forces every jump after that store to jump to itself. Therefore, padding can only begin where the real tracer would stop.

No Maximum-Length Trace

The guest program’s developer sets a maximum trace length T' in the program’s attribute, #[jolt::provable(max_trace_length = T')]; if they don’t, T' = 2^24. Jolt passes T' unchanged into the program preprocessing, as the field max_padded_trace_length:

pub struct JoltProgramPreprocessing {
    pub bytecode: BytecodePreprocessing,
    pub ram: RAMPreprocessing,
    pub memory_layout: MemoryLayout,
    pub max_padded_trace_length: usize,
}

Let T be the true trace length: the number of instructions the run executes. Our assumption in plain English simply states

To understand why this is an issue, let us understand what the Jolt prover does. Jolt’s prover pads the trace to T_1 = max(next_pow2(T + 1), 256) cycles, a power of two with at least one padding row, so T_1 ≥ T + 1 according to ProverConfig::derive_from_dimensions. The prover proceeds only if T_1 ≤ T'. Otherwise, the honest Jolt prover gives up and says, “I cannot prove things.”

  • Let T_2 = proof.trace_length denote the prover’s claim of the trace length. The verifier reads it with let trace_length = proof.trace_length. An honest prover sets T_2 = T_1. A cheating prover can put any T_2 in the proof.

  • As a consequence, T_2 is the claimed number of cycles in the committed witness. Every per-cycle witness polynomial has one value per cycle t < T_2.

  • The verifier checks that T_2 is a power of two and 256 ≤ T_2 ≤ T'. The Rust code that does this is validate_trace_length.

fn validate_trace_length(
    trace_length: usize,
    max_padded_trace_length: usize,
) -> Result<(), VerifierError> {
    if !trace_length.is_power_of_two()
        || trace_length < MIN_PADDED_TRACE_LENGTH
        || trace_length > max_padded_trace_length
    {
        return Err(VerifierError::InvalidTraceLength {
            got: trace_length,
            min: MIN_PADDED_TRACE_LENGTH,
            max: max_padded_trace_length,
        });
    }
    Ok(())
}

MIN_PADDED_TRACE_LENGTH is 256. The same assumption re-expressed in Lean.

def JoltInstance.NoMaxLengthTrace
    (joltInstance : JoltInstance SourceInstruction) : Prop :=
  ∀ (privateInputs : JoltPrivateInputs)
    (trace : JoltConstraints.Soundness.UntrustedAnswerTrace joltInstance privateInputs),
    trace.rows.size ≠ 2 ^ Nat.log2 joltInstance.max_padded_trace_length.toNat

Now imagine this assumption did not hold. Take T' = 1500 and a complete run with T = 1024. Although T < T', the honest prover pads the trace to T_1 = 2048, so T_1 > T' and it refuses to prove the run. But a dishonest prover could omit the padding and claim T_2 = 1024. The verifier’s length check would pass: T_2 is a power of two and 256 ≤ T_2 ≤ T'.

The Claim Says No Panic

A Jolt claim says, loosely, that program prog on input in produces output out, and either panicked or did not. We restrict our formal guarantees only to claims where the prover claims the program did not panic.

def JoltInstance.ClaimsNoPanic (joltInstance : JoltInstance SourceInstruction) : Prop :=
  joltInstance.panic = false

In other words, if the prover’s claim was

running prog on input in produces output out and the program panics, i.e., the panic region of memory is set to 1.

This claim may or may not be true, but our soundness theorem says there are no guarantees that the claim is definitively true even if the verifier accepts. On the other hand, if the prover ever claims that the program does not panic, then we show that the prover cannot lie without getting caught (assuming all other assumptions listed in this document hold).

It is important to note that this split only exists in the world of Lean proofs.

Jolt’s verifier runs the verification algorithm for both types of claims. However, when the prover claims the program panicked, under the current constraint system we are able to find a proof that the verifier accepts but the prover’s claim is a lie. More simply the prover can cheat. The reason the prover can cheat for one claim but not for the other has little to do with the constraint system, and everything to do with another temporary assumption - Termination Then Stall. That assumption exists because the constraint system currently does not restrict how a program stalls well enough. Loosely, we will show that the Jolt prover can lie about when a program ends (it could claim a program ends before it actually ends). Under the termination then stall assumption, it cannot lie if it claims the program did not panic. So these restrictions are not independent, but subtly interlinked. When it claims that the program did panic, there is nothing that the termination then stall assumption can do for us. Next, we get to our second temporary assumption.

Host Calls Succeed

A host call is the guest program asking the machine that runs Jolt’s tracer, the host, to do something for it, much like a system call. The guest makes a host call with the Jolt instruction VirtualHostIO.

VirtualHostIO is a 32-bit I-type instruction in RISC-V’s custom opcode space:

FieldBitsValue
opcode6–00x5B (1011011)
rd11–7x0; Jolt’s decoder rejects any other register
funct314–122 (010)
rs119–15ignored; x0 in practice
imm31–20ignored; 0 in practice

The guest emits it as .insn i 0x5B, 2, x0, x0, 0, which encodes as 0x0000205B (jolt-platform/src/print.rs).

Jolt’s tracer executes it in VirtualHostIO::exec (tracer/src/instruction/virtual_host_io.rs):

let call_id = cpu.x[10] as u32;

if call_id == JOLT_ADVICE_WRITE_CALL_ID {
    let ptr = cpu.x[11] as u64;
    let len = cpu.x[12] as u64;
    let _ = cpu.handle_advice_write(ptr, len);
} else {
    let ptr = cpu.x[11] as u32;
    let len = cpu.x[12] as u32;
    let event = cpu.x[13] as u32;

    if call_id == JOLT_CYCLE_TRACK_CALL_ID {
        let _ = cpu.handle_jolt_cycle_marker(ptr, len, event);
    } else if call_id == JOLT_PRINT_CALL_ID {
        let _ = cpu.handle_jolt_print(ptr, len, event);
    }
}

Written like ADDI rd, rs1, imm, the instruction is:

VirtualHostIO x0, x0, 0
  reads:  x10 = call id, x11 = pointer, x12 = length, x13 = event
  writes: no register, no memory
  PC <- PC + 4

Its fields rd, rs1 and imm are fixed; its inputs are the registers x10 to x13, as ecall reads a7.

Here are the three things it can do, chosen by the call id in x10:

  1. Print (x10 = 0x505249): print the x12 bytes at address x11 as a string; x13 = 1 prints it, x13 = 2 adds a newline, and any other x13 panics.
  2. Cycle marker (x10 = 0xC7C1E): x13 = 1 starts, and x13 = 2 ends, a cycle counter named by the x12 bytes at address x11; any other x13 panics.
  3. Advice write (x10 = 0xADBABE): copy the x12 bytes at address x11 onto the runtime advice tape; x13 is ignored.

Any other call id does nothing.

Loosely, this is used for debugging, and there is no Jolt constraint about this instruction. So if one of these instructions fails, then the tracer will not run. But the cheating prover can just ignore these VirtualHostIO calls and run the program as if they never existed. The verifier will accept.

This assumption assumes that every call to VirtualHostIO the program makes, for every untrusted advice and runtime advice, succeeds.

def JoltInstance.HostCallsSucceed (joltInstance : JoltInstance SourceInstruction) : Prop :=
  ∀ (privateInputs : JoltPrivateInputs)
    (run : JoltConstraints.Soundness.UntrustedAnswerRun joltInstance privateInputs)
    (next : Fin run.bytecode.size) (pre : SailJoltState),
    run.NextStep next pre →
      match run.bytecode[next].instruction with
      | .VirtualHostIO => ∃ post, execHostIO pre = .ok RETIRE_SUCCESS post
      | _ => True

This is a really mild assumption if we are not using the advice tape. As the rest of the use cases are just debugging.

  1. This translation was done by Galois and researchers at Cambridge University. See the Sail-to-Lean post for further details. ↩

  2. We could not figure out a way to get the Lean kernel to enforce this in a clean manner without completely redoing the project. So we do this manually by enforcing that each field uses something from the Assumptions namespace. If you, the reader, know a better way to do this, please reach out with a pull request. ↩

  3. By region I mean any of the 8-byte locations shown in the figure above. ↩