Implement BIP 54 (Consensus Cleanup) without mainnet activation #35793

Open
darosior wants to merge 22 commits from bip54 into master AGit
darosior commented 2026-07-24 14:18:35 +00:00 (Migrated from github.com)

This implements the Consensus Cleanup validation rules proposed in BIP 54. These rules are only enabled on regtest. Mainnet activation, if any, is to be considered separately.

This patchset is based on the code that was previously reviewed (1, 2) and tested (for instance here) on Bitcoin Inquisition. The tests and documentation have since been improved, but the consensus-critical commits have been carried over with only minor differences (the only behavioural one being the addition of the stripped-size check to PreChecks).

Roughly 95% of the added lines are tests or test data. The format, contents, and reproduction procedure for the BIP 54 test vectors are documented here. The bip54_tests unit test module exercises each mitigation extensively in isolation. The feature_bip54.py functional test verifies all of them end-to-end after and prior to activation. For the timestamp rules, it simulates timewarp and Murch–Zawy attacks, demonstrating the new timestamp rules prevent these exploits. A fuzz harness for the sigop accounting logic is also included, which can be seeded from the BIP test vectors (implemented here).

See commit messages for details.

This implements the Consensus Cleanup validation rules proposed in [BIP 54](https://github.com/bitcoin/bips/blob/master/bip-0054.md). These rules are only enabled on regtest. Mainnet activation, if any, is to be considered separately. This patchset is based on the code that was previously reviewed ([1](https://github.com/bitcoin-inquisition/bitcoin/pull/99), [2](https://github.com/bitcoin-inquisition/bitcoin/pull/110)) and tested (for instance [here](https://delvingbitcoin.org/t/consensus-cleanup-demo-of-slow-blocks-on-signet/2367)) on Bitcoin Inquisition. The tests and documentation have since been improved, but the consensus-critical commits have been carried over with only minor differences (the only behavioural one being the addition of the stripped-size check to `PreChecks`). Roughly 95% of the added lines are tests or test data. The format, contents, and reproduction procedure for the BIP 54 test vectors are documented [here](https://github.com/bitcoin/bips/tree/master/bip-0054/test_vectors). The `bip54_tests` unit test module exercises each mitigation extensively in isolation. The `feature_bip54.py` functional test verifies all of them end-to-end after and prior to activation. For the timestamp rules, it simulates timewarp and Murch–Zawy attacks, demonstrating the new timestamp rules prevent these exploits. A fuzz harness for the sigop accounting logic is also included, which can be seeded from the BIP test vectors (implemented [here](https://github.com/darosior/bitcoin/tree/bip54_seed_fuzz_corpus)). See commit messages for details.
DrahtBot commented 2026-07-24 14:18:43 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK instagibbs, nervana21, ViniciusCestarii, optout21, fanquake, theStack, ismaelsadeeq, polespinasa
Concept ACK dergoegge, hsjoberg, fjahr, stickies-v, 0xB10C
Stale ACK fametrano

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37006 (fuzz: add Silent Payments targets by devdavidejesus)
  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36847 (test: cover BIP30 for non coinbase txs by ViniciusCestarii)
  • #36455 (Test: Add legacy script edge case spender test by benthecarman)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #34864 (coins: tighten cache entry state invariants by l0rinc)
  • #32468 (rpc: generateblock to allow multiple outputs with custom payouts by polespinasa)
  • #29491 ([EXPERIMENTAL] Schnorr batch verification for blocks by fjahr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where comparison-specific test macros should replace generic comparisons:

  • test/functional/data/invalid_txs.py: assert len(tx.serialize_without_witness()) == 63 → Prefer assert_equal(len(tx.serialize_without_witness()), 63).
  • test/functional/data/invalid_txs.py: assert MIN_STANDARD_TX_NONWITNESS_SIZE - 1 == 64 → Prefer assert_equal(MIN_STANDARD_TX_NONWITNESS_SIZE - 1, 64).

2026-11-13 16:40:38

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35793 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35793.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35793#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [instagibbs](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-6859603224), [nervana21](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-6895180947), [ViniciusCestarii](https://github.com/bitcoin/bitcoin/pull/35793#pullrequestreview-5920611512), [optout21](https://github.com/bitcoin/bitcoin/pull/35793#pullrequestreview-5921434404), [fanquake](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-7170660097), [theStack](https://github.com/bitcoin/bitcoin/pull/35793#pullrequestreview-6075612975), [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/35793#pullrequestreview-6076845171), [polespinasa](https://github.com/bitcoin/bitcoin/pull/35793#pullrequestreview-6116954639) | | Concept ACK | [dergoegge](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-5119091655), [hsjoberg](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-5131035474), [fjahr](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-5153062504), [stickies-v](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-5220002904), [0xB10C](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-6186757010) | | Stale ACK | [fametrano](https://github.com/bitcoin/bitcoin/pull/35793#issuecomment-6394623793) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#37006](https://github.com/bitcoin/bitcoin/pull/37006) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37006.svg"></sub> (fuzz: add Silent Payments targets by devdavidejesus) * [#36990](https://github.com/bitcoin/bitcoin/pull/36990) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36990.svg"></sub> (test: replace hard-coded RPC error codes by l0rinc) * [#36847](https://github.com/bitcoin/bitcoin/pull/36847) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36847.svg"></sub> (test: cover BIP30 for non coinbase txs by ViniciusCestarii) * [#36455](https://github.com/bitcoin/bitcoin/pull/36455) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36455.svg"></sub> (Test: Add legacy script edge case spender test by benthecarman) * [#36122](https://github.com/bitcoin/bitcoin/pull/36122) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr) * [#34864](https://github.com/bitcoin/bitcoin/pull/34864) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34864.svg"></sub> (coins: tighten cache entry state invariants by l0rinc) * [#32468](https://github.com/bitcoin/bitcoin/pull/32468) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32468.svg"></sub> (rpc: generateblock to allow multiple outputs with custom payouts by polespinasa) * [#29491](https://github.com/bitcoin/bitcoin/pull/29491) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/29491.svg"></sub> ([EXPERIMENTAL] Schnorr batch verification for blocks by fjahr) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible places where comparison-specific test macros should replace generic comparisons: - `test/functional/data/invalid_txs.py`: `assert len(tx.serialize_without_witness()) == 63` → Prefer `assert_equal(len(tx.serialize_without_witness()), 63)`. - `test/functional/data/invalid_txs.py`: `assert MIN_STANDARD_TX_NONWITNESS_SIZE - 1 == 64` → Prefer `assert_equal(MIN_STANDARD_TX_NONWITNESS_SIZE - 1, 64)`. <sup>2026-11-13 16:40:38</sup>
DrahtBot commented 2026-07-24 14:43:50 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task macOS native: https://github.com/bitcoin/bitcoin/actions/runs/30100472888/job/89504946717
LLM reason (✨ experimental): CI failed because bip54_tests aborted on an assertion failure in CExtKey::SetSeed (seed.size() was outside the expected 16–64 byte range) during bip54_legacy_sigops.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `macOS native`: https://github.com/bitcoin/bitcoin/actions/runs/30100472888/job/89504946717</sub> <sub>LLM reason (✨ experimental): CI failed because `bip54_tests` aborted on an assertion failure in `CExtKey::SetSeed` (`seed.size()` was outside the expected 16–64 byte range) during `bip54_legacy_sigops`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
Christewart commented 2026-07-24 17:49:56 +00:00 (Migrated from github.com)

Congrats! Excited to see this work make it to this point 🎉

Congrats! Excited to see this work make it to this point 🎉
ariard (Migrated from github.com) reviewed 2026-07-29 02:50:48 +00:00
ariard (Migrated from github.com) left a comment

Let's start at least the review for the fix of the long validation block time.

Let's start at least the review for the fix of the long validation block time.
ariard (Migrated from github.com) commented 2026-07-29 02:38:02 +00:00

there could be a definition of what is understood as a "legacy signature ops" even if it's just echoing the bip doc, it's consensus/consensus.h where one can reasonably expect to find the definition of a "legacy signature" in opposition to signatures included in the witness for SegWit spends.

there could be a definition of what is understood as a "legacy signature ops" even if it's just echoing the bip doc, it's `consensus/consensus.h` where one can reasonably expect to find the definition of a "legacy signature" in opposition to signatures included in the witness for SegWit spends.
ariard (Migrated from github.com) commented 2026-07-29 02:49:50 +00:00

i was reading again the BIP part on the new CheckSigops limit and the computation price for each type of legacy checksig operations, i.e CHECKSIG counts as 1 signature operation, CHECKMULTISIG as 1 to 16 signature operation and (empty) CHECKMULTISIG as 20 signatures operation.

the asymmetry between OP_1 CHECKMULTISIG and (empty) CHECKMULTISIG sounds striking as the vbyte cost of a single CHECKMULTISIG is going to be 1 vbyte and the fee cost of a OP_1 CHECKMULTISIG, so in any collaborative txn among multi parties, one can force the tx to reach the new 2500 limit at a vbyte cost inferior rather than putting a OP_1 CHECKMULTISIG coming with a higher absolute vbyte cost, whatever the feerate.

curious if there is any rational somewhere in all the design notes, that's explaining that choice for the asymmetry in the legacy signature accounting for CHECKMULTISIG

i was reading again the BIP part on the new `CheckSigops` limit and the computation price for each type of legacy checksig operations, i.e `CHECKSIG` counts as 1 signature operation, `CHECKMULTISIG` as 1 to 16 signature operation and (empty) `CHECKMULTISIG` as 20 signatures operation. the asymmetry between `OP_1 CHECKMULTISIG` and (empty) `CHECKMULTISIG` sounds striking as the vbyte cost of a single `CHECKMULTISIG` is going to be 1 vbyte and the fee cost of a `OP_1 CHECKMULTISIG`, so in any collaborative txn among multi parties, one can force the tx to reach the new 2500 limit at a vbyte cost inferior rather than putting a `OP_1 CHECKMULTISIG` coming with a higher absolute vbyte cost, whatever the feerate. curious if there is any rational somewhere in all the design notes, that's explaining that choice for the asymmetry in the legacy signature accounting for `CHECKMULTISIG`
dergoegge commented 2026-07-29 14:25:55 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
fanquake commented 2026-07-30 10:20:53 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
polespinasa commented 2026-07-30 10:50:54 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
theStack commented 2026-07-30 12:41:23 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
hsjoberg commented 2026-07-30 12:50:45 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
darosior (Migrated from github.com) reviewed 2026-07-31 20:22:22 +00:00
darosior (Migrated from github.com) commented 2026-07-31 20:22:22 +00:00

Ok, i can replace with "non-Segwit signature operations". I've also checked all other instances of "legacy" in the diff here, and it's only used in tests, where the term is already present and i think fine to use.

Ok, i can replace with "non-Segwit signature operations". I've also checked all other instances of "legacy" in the diff here, and it's only used in tests, where the term is already present and i think fine to use.
fjahr commented 2026-08-01 19:31:35 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
fjahr (Migrated from github.com) reviewed 2026-08-03 08:36:28 +00:00
fjahr (Migrated from github.com) commented 2026-08-03 08:36:28 +00:00

The miner currently does not enforce the murch-zawy rule but I think it should. Suggested change along with a test: github.com/fjahr/bitcoin@edbc841eb5

The miner currently does not enforce the murch-zawy rule but I think it should. Suggested change along with a test: https://github.com/fjahr/bitcoin/commit/edbc841eb546b1c1c41cc6ed16021ddd7adb7b29
darosior (Migrated from github.com) reviewed 2026-08-03 14:28:15 +00:00
darosior (Migrated from github.com) commented 2026-08-03 14:28:15 +00:00

I considered it for #31376 and decided against because it's strictly theoretical. But your patch looks good. Could you PR it to master? This one is already large, and i think that commit can be merged on its own.

I considered it for #31376 and decided against because it's strictly theoretical. But your patch looks good. Could you PR it to master? This one is already large, and i think that commit can be merged on its own.
darosior (Migrated from github.com) reviewed 2026-08-04 21:24:05 +00:00
darosior (Migrated from github.com) commented 2026-08-04 21:24:05 +00:00

Absolutely, the rationale is to reuse BIP 16 accounting, instead of introducing another opcode counting method in consensus rules.

Absolutely, the rationale is to reuse BIP 16 accounting, instead of introducing another opcode counting method in consensus rules.
l0rinc (Migrated from github.com) reviewed 2026-08-06 22:53:03 +00:00
l0rinc (Migrated from github.com) commented 2026-08-06 21:52:40 +00:00

4a6b1c6 chainparams: add versionbits deployment for BIP 54:

I understand that the BIP mentions 2016/2015 because it describes mainnet's adjustment period. Since this PR applies the deployment only to regtest by default, could we adjust the BIP text, or add a note here to clarify that these values are derived from the network's adjustment period rather than fixed constants?

> [4a6b1c6](https://github.com/bitcoin/bitcoin/pull/35793/changes/4a6b1c6ffb598a5e96b678b8f9b0948182151857) _chainparams: add versionbits deployment for BIP 54_: I understand that the BIP mentions 2016/2015 because it describes mainnet's adjustment period. Since this PR applies the deployment only to regtest by default, could we adjust the BIP text, or add a note here to clarify that these values are derived from the network's adjustment period rather than fixed constants?
stickies-v commented 2026-08-07 17:16:12 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
ariard (Migrated from github.com) reviewed 2026-08-08 02:06:01 +00:00
ariard (Migrated from github.com) left a comment

Did a 1st read of the fix for long block validation time, I'll continue after the vacation.

Faut pas deconner c'est le mois d'aout.

Did a 1st read of the fix for long block validation time, I'll continue after the vacation. Faut pas deconner c'est le mois d'aout.
ariard (Migrated from github.com) commented 2026-08-08 01:57:28 +00:00

i would check the test before if it's covered though getting tortuous and valid control flow redeemScript with 10-depth OP_IF then the OP_CHECKSIG, then 10-depth OP_ENDIF, or with OP_ELSE to exerciser the consensus sigops script parser. not guarantee the fuzzer randomness might never yield a structured script for nested control flow.

i would check the test before if it's covered though getting tortuous and valid control flow redeemScript with 10-depth OP_IF then the OP_CHECKSIG, then 10-depth OP_ENDIF, or with OP_ELSE to exerciser the consensus sigops script parser. not guarantee the fuzzer randomness might never yield a structured script for nested control flow.
ariard (Migrated from github.com) commented 2026-08-08 02:03:37 +00:00

should this check be reflected in getblocktemplate given it's already caring about "sigoplimit", "weightlimit" etc. not infringing tx should be selected in the template and yield back in the template.

now of course, this check is enforced at tx mempool processing, so it should never appear in the template already, though having a sanitization check in getblocktemplate might good.

and there is the more transient aspect, than until BIP54 is activated a block is legit to have an infringing tx, even if it has been deployed as policy, though once it's activated, it should not be okay anymore (so don't go to produce an invalid block for the boundary block).

should this check be reflected in `getblocktemplate` given it's already caring about "sigoplimit", "weightlimit" etc. not infringing tx should be selected in the template and yield back in the template. now of course, this check is enforced at tx mempool processing, so it should never appear in the template *already*, though having a sanitization check in `getblocktemplate` might good. and there is the more transient aspect, than until BIP54 is activated a block is legit to have an infringing tx, even if it has been deployed as policy, though once it's activated, it should not be okay anymore (so don't go to produce an invalid block for the boundary block).
ariard (Migrated from github.com) commented 2026-08-08 02:05:02 +00:00

in fact it's a dumb nuisance attack vector for the few transition blocks during activation if the miners are running "lax" mempools. a tx might be okay at mempool reception, is stuck in the mempools, and even after few blocks is selected in a template rendering it invalid.

in fact it's a dumb nuisance attack vector for the few transition blocks during activation if the miners are running "lax" mempools. a tx might be okay at mempool reception, is stuck in the mempools, and even after few blocks is selected in a template rendering it invalid.
ariard (Migrated from github.com) commented 2026-08-08 01:47:13 +00:00

there could be a test for the case where the tx has 2501 sigops and as such is invalid per BIP54 new rule. to demonstrate the code is not doing < 2500 => good ; 2500 => not good ; > 2500 => good.

there might be a test for it elsewhere for the exact test vector. good to have it in the python framework.

there could be a test for the case where the tx has `2501 sigops` and as such is invalid per BIP54 new rule. to demonstrate the code is **not** doing < 2500 => good ; 2500 => not good ; > 2500 => good. there might be a test for it elsewhere for the exact test vector. good to have it in the python framework.
ariard (Migrated from github.com) reviewed 2026-08-08 02:25:35 +00:00
ariard (Migrated from github.com) commented 2026-08-08 02:25:35 +00:00

@darosior So I'm saying this because in fact before the fix for this class of vulnerabilities: https://bitcoincore.org/en/2025/10/24/disclose-cve-2025-46598/ one could have abuse the new 2500 sigops rule, at a lower marginal feerate cost.

Before https://github.com/bitcoin/bitcoin/pull/33050 a tx could have been executed twice, the first with standardness rule, the second with consensus check. An attacker could have done a marginal attack, where the tx would have had a huge OP_SHA256 element to hash and the minimal number of accounted for 20 OP_CHECKMULTISIG.

Therefore the transaction would have failed a first time on the standard check and then a second time on the consensus check with a reduced liquidity cost for the attacker (due to the lower feerate surface). and there was easy way to optimize the attack.

This one of the attack I did mention there even if never went to communicate it properly. I might have still have the python test vectors I played with at the time. Somehow the 20 OP_CHECKMULTISIG is a compact trick to render a tx invalid with the minimal of tx surface.

@darosior So I'm saying this because in fact before the fix for this class of vulnerabilities: https://bitcoincore.org/en/2025/10/24/disclose-cve-2025-46598/ one could have abuse the new 2500 sigops rule, at a lower marginal feerate cost. Before https://github.com/bitcoin/bitcoin/pull/33050 a tx could have been executed twice, the first with standardness rule, the second with consensus check. An attacker could have done a marginal attack, where the tx would have had a huge OP_SHA256 element to hash and the minimal number of accounted for 20 OP_CHECKMULTISIG. Therefore the transaction would have failed a first time on the standard check and then a second time on the consensus check with a reduced liquidity cost for the attacker (due to the lower feerate surface). and there was easy way to optimize the attack. This one of the attack I did mention [there](https://github.com/bitcoin/bips/pull/1800#issuecomment-2784299171) even if never went to communicate it properly. I might have still have the python test vectors I played with at the time. Somehow the 20 OP_CHECKMULTISIG is a compact trick to render a tx invalid with the minimal of tx surface.
darosior (Migrated from github.com) reviewed 2026-08-10 18:38:43 +00:00
darosior (Migrated from github.com) commented 2026-08-10 18:38:43 +00:00

I benchmarked the worst case processing time for various types of standard transactions back when i disclosed CVE-2025-46598. As far as i know the worst case for legacy transaction does not involve OP_SHA256. It does involve OP_CHECKMULTISIG, but not with the minimal amount of sigop accounted for (since you need it to actually do compute).

I am not sure what you are trying to get at. Could your point be related to this previous one you raised on the list?

I benchmarked the worst case processing time for various types of standard transactions back when i disclosed CVE-2025-46598. As far as i know the worst case for legacy transaction does not involve `OP_SHA256`. It does involve `OP_CHECKMULTISIG`, but not with the minimal amount of sigop accounted for (since you need it to actually do compute). I am not sure what you are trying to get at. Could your point be related to [this previous one](https://gnusha.org/pi/bitcoindev/[email protected]/) you raised on the list?
darosior (Migrated from github.com) reviewed 2026-08-10 19:01:36 +00:00
darosior (Migrated from github.com) commented 2026-08-10 19:01:36 +00:00

4a6b1c6 chainparams: add versionbits deployment for BIP 54:

I think your comment applies to the difficulty adjustment period values used by the timewarp and Murch-Zawy mitigations, not that commit (which sets a largely inconsequential dummy BIP 9 deployment for regtest), correct?

So i went and looked for a way to maybe clarify this for the code implementing those checks, but it's already pretty clear these values are derived from the network's adjustment period. Timewarp:

    // If the block is the first of a difficulty adjustment interval, check its timestamp against the previous
    // one to prevent timewarp attacks (see BIP 54).
    const int dai{static_cast<int>(consensusParams.DifficultyAdjustmentInterval())};
    const bool is_first_block{nHeight % dai == 0};
    if (is_first_block) {

Murch-Zawy:

    // Fix for the Murch-Zawy attack. See https://delvingbitcoin.org/t/zawy-s-alternating-timestamp-attack/1062 .
    // TL;DR: the duration of a retarget period must not be negative or the difficulty adjustment limit may be exploited to unduly
    // reduce difficulty similarly to the timewarp vulnerability. Along with the timewarp fix, this effectively makes retarget periods
    // monotonic (modulo the timewarp fix grace period).
    const bool is_last_block{nHeight % dai == dai - 1};
    if (is_last_block && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) {
        int first_height{nHeight - dai + 1};

Happy to consider any improvement to the comments there.

> [4a6b1c6](https://github.com/bitcoin/bitcoin/pull/35793/changes/4a6b1c6ffb598a5e96b678b8f9b0948182151857) _chainparams: add versionbits deployment for BIP 54_: I think your comment applies to the difficulty adjustment period values used by the timewarp and Murch-Zawy mitigations, not that commit (which sets a largely inconsequential dummy BIP 9 deployment for regtest), correct? So i went and looked for a way to maybe clarify this for the code implementing those checks, but it's already pretty clear these values are derived from the network's adjustment period. [Timewarp](https://github.com/darosior/bitcoin/blob/9630491bf2135d03dac586d3492cfca9939f6fbb/src/validation.cpp#L4117-L4121): ```cpp // If the block is the first of a difficulty adjustment interval, check its timestamp against the previous // one to prevent timewarp attacks (see BIP 54). const int dai{static_cast<int>(consensusParams.DifficultyAdjustmentInterval())}; const bool is_first_block{nHeight % dai == 0}; if (is_first_block) { ``` [Murch-Zawy](https://github.com/darosior/bitcoin/blob/9630491bf2135d03dac586d3492cfca9939f6fbb/src/validation.cpp#L4134-L4140): ```cpp // Fix for the Murch-Zawy attack. See https://delvingbitcoin.org/t/zawy-s-alternating-timestamp-attack/1062 . // TL;DR: the duration of a retarget period must not be negative or the difficulty adjustment limit may be exploited to unduly // reduce difficulty similarly to the timewarp vulnerability. Along with the timewarp fix, this effectively makes retarget periods // monotonic (modulo the timewarp fix grace period). const bool is_last_block{nHeight % dai == dai - 1}; if (is_last_block && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) { int first_height{nHeight - dai + 1}; ``` Happy to consider any improvement to the comments there.
darosior (Migrated from github.com) reviewed 2026-08-10 19:35:02 +00:00
darosior (Migrated from github.com) commented 2026-08-10 19:35:02 +00:00

Bound checking for sigops accounting is tested extensively in unit tests (d75143d393). I think it makes more sense for the integration tests to check higher-level boundaries, like for instance activation periods, than duplicate those tests.

Bound checking for sigops accounting is tested extensively in unit tests (d75143d39354d723c6a67a290dd03359841f2901). I think it makes more sense for the integration tests to check higher-level boundaries, like for instance activation periods, than duplicate those tests.
fjahr (Migrated from github.com) reviewed 2026-08-11 13:36:29 +00:00
fjahr (Migrated from github.com) commented 2026-08-11 13:36:29 +00:00

Done now here: #35949

Done now here: #35949
darosior (Migrated from github.com) reviewed 2026-08-11 15:43:26 +00:00
darosior (Migrated from github.com) commented 2026-08-11 15:43:26 +00:00

Yes, it's already an assumption we make that no invalid transaction make it to our mempool. Note how this commit changes two things in this regard:

  • The BIP 54 sigops check can't be bypassed anymore with -acceptnonstdtxs.
  • The mempool sanity checks now assert that it does not contain any transaction that violates the BIP 54 sigops rule.
Yes, it's already an assumption we make that no invalid transaction make it to our mempool. Note how this commit changes two things in this regard: - The BIP 54 sigops check can't be bypassed anymore with `-acceptnonstdtxs`. - The mempool sanity checks now assert that it does not contain any transaction that violates the BIP 54 sigops rule.
l0rinc (Migrated from github.com) reviewed 2026-08-12 21:59:37 +00:00
l0rinc (Migrated from github.com) commented 2026-08-12 21:59:37 +00:00

Yes, added the code comment to that line simply to demonstrate that regtest has a different difficulty adjustment period than what's documented in the BIP itself:

Given a block at height N:

  • if N % 2016 is equal to 0, the timestamp of the block must be set to a value higher than or
    equal to the value of the timestamp of block at height N-1 minus 7200 (TN ≥
    TN−1 − 7200);
  • if N % 2016 is equal to 2015, the timestamp of the block must be set to a value higher than
    or equal to the value of the timestamp of the block at height N-2015 (TN ≥
    TN−2015).

The code looks fine, was just wondering if we could update the BIP to make 2016 and 2015 variables, and in this PR draw attention to the fact that - strictly speaking - we're diverging from the BIP.

Yes, added the code comment to that line simply to demonstrate that regtest has a different difficulty adjustment period than what's documented in the BIP itself: > Given a block at height `N`: > - if `N % 2016` is equal to 0, the timestamp of the block must be set to a value higher than or > equal to the value of the timestamp of block at height `N-1` minus 7200 (T<sub>N</sub> &ge; > T<sub>N−1</sub> − 7200); >- if `N % 2016` is equal to 2015, the timestamp of the block must be set to a value higher than > or equal to the value of the timestamp of the block at height `N-2015` (T<sub>N</sub> &ge; > T<sub>N−2015</sub>). The code looks fine, was just wondering if we could update the BIP to make 2016 and 2015 variables, and in this PR draw attention to the fact that - strictly speaking - we're diverging from the BIP.
DrahtBot commented 2026-08-14 17:50:27 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
polespinasa (Migrated from github.com) reviewed 2026-08-24 11:05:55 +00:00
polespinasa (Migrated from github.com) left a comment

Did a swift first read to the code (skipping test code) while preparing for the PR review club.
The code looks pretty good, just left a comment. Will re-review again in more detail.

Did a swift first read to the code (skipping test code) while preparing for the PR review club. The code looks pretty good, just left a comment. Will re-review again in more detail.
polespinasa (Migrated from github.com) commented 2026-08-24 10:48:49 +00:00

in 29d1f3fd45 validation: make BIP54 sigops check consensus-critical

This signals the state as TX_CONSENSUS even if this is a policy check.
Does not affect in debug/log messages or the rejected reason message, but feels weird to miss-categorize it.

If we care about this, could set a three value struct{consensus, policy, ignore} and set the state according to it.

in 29d1f3fd458acf67830948707c483942dff56778 validation: make BIP54 sigops check consensus-critical This signals the state as TX_CONSENSUS even if this is a policy check. Does not affect in debug/log messages or the rejected reason message, but feels weird to miss-categorize it. If we care about this, could set a three value struct{consensus, policy, ignore} and set the state according to it.
polespinasa (Migrated from github.com) reviewed 2026-08-25 15:32:09 +00:00
polespinasa (Migrated from github.com) commented 2026-08-25 15:32:09 +00:00

in 67ebb0d57d validation: prevent timewarp attacks with a 2h grace period

nit: max_timewarp.has_value() ?

in 67ebb0d57d9eaf4e1998733c8d818dafd0422791 validation: prevent timewarp attacks with a 2h grace period nit: `max_timewarp.has_value()` ?
ariard (Migrated from github.com) reviewed 2026-09-10 00:09:45 +00:00
ariard (Migrated from github.com) left a comment

started to review the timewarp fix.

started to review the timewarp fix.
ariard (Migrated from github.com) commented 2026-09-10 00:06:24 +00:00

the comment could be "strictly inferior" which is more defined mathematically than "must not be more than 2 hours", where you never know if = is included, at least imho

the comment could be "strictly inferior" which is more defined mathematically than "must not be more than 2 hours", where you never know if `=` is included, at least imho
ariard (Migrated from github.com) commented 2026-09-09 23:52:49 +00:00

I think the description comment can be adjusted above to say it's only applied to testnet4 and not to signet, regtest, testnet3 (I guess from the enforce_BIP94).

I think the description comment can be adjusted above to say it's only applied to testnet4 and not to signet, regtest, testnet3 (I guess from the `enforce_BIP94`).
ariard (Migrated from github.com) commented 2026-09-10 00:08:57 +00:00

BLOCK_INVALID_HEADER comment in src/consensus/validation.h could be updated to include "invalid proof of work or time too old".

`BLOCK_INVALID_HEADER` comment in `src/consensus/validation.h` could be updated to include "invalid proof of work or time too old".
ariard (Migrated from github.com) reviewed 2026-09-10 00:16:20 +00:00
ariard (Migrated from github.com) commented 2026-09-10 00:16:20 +00:00

Okay if -acceptnonstdtxs effect starts to kickoff as short as there is a release including this code, I think this is limiting the risk surface for transaction blocks that could violate the rule by accident.

I'll re-check that.

Okay if `-acceptnonstdtxs` effect starts to kickoff as short as there is a release including this code, I think this is limiting the risk surface for transaction blocks that could violate the rule by accident. I'll re-check that.
ariard (Migrated from github.com) reviewed 2026-09-10 00:25:40 +00:00
ariard (Migrated from github.com) commented 2026-09-10 00:25:40 +00:00

I am not sure what you are trying to get at. Could your point be related to this previous one you raised on the list?

No it's something quite different. What I'm talking about in the present issue, it was relying on crafting small weight unit transaction to provoke the most of OP_SHA256 (it's less expensive than sigs, but it's still consuming some CPU cycles) during a validation, and therefore the smallest cost.

Note, it was strictly before #33050 that I did the test. It's not only the worst-case in CPU time to consider it's for a minimal mempool min fee, what's the average satoshis liquidity must avails to consume useless CPU cycles. I'll find back my notes on this and come back to you.

> I am not sure what you are trying to get at. Could your point be related to [this previous one](https://gnusha.org/pi/bitcoindev/[email protected]/) you raised on the list? No it's something quite different. What I'm talking about in the present issue, it was relying on crafting small weight unit transaction to provoke the most of `OP_SHA256` (it's less expensive than sigs, but it's still consuming some CPU cycles) during a validation, and therefore the smallest cost. Note, it was strictly before #33050 that I did the test. It's not only the worst-case in CPU time to consider it's for a minimal mempool min fee, what's the average satoshis liquidity must avails to consume useless CPU cycles. I'll find back my notes on this and come back to you.
darosior (Migrated from github.com) reviewed 2026-09-11 22:59:03 +00:00
darosior (Migrated from github.com) commented 2026-09-11 22:59:03 +00:00

I think the BIP should always optimize to be maximally clear for mainnet. When it does not affect clarity of the mainnet specifications, diverging values for public test networks may be integrated in the BIP (probably in a separate section). I don't think the values for a Bitcoin Core specific local test network should be mentioned in the BIP.

I think the BIP should always optimize to be maximally clear for mainnet. When it does not affect clarity of the mainnet specifications, diverging values for public test networks may be integrated in the BIP (probably in a separate section). I don't think the values for a Bitcoin Core specific local test network should be mentioned in the BIP.
darosior (Migrated from github.com) reviewed 2026-09-11 23:05:44 +00:00
darosior (Migrated from github.com) commented 2026-09-11 23:05:44 +00:00

What are you suggesting doing here? I agree code coverage guidance is sometimes lacking when fuzzing stateful logic. I think we can improve things a little with tweaks like Libfuzzer's extra counters. I had briefly looked into it in the past, and may pick it up in the future, but this improvement is largely orthogonal to this PR.

What are you suggesting doing here? I agree code coverage guidance is sometimes lacking when fuzzing stateful logic. I think we can improve things a little with tweaks like Libfuzzer's extra counters. I had briefly looked into it in the past, and may pick it up in the future, but this improvement is largely orthogonal to this PR.
darosior (Migrated from github.com) reviewed 2026-09-11 23:21:11 +00:00
darosior (Migrated from github.com) commented 2026-09-11 23:21:11 +00:00

I went back and forth on this. I ended up picking the current version because the error type is not used to choose whether to disconnect a peer anymore, nor exposed to the user.

Making the error depend on the activation status would only change the error string on RPC errors from "bad-txns-legacy-sigops"/"txn-size-64" to "bad-txns-nonstandard-inputs"/"tx-size-small" prior to activation. I have implemented this in https://github.com/bitcoin-inquisition/bitcoin/pull/118 before, but ended up discarding it because i don't think it is worth introducing more complexity and divergence from what has been tested on Inquisition just for this.

See this comment and the comments it links to for more details.

I went back and forth on this. I ended up picking the current version because the error type is not used to choose whether to disconnect a peer anymore, nor exposed to the user. Making the error depend on the activation status would only change the error string on RPC errors from "bad-txns-legacy-sigops"/"txn-size-64" to "bad-txns-nonstandard-inputs"/"tx-size-small" prior to activation. I have implemented this in https://github.com/bitcoin-inquisition/bitcoin/pull/118 before, but ended up discarding it because i don't think it is worth introducing more complexity and divergence from what has been tested on Inquisition just for this. See [this comment](https://github.com/bitcoin-inquisition/bitcoin/pull/118#issuecomment-5060191875) and the comments it links to for more details.
darosior (Migrated from github.com) reviewed 2026-09-11 23:25:27 +00:00
darosior (Migrated from github.com) commented 2026-09-11 23:25:27 +00:00

If i did that it would make sense to change the dereference to a max_timewarp.value() as well and together it makes the line unnecessarily long, in my opinion.

I did check and in the entire diff of this PR there is no use of has_value()/value(), so that change also can't be justified on consistency grounds.

For these reasons and because this is just a style nit, i'll keep it like that and resolve this comment.

If i did that it would make sense to change the dereference to a `max_timewarp.value()` as well and together it makes the line unnecessarily long, in my opinion. I did check and in the entire diff of this PR there is no use of `has_value()`/`value()`, so that change also can't be justified on consistency grounds. For these reasons and because this is just a style nit, i'll keep it like that and resolve this comment.
polespinasa (Migrated from github.com) reviewed 2026-09-12 06:10:58 +00:00
polespinasa (Migrated from github.com) commented 2026-09-12 06:10:58 +00:00

Then a comment in the code could be usefull, to not create confusion with the consensus word

Then a comment in the code could be usefull, to not create confusion with the `consensus` word
darosior (Migrated from github.com) reviewed 2026-09-13 19:39:14 +00:00
darosior (Migrated from github.com) commented 2026-09-13 19:39:14 +00:00

The constant was renamed with a TESTNET4 a suffix with the purpose of making it clear it's only used for testnet4. I think adding it to the description too would be redundant because it already mentions BIP 94 (which defines BIP 94), and because it's in the name of the constant already.

The constant was renamed with a TESTNET4 a suffix with the purpose of making it clear it's only used for testnet4. I think adding it to the description too would be redundant because it already mentions BIP 94 (which defines BIP 94), and because it's in the name of the constant already.
darosior (Migrated from github.com) reviewed 2026-09-13 19:54:10 +00:00
darosior (Migrated from github.com) commented 2026-09-13 19:54:10 +00:00

"No more" pretty explicitly means it can be equal, just not more. But fair enough, i updated the comment to use "superior or equal" language, and took the opportunity to define it positively "must be superior or equal to" rather than negatively "must not be inferior or equal".

"No more" pretty explicitly means it can be equal, just not more. But fair enough, i updated the comment to use "superior or equal" language, and took the opportunity to define it positively "must be superior or equal to" rather than negatively "must not be inferior or equal".
darosior (Migrated from github.com) reviewed 2026-09-13 19:58:56 +00:00
darosior (Migrated from github.com) commented 2026-09-13 19:58:56 +00:00
This is already what the comment says: https://github.com/bitcoin/bitcoin/blob/17817818da3cb67c95320b7a5d4d69bd649c1fbf/src/consensus/validation.h#L68
darosior (Migrated from github.com) reviewed 2026-09-13 20:22:09 +00:00
darosior (Migrated from github.com) commented 2026-09-13 20:22:09 +00:00

Sure. I gave the rationale for this decision in the commit message though, because i could not find a satisfactory place where to put a comment about it.

Sure. I gave the rationale for this decision in the commit message though, because i could not find a satisfactory place where to put a comment about it.
darosior (Migrated from github.com) reviewed 2026-09-13 20:58:18 +00:00
darosior (Migrated from github.com) commented 2026-09-13 20:58:18 +00:00

Rebased now that #35949 is merged.

Rebased now that #35949 is merged.
darosior commented 2026-09-13 21:00:35 +00:00 (Migrated from github.com)

Addressed all outstanding comments and rebased on master. The most significant change is the modification of the test introduced in 6e60c362bc to use BIP54-valid blocks, prior to enforcing the sigops rule by consensus.

Addressed all outstanding comments and rebased on master. The most significant change is the modification of the test introduced in 6e60c362bc1e373a284911381e2a513f57f5f26b to use BIP54-valid blocks, prior to enforcing the sigops rule by consensus.
DrahtBot commented 2026-09-13 21:04:23 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/34782490024/job/103791923572
LLM reason (✨ experimental): CI failed due to a Python lint (ruff) error: test_framework.script_util.MAX_TX_BIP54_SIGOPS is imported but unused in test/functional/p2p_segwit.py.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/34782490024/job/103791923572</sub> <sub>LLM reason (✨ experimental): CI failed due to a Python lint (ruff) error: `test_framework.script_util.MAX_TX_BIP54_SIGOPS` is imported but unused in `test/functional/p2p_segwit.py`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
nervana21 commented 2026-09-21 20:23:23 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
DrahtBot commented 2026-09-24 01:12:37 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-09-25 16:41:28 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/36150952253/job/108123775607
LLM reason (✨ experimental): CI failed because ipc_tests crashed with a kj::ExceptionImpl timer error (“can't advance backwards in time”), aborting the subprocess.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `ASan + LSan + UBSan + integer`: https://github.com/bitcoin/bitcoin/actions/runs/36150952253/job/108123775607</sub> <sub>LLM reason (✨ experimental): CI failed because `ipc_tests` crashed with a `kj::ExceptionImpl` timer error (“can't advance backwards in time”), aborting the subprocess.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
ariard commented 2026-09-29 00:07:59 +00:00 (Migrated from github.com)

With recent actualities, I was musing if there can be issues with the caches, including the disconnectpool one with the novel consensus rules, especially for the new sigops limit and the proposed 64-byte size tx inclusion. I don't think there is issues with MaybeUpdateMempoolForReorg, including if there is a reorg on the transient block of consensus rules activation, as there is a PolicyChecks done at some point.

Same with the cache as they're either script-indexed (m_script_execution_cache) or signature-indexed (m_signature_cache) and all the new checks are at the tx-level. I don't remember to have seen test coverage for all those edge cases, even if it's to demonstrate there is no unexpected interactions, though I'll re-check that. Better safe than not safe.

With recent actualities, I was musing if there can be issues with the caches, including the `disconnectpool` one with the novel consensus rules, especially for the new sigops limit and the proposed 64-byte size tx inclusion. I don't think there is issues with `MaybeUpdateMempoolForReorg`, including if there is a reorg on the transient block of consensus rules activation, as there is a `PolicyChecks` done at some point. Same with the cache as they're either script-indexed (`m_script_execution_cache`) or signature-indexed (`m_signature_cache`) and all the new checks are at the tx-level. I don't remember to have seen test coverage for all those edge cases, even if it's to demonstrate there is no unexpected interactions, though I'll re-check that. Better safe than not safe.
First-time contributor

6 additional verified findings in the Review report.

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

🟠 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).

🟠 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).

🟠 Minor · Clarify whether the first post-activation retarget checks the preceding interval

The negative-interval check at src/validation.cpp:4131 runs only on a period's last block, and only once BIP54 is active. The interval just before activation is never checked, yet it sets the first post-activation retarget. Every soft fork has this property, and rejecting the first active block based on pre-activation history could leave the chain with no valid successor.

Location: src/validation.cpp:4130 (head).

🟠 Minor · Always-active BIP54 removes valid-block coverage from two fuzz targets

Making BIP54 always active on regtest leaves two unchanged regtest fuzz targets building invalid blocks:

  • utxo_total_supply resets every prepared coinbase's nLockTime to 0 on purpose, so it can duplicate one later. Its chain cannot grow past height 1, so the BIP30 duplicate-coinbase and deeper supply/CVE-2018-17144 paths stop being exercised.
  • cmpctblock builds every new coinbase with nLockTime 0 and the default final sequence. Those blocks never reach the valid-block branch that selects high-bandwidth peers.

Location: src/test/fuzz/utxo_total_supply.cpp:57 (head).

🔵 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).

🔵 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).

Review coverage was incomplete.


Reviewed: 3f0f142b1d0d · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:f3e06854f254c480580a263b00f5c6aaa804717e751da362d6c3a17a8fae78d3:eaa37ea1cdada8fdd806ab11180fd9e0f01062422d9d8c5ea7dcfd80d5014b95 --> <!-- ralph-base:791173ae952bb07716531dd01a78d70dc3b7c038 --> <!-- ralph-head:3f0f142b1d0d08a18152d6b100e12d1abf09d58e --> <!-- ralph-case:e5a7acbcf66a1cd854eb16a1ea63947a93bdac0035d4213ce48f5826b7dda3e5 --> [6 additional verified findings in the Review report](<https://review.fish.foo/report/35793-3f0f142b1d0d08a18152d6b100e12d1abf09d58e-2584-12.html>). Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e/src/consensus/tx_verify.cpp#L205>) (head). **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e/src/test/bip54_tests.cpp#L1060>) (head). **🟠 Minor · Clarify whether the first post-activation retarget checks the preceding interval** The negative-interval check at src/validation.cpp:4131 runs only on a period's last block, and only once BIP54 is active. The interval just before activation is never checked, yet it sets the first post-activation retarget. Every soft fork has this property, and rejecting the first active block based on pre-activation history could leave the chain with no valid successor. Location: [`src/validation.cpp:4130`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e/src/validation.cpp#L4130>) (head). **🟠 Minor · Always-active BIP54 removes valid-block coverage from two fuzz targets** Making BIP54 always active on regtest leaves two unchanged regtest fuzz targets building invalid blocks: - `utxo_total_supply` resets every prepared coinbase's `nLockTime` to 0 on purpose, so it can duplicate one later. Its chain cannot grow past height 1, so the BIP30 duplicate-coinbase and deeper supply/CVE-2018-17144 paths stop being exercised. - `cmpctblock` builds every new coinbase with `nLockTime` 0 and the default final sequence. Those blocks never reach the valid-block branch that selects high-bandwidth peers. Location: [`src/test/fuzz/utxo_total_supply.cpp:57`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e/src/test/fuzz/utxo_total_supply.cpp#L57>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e/src/kernel/chainparams.cpp#L639>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e/test/functional/mempool_sigoplimit.py#L231>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`3f0f142b1d0d`](<https://git.fish.foo/bitcoin/bitcoin/commit/3f0f142b1d0d08a18152d6b100e12d1abf09d58e>) · [Review report](<https://review.fish.foo/report/35793-3f0f142b1d0d08a18152d6b100e12d1abf09d58e-2584-12.html>) · [Previous reports](<https://review.fish.foo/traces/35793/>) [permalink](<https://review.fish.foo/report/35793-3f0f142b1d0d08a18152d6b100e12d1abf09d58e-2584-12.html>)
0xB10C commented 2026-10-15 07:20:59 +00:00 (Migrated from github.com)

Concept ACK on implementing BIP 54 code and functionality here without mainnet activation to have it available.

I don't think I have the expertise nor the bandwidth to review this in detail soon.

Concept ACK on implementing BIP 54 code and functionality here without mainnet activation to have it available. I don't think I have the expertise nor the bandwidth to review this in detail soon.
murchandamus (Migrated from github.com) reviewed 2026-10-20 22:27:13 +00:00
murchandamus (Migrated from github.com) left a comment

I gave this a first read. The PR structure works well, it was easy to follow each commit. The consensus rules appear to match the BIP, I still have to look at the tests more closely.

I gave this a first read. The PR structure works well, it was easy to follow each commit. The consensus rules appear to match the BIP, I still have to look at the tests more closely.
murchandamus (Migrated from github.com) commented 2026-10-20 22:11:08 +00:00

Nit: I think “greater” is more common in this expression:

 * Under BIP54, the timestamp of the first block in a difficulty adjustment period must be greater
 * or equal to the timestamp of the last block of the previous period minus two hours (7200 seconds).
Nit: I think “greater” is more common in this expression: ```suggestion * Under BIP54, the timestamp of the first block in a difficulty adjustment period must be greater * or equal to the timestamp of the last block of the previous period minus two hours (7200 seconds). ```
murchandamus (Migrated from github.com) commented 2026-10-16 04:15:57 +00:00

Given that Genesis blocks of chains are hardcoded, should it be active for the Genesis block? Wouldn’t height 1 make more sense?

Given that Genesis blocks of chains are hardcoded, should it be active for the Genesis block? Wouldn’t height 1 make more sense?
murchandamus (Migrated from github.com) commented 2026-10-20 20:29:17 +00:00

In "Avoid creating <= 64-byte transactions in most functional tests" (f09286f609):
I was trying to figure out why the output script padding is necessary.
My explanation is that the coinbase field ("input script" of the coinbase transaction) must have at least 2 bytes, which means that the input has at least 43 bytes (36+4+1+2), the transaction header is 10 bytes, output amount is 8 bytes, output script length is 1 byte. Thus, to guarantee at least 65 bytes, the output script needs to have at least three bytes.

In "Avoid creating <= 64-byte transactions in most functional tests" (f09286f6095672c9462d99f1d616fba991efd630): I was trying to figure out why the output script padding is necessary. My explanation is that the coinbase field ("input script" of the coinbase transaction) must have at least 2 bytes, which means that the input has at least 43 bytes (36+4+1+2), the transaction header is 10 bytes, output amount is 8 bytes, output script length is 1 byte. Thus, to guarantee at least 65 bytes, the output script needs to have at least three bytes.
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-21 17:03:11 +00:00
ViniciusCestarii (Migrated from github.com) left a comment

Concept ACK

Reviewed commits up to 2afc853fc2, left a couple of comments. The commits are well structured so far. I plan to review the rest later.

Concept ACK Reviewed commits up to 2afc853fc2ac79bae789985c747f7292f3cd049d, left a couple of comments. The commits are well structured so far. I plan to review the rest later.
ViniciusCestarii (Migrated from github.com) commented 2026-10-21 14:58:00 +00:00

In "validation: make BIP54 sigops check consensus-critical" 2afc853fc2

The following mutant passes all test suite:

-    if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees, /*enforce_bip54=*/true)) {
+    if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees, /*enforce_bip54=*/DeploymentActiveAfter(m_active_chainstate.m_chain.Tip(), m_active_chainstate.m_chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP))) {

Since regtest has BIP54 always active and test_legacy_sigops_stdness now only covers post-activation and feature_bip54.py only checks block acceptance pre-activation. Nothing covers the pre-activation mempool rejection anymore, which is the rule in effect on mainnet until activation.

Maybe add a testmempoolaccept rejection (bad-txns-legacy-sigops) for the many-sigops tx in the pre-activation section of feature_bip54.py? Running it with -acceptnonstdtxn=1 would also cover the new behaviour that the check can't be bypassed with that option.

In "validation: make BIP54 sigops check consensus-critical" 2afc853fc2ac79bae789985c747f7292f3cd049d The following mutant passes all test suite: ```diff - if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees, /*enforce_bip54=*/true)) { + if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees, /*enforce_bip54=*/DeploymentActiveAfter(m_active_chainstate.m_chain.Tip(), m_active_chainstate.m_chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP))) { ``` Since regtest has BIP54 always active and `test_legacy_sigops_stdness` now only covers post-activation and `feature_bip54.py` only checks block acceptance pre-activation. Nothing covers the pre-activation mempool rejection anymore, which is the rule in effect on mainnet until activation. Maybe add a `testmempoolaccept` rejection (`bad-txns-legacy-sigops`) for the many-sigops tx in the pre-activation section of `feature_bip54.py`? Running it with `-acceptnonstdtxn=1` would also cover the new behaviour that the check can't be bypassed with that option.
ViniciusCestarii (Migrated from github.com) commented 2026-10-21 14:20:39 +00:00

In "validation: make BIP54 sigops check consensus-critical" 2afc853fc2

nit: now that this checks invalidity rather than non-standardness test_legacy_sigops_stdness / nonstd_tx / std_tx are misleading. Maybe test_legacy_sigops_limit / invalid_tx / valid_tx?

In "validation: make BIP54 sigops check consensus-critical" 2afc853fc2ac79bae789985c747f7292f3cd049d nit: now that this checks invalidity rather than non-standardness test_legacy_sigops_stdness / nonstd_tx / std_tx are misleading. Maybe test_legacy_sigops_limit / invalid_tx / valid_tx?
instagibbs (Migrated from github.com) reviewed 2026-10-21 17:03:19 +00:00
instagibbs (Migrated from github.com) left a comment

reviewed through fa6b7a7480

Logic matches up with the inquisition branch I reviewed, with a few differences:

  1. Deployment writing, which differs from heretical deployments
  2. mempool handling of 64-byte tx (AFAICT biggest difference is we wont add txid to recent reject filter?)
  3. comments

Ran a set of mutation tests focusing on things like off-by-one errors, only thing that wasn't killed was a test where rules are enforced one block late, for each rule. Bot implemented a throwaway test for that and passed.

Mutant list and results

Sigops

# Mutation Caught by
1 sigops >= 2500 instead of > U P F
31 limit 2501 U P F
2 scriptSig counted with fAccurate=false U P
4 scriptSig not counted U P F
3 prevout spk counted with GetSigOpCount(true) (no P2SH redeemScript) U P F
30 prevout spk not counted U P F
5 ConnectBlock never enforces P F
6 ConnectBlock always enforces (ungated) P F
33 ConnectBlock gating one block late P
22 mempool enforce_bip54=false F

Timewarp

# Mutation Caught by
8 grace 7199 U P
9 grace 7201 U P
10 <= instead of < U P F
7 ungated U P F
36 gating one block late P
23 BIP94 600s precedence dropped F
24 check removed U P F

Murch-Zawy

# Mutation Caught by
11 <= instead of < U P F
12 first_height = nHeight - dai + 2 U P F
13 first_height = nHeight - dai (Assert crash) U P F
14 last block at nHeight % dai == dai - 2 (Assert crash) U P F
15 ungated U P F
37 gating one block late none (can't change behaviour: BIP9 period == retarget interval)
25 check removed U P F

Coinbase

# Mutation Caught by
16 require nLockTime == nHeight U P F
29 require nLockTime == nHeight - 2 U P F
17 nSequence check dropped U P
18 ungated P F
34 gating one block late P
28 check removed U P F

64-byte transactions

# Mutation Caught by
27 checks 65 instead of 64 U P F
20 skips the coinbase F
19 ungated U P F
35 gating one block late P
26 check removed U P F
21 mempool TX_CONSENSUS branch removed (back to tx-size-small) F

Minor comments only

reviewed through fa6b7a7480a332f84f8ceba4393ee99ea960b8c3 Logic matches up with the inquisition branch I reviewed, with a few differences: 1. Deployment writing, which differs from heretical deployments 2. mempool handling of 64-byte tx (AFAICT biggest difference is we wont add txid to recent reject filter?) 3. comments Ran a set of mutation tests focusing on things like off-by-one errors, only thing that wasn't killed was a test where rules are enforced *one block late, for each rule*. Bot implemented a throwaway test for that and passed. <details> <summary>Mutant list and results</summary> **Sigops** | # | Mutation | Caught by | |---|---|---| | 1 | `sigops >= 2500` instead of `>` | U P F | | 31 | limit 2501 | U P F | | 2 | scriptSig counted with `fAccurate=false` | U P | | 4 | scriptSig not counted | U P F | | 3 | prevout spk counted with `GetSigOpCount(true)` (no P2SH redeemScript) | U P F | | 30 | prevout spk not counted | U P F | | 5 | ConnectBlock never enforces | P F | | 6 | ConnectBlock always enforces (ungated) | P F | | 33 | ConnectBlock gating one block late | P | | 22 | mempool `enforce_bip54=false` | F | **Timewarp** | # | Mutation | Caught by | |---|---|---| | 8 | grace 7199 | U P | | 9 | grace 7201 | U P | | 10 | `<=` instead of `<` | U P F | | 7 | ungated | U P F | | 36 | gating one block late | P | | 23 | BIP94 600s precedence dropped | F | | 24 | check removed | U P F | **Murch-Zawy** | # | Mutation | Caught by | |---|---|---| | 11 | `<=` instead of `<` | U P F | | 12 | `first_height = nHeight - dai + 2` | U P F | | 13 | `first_height = nHeight - dai` (Assert crash) | U P F | | 14 | last block at `nHeight % dai == dai - 2` (Assert crash) | U P F | | 15 | ungated | U P F | | 37 | gating one block late | none (can't change behaviour: BIP9 period == retarget interval) | | 25 | check removed | U P F | **Coinbase** | # | Mutation | Caught by | |---|---|---| | 16 | require `nLockTime == nHeight` | U P F | | 29 | require `nLockTime == nHeight - 2` | U P F | | 17 | nSequence check dropped | U P | | 18 | ungated | P F | | 34 | gating one block late | P | | 28 | check removed | U P F | **64-byte transactions** | # | Mutation | Caught by | |---|---|---| | 27 | checks 65 instead of 64 | U P F | | 20 | skips the coinbase | F | | 19 | ungated | U P F | | 35 | gating one block late | P | | 26 | check removed | U P F | | 21 | mempool TX_CONSENSUS branch removed (back to `tx-size-small`) | F | </details> Minor comments only
instagibbs (Migrated from github.com) commented 2026-10-21 14:36:40 +00:00

fa6b7a7480

v33* 🤞

fa6b7a7480a332f84f8ceba4393ee99ea960b8c3 v33* 🤞
instagibbs (Migrated from github.com) commented 2026-10-21 14:07:18 +00:00

b52976de09

Commit message could be pedantic and say it's already the bip54 sigops limit. I'd forgotten it was already the case and was confused

b52976de09edad1078866ca2381e65f2bc5f4690 Commit message could be pedantic and say it's already the bip54 sigops limit. I'd forgotten it was already the case and was confused
instagibbs (Migrated from github.com) commented 2026-10-21 14:30:45 +00:00

d2094c8f48

Since DEPLOYMENT_HEIGHTINCB check above would already violate this, do we want to do this assert near the top of CheckContextualBlock?

d2094c8f48e9b3cff5f4ce2631cb92fcaa9201eb Since DEPLOYMENT_HEIGHTINCB check above would already violate this, do we want to do this assert near the top of CheckContextualBlock?
instagibbs (Migrated from github.com) commented 2026-10-21 14:32:39 +00:00

f09286f609

self-documenting assert on witness-stripped serialization before returning the coinbase?

f09286f6095672c9462d99f1d616fba991efd630 self-documenting assert on witness-stripped serialization before returning the coinbase?
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:04 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:04 +00:00

The ALWAYS_ACTIVE start time always takes priority, so while it can't be validated on the genesis block, changing this value would just be an aesthetic change (which i'd rather not make because it would be misleading). Also, min activation height is merely a lower bound on the transition from LOCKED_IN to ACTIVE, so setting it to 0 would not prevent validation on the genesis block.

The ALWAYS_ACTIVE start time always takes priority, so while it can't be validated on the genesis block, changing this value would just be an aesthetic change (which i'd rather not make because it would be misleading). Also, min activation height is merely a lower bound on the transition from LOCKED_IN to ACTIVE, so setting it to 0 would not prevent validation on the genesis block.
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:38 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:38 +00:00

