Skip to content

perf(core): cached lifted keys in Schnorr verify, BC-native sign - #575

Merged
tcheeric merged 3 commits into
developfrom
perf/schnorr-key-cache
Nov 27, 2026
Merged

tcheeric merged 3 commits into
developfrom
perf/schnorr-key-cache

Conversation

@tcheeric

Copy link
Copy Markdown
Owner

Follow-up to #571 (2.4.4). Profiling 2.4.4 from cashu-voucher showed verify still lifting keys with BigInteger.modPow and BouncyCastle rebuilding its wNAF tables on a fresh point every call.

Changes

  • Schnorr.verify lifts x-only keys through a bounded cache (1024, cleared wholesale when full) of BouncyCastle points configured with WNafUtil.configureBasepoint, so repeat verifies under one key reuse the tables. Off-curve keys are never cached.
  • sign and genPubKey stay on BouncyCastle ECPoints (fixed-point comb) instead of round-tripping through Point; sign's self-check uses the cached key.
  • Public API of Point and Schnorr is unchanged.

Measurements (AAE harness from #571, 3 runs each, us)

2.4.4 this PR
verify 137 / 146 / 138 95 / 98 / 96
sign 272 / 279 / 272 245 / 251 / 243
pubkey 71 / 73 / 71 69 / 73 / 69

verify -31%, sign -10%, pubkey flat. Harness golden checks pass.

Correctness

  • New SchnorrReferenceTest: a plain BigInteger transcription of the BIP-340 reference; identical signatures and public keys for random inputs, identical verdicts on bit-flipped signatures, other messages, mutated/off-curve keys (checked twice, after caching), r = p, s = n, x >= p and zero keys.
  • core/event/identity/api test suites pass.

tcheeric added 3 commits November 27, 2026 13:39
Hypothesis: verify -20% and sign -8%: BouncyCastle keeps wNAF tables on the point, so a
cached point reuses them and skips the modPow lift.
Hypothesis: sign -5%, pubkey -5%: skip the BigInteger Point round trip (affine pair, mod-2 parity).
… cached keys

docs(changelog): note the cached-key verify speedup
@tcheeric
tcheeric merged commit 6155a98 into develop Nov 27, 2026
3 of 5 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