This does indeed catch a consensus drift that would otherwise pass CI:
diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
--- a/src/consensus/tx_verify.cpp (revision afa5e46bbc6dd750bd71920b659162a945abf0ae)
+++ b/src/consensus/tx_verify.cpp (revision 0175450a6ae5dc2dd5e8770492d46ca183fcbedd)
@@ -148,7 +148,7 @@
return nSigOps;
if (flags & SCRIPT_VERIFY_P2SH) {
- nSigOps += GetP2SHSigOpCount(tx, inputs) * WITNESS_SCALE_FACTOR;
+ nSigOps += std::min(GetP2SHSigOpCount(tx, inputs), 2'500U) * WITNESS_SCALE_FACTOR;
}
for (unsigned int i = 0; i < tx.vin.size(); i++)
With this PR it fails with:
2026-07-24T01:23:19.021298Z TestFramework (ERROR): Unexpected exception:
Traceback (most recent call last):
File "bitcoin/test/functional/test_framework/test_framework.py", line 145, in main
self.run_test()
~~~~~~~~~~~~~^^
File "bitcoin/build/test/functional/p2p_segwit.py", line 291, in run_test
self.test_witness_sigops()
~~~~~~~~~~~~~~~~~~~~~~~~^^
File "bitcoin/build/test/functional/p2p_segwit.py", line 112, in func_wrapper
func(self, *args, **kwargs)
~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "bitcoin/build/test/functional/p2p_segwit.py", line 2012, in test_witness_sigops
test_witness_block(self.nodes[0], self.test_node, block_7, accepted=False, reason='bad-blk-sigops')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "bitcoin/build/test/functional/p2p_segwit.py", line 146, in test_witness_block
assert_equal(node.getbestblockhash() == block.hash_hex, accepted)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "bitcoin/test/functional/test_framework/util.py", line 94, in assert_equal
raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
AssertionError: not(True == False)
Which revealed another mutation drift that wouldn't be caught by any existing test:
diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
--- a/src/consensus/tx_verify.cpp (revision 7a585306f2f6fea79706b496b2ebf306e78dd484)
+++ b/src/consensus/tx_verify.cpp (revision 309a37ffdfb419c87f2fc001fad3b0c611574843)
@@ -147,7 +147,7 @@
if (tx.IsCoinBase())
return nSigOps;
- if (flags & SCRIPT_VERIFY_P2SH) {
+ if ((flags & SCRIPT_VERIFY_P2SH) && !tx.HasWitness()) {
nSigOps += GetP2SHSigOpCount(tx, inputs) * WITNESS_SCALE_FACTOR;
}
I added a bug-injection-with-passing-CI/failing-test/revert-bug-passing-CI PR: https://github.com/l0rinc/bitcoin/pull/248
I have simplified the fix presented here, feel free to cherry-pick the fixes (but not the injected bugs) here.
Alternatively I can open a new PR and add you as coauthor.