Skip to content

musig: Require generated secnonce for partial sig#35422

Open
nervana21 wants to merge 2 commits into
bitcoin:masterfrom
nervana21:reject-partial-signing
Open

musig: Require generated secnonce for partial sig#35422
nervana21 wants to merge 2 commits into
bitcoin:masterfrom
nervana21:reject-partial-signing

Conversation

@nervana21
Copy link
Copy Markdown
Contributor

@nervana21 nervana21 commented May 30, 2026

Per BIP327, a secnonce consisting of only zero bytes is invalid for Sign and will cause it to fail.

Previously, MuSig2SecNonce::IsValid() only reported whether secure memory was allocated for the secnonce, not whether CreateMuSig2Nonce had succeeded in creating the secnonce.

This patch tracks successful secnonce generation, rejects CreateMuSig2PartialSig when generation has not succeeded, renames the query method to HasNonce, and adds a regression test.

Test plan

/build/bin/test_bitcoin --run_test=bip328_tests/secnonce_lifecycle

nervana21 added 2 commits May 30, 2026 22:12
IsValid() reported allocated secure memory, which is true for every
default-constructed object. Record successful CreateMuSig2Nonce in
m_has_nonce, clear it in Invalidate(), and have IsValid() report that
flag. Return nullopt from CreateMuSig2PartialSig when generation has
not yet succeeded.

Add a bip328 unit test for the generate-sign-invalidate lifecycle.
IsValid() on keys and pubkeys typically checks that the key material is
well-formed. HasNonce() reports whether CreateMuSig2Nonce has succeeded.
@DrahtBot
Copy link
Copy Markdown
Contributor

DrahtBot commented May 30, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35422.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

@nervana21
Copy link
Copy Markdown
Contributor Author

cc @real-or-random @jonasnick

@achow101
Copy link
Copy Markdown
Member

It shouldn't be possible to hit any error with this as the nonce is not stored if nonce generation fails.

Instead of a bool that needs to track state, the unique ptr can be created in CreateMuSig2Nonce and set after the successful nonce generation.

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.

3 participants