docs(formal-verification): keccak z3/QF-BV gate — the verification baseline - #923
Open
MauroToscano wants to merge 1 commit into
Open
docs(formal-verification): keccak z3/QF-BV gate — the verification baseline#923MauroToscano wants to merge 1 commit into
MauroToscano wants to merge 1 commit into
Conversation
…seline Add a standalone, reusable template for machine-checking chip round-wiring with z3 in the quantifier-free bitvector theory (QF-BV). The worked instance verifies one Keccak-f[1600] round as shipped on main (#889's inlined θ/ρ shift identities); the README is written as a generic oracle+checker method to be copied for the next chip. Verification only — no constraint or performance change. python/z3, no cargo. Board (regenerated, par.log): - positive control (non-vacuity): PASS — constraints uniquely pin output - negative controls: all SAT (caught) — theta_no_rot, rho_swap, chi_no_not, chi_swap, iota_no_rc, plus tamper_test's iota_wrong_rc, rho_off_by_one, drop_chi_xor_byte, drop_hwsl_carry (changed + removed constraints) - main check: all 24 round indices UNSAT - reference anchored to hashlib SHA3 + repo constants; concrete mirror matches FIPS-202 over random/structured inputs Files: z3_verify.py (gate), keccak_ref.py (independent FIPS-202 reference), model_dataflow.py + test_dataflow.py (concrete mirror), z3_parallel.py (runner), tamper_test.py (controls), test_ref.py (reference tests), README.md (methodology + width audit + scope), par.log (captured board).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
A standalone, reusable template for machine-checking that a bit/byte hash
chip's per-round transition wiring computes the function it claims, using z3 in
the quantifier-free bitvector theory (QF-BV). It lands the keccak
round-wiring verification under a clean, chip-agnostic home
(
thoughts/formal-verification/keccak/) and rewrites the README as a genericmethod the next chip gate should copy.
Verification code only — no constraint or performance change. python/z3, no
cargo. The z3 gate previously lived bundled inside an open perf PR
(
feat/keccak-hwsl-inline); this extracts the core round-wiring verifier as abaseline, off
main, without any perf change.The method (reusable)
f(FIPS-202 here, anchored to
hashlibSHA3 + repo constants), a column-rolemap, and a typed chip-contract library (
ByteAluXOR/AND/ADD,AreBytes0..256 range, the halfword-shift decomposition, word recomposition,
KeccakRc).interaction / eval constraint an equation under its contract; assert
output ≠ reference(input)and ask for a counterexample. UNSAT ⇒ correctgiven the contracts; SAT ⇒ under-constrained, with a forging witness.
negative controls (injected bug must flip to SAT, else UNSAT is
meaningless), a positive control (non-vacuity), the width audit (every
field-lifted byte/word width must cite a real range-check contract + a
non-overflow side condition, or a field-level attacker escapes the bitvector
model), and the rule that fail-open is the only dangerous failure mode.
Which round variant it verifies
The shipped round on
mainas of #889 (perf(keccak): inline θ/ρ halfword shifts as μ-gated identities, commit6a280121). On main the θ/ρ shifts areinline μ-gated linear identities
μ·(in·2^rnc − right·2¹⁶ − left)=0withrange-checked byte-pair halves; the QF-BV model encodes each shift as the unique
(left, right)decomposition those identities force, so the gate is faithful tothe inlined round. Verified: main's
keccak_rnd.rsis byte-identical to thebranch the model was authored against — the wiring transcribed is the wiring
shipped. (One documented follow-up: QF-BV cannot test that the range bounds are
sufficient mod
pfor the inline identities — that companion integer-mod-pcheck ships with the perf PR and is the first extension of this template.)
Verified board (regenerated,
par.log)theta_no_rot,rho_swap,chi_no_not,chi_swap,iota_no_rciota_wrong_rc,rho_off_by_one,drop_chi_xor_byte,drop_hwsl_carry(forged witnesses exhibited for the removed-constraint cases)
hashlibSHA3 + repoKECCAK_RC/KECCAK_RHO; concretemirror matches FIPS-202 over 200 random rounds + 20 full permutations +
structured inputs
Scope
QF-BV covers bit/byte hashes (Keccak/SHA-3, SHA-2, BLAKE3). Native-field chips
(Poseidon/Poseidon2) are out of scope — their round is field arithmetic and needs
a finite-field solver (
cvc5FF) or a proof assistant (Lean). The check is oneround's transition given the helper-chip contracts; it does not re-verify the
helper chips. The BLAKE3 chip gate and the keccak-sponge verification already
follow this method — this directory is the canonical template.
Running it