test: Add P2SH sigop counting test for segwit blocks #35816

pull dagimabebe wants to merge 3 commits into bitcoin:master from dagimabebe:test-p2sh-sigops-segwit changing 2 files +62 −2
  1. dagimabebe commented at 8:09 PM on July 26, 2026: none

    Replaces the TODO at p2p_segwit.py:1952 with tests for P2SH sigop counting in segwit-active blocks.

    The existing test_witness_sigops subtest only covers witness (P2WSH) sigop counting. P2SH sigops follow a different code path through GetP2SHSigOpCount() in consensus/tx_verify.cpp and are also multiplied by WITNESS_SCALE_FACTOR, but were not tested in the segwit context.

    Positive test: funds a P2SH P2PK output, spends it with a valid legacy signature, and verifies the block is accepted.

    Negative test: funds 101 P2SH outputs whose redeem scripts contain 200 OP_CHECKSIG each (200 sigops per input). Since P2SH sigops are scaled by WITNESS_SCALE_FACTOR (4), each input contributes 800 sigop cost. 101 inputs total 80800, exceeding MAX_SIGOP_COST (80000). Verifies the block is rejected with bad-blk-sigops.

  2. Update CMakeLists.txt fe033e23ae
  3. Merge branch 'bitcoin:master' into master 00afc8eca9
  4. test: Add P2SH sigop counting test for segwit blocks
    Add tests verifying that P2SH sigop counting works correctly in
    segwit-active blocks. This addresses the TODO at the end of the
    test_witness_sigops subtest.
    
    The positive test creates a P2SH output with a P2PK redeem script
    (1 sigop), mines it, and spends it with a valid signature to
    confirm basic P2SH sigop counting works.
    
    The negative test creates a block containing 101 P2SH inputs with
    high-sigop redeem scripts (200 OP_CHECKSIG each, 200 sigops per
    input). At WITNESS_SCALE_FACTOR=4, each input contributes 800
    sigop cost, totaling 80800 which exceeds MAX_SIGOP_COST (80000).
    The block is verified to be rejected with 'bad-blk-sigops'.
    
    Also updates the cleanup to reference tx_high_fund instead of the
    now-spent tx2 output.
    266fad091e
  5. DrahtBot added the label Tests on Jul 26, 2026
  6. DrahtBot commented at 8:09 PM on July 26, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35816.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35164 (test: cover P2SH sigop counting in test_witness_sigops by musaHaruna)

    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-->

  7. l0rinc commented at 8:21 PM on July 26, 2026: contributor

    seems to be a duplicate of #35164 - please review that one instead

  8. dagimabebe commented at 8:40 PM on July 26, 2026: none

    Closing as duplicate of #35164 which already covers the same TODO with a more comprehensive test suite.

  9. dagimabebe closed this on Jul 26, 2026

Labels

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-07-31 20:50 UTC

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