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 CreateSchnorrSig pass GetRandHash() instead, unless SignOptions::aux_rand sets a fixed value.
In the unit tests, only script_tests/bip341_keypath_test_vectors depended on the zero value: the BIP341 vectors were made with zero auxiliary data. It now builds the signature creator with aux_rand set 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. If CreateSchnorrSig ignores aux_rand, the vector check fails for all 7 key path inputs. The signing-related functional tests pass unchanged. The script_sign fuzz target can now reach GetRandHash(), so it seeds the RNG like the other signing targets.
I chose GetRandHash() over GetStrongRandBytes(). Both draw from the same RNG, which is seeded with OS entropy at startup, so the output is unpredictable; GetRandHash() skips the OS call GetStrongRandBytes() 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 tests GetRandHash() follows the test seed, so the tests stay reproducible; GetStrongRandBytes() does not.
Default signing is no longer deterministic. SignOptions::aux_rand sets 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.