Formally verifying the Equihash verifier

Let’s formally verify the Equihash verifier used by Zakura in zakura-equihash 4.0.0 and Zebra’s equihash 0.3.0 and 0.3.1!

Writing down the Equihash specification

The core object is a solution: a list of 2^k indices, each index i selects an n-bit hash:

X_i = the n-bit slice of BLAKE2b(header ‖ nonce ‖ i / (512/n)) for i

where:

  • n is the hash width in bits
  • k is the number of rounds
  • each round checks the next n/(k+1) bits

A solution is valid when its indices pair up into a binary tree in which, at every level, sibling hashes XOR to zero on that round’s bits, siblings are in order, and no index repeats. At the root, all n bits XOR to zero.

For Zcash, n = 200, k = 9: 512 indices, 20 bits per round, each index 21 bits wide, 1,344 bytes in total.

Spec.lean is the Protocol Spec’s §7.7.1 and §5.4.1.11 written out in Lean 4.

My goal was to keep the Lean code close to the wording of the specification, and have every theorem stated against the code so the two can be read side by side.

Transcribing the verifiers

Zakura’s crate has two Equihash verifiers. There’s a recursive one that follows the spec closely, which the crate only uses in tests, and a single-pass one that runs in production. Both verifiers were transcribed into Lean with Opus 5.5, and each Lean function pointsc to the Rust crate it came from.

Proving the recursive verifier correct came first, because it reads almost like the spec. The single-pass verifier was harder. It only compares the first index of each subtree, but the spec orders whole subtrees. That works only because it also checks for duplicate indices at every merge, and the proof has to rely on that.

The AVX2 and NEON kernels are proven to give the same hashes as the portable one. And the crates’ own tests, including mainnet block 415000, run against the Lean every time it builds.

What we proved

For each of the three releases, is_valid_solution accepts a solution if and only if it is valid according to §7.7.1, under every kernel. BLAKE2b is transcribed from RFC 7693 and computed within the proof.

The result assumes:

  1. The Lean transcription matches the Rust.
  2. Our models of the AVX2 and NEON instructions match Intel’s and Arm’s documentation.
  3. blake2b_simd is correct, where 0.3.0 and 0.3.1 use it.

What we found

Writing the specification in Lean showed four gaps, which I’ve reported in zcash/zips#1424 and proposed fixes for in #1425:

  1. The formal definition does not require the indices to be distinct. Only the prose does.
  2. The bit order for reading the BLAKE2b output is not stated. Mainnet block 415000 is valid when read most significant bit first, and invalid when read the other way.
  3. §5.4.1.11 is undefined for some parameters that §7.7.1 allows.
  4. §5.1 names the wrong function in the definition of I2LEOSP.

These do not affect consensus, since the code implementation already makes the correct choice.

equihash 0.3.0 does not check its expected solution length for overflow. For parameters (448, 63) the length wraps to zero, so an empty solution passes the length check before the verifier panics. 0.3.1 returns an error in this case.

We know that Zcash uses Equihash (200,9) so mainnet was never affected.

Read the Lean proof on GitHub

[Update: 6th Nov 2026]

i) The four gaps in the Zcash Protocol specification were confirmed by @daira

ii) The proposed fixes were merged into the Zcash Protocol specification by @str4d along with other NU6.3 fixes

I’d like to thank the editors for their review!


Support AI-assisted Formal Verification on Zcash

u16u39fss03kuea62t4efkw0fzp8wk2la5etvdrgypn3gdplh7uzgah2umufpyshz4056q3q68rsdjd7mm83e2twn2v3msk4nsys2vh9ud6yh2qv3u5u2kykvtkl8nz6dfpzuawksz4dy6kkw6mqver6vu96w0uukfznk09cqcegc7v4rr

4 Likes

this is excellent work and exactly the kind of contribution the zcash ecosystem needs more of.

the spec gaps are particularly interesting. the formal definition missing the distinct-index requirement, while the prose includes it, shows why machine-checked proofs matter. even when the implementation gets it right, the spec itself needs to be unambiguous.

also really liked the single-pass verifier proof. the fact that duplicate checking at every merge is essential for soundness is a subtle invariant that could easily be missed during a refactor.

the equihash overflow finding is another great catch, especially for non-standard parameters. these are exactly the edge cases formal verification is good at uncovering.

one thing i’m curious about: how did you validate the Rust-to-Lean transcription beyond running the existing test vectors? tools like Aeneas could be an interesting direction for reducing that trust gap further.

really solid work. this is what don’t trust, verify looks like in practice.

Thank you! I see you’re a cryptographer from your profile @annkkitaaa

I’d appreciate it if you took a minute to look over Spec.lean and include comments on proof-style etc

On Aeneas: While I did start off using Aeneas and proved the recursive verifier against its translation, I had to move onto hand-writing the single-pass verifier (used by Zakura, and soon Zebra) because Aeneas doesn’t yet support some of the Rust it uses.

1 Like