1
2
I'm trying to calculate the weight of a 2-of-3 multisignature P2SH-P2WSH input. I found the related question Predict multi signature transaction size, which I've calculated out with m=2, n=3 here:
pubkeySize=33
sigSize=72
SizeOfRedeemScript = 1+n*(1+pubkeySize)+1+1
// 2-of-3: SizeOfRedeemScript = 1+3*(1+33)+1+1 = 105
SizeOfScriptSig = 1+m*(1+sigSize)+SizeOfPushDataFor(RedeemScript)+SizeOfRedeemScript
// 2-of-3: SizeOfScriptSig = 1+2*(1+72)+2+105 = 1 + 146 + 2 + 105 = 254
sizeOf(input) = 32+4+SizeOfCsuintFor(SizeOfScriptSig) + SizeOfScriptSig + 4
// 2-of-3: sizeOf(input) = 32+4+3+254+4 = 297
The size of 2-of-3 input in P2SH has 293 to 297 bytes1. Thus, this would correspond to up to 297*4 = 1188 bytes weight (BW).
How would I calculate the same BW for a 2-of-3 multisignature P2SH-P2WSH input?
1Correction: Note that if both signatures are 71 bytes, the scriptSig is 252 bytes which as a length can be encoded in 1 byte, but in the worst case both signatures are 72 bytes and the length of the scriptSig needs 3 bytes.
So, I should be getting 293 in my calculation in the question? – Murch – 2017-08-02T21:26:52.667
2I believe it should be 292. – Andrew Chow – 2017-08-02T22:04:05.337
If
SizeOfVarIntFor(RedeemScript)would be be two bytes because redeemscript is longer than 75 bytes, wouldn't the same apply toSizeOfVarIntFor(SizeOfScriptSig)sinceSizeOfScriptSigis 251? – Murch – 2017-08-08T22:42:11.4371
@Murch No. There are two ways of representing the size of things in transactions. Within a script itself, we actually use pushdata opcodes. We need two bytes for scripts longer than 75 bytes because we then need to use the OP_PUSHDATA1 opcode before the size byte. However for sizes of things outside of scripts like
– Andrew Chow – 2017-08-08T22:58:17.700SizeOfScriptSig, we use Compact Size Unsigned Integers. The csuint only needs an additional byte on top of the number itself when the number itself needs more than 1 byte. You can see how csuint works here: https://bitcoin.org/en/developer-reference#compactsize-unsigned-integersI think I found an error in the calculation of my question making the redeem script 3 bytes larger. I've also edited your answer. Can you check whether you agree? – Murch – 2017-08-22T23:03:16.730