Skip to content

Commit 5bfb685

Browse files
committed
Merge pull request bitcoin#296 from jl2012/patch-8
Clarify txid and wtxid
2 parents 6a6c305 + b915ba5 commit 5bfb685

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

bip-0141.mediawiki

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,35 @@ By removing this data from the transaction structure committed to the transactio
3434
3535
==Specification==
3636

37+
=== Transaction ID ===
38+
39+
A new data structure, <code>witness</code>, is defined. Each transaction will have 2 IDs.
40+
41+
Definition of <code>txid</code> remains unchanged: the double SHA256 of the traditional serialization format:
42+
43+
[nVersion][txins][txouts][nLockTime]
44+
45+
A new <code>wtxid</code> is defined: the double SHA256 of the new serialization with witness data:
46+
47+
[nVersion][marker][flag][txins][txouts][witness][nLockTime]
48+
49+
Format of <code>nVersion</code>, <code>txins</code>, <code>txouts</code>, and <code>nLockTime</code> are same as traditional serialization.
50+
51+
The <code>marker</code> MUST be <code>0x00</code>.
52+
53+
The <code>flag</code> MUST be a 1-byte non-zero value. Currently, <code>0x01</code> MUST be used.
54+
55+
The <code>witness</code> is a serialization of all witness data of the transaction. Each txin is associated with a witness field. A witness field starts with a <code>var_int</code> to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a <code>var_int</code> to indicate the length. Witness data is NOT script and is not restricted by the 520-byte push limit.
56+
57+
A non-witness program (defined hereinafter) txin MUST be associated with an empty witness field, represented by a <code>0x00</code>. If all txins are not witness program, a transaction's <code>wtxid</code> is equal to its <code>txid</code>.
58+
3759
=== Commitment structure ===
3860

39-
A new block rule is added which requires a commitment to the witness hashes, the double SHA256 of a transaction including witnesses. The witness hash of coinbase transaction is assumed to be 0x0000....0000.
61+
A new block rule is added which requires a commitment to the <code>wtxid</code>. The <code>wtxid</code> of coinbase transaction is assumed to be <code>0x0000....0000</code>.
4062

41-
A witness root hash is calculated with all those witness hashes as leaves, in a way similar to the hashMerkleRoot in the block header.
63+
A witness root hash is calculated with all those <code>wtxid</code> as leaves, in a way similar to the hashMerkleRoot in the block header.
4264

43-
The commitment is recorded in a scriptPubKey of the coinbase transaction. It must be at least 38 bytes, with the first 6-byte of 0x6a24aa21a9ed, that is:
65+
The commitment is recorded in a scriptPubKey of the coinbase transaction. It must be at least 38 bytes, with the first 6-byte of <code>0x6a24aa21a9ed</code>, that is:
4466

4567
1-byte - OP_RETURN (0x6a)
4668
1-byte - Push the following 36 bytes (0x24)

0 commit comments

Comments
 (0)