Testnet 5 (BIP95)

bitcoin/bitcoin: PR #35861

3 minor findings · 7 suggestions

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

Findings

Link

[minor] · Regtest activation changes existing mining clients without a compatibility note

This 32.x backport newly enforces BIP54 on regtest, rejecting segwit-only GBT requests and noncompliant custom blocks, but its release note mentions only Testnet5.

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

Details and suggested fix

With the request fixed at {"rules":["segwit"]}, base regtest accepts it but head throws -8 because consensuscleanup is active and non-optional. Custom blocks must also use coinbase nLockTime = height - 1 and a non-final nSequence, and satisfy the new size, sigops and timestamp constraints. Base Core's assembler already sets those coinbase fields correctly, so this is not a blanket failure of older Core-generated blocks. If retaining this default on 32.x, add a regtest compatibility note covering the requirements and the deployment-override configuration available to legacy fixtures. Keeping regtest inactive and explicitly activating BIP54 in its tests would instead preserve the existing default contract.


Link

[minor] · Future-leaf BIP54 vector repeats the Tapscript spend

The BIP54 unit test records the ordinary Tapscript spend twice, so its future-leaf-version case and generated vector do not exercise a 0xc2 leaf.

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

Details and suggested fix

The first successful SignSignature call leaves sigdata.complete set. Changing the keystore keys and tr_spenddata does not clear it, so the second call returns immediately from ProduceSignature; UpdateInput then copies the old Tapscript witness back. Verification succeeds on that unchanged spend, which is recorded under the future-leaf description. Construct the witness explicitly from leaf_script_future and its control block from builder.GetSpendData(), then assert the masked control-block leaf version is 0xc2 and verify the input under consensus flags. Resetting complete alone is insufficient because SignTaprootScript only signs Tapscript leaves.


Link

[minor] · BIP support versions omit the 32.x backport

Both new bips.md entries name only v33.0, which would misstate feature availability when these changes ship in a 32.x release.

Location: doc/bips.md:21 (head).

Details and suggested fix

The BIP54 entry dates implementation to v33.0, and the BIP95 entry dates -testnet5 support to the same version. Neither records availability on this release branch. Add the actual 32.x backport release to both entries, retaining the upstream introduction version if desired, as the BIP65 entry does. The exact shipping point release is not established by the current 32.1 build metadata, so that number needs to be supplied during release preparation.


Optional improvements

Link

[suggestion] · Mempool compatibility changes are absent from release notes

The backport changes mempool reject strings on existing networks, including mainnet, and removes the test-network -acceptnonstdtxn sigops bypass, but documents only Testnet5.

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

Details and suggested fix

For transactions reaching these checks, aggregate BIP54-sigops rejection changes from bad-txns-nonstandard-inputs to bad-txns-legacy-sigops, and exactly-64-byte witness-stripped rejection changes from tx-size-small to txn-size-64. Both now use the internal TX_CONSENSUS classification independently of activation. Moving the sigops check outside require_standard also prevents -acceptnonstdtxn=1 from bypassing it on test networks. Add a compatibility note listing the new reject strings and stricter test-network admission behavior. These mempool changes do not activate BIP54 block rules on mainnet.


Link

[suggestion] · Inactive-deployment mempool enforcement lacks coverage

The new coverage never combines mempool admission with inactive BIP54, so it does not distinguish unconditional enforcement from deployment-gated enforcement.

Location: test/functional/feature_bip54.py:366 (head).

Details and suggested fix

PreChecks correctly passes enforce_bip54=true, unlike block connection's deployment-gated argument. The preactivation section here only submits blocks, while mempool_sigoplimit.py uses default, active regtest cleanup and the unit tests pass true directly. Add an inactive-deployment mempool rejection for an over-limit spend with default policy and with -acceptnonstdtxn=1, plus a fee-paying 2500-sigop control. Confirm the preparation transaction first and avoid other standardness failures masking the sigops result. The existing bare-script helper needs adaptation because its scriptSig is non-push-only and its spend pays no fee. Keep the assertion that the over-limit spend can still be mined before activation.


Link

[suggestion] · BIP54-sigops rejects lose txid caching

Witness-bearing BIP54-sigops rejects now cache only their wtxid, allowing eligible child orphans to trigger repeated parent fetching and cheap revalidation; existing orphan and request limits still bound this work.

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

Details and suggested fix

Under default standardness, this failure previously returned TX_INPUTS_NOT_STANDARD, which makes MempoolRejectedTx additionally cache the txid of a witness transaction. Returning TX_CONSENSUS skips that insertion. Since orphan handling checks parents by txid, a peer can now supply an eligible child and serve the rejected parent again with a different witness. The sigops result depends only on non-witness data, so that retry cannot help. Preserve txid caching for bad-txns-legacy-sigops specifically. This restores the existing optimization without treating all consensus failures as witness-independent; other such failures already share the current bounded behavior.


Link

[suggestion] · Mandatory cleanup-rule rejection is not tested

mining_basic.py checks the advertised rule but does not exercise the rejection of segwit-only clients.

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

Details and suggested fix

The {} request fails at the earlier segwit-specific check, and NORMAL_GBT_REQUEST_PARAMS now includes both rules. Neither assertion depends on the active-deployment explicit-support guard rejecting an unsupported client. Add assert_raises_rpc_error(-8, "Support for 'consensuscleanup' rule requires explicit client support", node.getblocktemplate, {"rules": ["segwit"]}) alongside these assertions. It would protect the guard that prevents unaware clients from receiving templates requiring BIP54 coinbase changes.


Link

[suggestion] · Testnet5 chain-selection branches lack coverage

The added alias and conflict term are absent from the argument-parsing tests, so those tests would not detect selecting the wrong chain or accepting conflicting flags.

Location: src/common/args.cpp:940 (head).

Details and suggested fix

util_GetChainTypeString registers and exercises Testnet3, Testnet4 and regtest, but not the new Testnet5 paths. Extend the fixture registration and assertions so -testnet5 and -chain=testnet5 select testnet5, -notestnet5 leaves main selected, and combining -testnet5 with -testnet4 or -chain=main throws. This would distinguish the new selection branch and conflict-count term from the otherwise similar existing-network cases.


Link

[suggestion] · BIP54 fuzzing has no accounting oracle

The new fuzz target ignores the boolean result, so incorrect sigop accounting cannot fail the harness unless it also crashes.

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

Details and suggested fix

Accumulate an independent total across all constructed inputs and assert that CheckSigopsBIP54 agrees with total <= MAX_TX_BIP54_SIGOPS. Sum both scriptSig.GetSigOpCount(true) and the spent scriptPubKey's GetSigOpCount(scriptSig). The latter matters for P2SH: a malformed or non-push-only scriptSig contributes no redeem-script count, so counting the supplied redeem script directly would create false failures. This would test transaction-level aggregation, including omitted scriptSig counts or a running total reset per input, while preserving the existing crash coverage.


Link

[suggestion] · The data-directory table omits Testnet5

The new network stores chain data in <datadir>/testnet5/, but doc/files.md gives users no Testnet5 mapping.

Location: src/chainparamsbase.cpp:50 (head).

Details and suggested fix

CreateBaseChainParams selects the testnet5 subdirectory, while the documented table lists every other supported chain. Add a row mapping -chain=testnet5 or -testnet5 to path_to_datadir/testnet5/ so users can locate the new network's files.


Backport verdict: Needs clarification

I couldn't confirm that this backport matches upstream. The packet lists 27 commits but resolves none of them to an upstream original, and no commit has Rebased-From or GitHub-Pull trailers. All 22 BIP54 commits (#35793) and all 5 Testnet5 commits therefore went unchecked against their originals. The PR description also says it should stay in draft "until #35793 lands", so it's unclear whether the BIP54 consensus commits being backported were ever merged on master. The target is the v32.1 release branch (CMakeLists sets 32.1.0 as a release). That makes several head-state items concrete problems for a point release. The docs say v33.0. The release note is a master-style snippet that leaves out user-visible BIP54 changes. Regtest now always enforces BIP54, so getblocktemplate fails for any client that doesn't pass 'consensuscleanup'. Mempool reject reasons change on every network. Testnet5 still has a TODO for its header-sync parameters, and its genesis contradicts the PR description. In the code I read, the Testnet5 wiring and the BIP54 validation hooks look internally consistent. I found no independently established code defect, so the verdict is Needs clarification rather than Defective.

Evidence:

Required fixes:

Limitations:

Coverage details

Earlier concerns

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

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The 20-minute difficulty exception was deliberately retained in Testnet4 to permit CPU mining of nonstandard transactions and help the chain progress after substantial hashpower leaves.

At the pinned base, Testnet4 enables fPowAllowMinDifficultyBlocks. GetNextWorkRequired uses the minimum target after a timestamp gap exceeding twice the target spacing. Testnet5 disables this exception, changing an intentional accessibility and recovery mechanism rather than merely removing an accidental special case.

Source 1 · Source 2 · Source 3

Testnet4's retarget changes attempted to retain that accessibility while preventing a minimum-difficulty final block from resetting the next period's effective difficulty. Testnet5 instead prioritizes reliability and similarity to mainnet after sustained exploitation of the exception.

The base sets enforce_BIP94, causing retargets to use the first block's difficulty. The head's Testnet5 parameters disable both the exception and BIP94, while retaining ordinary retargeting. The contemporary Testnet5 account identifies persistent difficulty-exception exploitation as the motivation for removing the rule and specifies the higher minimum difficulty.

Source 1 · Source 2 · Source 3

BIP54's timestamp restrictions address incentive failures beyond ordinary timestamp accuracy: timewarp can accelerate subsidy extraction and impose additional validation load, while alternating timestamps can exploit the difficulty-adjustment bounds. Its two-hour grace period was chosen conservatively over Testnet4's ten-minute bound.

The head checks the first block of a retarget period against its predecessor and prevents the last block from preceding the period's first block. Testnet5 uses these BIP54 checks rather than Testnet4's tighter BIP94 boundary rule. The documented grace-period choice balances attack resistance against unnecessarily constraining historical timestamp behavior.

Source 1 · Source 2

The BIP54 per-transaction signature-operation limit was designed to bound adversarial validation work without broadly disabling Script features or confiscating funds that depend on them. The authors chose 2,500 as the tightest limit that preserved non-pathological standard transactions and argued that it substantially reduces worst-case validation time and raises attack preparation costs.

The base already applies this accounting as input-standardness policy. The head moves it into consensus input validation, counting potentially executed non-witness operations in scriptSig and spent scripts, including P2SH redeem scripts. Block enforcement is deployment-gated, while mempool acceptance applies the check independently of activation.

Source 1

Exactly 64-byte transactions are singled out because Bitcoin's Merkle construction does not distinguish their serialization from the concatenation of two child hashes. BIP54's authors preferred eliminating this ambiguity at consensus over requiring SPV verifiers to recognize and implement an additional mitigation.

The head rejects witness-stripped transactions of exactly 64 bytes in blocks after activation and in mempool prechecks. Smaller transactions remain nonstandard rather than becoming invalid under this new block rule. That distinction follows the specific Merkle ambiguity, not a general consensus minimum transaction size.

Source 1

Requiring coinbases to be height-timelocked prevents future duplication of early coinbases whose scripts accidentally encode valid future BIP34 heights. BIP54 motivates this as a route away from costly BIP30 validation, including a check Utreexo clients cannot perform, and as a way to expose coinbase height without parsing Script.

The head requires nLockTime equal to block height minus one and a non-final nSequence when BIP54 is active, excluding genesis. These fields make the coinbase unavailable at earlier heights and therefore distinguish it from a historical duplicate. This explains the restriction; it does not establish that this patch removes all BIP30 checks.

Source 1

Ralph's inferences

Once the minimum-difficulty exception is absent, BIP94's special choice of the first block as the retarget difficulty base is no longer needed for its original purpose: within a period, ordinary proof-of-work rules preserve the same target.

This explains the combination fPowAllowMinDifficultyBlocks=false and enforce_BIP94=false in Testnet5. The separate BIP54 timestamp checks retain protection against timestamp manipulation without retaining the exception-specific retarget mechanism.

Source 1 · Source 2

Starting the new network with BIP54 active provides a public environment using the new validation rules without requiring a coordinated transition of an existing chain or implying mainnet activation.

The head marks consensuscleanup ALWAYS_ACTIVE on Testnet5 and regtest, but NEVER_ACTIVE by default on the other inspected networks. The Testnet5 versionbits test explicitly evaluates activation for block 1. This interpretation separates the new test network's rule set from a mainnet deployment decision.

Source 1 · Source 2

Unresolved disagreements

The inspected history leaves a continuing tradeoff between cheap independent public-chain experimentation and resilience to difficulty-rule exploitation. Earlier participants emphasized laptop mining and recovery after hashpower withdrawal; the Testnet5 proposal emphasizes reliability and mainnet-like behavior. The retrieved record does not demonstrate how removing the exception will perform under future large hashpower departures.

Testnet5 deliberately removes the CPU-mining escape hatch and raises the difficulty floor while retaining the two-week retarget schedule. This is historical context for that release-branch behavior, not a finding that the choice is incorrect or a recommendation to restore the exception.

Source 1 · Source 2 · Source 3 · Source 4