mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:44:38 +00:00
sign: use fresh randomness as BIP340 auxiliary data #36409
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36409
Loading…
Reference in a new issue
No description provided.
Delete branch "sign-bip340-aux-rand"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bitcoin Core signs Taproot inputs with all-zero BIP340 auxiliary data. BIP340 recommends fresh randomness there, as protection against fault injection and side-channel attacks. I made
CreateSchnorrSigpassGetRandHash()instead, unlessSignOptions::aux_randsets a fixed value.In the unit tests, only
script_tests/bip341_keypath_test_vectorsdepended on the zero value: the BIP341 vectors were made with zero auxiliary data. It now builds the signature creator withaux_randset to zero and compares its signature byte for byte with the vectors, then signs twice with default options and checks that the two signatures differ. IfCreateSchnorrSigignoresaux_rand, the vector check fails for all 7 key path inputs. The signing-related functional tests pass unchanged. Thescript_signfuzz target can now reachGetRandHash(), so it seeds the RNG like the other signing targets.I chose
GetRandHash()overGetStrongRandBytes(). Both draw from the same RNG, which is seeded with OS entropy at startup, so the output is unpredictable;GetRandHash()skips the OS callGetStrongRandBytes()makes on each draw. BIP340 says any non-repeating value increases protection against fault injection, and that no security property other than side-channel resistance depends on the quality of this randomness. In unit testsGetRandHash()follows the test seed, so the tests stay reproducible;GetStrongRandBytes()does not.Default signing is no longer deterministic.
SignOptions::aux_randsets a fixed auxiliary value where one is needed, as in the vector test; Yudis-bit suggested it.Fixes #31883.
Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
🔵 Suggestion · Nondeterministic Taproot signing lacks a release note
Independent signing of the same unsigned Taproot input now produces different signatures, witnesses and wtxids, but the PR adds no release note explaining this user-visible change.
Location:
src/script/sign.cpp:119(head).🔵 Suggestion ·
value_or(GetRandHash())draws randomness even with fixed auxiliary dataAn engaged
aux_randstill causes a discarded RNG draw, adding unnecessary work and advancing the shared RNG state in the BIP341 vector test.Location:
src/script/sign.cpp:119(head).Review coverage was incomplete.
Reviewed:
1f274eae23f4· Full review report · Previous reportspermalink
Tested on
be2bc19726.I think
GetRandHash()is definitely the right choice here. For BIP340, nonce generation already binds the secret key with the message via tagged hashes, so auxiliary randomness is purely for fault injection and side-channel mitigation rather than baseline entropy. Skipping theGetStrongRandBytes()OS syscall keeps transaction signing fast, and crucially keeps fuzzing and unit tests deterministic underSeedRandomStateForTest(SeedRand::ZEROS).Regarding your question about
SignOptions: I'd definitely lean towards addingstd::optional<uint256> aux_randthere.Notice what happens in
src/test/script_tests.cpp: becauseMutableTransactionSignatureCreatordoesn't accept an aux value, the test has to bypass the creator entirely and callkey.SignSchnorr(...)directly. But the whole point of that test case inscript_tests.cppwas to testMutableTransactionSignatureCreator's end-to-end handling of the BIP-341 witness generation against the official vectors.If
SignOptionshas:and in
MutableTransactionSignatureCreator::CreateSchnorrSig:Then default transaction signing keeps fresh randomness, but
script_testscan still test the creator against the exact BIP-341 vector:Verified this locally with
bip341_wallet_vectors.json. All 7 keypath test vector inputs reproduce the expected witness signature directly through the creator, alongside the two differing non-deterministic signatures under default options.Done in
1f274eae23, as you suggested:SignOptions::aux_rand, defaulting toGetRandHash(). The vector test goes through the creator again withaux_rand = uint256{}, and two default-options signatures are checked to differ. Withaux_randignored, the vector check fails for all 7 inputs. PR description updated. Thanks.ACK
1f274eae23Re-reviewed the commit. Cleanly addresses the test vector coupling by keeping
SignOptions::aux_randoptional while defaulting toGetRandHash(). Verified thatbip341_keypath_test_vectorsreproduces the BIP-341 witness with zero aux and confirms divergence under default options, withscript_signfuzzing seeded deterministically.