Tuesday, November 5, 2024

What’s the actual dimension and weight of a 2-of-2 P2WSH enter?

TL;DR:
A 2-of-2 P2WSH enter needs to be conservatively estimated with 96 vbytes. Normal 2-of-2 P2WSH inputs usually weigh 95.5, 95.75 or 96.0 vbytes, relying on whether or not the r-values within the signatures are low or excessive. A pockets utilizing signature grinding (which is extremely really helpful) will all the time produce 95.5 vbyte inputs. 96.0 vbytes is the conservative estimate permitting for high-r signatures.

Composition of a P2WSH enter

Every enter commits to spending a selected UTXO by offering its transaction outpoint:

PREVOUT: hash (32 bytes)
         index (4 bytes)

The scriptSig for a P2WSH enter is empty, nonetheless, the scriptSig size have to be offered as 0:

SCRIPTSIG: size (1 byte)
           <no content material>

Every transaction enter has its personal sequence quantity:

SEQUENCE: nSequence (4 bytes)

A 2-of-2 P2WSH enter requires a witness stack within the transaction’s witness block. The witness stack has 4 parts: the witness script, the 2 signatures, and the dummy aspect that OP_CHECKMULTISIG moreover pops from the stack however by no means makes use of. The dummy aspect is offered within the type of a size 0 push, similar to the scriptSig within the non-witness a part of the enter.

WITNESS: merchandise rely (1 byte)
         dummy aspect size (1 byte)
         <no content material>
         1st signature size (1 byte)
         1st signature (71 or 72 bytes)¹
         2nd signature size (1 byte)
         2nd signature (71 or 72 bytes)¹
         witness script size (1 byte)
           signature rely (OP_2, 1 byte)
           1st pubkey size (1 byte)
           1st pubkey (33 bytes)
           2nd pubkey size (1 byte)
           1nd pubkey (33 bytes)
           pubkey rely (OP_2, 1 byte)
           OP_CHECKMULTISIG (1 byte)

Conservative weight, vsize, and dimension estimate

A P2WSH transaction enter provides to a transactions…

weight:

non-witness knowledge: 4 × (32 + 4 + 1 + 4) = 164 WU
witness script: 1 + 1 + 33 + 1 + 33 + 1 + 1 = 71 WU
whole witness: 1 + (1 + 0) + (1 + 72) + (1 + 72) + (1 + witness script) = 220 WU
non-witness + witness = 164 + 220 = 384 WU

vsize:

32 + 4 + 1 + 4 + [1 + (1 + 0) + (1 + 72) + (1 + 72) + (1 + 71)] / 4 = 96 vbytes

serialized byte size:

32 + 4 + 1 + 4 + [1 + (1 + 0) + (1 + 72) + (1 + 72) + (1 + 71)] = 261 bytes

If the signing pockets makes use of signature grinding, the r-value is all the time 32 bytes, decreasing a signature to 71 bytes and the above maxima to 382 WU, 95.5 vbytes, and 259 bytes respectively.


¹ additionally see What’s the most dimension of a DER encoded ECDSA signature?.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles