Skip to content

refactor(hashsig): move the monad-map lemmas to the shared modules - #901

Merged
tcoratger merged 1 commit into
ethereum:masterfrom
tcoratger:hashsig-map-monad
Nov 6, 2026
Merged

tcoratger merged 1 commit into
ethereum:masterfrom
tcoratger:hashsig-map-monad

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Two lemmas about the helpers that leanXMSS and leanSPHINCS share move out of a leanSPHINCS proof file and into the shared proof modules of those helpers.
Their statements are unchanged, and leanXMSS can now use them.

The problem

A map of monads here is a function φ : m β → n β, for every type β, that keeps pure and bind.
The leanSPHINCS bridge uses two facts about such maps:

  • φ commutes with building a vector in order, the shared HashSig.ofFnInOrder.
  • φ commutes with a hash-chain walk, the shared Wots.chain.

Both facts are about shared helpers, but they were proved in Proofs/Sphincs/Unforgeability/VerifyQueries.lean.
The two schemes never import each other's files (decision HS-1, checked by check_layers.py), so a leanXMSS proof could not use them.
The XMSS stack under review (#855) proved both again under other names.

The idea

Put each lemma next to the helper it describes:

  • HashSig.ofFnInOrder_map_monad goes in Proofs/HashSig.lean, after the identity-monad lemma of the same builder.
  • Wots.chain_map_monad goes in Proofs/Wots.lean, at the end of its section on chains.

The leanSPHINCS callers in VerifyQueries.lean and HonestQueries.lean now use these names.
VerifyQueries.lean imports Proofs.HashSig for the first lemma.
Decision 90 forbids deprecated aliases, so the old names go away.

Example

The leanSPHINCS message digest is ofFnInOrder DIGEST_CALLS (fun call => thFull H …).
To show that a monad map φ sends the digest computed with H to the digest computed with φ ∘ H, the proof rewrites with

HashSig.ofFnInOrder_map_monad φ map_pure map_bind :
  φ (ofFnInOrder k f) = ofFnInOrder k (fun i => φ (f i))

The proof is the same as before, and only the name changes.

For reviewers

The statements before and after, from #check:

before: Sphincs.Unforgeability.ofFnInOrder_map_monad
        {m n} [Monad m] [Monad n] (φ) (map_pure) (map_bind) {α} (k) (f) :
        φ (ofFnInOrder k f) = ofFnInOrder k fun i => φ (f i)
after:  HashSig.ofFnInOrder_map_monad, the same binders and conclusion

before: Sphincs.Unforgeability.chain_map_monad
        {m n} [Monad m] [Monad n] (φ) (map_pure) (map_bind) {α} {k} (step) (start)
        (steps) (h) (value) :
        φ (chain step start steps h value) = chain (fun i v => φ (step i v)) start steps h value
after:  Wots.chain_map_monad
        {m} [Monad m] {α} {n} {m'} [Monad m'] (φ) (map_pure) (map_bind) (step) (start)
        (steps) (h) (value) : the same conclusion

Only the order of the implicit arguments of the chain lemma changes: the section variables of Proofs/Wots.lean come first.
The explicit arguments keep their order, so every call site keeps its arguments.

No other declaration moves.
The private copies in #855 (collect_natural, chain_natural) are not on master, so this pull request cannot remove them.

Checks

  • lake build --wfail of Proofs.Sphincs, Proofs.Xmss, Proofs.QueryAvoidance and Proofs.Wots.Binding: 5547 jobs, passed. These cover every importer of the four changed modules.
  • leanchecker replays at 8 GB, one module at a time: Proofs.HashSig (8.5 s, 2.7 GB), Proofs.Wots (8.9 s, 3.1 GB), VerifyQueries (5.6 s, 3.2 GB) and HonestQueries (4.3 s, 3.2 GB) passed.
  • lake exe check-decls on Proofs.HashSig, Proofs.Wots, Proofs.Sphincs and Proofs.Xmss: 18909 declarations, 0 findings.
  • git grep finds no use of the old names.
  • check_writing.py --base, the commit check, check_lean_layout.py --base, check_layers.py and soundness_facts.py --check: clean.

🤖 Generated with Claude Code

@tcoratger tcoratger changed the title refactor(hashsig): move the monad-map lemmas of the shared helpers out of leanSPHINCS refactor(hashsig): move the monad-map lemmas to the shared modules Nov 6, 2026
@tcoratger
tcoratger force-pushed the hashsig-map-monad branch 2 times, most recently from da56d96 to 720d362 Compare November 6, 2026 11:44
Two lemmas say that a map of monads that keeps pure and bind commutes
with the shared vector builder and with the WOTS hash chain. They sat in a
leanSPHINCS proof file, which leanXMSS may not import. They now live in
the shared proof modules of those helpers, so both schemes can use them.
The statements are unchanged, and the names move to the HashSig and Wots
namespaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tcoratger
tcoratger merged commit 8b2f54a into ethereum:master Nov 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant