From b915ba5378df097644d3d2b66aca86c3a5f09112 Mon Sep 17 00:00:00 2001 From: Johnson Lau Date: Sun, 24 Jan 2016 19:10:39 +0800 Subject: Clarify txid and wtxid --- bip-0141.mediawiki | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'bip-0141.mediawiki') diff --git a/bip-0141.mediawiki b/bip-0141.mediawiki index 7266e9d..9a5068e 100644 --- a/bip-0141.mediawiki +++ b/bip-0141.mediawiki @@ -34,13 +34,35 @@ By removing this data from the transaction structure committed to the transactio ==Specification== +=== Transaction ID === + +A new data structure, witness, is defined. Each transaction will have 2 IDs. + +Definition of txid remains unchanged: the double SHA256 of the traditional serialization format: + + [nVersion][txins][txouts][nLockTime] + +A new wtxid is defined: the double SHA256 of the new serialization with witness data: + + [nVersion][marker][flag][txins][txouts][witness][nLockTime] + +Format of nVersion, txins, txouts, and nLockTime are same as traditional serialization. + +The marker MUST be 0x00. + +The flag MUST be a 1-byte non-zero value. Currently, 0x01 MUST be used. + +The witness is a serialization of all witness data of the transaction. Each txin is associated with a witness field. A witness field starts with a var_int to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a var_int to indicate the length. Witness data is NOT script and is not restricted by the 520-byte push limit. + +A non-witness program (defined hereinafter) txin MUST be associated with an empty witness field, represented by a 0x00. If all txins are not witness program, a transaction's wtxid is equal to its txid. + === Commitment structure === -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. +A new block rule is added which requires a commitment to the wtxid. The wtxid of coinbase transaction is assumed to be 0x0000....0000. -A witness root hash is calculated with all those witness hashes as leaves, in a way similar to the hashMerkleRoot in the block header. +A witness root hash is calculated with all those wtxid as leaves, in a way similar to the hashMerkleRoot in the block header. -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: +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: 1-byte - OP_RETURN (0x6a) 1-byte - Push the following 36 bytes (0x24) -- cgit v1.2.3