Implement BIP 54 (Consensus Cleanup) without mainnet activation

bitcoin/bitcoin: PR #35793

2 minor findings · 6 suggestions

Earlier concerns neither republished nor resolved: 2 minor findings · 4 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · BIP54 sigops rejections lose txid-level reject caching

Witness-bearing BIP54 sigops rejections now lose txid-level download suppression on every network, although no in-tree producer of the triggering transaction was found.

Location: src/consensus/tx_verify.cpp:205 (head).

Details and suggested fix

PreChecks now returns TX_CONSENSUS for this check instead of the former standardness-path TX_INPUTS_NOT_STANDARD. Consequently, MempoolRejectedTx caches only the wtxid and no longer calls ForgetTxHash(txid). The check still depends only on scriptSig and the spent scriptPubKey, so changing the witness cannot change its result. Later missing-input children can enter orphan resolution and schedule another parent request by txid; txid announcements from non-wtxidrelay peers also lose suppression. Identical rejected wtxids remain filtered before mempool submission, and request and orphanage limits bound the work.

Carry witness-independent rejection metadata for this failure into the download manager and preserve the additional txid caching and request cancellation, with a txdownload_tests case. Do not extend txid caching to all TX_CONSENSUS failures, since script failures can depend on the witness.


Link

[minor] · The future-tapleaf test vector reuses the Tapscript witness

The unit-test case and generated vector labelled as a spend of the 0xc2 leaf repeat the preceding Tapscript spend, leaving the intended future-leaf case untested.

Location: src/test/bip54_tests.cpp:1060 (head).

Details and suggested fix

The first successful SignSignature call sets sigdata.complete. Replacing the keys and tr_spenddata does not reset it, so the second call returns immediately from ProduceSignature and copies the unchanged witness back into tx_copy2. Neither subsequent assertion checks which leaf was selected, and UPDATE_JSON_TESTS therefore exports the duplicate transaction under the future-leaf description. Resetting sigdata alone is insufficient because SignTaprootScript rejects non-Tapscript versions. Construct this witness explicitly from leaf_script_future and its matching control block in builder.GetSpendData().scripts, then assert (control[0] & TAPROOT_LEAF_MASK) == 0xc2 before verifying and recording it.


Optional improvements

Link

[suggestion] · BIP54 upgrade changes lack release notes

Default regtest activation changes getblocktemplate negotiation and old-chain compatibility, while mempool rejections change on every network; the release notes provide no upgrade guidance.

Location: src/kernel/chainparams.cpp:639 (head).

Details and suggested fix

doc/bips.md records activation but does not explain the user-visible changes:

  • Regtest getblocktemplate clients must include consensuscleanup in rules. The RPC help's segwit-only example is now rejected on default regtest.
  • Older non-genesis regtest blocks with a coinbase locktime other than height minus one, a final coinbase sequence, or a 64-byte transaction are rejected during full -reindex or fresh synchronization. Restarting or using -reindex-chainstate does not rerun these contextual checks, so retaining an existing chain does not establish compatibility.
  • Mempool sigops violations now return bad-txns-legacy-sigops instead of bad-txns-nonstandard-inputs, and -acceptnonstdtxn no longer bypasses that limit. The 64-byte rejection changes from tx-size-small to txn-size-64.

Add a release-note fragment covering these changes, the required GBT request, and resetting incompatible regtest chain data. Make clear that the mempool changes do not imply mainnet activation of the block rules.


Link

[suggestion] · Mempool sigops coverage omits disabled standardness

The mempool sigops test requires standardness and has BIP54 active, so its rejection assertions do not protect the new unconditional enforcement against option-dependent regressions.

Location: test/functional/mempool_sigoplimit.py:231 (head).

Details and suggested fix

PreChecks correctly passes enforce_bip54=true outside the require_standard guard and independently of activation. However, test_legacy_sigops_stdness restarts with defaults, and its block assertion tests active block validation separately. Making only mempool enforcement conditional on standardness or activation would leave these assertions passing. Before std_tx spends the fixture inputs, repeat the 2505-sigop rejection after restarting with -acceptnonstdtxn=1 and -vbparams=consensuscleanup:0:0, requiring the same bad-txns-legacy-sigops error. Restore defaults before the block-rejection assertion.


Link

[suggestion] · Mandatory consensuscleanup acknowledgement is untested

The test checks !consensuscleanup advertisement but never requests a template without acknowledging it, leaving the new mandatory-client-support behavior unprotected.

Location: test/functional/mining_basic.py:489 (head).

Details and suggested fix

getblocktemplate({}) fails at the separate segwit guard before reaching the active-deployment loop. The positive request supplies both rules, so bypassing only the mandatory-rule refusal would leave both existing assertions passing. Add a segwit-only request here and require error -8 with Support for 'consensuscleanup' rule requires explicit client support. That reaches the refusal branch for the active, nonoptional deployment rather than testing another missing-rule condition.


Link

[suggestion] · Exported sigops descriptions misstate script types and counts

The generated sigops-vector descriptions misidentify bare scripts as P2SH and give both sides of one boundary case the same input count, despite correct validity expectations.

Location: src/test/bip54_tests.cpp:519 (head).

Details and suggested fix

The 16-of-17 outputs contain spent_script directly, without a P2SH wrapper, so both descriptions should call them bare-script inputs. In the later P2SH case, each redeem script contains two 18-key multisig operations, each counted as 20 BIP54 sigops. The totals are therefore 2480 for 62 inputs and 2520 after appending the 63rd, not the nearby comments' 2400 and 2600. Update those totals and label the failing vector as 63 inputs. TestVectorSigops::GetJson() exports these descriptions unchanged, so the corrections also make the generated BIP vectors accurately explain their transactions.


Link

[suggestion] · The Taproot annex size vector lacks the annex tag

The synthetic Taproot-with-annex size vector has no annex tag, so its witness does not match the exported description even though its stripped-size verdict is correct.

Location: src/test/bip54_tests.cpp:1559 (head).

Details and suggested fix

For a Taproot prevout, [sig, 4242ffab2121] is interpreted as a script-path witness, with the six-byte final element failing the control-block size check. The size-vector test does not execute the input script, so that mismatch does not affect its assertions. Change the element to start with ANNEX_TAG, for example 5042ffab2121. This gives the advertised key-path-with-annex witness structure while preserving the element length and every stripped-size assertion.


Link

[suggestion] · The sigops fuzz target has no acceptance oracle

The bip54_sigops fuzz target discards the accounting result, so fuzzer-generated inputs cannot expose incorrect accept/reject decisions unless they also cause a crash.

Location: src/test/fuzz/bip54.cpp:53 (head).

Details and suggested fix

The decoder always creates non-null prevouts, so CheckSigopsBIP54's coinbase assertion cannot check the result either. Keep the seed format and compute a reference total over all inputs in a uint64_t, accumulating scriptSig.GetSigOpCount(true) and the spent scriptPubKey.GetSigOpCount(scriptSig) without early exit. Assert that the production result equals total <= MAX_TX_BIP54_SIGOPS. This makes aggregation, double-counting, and limit regressions observable on fuzzer-generated combinations, while still sharing and therefore not independently validating the counting helpers.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.