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 the direction of the blockweight. Since among the enter elements have moved to the witness stack in segwit transactions, segwit transactions have much less weight although their uncooked byte size is just like non-segwit transactions. Since charges are paid based on the burden (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 evaluate a 2-input and 2-output transaction for single-sig output sorts. I will consult with 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”.
-
P2PKH – Pay 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-P2WPKH – Pay to Script Hash-wrapped Pay to Witness Public Key Hash (aka “wrapped segwit”) locks funds to a P2SH output, however the enter’s redeemscript incorporates 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. -
P2WPKH – Pay 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.
-
P2TR – Pay to Taproot (v1 native segwit (keypath-spend)) additionally instantly resolves a witness program. Because the witness program already incorporates a public key as a substitute 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 most important 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, carefully adopted by P2TR, adopted by P2SH-P2WPKH and the legacy format P2PKH counts because the heaviest.
Dimension 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 sorts, the scriptSig
incorporates script arguments and/or a redeemscript to fulfill the output script (scriptPubKey
). For wrapped segwit inputs, the scriptSig
consists of a redeemscript that incorporates a witness program which redirects to the Witness Stack because the ultimate 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 should 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 haven’t got 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?