Merge bitcoin/bitcoin#33624: test: P2SH sig ops are only counted with SCRIPT_VERIFY_P2SH

3a10d700bc1889b3690097efc935c5a4ba5966bb test: P2SH sig ops are only counted with `SCRIPT_VERIFY_P2SH` flag (brunoerg)

Pull request description:

  This PR adds a test case for `GetTransactionSigOpCost` to check that P2SH sig ops are only counted when `SCRIPT_VERIFY_P2SH` flag is set.

  Kills the following [mutant](https://corecheck.dev/mutation/src/consensus/tx_verify.cpp#L150):

  ```diff
  diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
  index 9d09872597..cc7cdaaf8f 100644
  --- a/src/consensus/tx_verify.cpp
  +++ b/src/consensus/tx_verify.cpp
  @@ -147,7 +147,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
       if (tx.IsCoinBase())
           return nSigOps;

  -    if (flags & SCRIPT_VERIFY_P2SH) {
  +    if (1==1) {
           nSigOps += GetP2SHSigOpCount(tx, inputs) * WITNESS_SCALE_FACTOR;
       }
  ```

ACKs for top commit:
  l0rinc:
    Tested ACK 3a10d700bc1889b3690097efc935c5a4ba5966bb
  maflcko:
    re-lgtm ACK 3a10d700bc1889b3690097efc935c5a4ba5966bb
  instagibbs:
    ACK 3a10d700bc1889b3690097efc935c5a4ba5966bb
  janb84:
    tested ACK 3a10d700bc1889b3690097efc935c5a4ba5966bb

Tree-SHA512: f560b4f9f2ce5c5fdd0a86e7e1f8ea27a8c6fda0327a6186a0c21e2c06ef13beeb017686db1688cace68812a01701abe46e8e1a095afefc6f2aed6ed96ba8288
This commit is contained in:
merge-script 2025-10-15 09:55:49 +01:00
commit b1f8a13702
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -151,6 +151,9 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig, CScriptWitness());
assert(GetTransactionSigOpCost(CTransaction(spendingTx), coins, flags) == 2 * WITNESS_SCALE_FACTOR);
assert(VerifyWithFlag(CTransaction(creationTx), spendingTx, flags) == SCRIPT_ERR_CHECKMULTISIGVERIFY);
// P2SH sigops are not counted if we don't set the SCRIPT_VERIFY_P2SH flag
assert(GetTransactionSigOpCost(CTransaction(spendingTx), coins, /*flags=*/0) == 0);
}
// P2WPKH witness program