Yes, that looks correct to me.

Yes, that looks correct to me.
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:43 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:43 +00:00

Done, thanks.

Done, thanks.
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:49 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:49 +00:00

Updating the comments to say "invalid" was a compromise between a larger diff and being too misleading. I think it's fine if the variable / test names stay as the comments are updated. I'm also happy to go all the way if you feel strongly.

Updating the comments to say "invalid" was a compromise between a larger diff and being too misleading. I think it's fine if the variable / test names stay as the comments are updated. I'm also happy to go all the way if you feel strongly.
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:51 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:51 +00:00

The following mutant passes all test suite

But isn't this expected, since DeploymentActiveAfter is always true for regtest?

Nothing covers the pre-activation mempool rejection anymore, which is the rule in effect on mainnet until activation.

On mainnet before activation, the mempool rejection is the one tested here: "bad-txns-legacy-sigops".

> The following mutant passes all test suite But isn't this expected, since `DeploymentActiveAfter` is always `true` for regtest? > Nothing covers the pre-activation mempool rejection anymore, which is the rule in effect on mainnet until activation. On mainnet before activation, the mempool rejection is the one tested here: "bad-txns-legacy-sigops".
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:55 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:55 +00:00

The title already reads "rename BIP54-sigops constants", but sure, added a sentence to this effect in the body.

The title already reads "rename BIP54-sigops constants", but sure, added a sentence to this effect in the body.
darosior (Migrated from github.com) reviewed 2026-10-22 20:13:57 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:13:57 +00:00

Makes sense, done.

Makes sense, done.
darosior (Migrated from github.com) reviewed 2026-10-22 20:14:01 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:14:01 +00:00

Meh, if that didn't hold, tests using this would all fail anyways.

Meh, if that didn't hold, tests using this would all fail anyways.
darosior (Migrated from github.com) reviewed 2026-10-22 20:14:04 +00:00
darosior (Migrated from github.com) commented 2026-10-22 20:14:04 +00:00

Updated. :)

Updated. :)
instagibbs commented 2026-10-22 20:20:48 +00:00 (Migrated from github.com)
ACK https://github.com/bitcoin/bitcoin/pull/35793/commits/3f0f142b1d0d08a18152d6b100e12d1abf09d58e Minor changes only, including hte `Assert()` move in `CheckContextualBlock`
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-22 21:32:49 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-10-22 21:32:49 +00:00

But isn't this expected, since DeploymentActiveAfter is always true for regtest?

Yes, on regtest, but the mutant changes behaviour on mainnet before activation and no test catches that.

On mainnet before activation, the mempool rejection is the one tested here: "bad-txns-legacy-sigops".

