Skip to content

test: cover BIP30 for non coinbase txs - #36847

Open
ViniciusCestarii wants to merge 1 commit into
bitcoin:masterfrom
ViniciusCestarii:test-bip30-non-coinbase
Open

ViniciusCestarii wants to merge 1 commit into
bitcoin:masterfrom
ViniciusCestarii:test-bip30-non-coinbase

Conversation

@ViniciusCestarii

Copy link
Copy Markdown
Contributor

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");
             }
         }
     }

@DrahtBot DrahtBot added the Tests label Nov 12, 2026
@DrahtBot

DrahtBot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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.

@l0rinc

l0rinc commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

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

@ViniciusCestarii

Copy link
Copy Markdown
Contributor Author

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 johnnyasantoss left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@KY-U

KY-U commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants