Skip to content

perf(xmss): derive WOTS public keys only during key generation - #265

Draft
exocognosis wants to merge 1 commit into
leanEthereum:mainfrom
exocognosis:agent/avoid-wots-public-key-recomputation
Draft

perf(xmss): derive WOTS public keys only during key generation#265
exocognosis wants to merge 1 commit into
leanEthereum:mainfrom
exocognosis:agent/avoid-wots-public-key-recomputation

Conversation

@exocognosis

Copy link
Copy Markdown

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_sign only 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:

  • stores only the WOTS secret pre-images in WotsSecretKey
  • derives WotsPublicKey on demand when key generation builds Merkle leaves
  • removes the public parameter and slot from WOTS secret-key generation because they are only needed for public-key derivation and chain walking
  • leaves the signing and verification formats unchanged

Performance impact

With V = 42 and CHAIN_LENGTH = 8, signing no longer performs:

V * (CHAIN_LENGTH - 1) = 42 * 7 = 294

unnecessary 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 -- --check
  • cargo +nightly test --release -p xmss
    • 10 passed
    • 1 ignored
  • cargo +nightly clippy -p xmss --all-targets --no-deps -- -Dwarnings

The dependency-inclusive clippy command also reports three pre-existing needless_range_loop warnings in crates/backend/koala-bear/src/poseidon1_koalabear_16.rs. Those warnings are unrelated to this change.

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.

WOTS+ chains recomputed on every sign + missing slot range validation

1 participant