The unit test calls CheckTxInputs directly with a hardcoded enforce_bip54=true, bypassing what PreChecks passes.

> But isn't this expected, since `DeploymentActiveAfter` is always `true` for regtest? Yes, on regtest, but the mutant changes behaviour on mainnet before activation and no test catches that. > On mainnet before activation, the mempool rejection is the one tested here: "bad-txns-legacy-sigops". The unit test calls CheckTxInputs directly with a hardcoded enforce_bip54=true, bypassing what PreChecks passes.
fametrano commented 2026-10-25 06:57:45 +00:00 (Migrated from github.com)

tACK 3f0f142b1d

I checked the sigop count against btclib, a library I maintain, on the 39 published sigop vectors and on 27 cases of my own: the 2500/2501 bound across P2SH, bare multisig and CHECKMULTISIG in the scriptSig, oversized redeem scripts, and scriptSigs whose last item is not the redeem script. The PR and btclib agree on all of them. The size, timestamp and coinbase vectors also agree with a short checker I wrote from the BIP text. The unit suite, the touched functional tests and a 5-minute run of bip54_sigops pass.

Nit: the txsize.json case "A 61-byte legacy transaction with a witness" is 60 bytes stripped and 64 with its witness, as the Asserts in bip54_txsize say. The BIP's txsize.json has the same comment.

