2 minor findings · 5 suggestions
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Tapscript budget omits the control block and annex
evalscript can report a validation-weight failure for a tapscript execution that consensus accepts, even when -tx supplies the witness.
Location: src/bitcoin-util.cpp:414 (head).
Details and suggested fix
For tapscript, the tool initializes the validation budget from the serialized initial stack and script, plus 50. Consensus instead uses the serialized witness stack, which also includes the control block and any annex. Each non-empty signature check deducts 50, so the smaller tool budget can cause a false failure. For example, with the default flags, -sigversion=tapscript evalscript '2DUP CHECKSIGVERIFY CHECKSIG' 01010101010101010101 02 gives the tool a budget of 68, and the second check fails. A witness with the same two items, the 3-byte script and a minimal control block gives consensus a budget of 102, so both checks pass. Under mandatory flags, the 1-byte public key is an upgradable key type accepted without signature verification, so this example does not depend on the dummy checker. Supplying -tx does not resolve the mismatch because the tool deliberately ignores the transaction witness when initializing this budget. This underestimation causes false failures, not false successes, in the local tool; node validation still uses the full witness budget. Include the serialized control block and adjust the item-count prefix when synthesizing the budget, or use the transaction witness stack when it contains the supplied script and arguments. Add a boundary test.
[minor] · A negative spent-output amount aborts bitcoin-util
A malformed spent-output amount makes evalscript abort with an assertion failure instead of printing an error.
Location: src/bitcoin-util.cpp:378 (head).
Details and suggested fix
The -spentoutput parser accepts a serialized CTxOut with no trailing bytes but does not range-check nValue. For example, -spentoutput=ffffffffffffffff00 produces amount -1 with an empty scriptPubKey. The tool then creates a checker with MissingDataBehavior::ASSERT_FAIL. In witness_v0, a CHECKSIG with a validly encoded public key and a non-empty DER signature reaches CheckECDSASignature, which treats the negative amount as missing data and triggers an assertion. To reproduce, take the existing evalscript-tx-checksig case, remove -sigversion=base, and use that spent output. The command's exception handlers cannot catch the abort. This only aborts the local bitcoin-util process; node validation does not reach this path because CheckTxInputs rejects out-of-range input values first. Reject spent outputs whose nValue is outside MoneyRange with an argument error, or use MissingDataBehavior::FAIL, and add a negative-amount test.
Optional improvements
[suggestion] · Even-length decimal script tokens are interpreted as raw hex
evalscript 10 evaluates byte 0x10 rather than OP_10, while evalscript 1 evaluates OP_1.
Location: src/bitcoin-util.cpp:312 (head).
Details and suggested fix
The tool decodes any non-empty, even-length hex string as raw bytes before trying ParseScript, which parses an all-digit word as a decimal number. Thus evalscript 10 runs byte 0x10, a 16-byte push with no data, and fails with a bad-opcode error, while evalscript 1 runs OP_1. Values such as 16 and 1000 also become truncated pushes, and 99 becomes byte 0x99, which is disabled in base and witness_v0 but an OP_SUCCESS in tapscript. Adding a space changes the interpretation: 10 and 10 0 ADD use decimal parsing. The asm output shows the script that ran, but the tool gives no other warning. Always use ParseScript for the script argument; its 0x prefix already supports raw bytes. Update tests that rely on bare hex accordingly. If bare hex remains a convenience, document that it takes precedence over decimal parsing.
[suggestion] · Base mode accepts initial stack elements that scriptSig cannot produce
In base mode, evalscript can report success with initial stack elements over 520 bytes, which cannot occur in a legacy or P2SH spend.
Location: src/bitcoin-util.cpp:447 (head).
Details and suggested fix
The initial-stack checks enforce MAX_SCRIPT_ELEMENT_SIZE only for witness_v0 and tapscript. In base mode, the stack seen by a scriptPubKey or redeemScript comes from executing scriptSig, where every pushed element is capped at 520 bytes and no enabled opcode produces a larger element. Nevertheless, -sigversion=base evalscript 'SIZE 521 EQUAL' <521-byte hex> reports success. Apply the same per-element limit to base-mode initial stacks so the tool only evaluates states reachable by consensus execution, or flag such inputs in the output.
[suggestion] · Base-mode sigop cost overstates P2SH redeem-script counts
A 2-of-3 multisig redeem script is reported with a sigop cost of 80, while consensus charges 12.
Location: src/bitcoin-util.cpp:484 (head).
Details and suggested fix
For base mode, sigop_cost uses GetSigOpCount(false) * WITNESS_SCALE_FACTOR, which counts each CHECKMULTISIG as 20 sigops. That is correct for bare scripts, but SigVersion::BASE also covers BIP16 redeem scripts, whose sigops consensus counts accurately with GetSigOpCount(true). Thus 2 <pk1> <pk2> <pk3> 3 CHECKMULTISIG used as a redeem script is reported as 80 instead of 12. Report both the legacy and accurate counts, or name the field to make clear that it is the bare-script count.
[suggestion] · Options for other commands and ignored evalscript arguments are accepted silently
Options such as -tx are accepted with other commands, while -input and -spentoutput are ignored when -tx is absent.
Location: src/bitcoin-util.cpp:64 (head).
Details and suggested fix
bitcoin-util registers -sigversion, -scriptflags, -tx, -input and -spentoutput as evalscript options but does not check command-specific options before dispatch. For example, bitcoin-util -tx=... grind <hdr> is accepted without an error. In EvalScript, -input and -spentoutput are read only when -tx is present, so they are otherwise ignored; the only visible indication is dummy_sig_checker: true. Also, -input uses GetIntArg, which falls back to LocaleIndependentAtoi, so -input=abc silently selects input 0. Check command-specific options before dispatch, reject -input and -spentoutput when -tx is absent, and parse -input with ToIntegral so these mistakes produce explicit errors.
[suggestion] · Transaction-checker tests do not cover tapscript or witness_v0
Both functional cases that pass -tx use base mode, leaving the tapscript and witness_v0 transaction-checker paths untested.
Location: src/bitcoin-util.cpp:381 (head).
Details and suggested fix
Every tapscript case runs without -tx, and both functional cases that pass -tx use -sigversion=base. The tests therefore do not cover the tapleaf hash computed from the supplied script, annex detection and hashing from the transaction witness, or Schnorr sighash computation with the forced transaction data. They also do not cover the witness_v0 sighash path that depends on the amount. An incorrect tapleaf or annex hash would make real tapscript signature checks fail, and no test would catch it. Add a valid tapscript script-path vector, ideally with an annex, and a P2WSH signature vector.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Avoid requiring unrelated prevouts for non-tapscript checks