I'm looking for a detailed explanation of the weight, vsize and serialized length of a P2TR input, in the same vein as How big is the input of a P2PKH transaction?.
A P2TR keypath input will weigh 57.5 vbytes. A P2TR scriptpath input will weigh a variable amount greater than that.
Composition of a P2TR input
Each input commits to spending a specific UTXO by providing its transaction outpoint:
PREVOUT: hash (32 bytes) index (4 bytes)
The scriptsig for a P2TR input is empty, however, the scriptsig length must be provided as
SCRIPTSIG: length (1 byte) <no content>
Each transaction input has its own sequence number:
sequence (4 bytes)
A P2TR input requires a witness stack in the transaction's witness block. For a keypath spend, the witness stack will consist of:
WITNESS STACK: item count (1 byte) signature length (1 byte) signature (64 bytes)
For a scriptpath spend, the witness stack will require zero or more script arguments (e.g. signatures), the leaf script, and a control block (CB):
WITNESS STACK: item count (1 byte) script arguments (0–n) script argument length (1 byte) script argument (64 bytes for signatures, or variable) leaf script leaf script length (1 byte) leaf script (variable) Control Block CB length (1 byte) CB header (1 byte) hashing partners (32 bytes × CB depth) inner key (32 bytes)
Conservative weight, vsize, and size estimate
A P2TR keypath transaction input adds to a transactions…
4 × (32 + 4 + 1 + 4) + 1 + 1 + 64 = 230 WU (57.5 vB)
serialized byte length:
32 + 4 + 1 + 4 + 1 + 1 + 64 = 107 bytes
A simple P2TR scriptpath transaction input with a depth-0 control block and a
<pubkey> OP_CHECKSIG leaf script would weigh
4 × (32 + 4 + 1 + 4) + 1 + (1 + 64) + (1 + 34) + (34) = 299 WU (74.75 vB) <Non-witness data> <items> <sig> <leafscript> <CB>
but most scriptpath spends would probably end up being much heavier than this.
Note that using at least one segwit input adds 2 witness bytes to the transaction header, the witness marker and witness flag. Also, when there is at least one segwit input, the witness block must have a witness stack for every input, which must consist of at least a witness item counter indicating that the stack is empty provided as a
0x00 byte for non-segwit inputs.
The overall transaction elements of a segwit transaction therefore are:
version (4 bytes) witness marker (1 WU) witness flag (1 WU) input count (1 byte) inputs (variable size) output count (1 byte) outputs (variable size) witness stacks (as many as input count) witness item count (1 WU) witness items (0–n of variable weight) locktime (4 bytes)