feat(crypto): deterministic DLEQ nonce derivation (NUT-12)#1010
Open
robwoodgate wants to merge 2 commits into
Open
feat(crypto): deterministic DLEQ nonce derivation (NUT-12)#1010robwoodgate wants to merge 2 commits into
robwoodgate wants to merge 2 commits into
Conversation
Derive the DLEQ nonce `r` deterministically from the private key and proof context instead of from the RNG: r = HMAC-SHA256(key=a, "Cashu_DLEQ_R_v1" || A || B' || C' || ctr) mod n This removes the dependency on RNG quality. Reusing `r` across two proofs with different challenges would leak the private key. `step2_bob` now emits deterministic nonces for every signature; DLEQ verification is unaffected since (e, s) remain valid proofs. The `p_bytes` override is retained for the existing test vectors. Adds the NUT-12 deterministic-nonce test vector (cashubtc/nuts#368) plus reproducibility and context-sensitivity tests.
3 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1010 +/- ##
==========================================
- Coverage 74.99% 74.96% -0.03%
==========================================
Files 111 111
Lines 12065 12076 +11
==========================================
+ Hits 9048 9053 +5
- Misses 3017 3023 +6 ☔ View full report in Codecov by Sentry. |
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.
Implements the deterministic nonce derivation from cashubtc/nuts#368.
Summary
Derives the DLEQ nonce
rdeterministically from the mint's private key and the proof context, instead of sourcing it from the RNG:ais the 32-byte secp256k1 private key scalar (big-endian);A,B',C'are uncompressed SEC1 points (65 bytes each);ctris a single byte starting at0x00, incremented if the reduced value is0(max 256 attempts).This removes the dependency on RNG quality. Reusing
racross two proofs with different challenges leaks the private key immediately viaa = (s₁ - s₂)·(e₁ - e₂)⁻¹ mod n.Changes
cashu/core/crypto/b_dhke.py— newderive_dleq_nonce(a, A, B_, C_).step2_bob_dleqcomputesC_/Afirst, then derivespdeterministically. Thep_bytesoverride is retained for existing test vectors.tests/test_crypto.py— adds the NUT-12 deterministic-nonce test vector (asserts every fixed value pluse == hash(R1, R2, A, C_)verification), reproducibility, and context-sensitivity tests.Notes
step2_bob(used by the mint inledger.py) now emits deterministic nonces for every signature. DLEQ verification is unaffected —(e, s)remain valid proofs. No on-disk format or API change.e,s,A, andC_from the spec vector exactly.Test plan
tests/test_crypto.py— 19 passed, including the new NUT-12 vector and the two new determinism tests.make check(ruff + mypy) passes.