LORE

  • Stumble across Bitcoin, heard about it's P2P aspect
  • Initially thought fees are calculated in proportion to the payment amount
  • Quickly learned about UTXOs, TX input + output etc
  • Confused as to why some TXs have cheaper or more expensive TX fee even though they looked similar from quick glance
  • Learned script types, tryna find out how each script type are weighted and found these 1, 2 tools
  • Interested to know more & want to verify the information by myself
  • Conduct my own investigation
  • Results found, decided to share it on SN
  • Am i cooking ?

CLASSIFICATION & CORE ASPECTS

Script TypeOther
P2PKCoinbaseInput-only (can't spend to Coinbase)
P2PKHOP_ReturnOutput-only (can't spend from OP_Return)
P2MSP2QRHStill in the proposal-phase, add it anyway
P2SHP2AHaven't learned much of it, add it anyway
P2WPKHNon-standard
P2WSH
P2TR
Pre-SegWitPost-SegWit
OverheadnVersionnVersion
Input CountInput Count
Output CountOutput Count
nLocktimenLocktime
Mark & Flag
Input FieldOutpointOutpoint
scriptSig LengthscriptSig Length
scriptSignSequence
nSequenceWitness Items
Output FieldnValuenValue
scriptPubkey lengthscriptPubkey Length
scriptPubkeyscriptPubkey
Block Size/Weight 11 Megabyte4 Million Weight Units
4 Mega Virtual Bytes

RESULTS

OverheadInput VSizeOutput VSize
Coinbase≥ 48 ?
OP_Returm≥ 34 ?
P2PK10113 ~ 11576
P2PK (Raw)1011444
P2PKH10147 ~ 14934
P2PKH10179 ~ 18134
P2MS 1-of-110113 ~ 11546 or 78
P2MS 1-of-110148 ~ 15446
P2MS 1-of-210114 ~ 11680 or 112 or 144
P2MS 2-of-210187 ~ 18980 or 144
P2MS 1-of-310114 ~ 115114 or 146
P2MS 2-of-310186 ~ 189114 or 210
P2MS 3-of-310258114 or 210
P2SH 1-of-11079 or 15332
P2SH 1-of-110184 ~ 18632
P2SH 1-of-210186 ~ 18832
P2SH 1-of-21025232
P2SH 2-of-210260 ~ 26132
P2SH 2-of-210326 ~ 32832
P2SH 2-of-310293 ~ 29832
P2SH 2-of-31032932
P2SH 2-of-41033132
P2SH 3-of-410530 ~ 53432
P2SH 2-of-51036432
P2SH 3-of-510436 ~ 43832
P2SH 8-of-910936 ~ 93932
P2SH-P2WPKH10.590.75 ~ 9132
P2SH-P2WSH 1-of-110.510432
P2SH-P2WSH 2-of-210.5130.75 ~ 13132
P2SH-P2WSH 2-of-310.5139 ~ 139.2532
P2WPKH10.567.5 ~ 6831
P2WSH 1-of-110.569.2543
P2WSH 2-of-210.595.75 ~ 9643
P2WSH 2-of-310.5104 ~ 104.543
P2WSH 3-of-510.5139.25 ~ 139.7543
P2WSH 11-of-1510.5397.25 ~ 398.7543
P2TR10.557.5 ~ 57.7543

EXAMPLES

PartSizeTransactions Example
P2PK input1131, 2, 3, 4
1141, 2, 3
1151, 2
Raw P2PK input1141, 2
Raw P2PK output441, 2
P2PKH input1471, 2, 3, 4
1481 (2nd), 2 (except 1st), 3 (1st), 4 (all)
1491, 2, 3, 4 (1st)
1791, 2, 3 (2nd), 4 (2nd)
1801, 2, 3, 4
1811, 2, 3 (all), 4 (1st)
P2MS 1-of-1 input1131
1151
1481
1541
P2MS 1-of-1 output461, 2, 3, 4
781
P2MS 1-of-2 input1141, 2, 3, 4
1151, 2, 3, 4
1161
P2MS 1-of-2 output801, 2, 3, 4
1121, 2, 3
1441
P2MS 2-of-2 input1871, 2 (2nd)
1881, 2 (1st), 3 (2nd), 4 (2nd)
1891, 2, 3 (1st), 4
P2MS 2-of-2 output801, 2, 3
1441, 2, 3, 4
P2MS 1-of-3 input1141 (1st), 2 (2nd), 3 (2nd)
1151 (3rd), 2 (2nd)
P2MS 1-of-3 output1141, 2, 3 (3rd), 4
1461, 2, 3, 4
P2MS 2-of-3 input1861, 2
1871, 2, 3, 4
1881, 2, 3, 4
1891
P2MS 2-of-3 output1141, 2, 3
2101, 2, 3, 4
P2MS 3-of-3 input2581
P2MS 3-of-3 output1141
2101
P2SH 1-of-1 input791
1531
1841
1851, 2 (all)
1861, 2
P2SH 1-of-2 input1861, 2
1871, 2 (3rd), 3, 4
1881, 2
2521
P2SH 2-of-2 input2601, 2
2611
3261, 2
3271, 2
3281
P2SH 2-of-3 input2931 (1st), 2
2961, 2 (4th), 3
2971 (all), 2
2981 (5th), 2
3291
P2SH 2-of-4 input3311
P2SH 3-of-4 input5301 (1st)
5311 (2nd), 2, 3 (1st)
5331 (2nd)
5341 (3rd)
P2SH 2-of-5 input3641
P2SH 3-of-5 inout4361, 2
4371, 2
4381
P2SH 8-of-9 input9361 (3rd)
9381, 2 (2nd)
9391 (1nd)
P2SH-P2WPKH input90.751 (2nd), 2
911 (1st), 2, 3, 4
P2SH-P2WSH 1-of-1 input1041
P2SH-P2WSH 2-of-2 input130.751, 2
1311 (1st)
P2SH-P2WSH 2-of-3 input1391
139.251, 2, 3, 4
P2WPKH input67.751 (1st & 4th), 2, 3, 4
681, 2 (2nd & 3rd), 3, 4
P2WSH 1-of-1 input69.251
P2WSH 2-of-2 input95.751, 2, 3 (1st), 4 (1st)
961 (2nd)
P2WSH 2-of-3 input1041, 2, 3, 4
104.251, 2
104.51
P2WSH 3-of-5 input139.251, 2
139.51 (all), 2
139.751
P2WSH 11-of-15 input397.251 (3rd)
397.51, 2
397.751, 2 (2nd), 3, 4
3981, 2, 3 (all), 4
398.251, 2, 3, 4
398.51 (1st), 2, 3, 4
398.751
P2TR input57.51, 2, 3, 4
57.751 (all), 2, 3, 4

CLOSING BIT

Tools used :
Aight, i can't get any example of Pay-to-Anchor TX on mainnet yet. But who's gonna stop me from mentioning it ? Here are several examples of P2A TX on Testnet4 :
As output (receiver side)As input (spender side)
11
22
Now, if the law of TX size calculation on Testnet4 is the same as Mainnet, then a P2A script would have 13 vb output size or 41 vb input size. CMIIW tho, i only sampled one address i found here.
Historically, we've gotten a new address type every 4 years (P2SH 2012, SegWit 2017, Taproot 2021), but given the slow adaptation of P2TR and long process of development, we are not gonna get P2QRH next year. Read the documentation here.

Footnotes

Kudos for your efforts. Most of this looks good, but there are a few mistakes here and there. I’m prepping for the Optech Recap, so I’ll have to get back to this later, but I wanted to point out that a lot of the same information is compiled in topics tagged "transaction-weight" on Bitcoin Stack Exchange: https://bitcoin.stackexchange.com/questions/tagged/transaction-weight?tab=Frequent, e.g. https://bitcoin.stackexchange.com/a/75124/5406, https://bitcoin.stackexchange.com/questions/100159/what-is-the-size-and-weight-of-a-p2wpkh-input
reply
few mistakes here and there
Damn i wronged the P2PK output size, the compressed one should've been 44 vB and the uncompressed one should've been 76 vB
Pay to Witness Script Hash (P2WSH). Input¹: variable (2-of-3: 105 vBytes)
I can't find any example of it with 105 vB input size yet
Pay to Taproot (P2TR). Scriptpath 2-of-3²: 82.75 vB–115.5 vB
This is out of my knowledge, for now i only know about keypath and 2-of-2 P2TR, interested to find these example i haven't found before but i have no tools to automate this (i do it manually)
Null Data (OP_RETURN). Output: x ≤ 83 + 11(?) bytes
Now that is something arbitrary lol, i decided to just write "≥ 34" as it is the simplest example of OP_Return output i can find
If i had found these 1, 2 post before it would make my life so much easier. Much grateful for your contribution to the community🫡
reply
266 sats \ 0 replies \ @Murch 8 Oct
I can't find any example of it with 105 vB input size yet
It’s really 418 weight units, which would translate to 104.5 vB, but the way vsize is defined, it’s supposed to be rounded up to the next integer. To be fair, I think I’ve been inconsistent on that one in the past years.
Pay to Taproot (P2TR). Scriptpath 2-of-3²: 82.75 vB–115.5 vB
This is out of my knowledge, for now i only know about keypath and 2-of-2 P2TR, interested to find these example i haven't found before but i have no tools to automate this (i do it manually)
I think the shortest nulldata output is 11 B.
reply
1234 sats \ 6 replies \ @Murch 8 Oct
Okay, now I have a little more time.
The "Script Type" table was a bit confusing to me.
I assume that the third column only refers to the second column and the first column is independent. At first I was reading the table as rows, and that didn’t make sense to me.
Regarding the transaction components:
  • minor typo: it’s "Marker" and "Flag"
  • The two columns seem to represent legacy inputs and native segwit inputs, but there is also a transitory mix of the two: wrapped segwit where inputs can have both an input script and witness items.
  • Also given that you reference serialization artifacts like the script length, it should maybe be pointed out that in the serialization the witness structure is separate from the input and output sections.
You may be interested in my opinionated BIP draft for transaction terminology here: https://github.com/murchandamus/bips/pull/1 (I really need to pick that up again!)
Regarding the block size/weight: given that unfortunately megabyte can both refer to 1000² bytes and 1024² bytes, to be clear the block size limit was 1,000,000 bytes which corresponds to just 1,000,000 vB, not 4,000,000 vB (see e.g. https://bitcoin.stackexchange.com/a/53626/5406).
Regarding Results:
  • As mentioned in my other comment, the smallest possible OP_RETURN output should come in as 11 bytes.
  • Regarding the multisig stuff, I think that some of them are off by a byte or so, e.g.:
Regarding P2A, the 13 vB output would always be the same across all anchors, since it’s a standard template.
Thanks for sharing your research, very cool!
reply
I assume that the third column only refers to the second column and the first column is independent
Correct
minor typo: it’s "Marker" and "Flag"
Noted
wrapped segwit where inputs can have both an input script and witness items.
Is this about Nested P2WPKH & P2WSH ? I might have to redo this part again to fix this
it should maybe be pointed out that in the serialization the witness structure is separate from the input and output sections.
Yes, i'm using the same TX structuring as what currently used by Bitcoin Optech Calculator. I don't mind separating the witness part with dedicated space though
megabyte can both refer to 1000² bytes and 1024² bytes
I always have this confusion, other people might have this too. Will specifically fix this in the future
the smallest possible OP_RETURN output should come in as 11 bytes.
Noted
P2SH 2-of-3 should be 293–297
Now that is confusing, i still don't understand how can the same address have different scriptSig (what could possibly caused that ?)
  • TX ID + Vout = 36 + 4
  • scriptSig length = 3
  • scriptSg = 255
  • Total = 298
And not just once, the second example also behaves the same
This one example has even bigger input size :
  • TX ID + Vout = 36 + 4
  • scriptSig length = 3
  • scriptSig = 286
  • Total = 329, is this a non-standard example ?
P2SH-P2WSH 2-of-3 should be 139–139.5
For input size 139 vB & 139.25 vB i can find example of that, but haven't found any example of 139.5 vB input size
output would always be the same across all anchors, since it’s a standard template.
Yeah, there is barely any debate about output size since it's standardized already
Thanks for sharing your research, very cool!
Thanks, may i ask a favor for one or two mainnet example of P2TR 2-of-3 scriptpath tho, it's for research purpose i promise
reply
64 sats \ 4 replies \ @Murch 8 Oct
wrapped segwit where inputs can have both an input script and witness items.
Is this about Nested P2WPKH & P2WSH ? I might have to redo this part again to fix this
Yeah, that’s right. Nested P2WPKH/P2WSH is another term for Wrapped P2WPKH/P2WSH.
it should maybe be pointed out that in the serialization the witness structure is separate from the input and output sections.
Yes, i'm using the same TX structuring as what currently used by Bitcoin Optech Calculator. I don't mind separating the witness part with dedicated space though
Yeah, we did not make that distinction in the calculator, because the weight of the witness stack directly is dictated by the input type. However, as soon as one input has a witness stack, you need a witness structure, and a witness structure must contain a witness stack for every single input. For non-segwit inputs the witness stack consists simply of a witness item counter that is 0, but this means that the weight of non-segwit inputs goes up by one weight unit when they are combined with segwit inputs.
You can see the separate witness structure for example in the yogh.io explorer that nicely visualizes the transaction serialization (I picked a 2-of-3 wrapped segwit example from your list above): https://yogh.io/tx/23e2e8453fd9d00fc38833e996e042c35d60f5ac2196a2462a44930323694c17/
P2SH 2-of-3 should be 293–297
Now that is confusing, i still don't understand how can the same address have different scriptSig (what could possibly caused that ?)
  • TX ID + Vout = 36 + 4
  • scriptSig length = 3
  • scriptSg = 255
  • Total = 298
And not just once, the second example also behaves the same
This one example has even bigger input size :
  • TX ID + Vout = 36 + 4
  • scriptSig length = 3
  • scriptSig = 286
  • Total = 329, is this a non-standard example ?
Ah, fair point. I haven’t verified, but given the date of the transaction I can still suggest a possible explanation. ECDSA signatures are not fixed in size, among other things, the r and s component of the signature varies in size depending on whether the value falls in the upper half or lower half of the value range. High-s signatures became non-standard after 2014, given that your example is from 2012, I expect that some of the signatures are high-s.
P2SH-P2WSH 2-of-3 should be 139–139.5
For input size 139 vB & 139.25 vB i can find example of that, but haven't found any example of 139.5 vB input size
Thanks, may i ask a favor for one or two mainnet example of P2TR 2-of-3 scriptpath tho, it's for research purpose i promise
Sorry, I don’t have one on hand from the top of my head, but I will think about how to find one.
reply
64 sats \ 2 replies \ @Murch 8 Oct
I can offer this 2-of-2 P2TR transaction meanwhile, if that is of help: https://mempool.space/tx/905ecdf95a84804b192f4dc221cfed4d77959b81ed66013a7e41a6e61e7ed530
reply
That was beautiful ngl, not quite the same but Greg Walker also made something similar with his explorer
ECDSA signatures are not fixed in size. High-s signatures became non-standard after 2014
LOL, are Schnorr (for P2TR) & FALCON (for upcoming P2QRH) safe from this ?
b426792a6f8f78e59172c1a65db1da4b60797162f9081b6f7a8b31665597d537 should fit the bill.
TX ID + VOUT + scriptSig length + scriptSig + nSequence = 32 + 4 + 1 + 35 + 4 = 76 Witness = 63.5 Total = 139.5 (yeay, finally)
I can offer this 2-of-2 P2TR transaction meanwhile, if that is of help: https://mempool.space/tx/905ecdf95a84804b192f4dc221cfed4d77959b81ed66013a7e41a6e61e7ed530
TX ID + VOUT + scriptSig length + nSequence = 32 + 4 + 1 + 4 = 41 Witness = 66.75 Total = 107.75 (that's new to me)
reply
That was beautiful ngl, not quite the same but Greg Walker also made something similar with his explorer
Oh cool, I hadn’t seen that addition to Greg’s site yet.
ECDSA signatures are not fixed in size. High-s signatures became non-standard after 2014
LOL, are Schnorr (for P2TR) & FALCON (for upcoming P2QRH) safe from this ?
Yeah, ECDSA signatures used a weird encoding, but the schnorr signatures have a fixed size encoding. No idea about P2QRH, that seems a bit far out still.
reply
Oh, I missed that 329 byte input last time. I would suspect that an uncompressed pubkey was in play.
reply