Skip to main content
3 of 12
added 170 characters in body
Murch
  • 77.9k
  • 35
  • 190
  • 641

Each input commits to spending a specific UTXO by providing its transaction outpoint:

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

The scriptsig for a P2WPKH input is empty, however, the scriptsig length must be provided as 0:

SCRIPTSIG: length (1 byte)
  no content

Each transaction input has its own sequence number:

sequence (4 bytes)

A P2WPKH input requires a witness in the transaction's witness block:

WITNESS: length (1 byte)
  push opcode (1 byte)
  signature: (71 or 72 bytes)¹
  push opcode (1 byte)
  pubkey (33 bytes)

Adding a P2WPKH transaction input to a transactions adds a maximum of…

weight:

4 × (32 + 4 + 1 + 4) + 1 + 1 + 72 + 1 + 33 = 272 WU

vsize:

32 + 4 + 1 + 4 + (1 + 1 + 72 + 1 + 33) / 4 = 68 vbytes

serialized byte length:

32 + 4 + 1 + 4 + 1 + 1 + 72 + 1 + 33 = 149 bytes

If the signing wallet uses signature grinding (which is highly recommended), the r-value would always be 32 bytes², reducing the signature to 71 bytes, and the above maxima to 271 WU, 67.75 vbytes, and 148 bytes respectively.

Note that adding the first segwit input adds 3 witness bytes to the transaction: the witness marker and witness flag after the transaction version, and the witness count as the first byte of the witness block after the outputs.
The overall transaction elements of a segwit transaction 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 count (1 WU)
  witnesses (variable weight)
locktime (4 bytes)

¹ the r-value can be 32 or 33 bytes, high-s is non-standard for segwit inputs, see What is the maximum size of a DER encoded ECDSA signature?.
² strictly speaking 32 bytes or less, since r-values can be shorter with a low probability.

Murch
  • 77.9k
  • 35
  • 190
  • 641