test: cover BIP30 for non coinbase txs #36847

Open
ViniciusCestarii wants to merge 1 commit from test-bip30-non-coinbase into master AGit
ViniciusCestarii commented 2026-11-12 15:19:36 +00:00 (Migrated from github.com)

The BIP30 tests in feature_block.py only cover duplicate coinbase transactions, but the check applies to every transaction in a block.

Add coverage for a duplicate non-coinbase transaction:

  • tx A spends coinbase C
  • a duplicate of C is mined and matures, so A can be included again
  • re-including A is rejected while A's outputs are unspent
  • re-including A is accepted after A's outputs are spent

Kills the following mutant (https://mutanthub.space/mutants/4389):

diff --git a/src/validation.cpp b/src/validation.cpp
index 6bed39ba5f..a8a6b46b3d 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2538,12 +2538,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
     // consensus change that ensures coinbases at those heights cannot
     // duplicate earlier coinbases.
     if (fEnforceBIP30 || pindex->nHeight >= BIP34_IMPLIES_BIP30_LIMIT) {
-        for (const auto& tx : block.vtx) {
-            for (size_t o = 0; o < tx->vout.size(); o++) {
-                if (view.HaveCoin(COutPoint(tx->GetHash(), o))) {
-                    state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
-                                  "tried to overwrite transaction");
-                }
+        const CTransaction& coinbase{*block.vtx[0]};
+        for (size_t o = 0; o < coinbase.vout.size(); o++) {
+            if (view.HaveCoin(COutPoint(coinbase.GetHash(), o))) {
+                state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
+                              "tried to overwrite transaction");
             }
         }
     }
The BIP30 tests in `feature_block.py` only cover duplicate coinbase transactions, but the check applies to every transaction in a block. Add coverage for a duplicate non-coinbase transaction: - tx A spends coinbase C - a duplicate of C is mined and matures, so A can be included again - re-including A is rejected while A's outputs are unspent - re-including A is accepted after A's outputs are spent Kills the following mutant (https://mutanthub.space/mutants/4389): ```diff diff --git a/src/validation.cpp b/src/validation.cpp index 6bed39ba5f..a8a6b46b3d 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2538,12 +2538,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, // consensus change that ensures coinbases at those heights cannot // duplicate earlier coinbases. if (fEnforceBIP30 || pindex->nHeight >= BIP34_IMPLIES_BIP30_LIMIT) { - for (const auto& tx : block.vtx) { - for (size_t o = 0; o < tx->vout.size(); o++) { - if (view.HaveCoin(COutPoint(tx->GetHash(), o))) { - state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30", - "tried to overwrite transaction"); - } + const CTransaction& coinbase{*block.vtx[0]}; + for (size_t o = 0; o < coinbase.vout.size(); o++) { + if (view.HaveCoin(COutPoint(coinbase.GetHash(), o))) { + state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30", + "tried to overwrite transaction"); } } } ```
DrahtBot commented 2026-11-12 15:19:48 +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 johnnyasantoss, KY-U

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:

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

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.

<!--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/36847 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36847.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36847#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 | [johnnyasantoss](https://github.com/bitcoin/bitcoin/pull/36847#pullrequestreview-5892464961), [KY-U](https://github.com/bitcoin/bitcoin/pull/36847#issuecomment-6857408111) | 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: * [#35793](https://github.com/bitcoin/bitcoin/pull/35793) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35793.svg"></sub> (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior) 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-->
First-time contributor

🔵 Suggestion · The non-coinbase BIP30 test misses partially spent transactions

Like the existing coinbase cases, the new single-output fixture cannot distinguish checking every output from checking only output 0, leaving the partially spent BIP30 case uncovered.

Location: test/functional/feature_block.py:876 (head).

Review coverage was incomplete.


Reviewed: 404d102878ad · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:8fa46da13758fe55dfdc78f36e5156483169b9353c6046c9c84f4c16d0cba459:630667d10bbb410bd46501d483dc1e4922cfe499482d60a51fbad7c921ce8015 --> <!-- ralph-base:791173ae952bb07716531dd01a78d70dc3b7c038 --> <!-- ralph-head:404d102878ad91123ef02db8bad9a3d561f9efe6 --> <!-- ralph-case:c90205d81af7abfad14bfccc00bd77054f2534e1fe6142067349468311424a38 --> **🔵 Suggestion · The non-coinbase BIP30 test misses partially spent transactions** Like the existing coinbase cases, the new single-output fixture cannot distinguish checking every output from checking only output 0, leaving the partially spent BIP30 case uncovered. Location: [`test/functional/feature_block.py:876`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/404d102878ad91123ef02db8bad9a3d561f9efe6/test/functional/feature_block.py#L876>) (head). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`404d102878ad`](<https://git.fish.foo/bitcoin/bitcoin/commit/404d102878ad91123ef02db8bad9a3d561f9efe6>) · [Review report](<https://review.fish.foo/report/36847-404d102878ad91123ef02db8bad9a3d561f9efe6-2589-1.html>) · [Previous reports](<https://review.fish.foo/traces/36847/>) [permalink](<https://review.fish.foo/report/36847-404d102878ad91123ef02db8bad9a3d561f9efe6-2589-1.html>)
l0rinc commented 2026-11-13 09:19:57 +00:00 (Migrated from github.com)

Not sure this is important, in fact I think we should completely remove the BIP30 checks during assumevalid (and sigop counting, see https://github.com/bitcoin/bitcoin/issues/36476).
That doesn't necessarily contradict adding new tests for it, but doesn't seem like a priority to me.

Not sure this is important, in fact I think we should completely remove the BIP30 checks during assumevalid (and sigop counting, see https://github.com/bitcoin/bitcoin/issues/36476). That doesn't necessarily contradict adding new tests for it, but doesn't seem like a priority to me.
ViniciusCestarii commented 2026-11-13 12:16:54 +00:00 (Migrated from github.com)

I agree that it is not urgent, but I still think it is worth covering as long as the check exists because it affects consensus. Even with that change, nodes running with -assumevalid=0 would still use BIP 30.

I agree that it is not urgent, but I still think it is worth covering as long as the check exists because it affects consensus. Even with that change, nodes running with `-assumevalid=0` would still use BIP 30.
johnnyasantoss (Migrated from github.com) reviewed 2026-11-13 14:12:11 +00:00
johnnyasantoss (Migrated from github.com) left a comment

404d102878 tACK. The code exists today, this simply exercises it further.

404d102878ad91123ef02db8bad9a3d561f9efe6 tACK. The code exists today, this simply exercises it further.
KY-U commented 2026-11-13 15:28:15 +00:00 (Migrated from github.com)

tACK 404d102878. Verified the mutant is killed by timeout.

tACK 404d102878ad91123ef02db8bad9a3d561f9efe6. Verified the mutant is killed by timeout.
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!36847
No description provided.