perf(xmss): derive WOTS public keys only during key generation - #265
Draft
exocognosis wants to merge 1 commit into
Draft
perf(xmss): derive WOTS public keys only during key generation#265exocognosis wants to merge 1 commit into
exocognosis wants to merge 1 commit into
Conversation
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.
Summary
The WOTS secret-key constructor currently derives and stores every public-key chain end eagerly. That is required while building XMSS Merkle leaves, but
xmss_signonly needs the secret pre-images. As a result, every signature performs all 42 chains across 7 steps before walking the message-selected portions of those chains.This change:
WotsSecretKeyWotsPublicKeyon demand when key generation builds Merkle leavesPerformance impact
With
V = 42andCHAIN_LENGTH = 8, signing no longer performs:V * (CHAIN_LENGTH - 1) = 42 * 7 = 294unnecessary Poseidon chain hashes.
Signing still performs the chain work selected by the incomparable encoding, which is required to construct the WOTS signature. Key generation performs the same public-key derivation as before, so Merkle roots and deterministic outputs remain unchanged.
Computing the public key only when it is needed also avoids an unbounded cache and does not retain additional secret material. The optimization applies to every signing slot, including batch signing across distinct slots.
Issue context
This addresses the remaining performance finding in leanEthereum/leanSig#37. The issue cites
crates/xmss, which belongs to this repository after the leanMultisig to leanVM rename. The slot-range validation half was addressed separately, while the eager WOTS public-key derivation remained in the current XMSS signing path.Fixes leanEthereum/leanSig#37.
Validation
cargo +nightly fmt --all -- --checkcargo +nightly test --release -p xmsscargo +nightly clippy -p xmss --all-targets --no-deps -- -DwarningsThe dependency-inclusive clippy command also reports three pre-existing
needless_range_loopwarnings incrates/backend/koala-bear/src/poseidon1_koalabear_16.rs. Those warnings are unrelated to this change.