← All insights
GRANTZcash Forum · craftsoldier

Proposal to verify Zebra and Zakura consensus libraries in Lean 4

craftsoldier proposed a grant to specify and prove Zebra's and Zakura's consensus-related libraries in Lean 4. The background is seven serious consensus divergences in Zebra this year.

The author points out that Zebra had seven Critical-severity consensus divergence issues this year, most found because behavior differed from zcashd. In April it accepted a signature that zcashd rejects, and two weeks later the fix split the chain in a different way. In May, a different signature rule and a sigop counting problem followed, along with an advisory titled "Not Correctly Fixed". The author's diagnosis is that unintended transactions are hard to catch with tests.

The proposal is to write the consensus rules in Lean 4, based on the protocol specification and ZIPs and, where the specification is silent, on zcashd. Functions from each Zebra and Zakura library would be ported to Lean and checked against the official test vectors, and then proven to follow the rules for all inputs. The transparent script rules would be documented for the first time in this process. If a fix covers only part of a rule, the proof fails, so it is caught before deployment.

The targets include equihash, zcash_primitives, zcash_transparent, zcash_script, zebra-script, zcash_history, zcash_note_encryption, incrementalmerkletree and the corresponding Zakura crates. The milestones are 1) transactions, txids and signature hashes, 2) transparent scripts and sigop counting, and 3) Equihash, the history tree, the note commitment tree and shielded coinbase.

Verification work by core developers has focused on Ironwood's cryptographic parts and on ZFND's zebrafm, and zebrafm lists Equihash, digests, the script interpreter and the trees as unverified areas. The full application is in ZCG repository issue #564. This post is a proposal only, not an approval result.

This summary is based on the original; check the original for exact details.