fuzz: add musig harness

bitcoin/bitcoin: PR #36073

3 suggestions

Optional improvements

Link

[suggestion] · Aggregation lacks a rejection assertion for tampered partial signatures

The harness checks only honest aggregation and discards the malformed-input result, so removing per-signer verification from CreateMuSig2AggregateSig would leave its assertions passing.

Location: src/test/fuzz/musig.cpp:172 (head).

Details and suggested fix

The final Schnorr check uses only honestly generated partial signatures. Rejection of an incorrect partial depends on the secp256k1_musig_partial_sig_verify loop in src/musig.cpp; secp256k1_musig_partial_sig_agg only sums the scalars. After the successful Schnorr assertion, copy partial_sigs, flip one byte of one entry, and assert that CreateMuSig2AggregateSig returns no value with the otherwise unchanged inputs. The changed scalar either fails parsing or fails partial-signature verification. This adds a negative oracle while preserving the successful fixture's other guards, and aggregation does not reuse a secret nonce.


Link

[suggestion] · Tweak input decoding depends on argument evaluation order

Near input exhaustion, the two provider reads in emplace_back can decode the same corpus entry into different tweak/flag pairs depending on compiler evaluation order; this follows from source inspection, not a measured cross-compiler replay.

Location: src/test/fuzz/musig.cpp:143 (head).

Details and suggested fix

Both tweak loops call tweaks.emplace_back(ConsumeUInt256(fdp), fdp.ConsumeBool()), whose arguments are indeterminately sequenced. With exactly 32 bytes remaining after the loop condition, reading the tweak first consumes all bytes and gives a false flag. Reading the flag first consumes the last byte, then the short 31-byte tweak read returns zero. An odd final byte therefore also selects a different xonly/plain tweak path. With at least 33 bytes, the reads do not interfere. In both loops, consume the tweak and flag into locals in separate statements before calling emplace_back to fix their order.


Link

[suggestion] · Session-ID arm lacks an input-sensitivity oracle

The fuzz arm discards MuSig2SessionID results, so dropping sighash or pubnonce from the hash would leave this harness passing; no direct unit test exercises the helper.

Location: src/test/fuzz/musig.cpp:114 (head).

Details and suggested fix

MuSig2SessionID hashes the keys, sighash, and public nonce to identify the stored secret nonce for a signing session, but this arm checks none of those dependencies. Store the consumed sighash and returned ID, flip one bit of the sighash, and assert that the ID changes with all other inputs fixed. When pubnonce is nonempty, also flip one of its bits and assert a different ID using the original sighash. These sensitivity checks detect omitted fields, unlike a repeatability check alone.


Coverage details