test: cover negative output after positive in CheckTransaction #36931

pull ViniciusCestarii wants to merge 1 commits into bitcoin:master from ViniciusCestarii:tx_negative_output_after_positive changing 1 files +4 −0
  1. ViniciusCestarii commented at 7:31 PM on November 20, 2026: contributor

    Kills mutant https://mutanthub.space/mutants/4675:

    diff --git a/src/consensus/tx_check.cpp b/src/consensus/tx_check.cpp
    index 473538e..d484547 100644
    --- a/src/consensus/tx_check.cpp
    +++ b/src/consensus/tx_check.cpp
    @@ -32,11 +32,11 @@ bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
         CAmount nValueOut = 0;
         for (const auto& txout : tx.vout)
         {
    -        if (txout.nValue < 0)
    +        nValueOut += txout.nValue;
    +        if (nValueOut < 0)
                 return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vout-negative");
             if (txout.nValue > MAX_MONEY)
                 return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vout-toolarge");
    -        nValueOut += txout.nValue;
             if (!MoneyRange(nValueOut))
                 return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-txouttotal-toolarge");
         }
    

    This mutant could lead to an inflation bug, and the only other check that prevents that is in GetValueOut.

  2. DrahtBot added the label Tests on Nov 20, 2026
  3. DrahtBot commented at 7:32 PM on November 20, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    ACK mercie-ux, nebula-21, brunoerg

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in src/test/transaction_tests.cpp:382 in 803b0acd82
     375 | @@ -376,6 +376,18 @@ BOOST_AUTO_TEST_CASE(tx_oversized)
     376 |      }
     377 |  }
     378 |  
     379 | +BOOST_AUTO_TEST_CASE(tx_negative_output_after_positive)
     380 | +{
     381 | +    CMutableTransaction tx;
     382 | +    tx.vin.resize(1);
    


    mercie-ux commented at 8:09 PM on November 21, 2026:
        tx.vin.resize(1);
        tx.vin[0].prevout = COutPoint{Txid::FromUint256(uint256::ONE), 0};
    

    nit: the null prevout makes this a coinbase, so with the mutant the transaction is still rejected with bad-cb-length and !CheckTransaction passes anyway.


    ViniciusCestarii commented at 1:10 PM on November 24, 2026:

    Thanks for reviewing! I force-pushed 8e7e39d63ffb8c4bc5759648f46f94c7db840a21 to kill the mutant in tx_invalid.json instead

  5. mercie-ux commented at 8:12 PM on November 21, 2026: contributor

    tACK 803b0ac

  6. fanquake commented at 3:52 PM on November 23, 2026: member
  7. brunoerg commented at 12:29 AM on November 24, 2026: contributor

    No strong objection on adding this test case but the coins_view_stacked fuzz target kills this mutant with the current corpora. It calls CheckTxInputs only after CheckTransaction passes. CheckTxInputs then calls tx.GetValueOut(), which throws on any negative output.

  8. test: cover negative output after positive in CheckTransaction 8e7e39d63f
  9. in src/test/transaction_tests.cpp:379 in 803b0acd82
     375 | @@ -376,6 +376,18 @@ BOOST_AUTO_TEST_CASE(tx_oversized)
     376 |      }
     377 |  }
     378 |  
     379 | +BOOST_AUTO_TEST_CASE(tx_negative_output_after_positive)
    


    brunoerg commented at 12:22 PM on November 24, 2026:

    Instead, what about adding a tx with this case in tx_invalid.json?


    ViniciusCestarii commented at 12:47 PM on November 24, 2026:

    Thanks for the suggestion! That is better since some other implementations also uses it for testing.


    ViniciusCestarii commented at 1:10 PM on November 24, 2026:

    Done in 8e7e39d63ffb8c4bc5759648f46f94c7db840a21

  10. ViniciusCestarii force-pushed on Nov 24, 2026
  11. ViniciusCestarii commented at 1:09 PM on November 24, 2026: contributor

    Thanks for the reviews! Force-pushed 8e7e39d63ffb8c4bc5759648f46f94c7db840a21 adding a tx that tries to create a negative output (-1) after a positive (1) in tx_invalid.json as suggested by @brunoerg in #36931 (review)

  12. mercie-ux commented at 9:16 AM on November 25, 2026: contributor

    re-ACK 8e7e39d

  13. nebula-21 commented at 4:35 PM on November 25, 2026: contributor

    tACK 8e7e39d63ffb8c4bc5759648f46f94c7db840a21

  14. brunoerg commented at 5:40 PM on November 25, 2026: contributor

    ACK 8e7e39d63ffb8c4bc5759648f46f94c7db840a21


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-12-01 02:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me