In collaboration with dmpierre
TLDR: we implement the recovery statement of ZCash’s ZIP 2005 as a RISC-V zkVM guest reusing the Orchard crates and prove it on a laptop. We verify the guest’s RISC-V bytecode directly in Lean, against a formalized version of the ZIP, thereby taking the compiler out of the trusted computing base. This is the long version of the talk we gave at the Cambridge workshop.
Introduction
Quantum resource estimates keep going down. Architectural improvements, smaller quantum circuits for discrete logarithms and, more recently, AI-assisted autoresearch all point the same way.
Quantum recoverability is a more modest goal compared to a full post-quantum (pq) protocol. Instead of fully fledging a fully quantum safe implementation, it is instead to only make sure that assets secured by classical cryptography remain accessible to their rightful owners in the event of a cryptographically relevant quantum computer (CRQC). A quantum recoverability does not protect privacy against harvest-now-decrypt-later attacks. It only guarantees that users can get their funds out, through a recovery protocol proven under a pq proof system.
We wanted to run such a recovery protocol on ZCash Ironwood notes using a RISC-V zkVM rather than a hand-written circuit. Recent progress on binary fields and RISC-V zkVMs (Flock, SP1 Hypercube) has made proving a Rust program competitive with writing a circuit. Also, Ethereum privacy protocols developers write most of their application logic using such zkVMs. In that sense, having a recovery protocol reusing the protocol’s own crates is one that teams can realistically audit and maintain. Finally, standardization around RISC-V zkVMs lets existing and upcoming privacy protocols plan a recovery path without betting on a particular proof system.
This writeup will show:
- An implementation of the ZIP 2005 recovery statement as an SP1 guest, along with the precompile work required to make it practical.
- A method for proving, in Lean, that the guest’s bytecode enforces the ZIP, without trusting the compiler.
ZIP 2005
Ironwood recently activated and introduces a new shielded pool replacing Orchard. In that context, ZIP 2005 changes how Ironwood notes are constructed so that a future recovery protocol can work. The problem it addresses is that Orchard’s note commitment scheme is not pq binding: even under a pq proof system and a rehashed Merkle tree, a discrete-log-breaking adversary could forge notes that are not in the tree.
The quantum recoverability fix is twofold:
- A new note plaintext format binds all of the note’s fields into the derivation of the commitment randomness \mathsf{rcm}, such that an adversary constrained to treat the PRF as a random oracle cannot vary a field without changing \mathsf{rcm}.
- A new derivation path for \mathsf{rivkext}, the randomness behind \mathsf{Commit^{ivk}}, covers both existing keys derived from \mathsf{sk} and FROST or hardware wallet keys, for which exporting \mathsf{sk} is undesirable.
The ZIP then describes the recovery statement a pq proof system should enforce. Given an anchor, a randomized spend validating key \mathsf{rk} and a nullifier \mathsf{nf}, the prover knows a note, its keys and a Merkle path such that the key derivations hold, \mathsf{ivk}, \mathsf{pk_d}, \psi, \mathsf{rcm} and the note commitment are derived as specified, the commitment sits in the rehashed tree and \mathsf{nf} is its nullifier.
Implementation
We implemented the statement as an SP1 guest program. The guest follows the statement step by step and does not reimplement anything: it calls into the Orchard crate itself for key derivations, commitments and nullifiers, and into pasta_curves for Pallas arithmetic. Compiled as is, it runs in about 17m cycles, most of them spent on 255-bit modular arithmetic in software.
We brought this intial number down in three steps:
- Registering Pallas as a curve in SP1’s already audited Weierstrass add and double precompile
- Routing \mathbb{F}_p and \mathbb{F}_q multiplications through SP1’s
uint256precompile - Routing Pallas curve operations through the new precompile.
All in all, this is about 1.2k added lines across forks of SP1, pasta_curves, sinsemilla and Orchard, for a more than 10× improvement down to 1.33m cycles. The two Sinsemilla commitments and the nullifier derivation now account for close to 60% of the cycles, which is the opposite of the hand-written circuit cost model where the BLAKE2b compressions dominate. Today, proving takes around 100s on a 2023 M2 Pro, attesting to the feasibility of the recoverability protocol on day-to-day hardware.
Two pieces of the statement are not in the guest yet: the FROST and hardware wallet authorization path, and the Merkle path check, which requires the commitment tree to be recomputed with a collapsing hash first.
Formal Verification
A zkVM proof says that some RISC-V program with a given hash executed correctly. It however says nothing about whether that program does what the specification says. The usual answer is to trust the compiler: the Rust source is reviewed, rustc and the zkVM toolchain turn it into an ELF, and the ELF is what gets proven.
For a recovery protocol that users will run once, possibly years from now and under adversarial conditions, we would rather not have rustc in the trusted computing base. The idea, following the evm-asm experiments on the Ethereum side, is to prove the correct at the bytecode level, foregoing the compiler entirely.
Approach
We work on the two ends of the pipeline. At the top, the ZIP is autoformalized in Lean as a GuestStatement: a predicate over field elements and Pallas points listing the checks the guest’s main runs. Since it is the artifact a reader has to trust, it remains short enough to be read against the ZIP side by side. It sits on top of a Lean model of Ironwood’s algebra, i.e. \mathbb{F}_p, \mathbb{F}_q and Pallas points, with their operations defined mathematically.
At the bottom, elf2lean reads the guest ELF produced by rustc and SP1’s toolchain and emits its instructions as decoded RV64IM values in Lean. Their semantics come from riscv-zkvm, a Lean extraction of the official Sail RISC-V model restricted to RV64IM, together with a hand-written executable machine model proven equivalent to the extraction instruction by instruction. It comes with both Zisk and SP1 backends.
In the middle, we prove the bytecode up to the specification in layers:
| Layer | Object | Established by |
|---|---|---|
| 5 | GuestStatement: the checks main runs, over field elements |
accepting checks |
| 4 | Ironwood’s \mathbb{F}_p, \mathbb{F}_q, Pallas points | coupling |
| 3 | The arithmetic the binary computes: limb-wise Fp.mul, Montgomery reduction |
postconditions |
| 2 | One continuation theorem per guest function, Safe P s |
symbolic executor |
| 1 | RV64IM words: the decoded instructions | elf2lean |
Layer 2 is where most of the work happens. For each function in the guest, from the Montgomery multiplication up to main, we state a continuation theorem: from any machine state s satisfying the function’s precondition P, executing its instructions is safe and reaches the continuation in a state satisfying its postcondition. These are proven with a symbolic executor stepping through the decoded instructions and discharging the resulting verification conditions. Theorems compose: a caller’s proof uses its callees’ theorems as black boxes, so the ELF is never executed symbolically in one piece.
Layer 3 reads the postconditions as statements in natural number arithmetic, say what the output limbs of Fp.mul hold in terms of its input limbs. Layer 4 couples this limb-level arithmetic to the mathematical field, so that the sequence of calls the binary makes corresponds to a sequence of operations on \mathbb{F}_p, \mathbb{F}_q and Pallas. Layer 5 shows that an accepting run of main implies the GuestStatement on the decoded inputs. Put together: if the ELF runs to completion on an input, the recovery statement holds on it. The zkVM proof certifies the former and Lean certifies the implication.
All in all, what remains in the trusted base consists of the Lean kernel, riscv-zkvm’s axioms, the GuestStatement as a faithful rendering of the ZIP, elf2lean’s decoding of the ELF, the specification of the SP1 precompiles the guest calls, and SP1 Hypercube’s own soundness, which is a separate verification effort. What is no longer in it: rustc, LLVM, the SP1 toolchain and every crate the guest depends on.
Challenges
We lay out two main challenges to this approach:
- The ELF is big. The recovery statement itself compiles to around 1.4k instructions, but the guest links the whole of Orchard,
pasta_curvesand the standard library, for a total of 41,783 RISC-V instructions. - The proofs are very large: more than 333k lines of Lean, with cold builds above two hours. This makes iteration slow and makes it hard to check assumptions for vacuity, which we consider the main risk at this stage, since a precondition that is never satisfiable makes every theorem downstream of it true for the wrong reason.
Note that none of these are theoretical blockers. They are proof engineering problems, and the kind that proof automation and agentic proving are getting pretty good at.
Future Directions
Scaling should improve on its own, as both agentic proof generation and the underlying tactics are moving fast. More interestingly, the ELF infrastructure is independent of ZIP 2005: any small guest with a short specification should be provable the same way, with only the top two layers rewritten.
A recovery protocol for Ethereum privacy pools, along the lines of the one we described in our previous post, is an obvious candidate. On the tooling side, a decompiler from the decoded instructions back to structured control flow, better tactics for limb arithmetic and more proof automation would each cut iteration time substantially.