@ViniciusCestarii's mutant can be caught on regtest. On a node started with -vbparams=consensuscleanup:0:3999999999 -acceptnonstdtxn=1, the deployment is only started, and the PR rejects a 2501-sigop transaction in testmempoolaccept with bad-txns-legacy-sigops. Under the mutant it is accepted, while feature_bip54.py, mempool_sigoplimit.py and mempool_accept.py still pass. That check could go in feature_bip54.py. I can share it and my other scripts as a gist.

tACK 3f0f142b1d0d08a18152d6b100e12d1abf09d58e I checked the sigop count against btclib, a library I maintain, on the 39 published sigop vectors and on 27 cases of my own: the 2500/2501 bound across P2SH, bare multisig and `CHECKMULTISIG` in the scriptSig, oversized redeem scripts, and scriptSigs whose last item is not the redeem script. The PR and btclib agree on all of them. The size, timestamp and coinbase vectors also agree with a short checker I wrote from the BIP text. The unit suite, the touched functional tests and a 5-minute run of `bip54_sigops` pass. Nit: the `txsize.json` case "A 61-byte legacy transaction with a witness" is 60 bytes stripped and 64 with its witness, as the `Assert`s in `bip54_txsize` say. The BIP's `txsize.json` has the same comment. @ViniciusCestarii's mutant can be caught on regtest. On a node started with `-vbparams=consensuscleanup:0:3999999999 -acceptnonstdtxn=1`, the deployment is only started, and the PR rejects a 2501-sigop transaction in `testmempoolaccept` with `bad-txns-legacy-sigops`. Under the mutant it is accepted, while `feature_bip54.py`, `mempool_sigoplimit.py` and `mempool_accept.py` still pass. That check could go in `feature_bip54.py`. I can share it and my other scripts as a gist.
optout21 (Migrated from github.com) reviewed 2026-10-27 11:06:35 +00:00
optout21 (Migrated from github.com) left a comment

Performed a review pass, only over the 64-byte-tx changes. Looks correct and complete.
I've left some comments, notably about getblocktemplate breakage (on regtest), and the inconsistency in mempool vs. block acceptance rejection reason in non-BIP54-active chains.
(3f0f142b1d)

Performed a review pass, only over the 64-byte-tx changes. Looks correct and complete. I've left some comments, notably about `getblocktemplate` breakage (on regtest), and the inconsistency in mempool vs. block acceptance rejection reason in non-BIP54-active chains. (3f0f142b1d0d08a18152d6b100e12d1abf09d58e)
optout21 (Migrated from github.com) commented 2026-10-27 10:37:16 +00:00

913520a chainparams: add versionbits deployment for BIP 54:

This commit breaks existing getblocktemplate calls on Regtest. With gbt_optional_rule = false and ALWAYS_ACTIVE on Regtest, a getblocktemplate call now has to include "consensuscleanup" in the "rules" ({"rules": ["segwit", "consensuscleanup"]}). Otherwise the error "Support for 'consensuscleanup' rule requires explicit client support" is returned. This affects external mining software, Stratum proxies, and other projects' integration tests. In our tests this works as NORMAL_GBT_REQUEST_PARAMS is updated too.
This is a behavior change that warrants mentioning in release notes. Making the rule optional (gbt_optional_rule = true) is another option for discussion.

