This continues the work originally started by dergoegge in #31460.
The script_flags fuzz harness tests that script verification flags are soft-forks applying flags can only tighten rules never widen them. Currently, the fuzzer can’t reach SigVersion::WITNESS_V0 or SigVersion::TAPSCRIPT code paths because it can’t construct inputs that pass the P2WSH script hash check or a valid taproot commitment.
This PR makes those checks mockable by moving them into virtual methods on BaseSignatureChecker
CheckWitnessScriptHash(program, exec_script)for P2WSH script hash verificationCheckTaprootCommitment(control, program, tapleaf_hash)for taproot script-path commitment
A new script_flags_mocked fuzz target uses FuzzedSignatureChecker which mocks out signature validation and these commitment checks, allowing the fuzzer to exercise the interpreter under witness v0 and tapscript contexts
so the coverage report shows that script_flags_mocked reaches segwit v0 and tapscript paths
Segwit v0 (P2WSH / P2WPKH)
| Line | Hits | Code path |
|---|---|---|
program.size() == WITNESS_V0_SCRIPTHASH_SIZE |
10.0k | P2WSH branch entered |
checker.CheckWitnessScriptHash(program, exec_script) |
6.77k | P2WSH script-hash check |
ExecuteWitnessScript(..., SigVersion::WITNESS_V0, ...) (P2WSH) |
4.87k | Witness v0 script execution (P2WSH) |
ExecuteWitnessScript(..., SigVersion::WITNESS_V0, ...) (P2WPKH) |
2.11k | Witness v0 script execution (P2WPKH) |
Taproot / tapscript
| Line | Hits | Code path |
|---|---|---|
checker.CheckSchnorrSignature(..., SigVersion::TAPROOT, ...) |
88 | Key-path spend |
checker.CheckTaprootCommitment(control, program, ...) |
273 | Script-path commitment |
(control[0] & TAPROOT_LEAF_MASK) == TAPROOT_LEAF_TAPSCRIPT |
87 | Tapscript leaf branch |
ExecuteWitnessScript(..., SigVersion::TAPSCRIPT, ...) |
80 | Tapscript execution |