WITNESS STACK:
item count (1 byte)
signature length (1 byte)
signature (71 or 72 bytes)¹
pubkey length (1 byte)
pubkey (33 bytes)
Note that using at least one segwit input adds 2 witness bytes to the transaction header, the witness marker and witness flag. Also Also, when there is at least one segwit input, the witness block must have a witness count itemstack for every input, which must beconsist 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 item countsstacks (1as WUmany ×as input count)
witnesseswitness item count (1 WU)
witness items (0–n of variable weight)
locktime (4 bytes)