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:
nis the hash width in bitskis 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:
- The Lean transcription matches the Rust.
- Our models of the AVX2 and NEON instructions match Intel’s and Arm’s documentation.
blake2b_simdis 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:
- The formal definition does not require the indices to be distinct. Only the prose does.
- 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.
- §5.4.1.11 is undefined for some parameters that §7.7.1 allows.
- §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.
[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