9

How are sigops calculated on a transaction? For example in the (randomly selected) following transaction:

https://btc.com/bc9384919ad5d08b2c66e31f29e7c63572c398a87631c03a4ce9e94ff1cbe62f

It says there were 5 sigops. What is the rule for calculating this number?

1 Answer 1

12

Each OP_CHECKSIG and OP_CHECKSIGVERIFY is counted as 1 sigop.

Each OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY, is counted as 20 sigops if they are found in an output or scriptSig and not part of a redeemScript, i.e. not P2SH.

If OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY are in a redeemScript (i.e. it's P2SH), then the number of sigops is the number of public keys in the multisig redeemScript. If there is more than 16 public keys, then it is always accounted as 20.

For non-segwit inputs, these numbers are multiplied by 4, so 4 sigops for OP_CHECKSIG and OP_CHECKSIGVERIFY, and 80 sigops for OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY.

However segwit inputs don't use these scripts explicitly. So a segwit input where the witness program is version 0 and the program is 20 bytes (i.e. P2WPKH), the number of sigops is 1. If the witness program is version 0 and the program is 32 bytes (i.e. P2WSH), the witnessScript is interpreted and its sigop count is as above as that uses the opcodes explicitly.


So in your example transaction, the input spends a P2SH-P2WPKH and the output has an OP_CHECKSIG. Since the input is P2WPKH, it is counted as 1 sigop. The output as an OP_CHECKSIG, so that's another 1 sigop. However because that output is not a segwit output, its number of sigops is multiplied by 4. Thus the output is actually 4 sigops. Summing those is 1 + 4 = 5 sigops in the entire transaction.

2
  • 1
    Why is OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY counted as 20 sigops if they are found in output?
    – rny
    Jul 19, 2019 at 7:10
  • "then the number of sigops is the number of public keys in the multisig redeemScript" -> Hmm if it's >16 then it's accounted as 20, if i remember correctly. Apr 10 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.