> [913520a](https://github.com/bitcoin/bitcoin/pull/35793/changes/913520ac1340730340050481e031d83ceb9148b1) _chainparams: add versionbits deployment for BIP 54_: This commit breaks existing `getblocktemplate` calls on Regtest. With `gbt_optional_rule = false` and `ALWAYS_ACTIVE` on Regtest, a `getblocktemplate` call now has to include `"consensuscleanup"` in the `"rules"` (`{"rules": ["segwit", "consensuscleanup"]}`). Otherwise the error `"Support for 'consensuscleanup' rule requires explicit client support"` is returned. This affects external mining software, Stratum proxies, and other projects' integration tests. In our tests this works as `NORMAL_GBT_REQUEST_PARAMS` is updated too. This is a behavior change that warrants mentioning in release notes. Making the rule optional (`gbt_optional_rule = true`) is another option for discussion.
optout21 (Migrated from github.com) commented 2026-10-27 10:58:57 +00:00

1f487ba qa: unit tests for BIP54 rule on 64-byte transactions (with JSON test vectors):

The 64-byte rule is tested on BIP54-active chain (RegTest) only, not on non-active chain. I recommend adding a test on mainnet, to verify non-activation on mainnet (at current heights).

> [1f487ba](https://github.com/bitcoin/bitcoin/pull/35793/changes/1f487baac5135822957574496c0356da5f89bb3c) _qa: unit tests for BIP54 rule on 64-byte transactions (with JSON test vectors)_: The 64-byte rule is tested on BIP54-active chain (RegTest) only, not on non-active chain. I recommend adding a test on mainnet, to verify non-activation on mainnet (at current heights).
optout21 (Migrated from github.com) commented 2026-10-27 10:50:36 +00:00

1f487ba qa: unit tests for BIP54 rule on 64-byte transactions (with JSON test vectors):

Minor: Isn't this 60 bytes, not 61? INVALID_TX_NONWITNESS_SIZE - 4

> [1f487ba](https://github.com/bitcoin/bitcoin/pull/35793/changes/1f487baac5135822957574496c0356da5f89bb3c) _qa: unit tests for BIP54 rule on 64-byte transactions (with JSON test vectors)_: Minor: Isn't this 60 bytes, not 61? `INVALID_TX_NONWITNESS_SIZE - 4`
optout21 (Migrated from github.com) commented 2026-10-27 10:42:17 +00:00

689f45a validation: make 64-byte transactions invalid:

Elsewhere (in ContextualCheckBlock) the value bad-txns-size is used. I propose using the same value here as well, and dropping txn-size-64, for consistency.
Whether the error code should be 64-byte specific or not, is up for discussion. (I lean towards the more generic bad-txns-size, but I'm indifferent.)

> [689f45a](https://github.com/bitcoin/bitcoin/pull/35793/changes/689f45ae127bbb0ed53634e1687becea203bedec) _validation: make 64-byte transactions invalid_: Elsewhere (in `ContextualCheckBlock`) the value `bad-txns-size` is used. I propose using the same value here as well, and dropping `txn-size-64`, for consistency. Whether the error code should be 64-byte specific or not, is up for discussion. (I lean towards the more generic `bad-txns-size`, but I'm indifferent.)
optout21 (Migrated from github.com) commented 2026-10-27 10:45:37 +00:00

689f45a validation: make 64-byte transactions invalid:

Order of checks: I believe any validity check should come before standardness checks. Otherwise a tx that fails both checks is reported as non-standard, instead of the stronger invalid.
I propose moving the 64-byte invalid check before the IsStandardTx call before.

> [689f45a](https://github.com/bitcoin/bitcoin/pull/35793/changes/689f45ae127bbb0ed53634e1687becea203bedec) _validation: make 64-byte transactions invalid_: Order of checks: I believe any validity check should come before standardness checks. Otherwise a tx that fails both checks is reported as non-standard, instead of the stronger invalid. I propose moving the 64-byte invalid check before the `IsStandardTx` call before.
optout21 (Migrated from github.com) commented 2026-10-27 10:56:44 +00:00

689f45a validation: make 64-byte transactions invalid:

Unconditional consensus error at mempool check. 64-byte transactions are rejected from mempool with consensus error now, regardless of deployment (so on mainnet as well). This is inconsistent, as such transactions are considered consensus-valid at block checking. The status quo is rejecting 64-byte transactions with non-standardness error. Therefore the behavior is unchanged, only the error is changed from non-standard to invalid in this case.

All this seems intended behavior. Nonetheless, I think it would make sense to explicitly mention this inconsistency in:

  • a code comment here
  • in the commit message
  • in the PR description
  • in release notes (?)

The discarded alternative is to reject with consensus failure only if BIP54 is active, otherwise leave the non-standardness rejection.

> [689f45a](https://github.com/bitcoin/bitcoin/pull/35793/changes/689f45ae127bbb0ed53634e1687becea203bedec) _validation: make 64-byte transactions invalid_: Unconditional consensus error at mempool check. 64-byte transactions are rejected from mempool with consensus error now, regardless of deployment (so on mainnet as well). This is inconsistent, as such transactions are considered consensus-valid at block checking. The status quo is rejecting 64-byte transactions with non-standardness error. Therefore the behavior is unchanged, only the error is changed from non-standard to invalid in this case. All this seems intended behavior. Nonetheless, I think it would make sense to explicitly mention this inconsistency in: - a code comment here - in the commit message - in the PR description - in release notes (?) The discarded alternative is to reject with consensus failure only if BIP54 is active, otherwise leave the non-standardness rejection.
optout21 (Migrated from github.com) commented 2026-10-27 10:52:31 +00:00

689f45a validation: make 64-byte transactions invalid:

Nit: The 64 here could be replaced by INVALID_TX_NONWITNESS_SIZE now.

> [689f45a](https://github.com/bitcoin/bitcoin/pull/35793/changes/689f45ae127bbb0ed53634e1687becea203bedec) _validation: make 64-byte transactions invalid_: Nit: The `64` here could be replaced by `INVALID_TX_NONWITNESS_SIZE` now.
optout21 (Migrated from github.com) commented 2026-10-27 11:00:26 +00:00

689f45a validation: make 64-byte transactions invalid:

Minor optimization observation: a custom, IsSizeInvalid() method could perform faster than the generic compute-size-and-compare-to-64. However, the difference is minimal, especially compared to costly part of block validation.
Nonetheless, a custom method would make the intent more explicit and leave room for further optimization.

Sample `IsSizeInvalid()` implementation
/** Whether the witness-stripped serialized size of this transaction is exactly 64 bytes (BIP 54). */
bool IsSizeInvalid(const CTransaction& tx)
{
    // Each input takes at least 41 and each output at least 9 non-witness bytes, on top of
    // 10 bytes for the version, locktime and the input and output counts.
    if (10 + 41 * tx.vin.size() + 9 * tx.vout.size() > INVALID_TX_NONWITNESS_SIZE) return false;
    return ::GetSerializeSize(TX_NO_WITNESS(tx)) == INVALID_TX_NONWITNESS_SIZE;
}
> [689f45a](https://github.com/bitcoin/bitcoin/pull/35793/changes/689f45ae127bbb0ed53634e1687becea203bedec) _validation: make 64-byte transactions invalid_: Minor optimization observation: a custom, `IsSizeInvalid()` method could perform faster than the generic compute-size-and-compare-to-64. However, the difference is minimal, especially compared to costly part of block validation. Nonetheless, a custom method would make the intent more explicit and leave room for further optimization. <details> <summary>Sample `IsSizeInvalid()` implementation</summary> ```C++ /** Whether the witness-stripped serialized size of this transaction is exactly 64 bytes (BIP 54). */ bool IsSizeInvalid(const CTransaction& tx) { // Each input takes at least 41 and each output at least 9 non-witness bytes, on top of // 10 bytes for the version, locktime and the input and output counts. if (10 + 41 * tx.vin.size() + 9 * tx.vout.size() > INVALID_TX_NONWITNESS_SIZE) return false; return ::GetSerializeSize(TX_NO_WITNESS(tx)) == INVALID_TX_NONWITNESS_SIZE; } ``` </details>
optout21 (Migrated from github.com) commented 2026-10-27 10:48:45 +00:00

7407f3c qa: end-to-end test all BIP54 mitigations:

Nit: There is no assert here that indeed the tx is 64 bytes, I suggest adding one, like in submit_block_64byte above.

> [7407f3c](https://github.com/bitcoin/bitcoin/pull/35793/changes/7407f3c134aebf57329581e08a8b81c5e9ab340c) _qa: end-to-end test all BIP54 mitigations_: Nit: There is no assert here that indeed the tx is 64 bytes, I suggest adding one, like in `submit_block_64byte` above.
ViniciusCestarii commented 2026-10-27 13:51:28 +00:00 (Migrated from github.com)

I ran some mutation testing and found 3 live mutants besides https://github.com/bitcoin/bitcoin/pull/35793#discussion_r4338365979. These 3 move BIP54 enforcement by one block at activation.

I also published them at https://mutanthub.space/projects/bitcoin/bitcoin/pulls/35793, where they can be discussed.

src/validation.cpp (3)
Sigops limit enforced a block early
@@ -2519,7 +2519,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
     std::optional<CCheckQueueControl<CScriptCheck>> control;
     if (auto& queue = m_chainman.GetCheckQueue(); queue.HasThreads() && fScriptChecks) control.emplace(queue);
 
-    const bool enforce_bip54{DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)};
+    const bool enforce_bip54{DeploymentActiveAfter(pindex, m_chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)};
     std::vector<int> prevheights;
     CAmount nFees = 0;
     int nInputs = 0;
Timewarp skipped at activation block
@@ -4115,7 +4115,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
         if (consensusParams.enforce_BIP94) {
             static_assert(MAX_TIMEWARP_TESTNET4 <= MAX_TIMEWARP_BIP54);
             max_timewarp = MAX_TIMEWARP_TESTNET4;
-        } else if (DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) {
+        } else if (DeploymentActiveAt(*pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) {
             max_timewarp = MAX_TIMEWARP_BIP54;
         }
         if (max_timewarp && block.GetBlockTime() < pindexPrev->GetBlockTime() - *max_timewarp) {
Coinbase locktime skipped at activation
@@ -4197,7 +4197,7 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
     }
 
     // Make sure the coinbase transaction is timelocked to the block's height.
-    if (nHeight > 0 && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) {
+    if (nHeight > 0 && DeploymentActiveAt(*pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) {
         if (block.vtx[0]->nLockTime != static_cast<uint32_t>(nHeight - 1)) {
             return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-locktime", "block height mismatch in coinbase nLockTime");
         }
I ran some mutation testing and found 3 live mutants besides https://github.com/bitcoin/bitcoin/pull/35793#discussion_r4338365979. These 3 move BIP54 enforcement by one block at activation. I also published them at https://mutanthub.space/projects/bitcoin/bitcoin/pulls/35793, where they can be discussed. <details> <summary>src/validation.cpp (3)</summary> <details> <summary>Sigops limit enforced a block early</summary> ```diff @@ -2519,7 +2519,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, std::optional<CCheckQueueControl<CScriptCheck>> control; if (auto& queue = m_chainman.GetCheckQueue(); queue.HasThreads() && fScriptChecks) control.emplace(queue); - const bool enforce_bip54{DeploymentActiveAt(*pindex, m_chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)}; + const bool enforce_bip54{DeploymentActiveAfter(pindex, m_chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)}; std::vector<int> prevheights; CAmount nFees = 0; int nInputs = 0; ``` </details> <details> <summary>Timewarp skipped at activation block</summary> ```diff @@ -4115,7 +4115,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio if (consensusParams.enforce_BIP94) { static_assert(MAX_TIMEWARP_TESTNET4 <= MAX_TIMEWARP_BIP54); max_timewarp = MAX_TIMEWARP_TESTNET4; - } else if (DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) { + } else if (DeploymentActiveAt(*pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) { max_timewarp = MAX_TIMEWARP_BIP54; } if (max_timewarp && block.GetBlockTime() < pindexPrev->GetBlockTime() - *max_timewarp) { ``` </details> <details> <summary>Coinbase locktime skipped at activation</summary> ```diff @@ -4197,7 +4197,7 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat } // Make sure the coinbase transaction is timelocked to the block's height. - if (nHeight > 0 && DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) { + if (nHeight > 0 && DeploymentActiveAt(*pindexPrev, chainman, Consensus::DEPLOYMENT_CONSENSUSCLEANUP)) { if (block.vtx[0]->nLockTime != static_cast<uint32_t>(nHeight - 1)) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-locktime", "block height mismatch in coinbase nLockTime"); } ``` </details> </details>
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-28 17:08:21 +00:00
ViniciusCestarii (Migrated from github.com) left a comment

Reviewed the rest of the code, looks good. Left some nits.

Reviewed the rest of the code, looks good. Left some nits.
ViniciusCestarii (Migrated from github.com) commented 2026-10-27 19:34:11 +00:00

nit:

    // Make sure the coinbase transaction is timelocked to the block's height. (BIP 54)
nit: ```suggestion // Make sure the coinbase transaction is timelocked to the block's height. (BIP 54) ```
ViniciusCestarii (Migrated from github.com) commented 2026-10-28 14:38:23 +00:00

nit: this should be start_time + 2 * 4 * interval_expected_sec. As is, period 2's elapsed time is 0, so difficulty goes D -> D/4 -> D -> 4D instead of D -> D/4 -> D/16 -> D/4. The mitigation is still covered either way.

nit: this should be `start_time + 2 * 4 * interval_expected_sec`. As is, period 2's elapsed time is 0, so difficulty goes D -> D/4 -> D -> 4D instead of D -> D/4 -> D/16 -> D/4. The mitigation is still covered either way.
ViniciusCestarii (Migrated from github.com) commented 2026-10-28 14:20:43 +00:00

nit: could assert:

assert_equal(len(block.vtx[0].serialize_without_witness()), 64)
nit: could assert: ``` assert_equal(len(block.vtx[0].serialize_without_witness()), 64) ```
ViniciusCestarii (Migrated from github.com) commented 2026-10-28 11:19:23 +00:00

nit:

        # Use two OP_TRUEs and an OP_DROP to ensure we're always > 64 bytes in non-witness size (BIP 54)
nit: ```suggestion # Use two OP_TRUEs and an OP_DROP to ensure we're always > 64 bytes in non-witness size (BIP 54) ```
DrahtBot commented 2026-10-30 19:02:51 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
darosior (Migrated from github.com) reviewed 2026-11-10 21:21:46 +00:00
darosior (Migrated from github.com) commented 2026-11-10 21:21:46 +00:00

Yes, this is intentional. The point of having mandatory rules is to alert miners for soft forks that require a change in pool software. So making the rule optional is a non-starter.

Mentioning it in the release notes could make sense, indeed.

Yes, this is intentional. The point of having mandatory rules is to alert miners for soft forks that require a change in pool software. So making the rule optional is a non-starter. Mentioning it in the release notes could make sense, indeed.
darosior (Migrated from github.com) reviewed 2026-11-10 21:26:32 +00:00
darosior (Migrated from github.com) commented 2026-11-10 21:26:32 +00:00

Errors use different short names for standalone and block transactions. The current names were chosen to be consistent with the vast majority of prefixes used in each context.

Errors use different short names for standalone and block transactions. The current names were chosen to be consistent with the vast majority of prefixes used in each context.
darosior (Migrated from github.com) reviewed 2026-11-10 21:39:18 +00:00
darosior (Migrated from github.com) commented 2026-11-10 21:39:18 +00:00

It's not practical to check standardness rules after consensus rules, if only because some standardness rules are meant to protect from consensus validation DoS. As a result, we return a standardness error for a consensus-invalid transaction in plenty of cases. Therefore i don't think it's worth trying to avoid that in some specific situations for that specific check, and i prefer to keep the newly introduced consensus check next to the related existing standardness check.

It's not practical to check standardness rules after consensus rules, if only because some standardness rules are meant to protect from consensus validation DoS. As a result, we return a standardness error for a consensus-invalid transaction in plenty of cases. Therefore i don't think it's worth trying to avoid that in some specific situations for that specific check, and i prefer to keep the newly introduced consensus check next to the related existing standardness check.
darosior (Migrated from github.com) reviewed 2026-11-10 21:47:29 +00:00
darosior (Migrated from github.com) commented 2026-11-10 21:47:29 +00:00

Previous discussion on this in https://github.com/bitcoin/bitcoin/pull/35793#discussion_r3994152368.

This is mentioned in the commit message. More rationale for the decision is given in the earlier commit message for the other newly introduced TX_CONSENSUS error.

Previous discussion on this in https://github.com/bitcoin/bitcoin/pull/35793#discussion_r3994152368. This is mentioned in the commit message. More rationale for the decision is given in the earlier commit message for the other newly introduced TX_CONSENSUS error.
nervana21 (Migrated from github.com) reviewed 2026-11-10 22:30:08 +00:00
nervana21 (Migrated from github.com) left a comment

I've reviewed the code and it lgtm. Needs rebase. I've left small, non-blocking suggestions

I've reviewed the code and it lgtm. Needs rebase. I've left small, non-blocking suggestions
nervana21 (Migrated from github.com) commented 2026-10-29 14:20:03 +00:00

0d14d064f4: qa: extensive unit tests for BIP54 legacy sigops limit

This case is bare CMS.

        CheckWithinBIP54Limits(CTransaction(tx_copy), coins, test_vectors, "Bare Script inputs totalling 125 16-of-17 CHECKMULTISIGs");
0d14d064f4ef3b1be65073ce8707fa2b366c7595: qa: extensive unit tests for BIP54 legacy sigops limit This case is bare CMS. ```suggestion CheckWithinBIP54Limits(CTransaction(tx_copy), coins, test_vectors, "Bare Script inputs totalling 125 16-of-17 CHECKMULTISIGs"); ```
nervana21 (Migrated from github.com) commented 2026-10-29 14:20:39 +00:00

0d14d064f4: qa: extensive unit tests for BIP54 legacy sigops limit

This case is bare CMS.

        CheckExceedsBIP54Limits(CTransaction(tx_copy), coins, test_vectors, "Bare Script inputs totalling 125 16-of-17 CHECKMULTISIGs + 1 P2PKH input");
0d14d064f4ef3b1be65073ce8707fa2b366c7595: qa: extensive unit tests for BIP54 legacy sigops limit This case is bare CMS. ```suggestion CheckExceedsBIP54Limits(CTransaction(tx_copy), coins, test_vectors, "Bare Script inputs totalling 125 16-of-17 CHECKMULTISIGs + 1 P2PKH input"); ```
nervana21 (Migrated from github.com) commented 2026-10-29 14:23:22 +00:00

0d14d064f4: qa: extensive unit tests for BIP54 legacy sigops limit

62 * 40 = 2480

        // Reach 2480 sigops with 62 inputs.
0d14d064f4ef3b1be65073ce8707fa2b366c7595: qa: extensive unit tests for BIP54 legacy sigops limit 62 * 40 = 2480 ```suggestion // Reach 2480 sigops with 62 inputs. ```
Lines 519-520
nervana21 (Migrated from github.com) commented 2026-10-29 15:22:32 +00:00

0d14d064f4: qa: extensive unit tests for BIP54 legacy sigops limit

63 * 40 = 2520.
Exceed case has 63 inputs.

        // We now reached 2520 sigops. We exceed the limit.
        CheckExceedsBIP54Limits(CTransaction(tx_copy), coins, test_vectors, "63 inputs with a contrived P2SH redeemScript executing 2 18-of-18 CHECKMULTISIGs");
0d14d064f4ef3b1be65073ce8707fa2b366c7595: qa: extensive unit tests for BIP54 legacy sigops limit 63 * 40 = 2520. Exceed case has 63 inputs. ```suggestion // We now reached 2520 sigops. We exceed the limit. CheckExceedsBIP54Limits(CTransaction(tx_copy), coins, test_vectors, "63 inputs with a contrived P2SH redeemScript executing 2 18-of-18 CHECKMULTISIGs"); ```
nervana21 (Migrated from github.com) commented 2026-10-29 15:32:12 +00:00

0d14d064f4: qa: extensive unit tests for BIP54 legacy sigops limit

        // A P2SH with 9 13-of-13 CMS followed by 5 CHECKSIGs. The 9 CHECKMULTISIG's are in
0d14d064f4ef3b1be65073ce8707fa2b366c7595: qa: extensive unit tests for BIP54 legacy sigops limit ```suggestion // A P2SH with 9 13-of-13 CMS followed by 5 CHECKSIGs. The 9 CHECKMULTISIG's are in ```
nervana21 (Migrated from github.com) commented 2026-10-29 15:34:52 +00:00

0d14d064f4: qa: extensive unit tests for BIP54 legacy sigops limit

166 * 15 = 2490

        // 166 * 15 = 2490 CMS sigops + 10 CHECKSIG sigops = 2500 sigops.
0d14d064f4ef3b1be65073ce8707fa2b366c7595: qa: extensive unit tests for BIP54 legacy sigops limit 166 * 15 = 2490 ```suggestion // 166 * 15 = 2490 CMS sigops + 10 CHECKSIG sigops = 2500 sigops. ```
darosior (Migrated from github.com) reviewed 2026-11-12 20:05:35 +00:00
darosior (Migrated from github.com) commented 2026-11-12 20:05:35 +00:00

Right, good catch.

Right, good catch.
darosior (Migrated from github.com) reviewed 2026-11-12 20:35:13 +00:00
darosior (Migrated from github.com) commented 2026-11-12 20:35:13 +00:00

Great catch.

Great catch.
darosior (Migrated from github.com) reviewed 2026-11-12 20:59:38 +00:00
darosior (Migrated from github.com) commented 2026-11-12 20:59:38 +00:00

Good catch, looks like i updated these tests at some point, without updating the comments.

Good catch, looks like i updated these tests at some point, without updating the comments.
darosior (Migrated from github.com) reviewed 2026-11-12 20:59:43 +00:00
darosior (Migrated from github.com) commented 2026-11-12 20:59:43 +00:00

Same here. Thanks for the careful read here, i'll make sure to point an LLM to this file to surface any inconsistency before pushing again.

Same here. Thanks for the careful read here, i'll make sure to point an LLM to this file to surface any inconsistency before pushing again.
nervana21 (Migrated from github.com) reviewed 2026-11-12 21:05:09 +00:00
nervana21 (Migrated from github.com) commented 2026-11-12 21:05:09 +00:00

no problem!

no problem!
darosior (Migrated from github.com) reviewed 2026-11-13 16:33:17 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:33:17 +00:00

I'm not sure what you suggest here? Clearly we can't bootstrap a mainnet chainstate at the current height in our unit test, and we have other ways of being confident our inactive BIP 9 deployments are not incorrectly treated as active.

I'm not sure what you suggest here? Clearly we can't bootstrap a mainnet chainstate at the current height in our unit test, and we have other ways of being confident our inactive BIP 9 deployments are not incorrectly treated as active.
darosior (Migrated from github.com) reviewed 2026-11-13 16:37:43 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:37:43 +00:00

I think this is unnecessary complexity: i would rather keep the consensus check simple and "obvious" than get some minimal performance gains, especially on a path that is currently not a bottleneck.

I think this is unnecessary complexity: i would rather keep the consensus check simple and "obvious" than get some minimal performance gains, especially on a path that is currently not a bottleneck.
darosior (Migrated from github.com) reviewed 2026-11-13 16:37:51 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:37:51 +00:00

Taken, thanks.

Taken, thanks.
darosior (Migrated from github.com) reviewed 2026-11-13 16:37:54 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:37:54 +00:00

Taken.

Taken.
darosior (Migrated from github.com) reviewed 2026-11-13 16:38:12 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:38:12 +00:00

Taken.

Taken.
darosior (Migrated from github.com) reviewed 2026-11-13 16:38:16 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:38:16 +00:00

Taken.

Taken.
darosior (Migrated from github.com) reviewed 2026-11-13 16:38:21 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:38:21 +00:00

Done.

Done.
darosior (Migrated from github.com) reviewed 2026-11-13 16:38:59 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:38:59 +00:00

Done, thanks.

Done, thanks.
darosior (Migrated from github.com) reviewed 2026-11-13 16:39:05 +00:00
darosior (Migrated from github.com) commented 2026-11-13 16:39:05 +00:00

Oh, the pre-LLM-enlightenment times where we hand rolled thousands of lines of tests and made silly copy-pasta mistakes along the way. Dark, uncertain times.

Done, thanks!

Oh, the pre-LLM-enlightenment times where we hand rolled thousands of lines of tests and made silly copy-pasta mistakes along the way. Dark, uncertain times. Done, thanks!
darosior (Migrated from github.com) reviewed 2026-11-13 16:39:25 +00:00
Lines 519-520
darosior (Migrated from github.com) commented 2026-11-13 16:39:25 +00:00

Done.

Done.
darosior commented 2026-11-13 16:42:41 +00:00 (Migrated from github.com)

Rebased, and addressed both human and bot review.

I updated the functional test to run the post activation checks on the first block for which the rules are active. In addition, it now mines a BIP 54 invalid block as the last block for which the rules are inactive. This kills some of the mutants shared by @ViniciusCestarii, and more generally better guards against off-by-one errors (such as that which could come from mixing up DeploymentActiveAt() / DeploymentActiveAfter()). Some mutants remain for the timewarp check for instance, because it requires a full retarget period setup. I think the test now strikes a good balance between better checking the activation boundaries but keeping the test easy to follow.

I addressed a bunch of cleanups and fixups suggested by @optout21, @ViniciusCestarii and @nervana21. Because they pointed a number of small mistakes in the extensive sigops unit test, i had a bot comprehensively check for those. I fixed a few more inconsistencies (invalid CHECKSIG counts, sigops counts, etc..) and also a stale comment that was referring to a test that did not exist anymore. The test made sense (check that a CMS for OP_0 keys is correctly accounted for 20 sigops as in BIP 16), so i (re-)added it instead of updating the outdated comment.

I also had a clanker check for arithmetic nits like https://github.com/bitcoin/bitcoin/pull/35793#discussion_r4401934437 in the functional test. It found a few more nits that did not impact the test, but should be fixed for correctness or consistency (for instance a comment that would say "reach the end of the period" instead of "reach the beginning of the next period", etc..)

I'll update the test vectors in the BIP in time, but i want to check for more similar human slop in the pre-generated tests first (my bot already detected an off-by-one in the timestamps JSON).

Rebased, and addressed both human and bot review. I updated the functional test to run the post activation checks on the first block for which the rules are active. In addition, it now mines a BIP 54 invalid block as the last block for which the rules are inactive. This kills some of the mutants shared by @ViniciusCestarii, and more generally better guards against off-by-one errors (such as that which could come from mixing up `DeploymentActiveAt()` / `DeploymentActiveAfter()`). Some mutants remain for the timewarp check for instance, because it requires a full retarget period setup. I think the test now strikes a good balance between better checking the activation boundaries but keeping the test easy to follow. I addressed a bunch of cleanups and fixups suggested by @optout21, @ViniciusCestarii and @nervana21. Because they pointed a number of small mistakes in the extensive sigops unit test, i had a bot comprehensively check for those. I fixed a few more inconsistencies (invalid CHECKSIG counts, sigops counts, etc..) and also a stale comment that was referring to a test that did not exist anymore. The test made sense (check that a CMS for `OP_0` keys is correctly accounted for 20 sigops as in BIP 16), so i (re-)added it instead of updating the outdated comment. I also had a clanker check for arithmetic nits like https://github.com/bitcoin/bitcoin/pull/35793#discussion_r4401934437 in the functional test. It found a few more nits that did not impact the test, but should be fixed for correctness or consistency (for instance a comment that would say "reach the end of the period" instead of "reach the beginning of the next period", etc..) I'll update the test vectors in the BIP in time, but i want to check for more similar human slop in the pre-generated tests first (my bot already detected an off-by-one in the timestamps JSON).
instagibbs commented 2026-11-13 17:03:57 +00:00 (Migrated from github.com)

reACK https://github.com/bitcoin/bitcoin/pull/35793/commits/58b418f85582b559ad9ac718e42251e5bc5aab3a

Test and comment fixes, plus INVALID_TX_NONWITNESS_SIZE usage swapped in IsBlockMutated.

Mutants for activation boundary are now killed for sigops rule early/late, 64 byte tx on block late, and coinbase-locktime one block late

reACK https://github.com/bitcoin/bitcoin/pull/35793/commits/58b418f85582b559ad9ac718e42251e5bc5aab3a Test and comment fixes, plus `INVALID_TX_NONWITNESS_SIZE` usage swapped in IsBlockMutated. Mutants for activation boundary are now killed for sigops rule early/late, 64 byte tx on block late, and coinbase-locktime one block late
nervana21 commented 2026-11-15 13:40:51 +00:00 (Migrated from github.com)

tACK 58b418f855

tACK 58b418f85582b559ad9ac718e42251e5bc5aab3a
optout21 (Migrated from github.com) reviewed 2026-11-16 12:46:32 +00:00
optout21 (Migrated from github.com) commented 2026-11-16 12:46:32 +00:00

Got it, thx

Got it, thx
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-16 13:19:01 +00:00
ViniciusCestarii (Migrated from github.com) left a comment

ACK 58b418f855

Can confirm the 2 mutants were killed.

nit: the timewarp activation mutant can be killed without a full retarget setup:

diff --git a/test/functional/feature_bip54.py b/test/functional/feature_bip54.py
index b6271d866d..c7a557efec 100755
--- a/test/functional/feature_bip54.py
+++ b/test/functional/feature_bip54.py
@@ -407,6 +407,29 @@ class Bip54Test(BitcoinTestFramework):
         assert_equal(cc_dep["status"], "locked_in")
         assert_equal(cc_dep["status_next"], "active")
 
+        # The first active block starts a retarget period, so the timewarp rule must apply to it.
+        # Fork the tip with a header in the future to leave room above the MTP.
+        assert_equal((node.getblockcount() + 1) % 144, 0)
+        parent_hash = node.getblockhash(node.getblockcount() - 1)
+        future_time = node.getblockheader(parent_hash)["time"] + 3 * 60 * 60
+        node.setmocktime(future_time)
+        fork = create_block(tmpl={
+            "previousblockhash": parent_hash,
+            "height": node.getblockcount(),
+            "curtime": future_time,
+        })
+        fork.solve()
+        node.submitheader(CBlockHeader(fork).serialize().hex())
+
+        block = create_block(tmpl={
+            "previousblockhash": fork.hash_hex,
+            "height": node.getblockcount() + 1,
+            "curtime": future_time - 2 * 60 * 60 - 1,  # 2h + 1s before its parent.
+        })
+        block.solve()
+        assert_raises_rpc_error(-25, "time-timewarp-attack", node.submitheader, CBlockHeader(block).serialize().hex())
+        node.setmocktime(0)
+
         # Perform as many post activation checks as we can right on the first block
         # with the rules active, to also check for an off-by-one mistake.
         self.log.info("BIP54 tests after activation")

ACK 58b418f85582b559ad9ac718e42251e5bc5aab3a Can confirm the 2 mutants were killed. nit: the timewarp activation mutant can be killed without a full retarget setup: ```diff diff --git a/test/functional/feature_bip54.py b/test/functional/feature_bip54.py index b6271d866d..c7a557efec 100755 --- a/test/functional/feature_bip54.py +++ b/test/functional/feature_bip54.py @@ -407,6 +407,29 @@ class Bip54Test(BitcoinTestFramework): assert_equal(cc_dep["status"], "locked_in") assert_equal(cc_dep["status_next"], "active") + # The first active block starts a retarget period, so the timewarp rule must apply to it. + # Fork the tip with a header in the future to leave room above the MTP. + assert_equal((node.getblockcount() + 1) % 144, 0) + parent_hash = node.getblockhash(node.getblockcount() - 1) + future_time = node.getblockheader(parent_hash)["time"] + 3 * 60 * 60 + node.setmocktime(future_time) + fork = create_block(tmpl={ + "previousblockhash": parent_hash, + "height": node.getblockcount(), + "curtime": future_time, + }) + fork.solve() + node.submitheader(CBlockHeader(fork).serialize().hex()) + + block = create_block(tmpl={ + "previousblockhash": fork.hash_hex, + "height": node.getblockcount() + 1, + "curtime": future_time - 2 * 60 * 60 - 1, # 2h + 1s before its parent. + }) + block.solve() + assert_raises_rpc_error(-25, "time-timewarp-attack", node.submitheader, CBlockHeader(block).serialize().hex()) + node.setmocktime(0) + # Perform as many post activation checks as we can right on the first block # with the rules active, to also check for an off-by-one mistake. self.log.info("BIP54 tests after activation") ```
optout21 (Migrated from github.com) reviewed 2026-11-17 09:59:15 +00:00
optout21 (Migrated from github.com) left a comment

ACK 58b418f855
Performed review on the whole changeset. Only found some nits.

A general remark: I think a release not would make sense, mentioning:

I consider the changes correct and acceptable in the current form already (in spite the minor findings).

ACK 58b418f85582b559ad9ac718e42251e5bc5aab3a Performed review on the whole changeset. Only found some nits. A general remark: I think a release not would make sense, mentioning: - The chains where BIP54 is active (regtest) - On chains where it is active, the new and changed error cases - The `getblocktemplate` changed requirement, see https://github.com/bitcoin/bitcoin/pull/35793#discussion_r4387647295 I consider the changes correct and acceptable in the current form already (in spite the minor findings).
optout21 (Migrated from github.com) commented 2026-11-16 14:15:11 +00:00

af2a89f validation: make BIP54 sigops check consensus-critical:

Nit: tx_verify.h include no longer needed.

> [af2a89f](https://github.com/bitcoin/bitcoin/pull/35793/changes/af2a89fe3369a69ec773590da4ee4dc3943f90ee) _validation: make BIP54 sigops check consensus-critical_: Nit: `tx_verify.h` include no longer needed.
Lines 4209-4210
optout21 (Migrated from github.com) commented 2026-11-17 09:34:44 +00:00

Nit: consider avoiding using ’ character in error message, may cause issues in RPC calls. Use simple quote ', or "timestamp of the block" construct.

Nit: consider avoiding using `’` character in error message, may cause issues in RPC calls. Use simple quote `'`, or "timestamp of the block" construct.
optout21 (Migrated from github.com) commented 2026-11-17 09:35:56 +00:00

Nit: wording "64 bytes transaction" -> "64-byte transaction"

            return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-size", "block contains a 64-byte transaction");
Nit: wording "64 bytes transaction" -> "64-byte transaction" ```suggestion return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-size", "block contains a 64-byte transaction"); ```
optout21 (Migrated from github.com) commented 2026-11-16 14:17:26 +00:00

8499388 [test] Separate 64B and 63B tx size tests:

Nit: expect_disconnect field is no longer exists, should be removed from here.

> [8499388](https://github.com/bitcoin/bitcoin/pull/35793/changes/84993880432061ff0152baa23c734df83887a031) _[test] Separate 64B and 63B tx size tests_: Nit: `expect_disconnect` field is no longer exists, should be removed from here.
optout21 (Migrated from github.com) commented 2026-11-16 14:18:49 +00:00

fa2c08f qa: end-to-end test all BIP54 mitigations:

Nit: These lines are useless in this form. Also one more occurrence of the same pattern further below.

> [fa2c08f](https://github.com/bitcoin/bitcoin/pull/35793/changes/fa2c08f797031da8a07e5a1412b4bd3f8d345830) _qa: end-to-end test all BIP54 mitigations_: Nit: These lines are useless in this form. Also one more occurrence of the same pattern further below.
theStack (Migrated from github.com) reviewed 2026-11-17 18:28:18 +00:00
theStack (Migrated from github.com) left a comment

ACK on the actual consensus changes, planning to look closer to the tests within the next days

ACK on the actual consensus changes, planning to look closer to the tests within the next days
theStack (Migrated from github.com) commented 2026-11-17 18:26:21 +00:00

The generated .json test vector files (bip54_{sigops,txsize}.json.gen) both differ from the ones currently included in the BIPs repo ({sigops,txsize}.json). Didn't look closer on the details, I assume there were (minor) changes triggered by review comments and one could just update them on the latter repo, as previously done in https://github.com/bitcoin/bips/pull/2122 / https://github.com/bitcoin/bips/pull/2122/changes/ff39733e70a237d3472af68ddf68441e6ecbab51?

The generated .json test vector files (`bip54_{sigops,txsize}.json.gen`) both differ from the ones currently [included in the BIPs repo](https://github.com/bitcoin/bips/tree/master/bip-0054/test_vectors) (`{sigops,txsize}.json`). Didn't look closer on the details, I assume there were (minor) changes triggered by review comments and one could just update them on the latter repo, as previously done in https://github.com/bitcoin/bips/pull/2122 / https://github.com/bitcoin/bips/pull/2122/changes/ff39733e70a237d3472af68ddf68441e6ecbab51?
darosior (Migrated from github.com) reviewed 2026-11-17 18:32:57 +00:00
darosior (Migrated from github.com) commented 2026-11-17 18:32:57 +00:00

Yes. There is a bunch of small fixes and a couple new tests included. I plan to do another round of updates of the BIP test vectors (similar to https://github.com/bitcoin/bips/pull/2122) after this PR is merged.

Yes. There is a bunch of small fixes and a couple new tests included. I plan to do another round of updates of the BIP test vectors (similar to https://github.com/bitcoin/bips/pull/2122) after this PR is merged.
ariard (Migrated from github.com) reviewed 2026-11-23 21:58:46 +00:00
ariard (Migrated from github.com) left a comment

Aiming to have a complete a real serious re-review of the whole code change before the end of year vacations.

Not forgetting to re-check if there is no bad interactions with the disconnectpool due to the new rules applying on the coinbase or the max sigops for old inputs spends, among other concerns.

Aiming to have a complete a real serious re-review of the whole code change before the end of year vacations. Not forgetting to re-check if there is no bad interactions with the `disconnectpool` due to the new rules applying on the coinbase or the max sigops for old inputs spends, among other concerns.
ariard (Migrated from github.com) commented 2026-11-23 21:54:54 +00:00

This new consensus sanitization check is stateless, that it whatever the inclusion height of the coinbase, after the activation of BIP54, the nSequence of the 1st input should NOT be equal to SEQUENCE_FINAL.

There is nothing which is context-dependent or even tx-structure dependent (like the BIP141 commitment which is allowed to be in any scriptpubkey of the coinbase tx), so this check could be replicated in other code paths to proceed to the early rejection of ill-crafted transactions.

E.g I wonder if the check should be added in CheckTransaction() and be used in the PreChecks() code path (where CheckTransaction() is called before IsCoinBase() detection) or in CheckBlock() (where we do a CheckTransaction()).

I have not test it but lacking to do so, it sounds you can mutate a valid coinbase to alter its nSequence field and provoke the invalidity of the whole block. It sounds there are code paths where CheckBlock() is done before ContextualCheckBlock() (e.g in AcceptBlock()). It sounds as such you might have CheckBlock() result where the validity is not wholly complete, at least the state of information that is available in the code path.

There is also the question of compact block (BIP152), the spec says "When in doubt, nodes SHOULD only include the coinbase transaction in prefilledtxn." This is unsure if the compact block validation code already sanitize on the reception of a coinbase (to avoid fulfilling resources after the CMPCTBLOCK), I have no re-checked fully, though looking shortly in blockencoding.cpp it doesn't sound to.

This new consensus sanitization check is stateless, that it whatever the inclusion height of the coinbase, after the activation of BIP54, the nSequence of the 1st input should NOT be equal to `SEQUENCE_FINAL`. There is nothing which is context-dependent or even tx-structure dependent (like the BIP141 commitment which is allowed to be in _any_ `scriptpubkey `of the coinbase tx), so this check could be replicated in other code paths to proceed to the early rejection of ill-crafted transactions. E.g I wonder if the check should be added in `CheckTransaction()` and be used in the `PreChecks()` code path (where `CheckTransaction()` is called before `IsCoinBase()` detection) or in `CheckBlock()` (where we do a `CheckTransaction()`). I have not test it but lacking to do so, it sounds you can mutate a valid coinbase to alter its nSequence field and provoke the invalidity of the whole block. It sounds there are code paths where `CheckBlock()` is done before `ContextualCheckBlock()` (e.g in `AcceptBlock()`). It sounds as such you might have `CheckBlock()` result where the validity is not wholly complete, at least the state of information that is available in the code path. There is also the question of compact block (BIP152), the spec says "When in doubt, nodes SHOULD only include the coinbase transaction in prefilledtxn." This is unsure if the compact block validation code already sanitize on the reception of a coinbase (to avoid fulfilling resources after the `CMPCTBLOCK`), I have no re-checked fully, though looking shortly in `blockencoding.cpp` it doesn't sound to.
fanquake commented 2026-11-25 18:15:28 +00:00 (Migrated from github.com)
ACK 58b418f85582b559ad9ac718e42251e5bc5aab3a
theStack (Migrated from github.com) approved these changes 2026-11-26 14:14:59 +00:00
theStack (Migrated from github.com) left a comment
ACK 58b418f85582b559ad9ac718e42251e5bc5aab3a
theStack (Migrated from github.com) commented 2026-11-26 14:14:27 +00:00

in a730c789ce: nit: not an issue now, but I think for disabling BIP 54, setting the start time to -2 (NEVER_ACTIVE), e.g. -vbparams=consensuscleanup:-2:0, would be more robust here. With 0:0 the deployment still goes through the regular versionbits state machine, and since the node's miner signals once it's in started, it can still lock in and activate if the node mines enough blocks itself. The current tests don't run into this as their chains are too short or don't contain enough signalling blocks.

in a730c789ceb110e587ce16d087354732118e592e: nit: not an issue now, but I think for disabling BIP 54, setting the start time to -2 ([NEVER_ACTIVE](https://github.com/bitcoin/bitcoin/blob/63a3c03235b3263cda1ded2459188106c838438d/src/consensus/params.h#L82)), e.g. `-vbparams=consensuscleanup:-2:0`, would be more robust here. With 0:0 the deployment still goes through the regular versionbits state machine, and since the node's miner signals once it's in started, it can still lock in and activate if the node mines enough blocks itself. The current tests don't run into this as their chains are too short or don't contain enough signalling blocks.
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-26 16:34:13 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

ACK 58b418f855

I did a review of the consensus rules here, cross-checking with the specification in https://github.com/bitcoin/bips/blob/master/bip-0054.md. I think they are correct and mirror it.

I did manual mutations of the rules and saw failures from the test vectors added.

I did not look at the test vectors in depth; I was mostly interested in the production code correctness.
I left a few comments but nothing major.

ACK 58b418f85582b559ad9ac718e42251e5bc5aab3a I did a review of the consensus rules here, cross-checking with the specification in https://github.com/bitcoin/bips/blob/master/bip-0054.md. I think they are correct and mirror it. I did manual mutations of the rules and saw failures from the test vectors added. I did not look at the test vectors in depth; I was mostly interested in the production code correctness. I left a few comments but nothing major.
ismaelsadeeq (Migrated from github.com) commented 2026-11-26 15:48:27 +00:00

This brings noisy logs when you execute the test without ctest, worth suppressing?

❯ ./build/bin/test_bitcoin --run_test=bip54_tests
Running 4 test cases...
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.
Error: The -vbparams option may not be used on mainnet.

*** No errors detected

This brings noisy logs when you execute the test without ctest, worth suppressing? ``` ❯ ./build/bin/test_bitcoin --run_test=bip54_tests Running 4 test cases... Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. Error: The -vbparams option may not be used on mainnet. *** No errors detected ```
ismaelsadeeq (Migrated from github.com) commented 2026-11-26 16:16:43 +00:00

nitty-nit feel free to ignore: As more input-level rules get added here, that grows into a list of bools. Could mirror the script-verification flags, pass an unsigned int bitfield (TX_INPUT_CHECK_BIP54_SIGOPS, …) the same way SCRIPT_VERIFY_* flows into CheckInputScripts.

nitty-nit feel free to ignore: As more input-level rules get added here, that grows into a list of bools. Could mirror the script-verification flags, pass an unsigned int bitfield (`TX_INPUT_CHECK_BIP54_SIGOPS`, …) the same way `SCRIPT_VERIFY_*` flows into `CheckInputScripts`.
ismaelsadeeq (Migrated from github.com) commented 2026-11-26 15:34:43 +00:00

nit: will be good for debugging to see the values that trigger the failure here and the murch zawy check?

            return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "time-timewarp-attack",
                                 strprintf("block's timestamp is too early on diff adjustment block: %d < %d - %d",
                                           block.GetBlockTime(), pindexPrev->GetBlockTime(), *max_timewarp));
nit: will be good for debugging to see the values that trigger the failure here and the murch zawy check? ```suggestion return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "time-timewarp-attack", strprintf("block's timestamp is too early on diff adjustment block: %d < %d - %d", block.GetBlockTime(), pindexPrev->GetBlockTime(), *max_timewarp)); ```
ismaelsadeeq (Migrated from github.com) commented 2026-11-26 15:54:55 +00:00

It seems that this nHeight > 0 check is never gonna be false, so belt and suspenders? Removing it has no test failing, and adding an assert indicates no genesis block goes through that path?

It seems that this `nHeight > 0` check is never gonna be false, so belt and suspenders? Removing it has no test failing, and adding an assert indicates no genesis block goes through that path?
ajtowns (Migrated from github.com) reviewed 2026-11-27 04:58:00 +00:00
ajtowns (Migrated from github.com) commented 2026-11-27 04:58:00 +00:00

If you want to rely on that, then an assert(pindexPrev != nullptr); // genesis block never goes through this path at the top of the function would make sense?

If it did ever go through the path, the exception is necessary since otherwise versionbits activation set to "always active" would incorrectly apply the rule to the genesis block.

If you want to rely on that, then an `assert(pindexPrev != nullptr); // genesis block never goes through this path` at the top of the function would make sense? If it did ever go through the path, the exception is necessary since otherwise versionbits activation set to "always active" would incorrectly apply the rule to the genesis block.
ajtowns (Migrated from github.com) reviewed 2026-11-27 05:01:53 +00:00
ajtowns (Migrated from github.com) commented 2026-11-27 05:01:53 +00:00

FWIW, I seem to get an error around test/kernel/test_kernel.cpp(935) (so chainman->ImportBlocks) if I add a pindexPrev != nullptr assert at the top of ContextualCheckBlock; haven't looked in any further detail.

FWIW, I seem to get an error around `test/kernel/test_kernel.cpp(935)` (so `chainman->ImportBlocks`) if I add a `pindexPrev != nullptr` assert at the top of `ContextualCheckBlock`; haven't looked in any further detail.
polespinasa (Migrated from github.com) reviewed 2026-11-30 18:33:48 +00:00
polespinasa (Migrated from github.com) left a comment

ACK 58b418f855

Left some small feel-free-to-ignore nits

in de464d3e35 the commit message says as it will be made consensus-critical in the next commit, but that is not true, next two commits only clarifies a documentation comment and modifies some testing.

ACK 58b418f85582b559ad9ac718e42251e5bc5aab3a Left some small feel-free-to-ignore nits in de464d3e35ec9eb67c499cf1d8a587480acc9b87 the commit message says `as it will be made consensus-critical in the next commit`, but that is not true, next two commits only clarifies a documentation comment and modifies some testing.
polespinasa (Migrated from github.com) commented 2026-11-30 17:17:46 +00:00

in af2a89fe33 validation: make BIP54 sigops check consensus-critical

maybe add BOOST_CHECK(state.GetResult() == TxValidationResult::TX_CONSENSUS); ?

in af2a89fe3369a69ec773590da4ee4dc3943f90ee validation: make BIP54 sigops check consensus-critical maybe add `BOOST_CHECK(state.GetResult() == TxValidationResult::TX_CONSENSUS);` ?
polespinasa (Migrated from github.com) commented 2026-11-30 17:30:45 +00:00

in fae79e5112 qa: add to utilities a version of SignSignature for Taproot inputs

I think we can drop fromPubKey and amount since spent_outputs[nIn] already contains both, passing them separately lets a caller supply conflicting values.

in fae79e51124afc32061e6684d9983cdd1eccda46 qa: add to utilities a version of SignSignature for Taproot inputs I think we can drop `fromPubKey` and `amount` since `spent_outputs[nIn]` already contains both, passing them separately lets a caller supply conflicting values.
polespinasa (Migrated from github.com) commented 2026-11-30 17:56:01 +00:00

in b4381856dd validation: prevent negative difficulty adjustment intervals

maybe could make this int const?

in b4381856dd15121ca2700818ac182d815381da3a validation: prevent negative difficulty adjustment intervals maybe could make this int const?
ariard (Migrated from github.com) reviewed 2026-12-01 00:46:28 +00:00
ariard (Migrated from github.com) left a comment

It's a more BIP feedback, but "Transactions whose witness-stripped serialized size is exactly 64 bytes are invalid" would win to explicitly reference BIP 144.

At first sight, without going to read the code implementation, it's ambiguous if the 64 byte serialized size is including the witness marker and flag (2-bytes).

It's a more BIP feedback, but "Transactions whose witness-stripped serialized size is exactly 64 bytes are invalid" would win to explicitly reference BIP 144. At first sight, without going to read the code implementation, it's ambiguous if the 64 byte serialized size is including the witness marker and flag (2-bytes).
ariard (Migrated from github.com) commented 2026-12-01 00:45:04 +00:00

thinking the comment should be "bad-txn-size" and not "bad-txns-size" the plural form.

i think it's okay not to cache all the 64-byte transactions of a block as in case of malicious crafted list of block transactions all composed of a 64-byte transaction, a BLOCK_CONSENSUS error is yield and the whole block is marked as invalid. the peer should punished accordingly to MaybePunishNodeForBlock() unless it's a compact block (L2042 in src/net_processing.cp) where the trick is repeated. if we're caching well the block invalidity at reception of CMPCTBLOCK message, i think it should be good as it's doesn't matter than one or many invalid 64 byte transactions are existent.

maybe you're able to encumber the txn_available between the completion of a compact block message round trip with junk, though doesn't change from already existent garbage fulfilling vector, i'm thinking.

thinking the comment should be "bad-txn-size" and not "bad-txns-size" the plural form. i think it's okay not to cache all the 64-byte transactions of a block as in case of malicious crafted list of block transactions all composed of a 64-byte transaction, a `BLOCK_CONSENSUS` error is yield and the whole block is marked as invalid. the peer should punished accordingly to `MaybePunishNodeForBlock()` unless it's a compact block (L2042 in `src/net_processing.cp`) where the trick is repeated. if we're caching well the block invalidity at reception of `CMPCTBLOCK` message, i think it should be good as it's doesn't matter than one or many invalid 64 byte transactions are existent. maybe you're able to encumber the `txn_available` between the completion of a compact block message round trip with junk, though doesn't change from already existent garbage fulfilling vector, i'm thinking.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35793
No description provided.