Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 3, 2021

Conversation

darosior
Copy link
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.

@darosior
Copy link
Member Author

cc @sipa

@@ -127,7 +127,7 @@ Sigops per block is currently limited to 20,000. We change this restriction as f
Sigops in the current pubkey script, signature script, and P2SH check script are counted at 4 times their previous value.
The sigop limit is likewise quadrupled to ≤ 80,000.

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.
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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>
@sipa
Copy link
Member

sipa commented Jan 19, 2021

ACK 644610f

@maflcko
Copy link
Member

maflcko commented Jan 26, 2021

@luke-jr

@luke-jr luke-jr merged commit bc50a29 into bitcoin:master Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants