Sunday, April 21, 2024
HomeBitcoinsegregated witness - How do digital dimension, stripped dimension and uncooked dimension...

segregated witness – How do digital dimension, stripped dimension and uncooked dimension examine between legacy handle codecs and native segwit?


Segwit launched a brand new restrict for blocks, the blockweight restrict, superseding the earlier blocksize restrict. Underneath the segwit guidelines, witness knowledge is counted at a decrease weighting than non-witness knowledge in direction of the blockweight. Since a number of the enter elements have moved to the witness stack in segwit transactions, segwit transactions have much less weight regardless that their uncooked byte size is much like non-segwit transactions. Since charges are paid in line with the load (i.e. the portion of “blockspace” transactions bid on), segwit transactions are cheaper than non-segwit transaction as they’ve much less weight.


Let’s examine a 2-input and 2-output transaction for single-sig output varieties. I will seek advice from the byte size of the transaction as “uncooked dimension”, the transaction with out its witness knowledge as “stripped dimension”, and the size-equivalent when accounting for the witness low cost as “digital dimension”.

Table showing the detailed data

  • P2PKHPay to Public Key Hash has no witness knowledge, so uncooked dimension is the same as stripped dimension is the same as digital dimension. A P2PKH transaction with two inputs and two outputs has 374 bytes (= 374 vbytes).

  • P2SH-P2WPKHPay to Script Hash-wrapped Pay to Witness Public Key Hash (aka “wrapped segwit”) locks funds to a P2SH output, however the enter’s redeemscript accommodates a witness program that redirects the analysis to the witness stack. The content material of the witness stack is similar as a P2PKH scriptSig. A P2SH-P2WPKH transaction with two inputs and two outputs has a uncooked dimension of 420 bytes, a stripped dimension (eradicating witness knowledge) of 202 bytes, and a digital dimension of 256.5 vbytes.

  • P2WPKHPay to Witness Public Key Hash (aka single-sig v0 native segwit) doesn’t want the P2SH indirection, however instantly resolves a witness program. It has the identical witness stack as a P2SH-P2WPKH enter. A P2WPKH transaction with two inputs and two outputs has a uncooked dimension of 372 bytes, a stripped dimension of 154 bytes and a digital dimension of 208.5 vbytes.

  • P2TRPay to Taproot (v1 native segwit (keypath-spend)) additionally instantly resolves a witness program. For the reason that witness program already accommodates a public key as an alternative of a pubkey hash, the witness stack is smaller by the general public key, however the output script is bigger. A P2TR transaction with two inputs and two outputs has a uncooked dimension of 312 bytes, a stripped dimension of 178 bytes, and a digital dimension of 211.5 vbytes.

The uncooked dimension corresponds to the knowledge footprint of the transaction on disk or the bandwidth price to transmit it. We see that P2SH-P2WPKH is definitely the largest in uncooked dimension by a margin. P2WPKH and P2PKH are very shut to one another in uncooked dimension with the legacy format P2PKH being barely smaller in enter dimension, however barely larger in output dimension. P2TR has the smallest knowledge footprint.

The digital dimension corresponds to the blockweight which determines the charges and what number of transactions can slot in a block. After making use of the weighting that the witness is topic to, P2WPKH has the smallest weight, intently adopted by P2TR, adopted by P2SH-P2WPKH and the legacy format P2PKH counts because the heaviest.


Measurement calculations

Transaction headers listing the transaction model (4 B), the rely of inputs (VarInt, often 1 B, however as much as 9 B), the rely of outputs (varInt, often 1 B, however as much as 9 B), and the locktime (4 B). For segwit transactions, we add a witness marker (1 WU) and a witness flag (1 WU) that pertain to the entire transaction.

Each enter should point out the UXTO it is spending per an outpoint (txid+vout = 32+4 B), have a sequence worth (4 B), and have an enter script (scriptSig). For non-segwit output varieties, the scriptSig accommodates script arguments and/or a redeemscript to fulfill the output script (scriptPubKey). For wrapped segwit inputs, the scriptSig consists of a redeemscript that accommodates a witness program which redirects to the Witness Stack because the closing script. For native segwit outputs, the scriptSig is empty which is indicated by a scriptSig size of 0. Per the segwit guidelines that is interpreted as a validation redirection to the Witness Stack. Observe that if a transaction has no less than one segwit enter, there have to be a Witness Stack for each enter, with non-segwit inputs having a length-zero Witness Stack (i.e. only one byte to point the size of 0).

Outputs include an quantity of satoshis (8 B) and an output script (scriptPubKey). Outputs do not have witness knowledge.

P2PKH

TxHeader: 10 B = 40 WU
Input¹: 148 B = 592 WU
Output: 34 B = 136 WU

For legacy codecs, the uncooked dimension, stripped dimension and digital dimension are all equal as a result of they don’t have witness knowledge.

Tx with 2 inputs and a pair of outputs:
uncooked = stripped = vsize = 10 B + 2×148 B + 2×34 B = 374 B = 374 vB
weight = 4×374 vB = 1496 WU

P2SH-P2WPKH

TxHeader: 10 B + 2 WU = 10.5 vB = 42 WU
Input²: 64 B + 108 WU = 91 vB = 364 WU
Output: 32 vB = 128 WU

Tx with 2 inputs and a pair of outputs:
uncooked = 12 B + 2×(64 B + 108 B) + 2×32 B = 420 B
stripped = 10 B + 2×64 B + 2+32 B = 202 B
weight = 42 WU + 2×(4×64 vB + 108 WU) + 2×128 WU = 1026 WU = 256.5 vB

P2WPKH

TxHeader: 10 B + 2 WU = 10.5 vB = 42 WU
Input³: 41 vB + 108 WU = 68 vB = 272 WU
Output: 31 vB = 124 WU

Tx with 2 inputs and a pair of outputs:
uncooked = 12 B + 2×(41 B + 108 B) + 2×31 B = 372 B
stripped = 10 B + 2×41 B + 2×31 B = 154 B
weight = 42 WU + 2×(4×41 vB + 108 WU) + 2×124 WU = 834 WU = 208.5 vB

P2TR

TxHeader: 10 B + 2 WU = 10.5 vB = 42 WU
Input⁴: 41 vB + 66 WU = 57.5 vB = 230 WU
Output: 43 vB = 172 WU

Tx with 2 inputs and a pair of outputs:
uncooked = 12 B + 2×(41 B + 66 B) + 2×43 B = 312 B
stripped = 10 B + 2×41 B + 2×43 B = 178 B
weight = 42 WU + 2×(4×41 vB + 66 WU) + 2×178 WU = 846 WU = 211.5 vB


Particulars of the enter script weights might be present in:
¹ How massive is the enter of a P2PKH transaction?
² What’s the dimension and weight of a wrapped segwit single-sig enter?
³ What’s the dimension and weight of a P2WPKH enter?
What’s the weight of a P2TR enter?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments