#35793 Implement BIP 54 (Consensus Cleanup) without mainnet activation
https://github.com/bitcoin/bitcoin/pull/35793 · · +6584/-123 in 39 files, 22 commits · labels: none
Goal
- Protect the network against known consensus attacks including timewarp exploits and Merkle tree collisions
- Prevent severe block validation delays caused by excessive legacy signature operations
This pull request implements the validation rules for the BIP 54 Consensus Cleanup soft fork on regtest while keeping mainnet activation inactive. The rules address legacy sigops computational DoS, timewarp attacks, negative difficulty adjustment periods (Murch-Zawy), unspendable coinbase height timelocks, and 64-byte Merkle tree collision vulnerabilities. Around 95% of the patch consists of unit tests, functional test coverage, and test vectors.
Problem: Bitcoin consensus retains legacy vulnerabilities, including timewarp difficulty manipulation, quadratic hashing attacks from legacy sigops, and potential 64-byte transaction collisions in Merkle trees. Without implementing BIP 54 rules in Bitcoin Core, these attack vectors cannot be thoroughly tested across node validation infrastructure in preparation for potential mainnet deployment.
Category: Validation (#1 of 48)
P2 · DoS protection
- P1 because it addresses critical consensus vulnerabilities including timewarp exploits and CVE-2017-12842
- Eliminates block validation denial-of-service vectors caused by legacy signature operations
- Enforces new consensus soft fork rules requiring thorough review before activation
P2 because it implements the long-discussed consensus rules of BIP 54 to resolve serious historical consensus vulnerabilities, including timewarp manipulation, quadratic legacy sigops block verification DoS, and 64-byte transaction Merkle collisions. While not yet active on mainnet, implementing and testing these rules in Core is strategically critical for the consensus roadmap.
Membership: Implements BIP 54 consensus validation rules in src/consensus/tx_verify.cpp and src/validation.cpp.
Factors: security/stability 3, bug 2, performance 1, user value 0, leverage 2
Category: Mempool and policy (#8 of 10)
P3 · new feature
- P3 because it aligns mempool validation and standardness checks with BIP 54 rules, ensuring transactions that violate the 2500 legacy sigops threshold or the 64-byte size boundary cannot enter the mempool even with acceptnonstdtxn enabled.
P3 because it aligns mempool validation and standardness checks with BIP 54 rules, ensuring transactions that violate the 2500 legacy sigops threshold or the 64-byte size boundary cannot enter the mempool even with acceptnonstdtxn enabled.
Membership: Changes policy checks in src/policy/policy.h and enforces BIP 54 input sigop validation in src/txmempool.cpp.
Factors: security/stability 2, bug 1, performance 0, user value 0, leverage 1
Reviewability: Ready
- Ready for review
- Cleanly rebased on master with passing CI and all feedback addressed
The PR has clean mergeable state, passes CI, and was recently rebased following the merge of related PR #35949.
Author status: Active; rebased on master and addressed review feedback on 2026-09-13.
Resolved concerns:
- Miner enforcement of Murch-Zawy rule: raised by fjahr, spun out into PR #35949, merged into master, and rebased here.
- Validation result classification (TX_CONSENSUS vs policy) prior to activation: raised by polespinasa, resolved by author with rationale in commit message.
- Mempool transition behavior and sigops counting edge cases: discussed by ariard, resolved with author explanation of acceptnonstdtxs handling.
Agreement: Strong
- Broad concept support across contributors and maintainers
- Concept approval without stated reasons (dergoegge, fanquake, theStack, hsjoberg, stickies-v)
- Detailed review on sigops limits and timewarp mitigations with concerns addressed (ariard, polespinasa)
- Collaborated on mining template enforcement merged in a prior PR (fjahr)
Strong concept consensus with 7 member Concept ACKs; initial implementation concerns have been resolved.
Seven project members Concept ACKed the PR. Technical questions raised around miner rules, validation result codes, and sigop metrics have been answered and resolved without ongoing opposition.
- Concept ACKs from dergoegge, fanquake, polespinasa, theStack, hsjoberg, fjahr, and stickies-v
- Fjahr suggested the Murch-Zawy miner rule in #35949 which was reviewed and merged before rebasing here
- Polespinasa and ariard review discussions concluded without outstanding blocking concerns
Objections:
| Reviewer | Kind | Harm | Status | Blocking | Author replied | Quote |
|---|---|---|---|---|---|---|
| polespinasa | correctness | Categorizing BIP54 check failures as TX_CONSENSUS before activation misrepresents policy rejections | resolved | no | yes | 2026-08-24: '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.' Settled: 2026-09-13: '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.' |
| fjahr | approach | Miner does not enforce Murch-Zawy rule, risking invalid block creation under BIP 54 | resolved | no | yes | 2026-08-03: 'The miner currently does not enforce the murch-zawy rule but I think it should.' Settled: 2026-09-13: 'Rebased now that #35949 is merged.' |
| ariard | approach | Lax mempools could generate invalid block templates across the activation boundary | resolved | no | yes | 2026-08-08: 'in fact it's a dumb nuisance attack vector for the few transition blocks during activation if the miners are running "lax" mempools.' Settled: 2026-09-10: '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.' |
Support:
- dergoegge: Concept ACK [not substantive]
- fanquake: Concept ACK [not substantive]
- polespinasa: Concept ACK and review of validation logic
- theStack: Concept ACK [not substantive]
- hsjoberg: Concept ACK [not substantive]
- fjahr: Concept ACK and contributed miner check PR
- stickies-v: Concept ACK [not substantive]
- Christewart: Excited to see this work make it to this point [not substantive]
Participants: Christewart (support), ariard (objection), dergoegge (support), fanquake (support), polespinasa (support), theStack (support), hsjoberg (support), fjahr (objection), l0rinc (question), stickies-v (support)
State derived from the lists: substantive support, no open objection (polespinasa, fjahr)
Review verdicts (DrahtBot): 0
- Concept ACK: dergoegge, fanquake, polespinasa, theStack, hsjoberg, fjahr, stickies-v
Dependencies
Enables:
- BIP 54 testing and future mainnet deployment consideration
Files
6495 lines under test/bench/ci.
- src/test/data/bip54_timestamps.json +4134/-0
- src/test/bip54_tests.cpp +1608/-0
- test/functional/feature_bip54.py +417/-0
- src/test/data/bip54_coinbases.json +80/-0
- src/validation.cpp +54/-14
- src/test/fuzz/bip54.cpp +54/-0
- src/test/transaction_tests.cpp +26/-24
- src/policy/policy.cpp +1/-36
- src/consensus/tx_verify.cpp +31/-1
- src/kernel/chainparams.cpp +28/-0
- test/functional/data/invalid_txs.py +17/-3
- test/functional/p2p_segwit.py +11/-8
- src/consensus/consensus.h +16/-1
- test/functional/mempool_sigoplimit.py +8/-9
- src/test/util/transaction_utils.cpp +14/-0
- test/functional/rpc_blockchain.py +13/-0
- test/functional/feature_block.py +9/-1
- test/functional/mining_basic.py +5/-5
- src/consensus/tx_verify.h +7/-1
- test/functional/feature_taproot.py +5/-3
- src/test/fuzz/coins_view.cpp +6/-1
- src/node/miner.cpp +3/-3
- test/functional/test_framework/blocktools.py +4/-2
- test/functional/wallet_migration.py +4/-2
- src/policy/policy.h +2/-3
- test/functional/wallet_ancient_migration.py +4/-1
- src/deploymentinfo.cpp +4/-0
- test/functional/test_framework/script_util.py +2/-2
- src/test/CMakeLists.txt +3/-0
- src/test/util/transaction_utils.h +3/-0
- test/functional/rpc_getblockstats.py +3/-0
- src/CMakeLists.txt +1/-1
- src/txmempool.cpp +1/-1
- test/functional/mempool_accept.py +1/-1
- doc/bips.md +1/-0
- src/consensus/params.h +1/-0
- src/rpc/blockchain.cpp +1/-0
- src/test/fuzz/CMakeLists.txt +1/-0
- test/functional/test_runner.py +1/-0
Card
This PR implements the validation logic for BIP 54 (Consensus Cleanup) with activation configured exclusively on regtest. It resolves long-standing consensus-level issues including quadratic legacy sigop verification DoS, timewarp attacks, negative difficulty retarget intervals, and 64-byte transaction Merkle collision vulnerabilities. The PR enjoys strong concept support with seven Concept ACKs from maintainers and regular contributors, and an accompanying miner PR (#35949) has already been merged into master. Reviewing this PR represents timely, high-value validation work as the project considers soft fork readiness.