feat(nut12): deterministic DLEQ nonce derivation#368
Open
robwoodgate wants to merge 2 commits into
Open
Conversation
This was referenced May 4, 2026
Contributor
|
Why are we hashing the key |
Contributor
Author
Mostly for defense in depth - it keeps the raw scalar out of direct HMAC-key use, and ensures the HMAC key is always fixed-width 32-byte, regardless of keygen. So just key-derivation hygiene (it doesn't add entropy or protect weak mint keys etc) |
Contributor
|
@robwoodgate I think it's an unnecessary measure and also |
Contributor
Author
Agree it's a bit belt and braces - am happy we just use the scalar without hashing if you think it adds nothing. |
Clarify the encoding of the private key as BE bytes Clarify the s = (r + e*a) part of the calculation is mod n
Contributor
Author
Addressed in e57b141 |
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.
Problem
In a DLEQ proof, the mint publishes challenge and response values
eands, related by:a- the mint’s long-lived private key (from its keyset).r- a temporary, per-proof nonce used in the DLEQ signature.If the same
ris ever reused with two different challengese₁ande₂, the private key can be recovered immediately:It’s the same class of failure that affected Bitcoin Android wallets in 2013, where repeated ECDSA nonces (
k) allowed attackers to derive private keys and drain funds.Important
Current Cashu implementations are secure in practice, because they use modern CSPRNGs, such as
crypto.getRandomValues()in browsers,crypto.randomBytes()in Node.However, the current spec does not "fail safe". A poorly written RNG wrapper, re-used seed, or language-level entropy issue could silently break key safety while remaining spec-compliant.
Solution - The spec should "Fail Safe"
To remove the RNG "weak link", RFC 6979 and BIP-340 both moved from "random nonce" to deterministic nonce derivation: the nonce is derived from the private key and the signing context rather than sampled fresh each time.
This PR brings the same approach to NUT-12's DLEQ proof.
The nonce
ris now derived via HMAC-SHA256, keyed on the mint's private key and bound to the proof context:Mints SHOULD use this derivation. Mints using random nonces MUST use a CSPRNG.
This is not a breaking change, as verifiers reconstruct R1 and R2 from (e, s) and never see r.
All existing proofs continue to verify.
Also adds a test vector section to
tests/12-tests.mdwith fixed inputs and exact expected (e, s) output, so implementations can verify byte-for-byte conformance.Proof
Here is a simplified TS proof showing how nonce reuse allows private key recoverability: