bip-0141: clarify the sigop count calculation for CHECKMULTISIG #1054

pull darosior wants to merge 1 commits into bitcoin:master from darosior:bip141_multisig_sigops changing 1 files +1 −1
  1. darosior commented at 11:50 AM on January 10, 2021: member

    This makes the behaviour of the reference implementation clear for this computation, which was implied by the previous sentence but not explicited in the next one.

  2. darosior commented at 11:53 AM on January 10, 2021: member

    cc @sipa

  3. in bip-0141.mediawiki:130 in 0fc6b6baa6 outdated
     126 | @@ -127,7 +127,7 @@ Sigops per block is currently limited to 20,000. We change this restriction as f
     127 |  Sigops in the current pubkey script, signature script, and P2SH check script are counted at 4 times their previous value.
     128 |  The sigop limit is likewise quadrupled to ≤ 80,000.
     129 |  
     130 | -Each P2WPKH input is counted as 1 sigop. In addition, opcodes within a P2WSH <code>witnessScript</code> are counted identically as previously within the P2SH <code>redeemScript</code>. That is, CHECKSIG is counted as only 1 sigop, and CHECKMULTISIG is counted as 1 to 20 sigops according to the arguments. This rule applies to both native witness program and P2SH witness program.
     131 | +Each P2WPKH input is counted as 1 sigop. In addition, opcodes within a P2WSH <code>witnessScript</code> are counted identically as previously within the P2SH <code>redeemScript</code>. That is, CHECKSIG is counted as only 1 sigop. For 1 to 16 total public keys CHECKMULTISIG is counted as 1 to 16 sigops respectively, and for 17 to 20 total public keys it is counted as 20 sigops. This rule applies to both native witness program and P2SH witness program.
    


    sipa commented at 7:09 PM on January 10, 2021:

    I'd be more specific and say this rule only applies to OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY preceded immediately by OP_1 through OP_16. That implicitly excludes 17-20, but it also makes it clear that if you'd use a direct push for 1-16 (or OP_PUSHDATA, or some other construction) it won't work.


    darosior commented at 9:56 AM on January 11, 2021:

    That's much clea[n/r]er, updated.

  4. bip-0141: clarify the sigop count calculation for CHECKMULTISIG
    Since the sigOpCount calculation was copied from P2SH, and P2SH
    restricts the use of CHECKMULTISIG with pushed integers the reference
    implementation would not take into account the number of public keys for
    17 to 20 keys (not representable with an OP_N) even for P2WSH.
    Therefore it fallbacks to accounting for 20 sigops in this case, which
    this sentence seemed to mismatch with.
    
    Btcd and Libbitcoin use the same calculation as in Bitcoin Core.
    
    Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
    644610f7b8
  5. darosior force-pushed on Jan 11, 2021
  6. sipa commented at 10:50 PM on January 19, 2021: member

    ACK 644610f7b87e3e5f4757fb9e80d24f8e6e75d93e

  7. sipa approved
  8. MarcoFalke commented at 6:31 PM on January 26, 2021: member
  9. luke-jr merged this on Feb 3, 2021
  10. luke-jr closed this on Feb 3, 2021


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 18:10 UTC

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