Skip to main content
Update terminology and formatting to match similar posts.
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
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)
WITNESS: 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, when there is at least one segwit input, the witness block must have a witness count item for every input, which must be 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 counts (1 WU × input count)
  witnesses (variable weight)
locktime (4 bytes)
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, 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)
Refer to the data in the witness block pertaining to one input as the "witness stack"
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641

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

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

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

added 11 characters in body
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
added 48 characters in body
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
added 2 characters in body
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
Fix grammar error
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
Correction for witness item counts
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
Correction for witness item counts
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
added 170 characters in body
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
added 170 characters in body
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
added 138 characters in body
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading
Source Link
Murch
  • 77.9k
  • 35
  • 190
  • 641
Loading