Skip to content

Commit aa5531d

Browse files
committed
Merge pull request bitcoin#378 from jl2012/patch-18
BIP141 clarifications and formatting
2 parents c3e5f14 + ab4f511 commit aa5531d

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

bip-0141.mediawiki

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,30 @@ A non-witness program (defined hereinafter) txin MUST be associated with an empt
6060

6161
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>.
6262

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.
63+
A <code>witness root hash</code> is calculated with all those <code>wtxid</code> as leaves, in a way similar to the <code>hashMerkleRoot</code> in the block header.
6464

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

6767
1-byte - OP_RETURN (0x6a)
6868
1-byte - Push the following 36 bytes (0x24)
6969
4-byte - Commitment header (0xaa21a9ed)
70-
32-byte - Commitment hash: Double-SHA256(witness root hash|witness nonce)
70+
32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)
7171
7272
39th byte onwards: Optional data with no consensus meaning
7373
74-
and the coinbase's input's witness must consist of a single 32-byte array for the witness nonce.
74+
and the coinbase's input's witness must consist of a single 32-byte array for the <code>witness reserved value</code>.
7575

76-
If there are more than one scriptPubKey matching the pattern, the one with highest output index is assumed to be the commitment.
76+
If there are more than one <code>scriptPubKey</code> matching the pattern, the one with highest output index is assumed to be the commitment.
7777

7878
If all transactions in a block do not have witness data, the commitment is optional.
7979

8080
=== Witness program ===
8181

82-
A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that consists of a 1-byte push opcode (for 0 to 16) followed by a data push between 2 and 32 bytes gets a new special meaning. The value of the first push is called the "version byte". The following byte vector pushed is called the "witness program".
82+
A <code>scriptPubKey</code> (or <code>redeemScript</code> as defined in BIP16/P2SH) that consists of a 1-byte push opcode (for 0 to 16) followed by a data push between 2 and 32 bytes gets a new special meaning. The value of the first push is called the "version byte". The following byte vector pushed is called the "witness program".
8383

8484
There are two cases in which witness validation logic are triggered. Each case determines the location of the witness version byte and program, as well as the form of the scriptSig:
85-
# Triggered by a scriptPubKey that is exactly a push of a version byte, plus a push of a witness program. The scriptSig must be exactly empty or validation fails.
86-
# Triggered when a scriptPubKey is a P2SH script, and the BIP16 redeemScript pushed in the scriptSig is exactly a push of a version byte plus a push of a witness program. The scriptSig must be exactly a push of the BIP16 redeemScript or validation fails.
85+
# Triggered by a <code>scriptPubKey</code> that is exactly a push of a version byte, plus a push of a witness program. The scriptSig must be exactly empty or validation fails.
86+
# Triggered when a <code>scriptPubKey</code> is a P2SH script, and the BIP16 <code>redeemScript</code> pushed in the <code>scriptSig</code> is exactly a push of a version byte plus a push of a witness program. The <code>scriptSig</code> must be exactly a push of the BIP16 <code>redeemScript</code> or validation fails.
8787
8888
If the version byte is 0, and the witness program is 20 bytes:
8989
* It is interpreted as a pay-to-witness-public-key-hash (P2WPKH) program.
@@ -93,9 +93,9 @@ If the version byte is 0, and the witness program is 20 bytes:
9393
9494
If the version byte is 0, and the witness program is 32 bytes:
9595
* It is interpreted as a pay-to-witness-script-hash (P2WSH) program.
96-
* The witness must consist of an input stack to feed to the script, followed by a serialized script ("witnessScript").
97-
* The witnessScript (≤ 10,000 bytes) is popped off the initial witness stack. SHA256 of the witnessScript must match the 32-byte witness program.
98-
* The witnessScript is deserialized, and executed after normal script evaluation with the remaining witness stack (≤ 520 bytes for each stack item).
96+
* The witness must consist of an input stack to feed to the script, followed by a serialized script (<code>witnessScript</code>).
97+
* The <code>witnessScript</code> (≤ 10,000 bytes) is popped off the initial witness stack. SHA256 of the <code>witnessScript</code> must match the 32-byte witness program.
98+
* The <code>witnessScript</code> is deserialized, and executed after normal script evaluation with the remaining witness stack (≤ 520 bytes for each stack item).
9999
* The script must not fail, and result in exactly a single TRUE on the stack.
100100
101101
If the version byte is 0, but the witness program is neither 20 nor 32 bytes, the script must fail.
@@ -108,7 +108,7 @@ If the version byte is 1 to 16, no further interpretation of the witness program
108108

109109
Blocks are currently limited to 1,000,000 bytes (1MB) total size. We change this restriction as follows:
110110

111-
''Block cost'' is defined as ''Base size'' * 3 + ''Total size''.
111+
''Block cost'' is defined as ''Base size'' * 3 + ''Total size''. (rationale<ref>Rationale of using a single composite constraint, instead of two separate limits such as 1MB base data and 3MB witness data: Using two separate limits would make mining and fee estimation nearly impossible. Miners would need to solve a complex non-linear optimization problem to find the set of transactions that maximize fees given both constraints, and wallets would not be able to know what to pay as it depends on which of the two conditions is most constrained by the time miners try to produce blocks with their transactions in. Another problem with such an approach is freeloading. Once a set of transactions hit the base data 1MB constraint, up to 3MB extra data could be added to the witness by just minimally increasing the fee. The marginal cost for extra witness space effectively becomes zero in that case.</ref>)
112112

113113
''Base size'' is the block size in bytes with the original transaction serialization without any witness-related data, as seen by a non-upgraded node.
114114

@@ -202,14 +202,13 @@ Comparing with the previous example, the scriptPubKey is 11 bytes smaller (with
202202

203203
=== Extensible commitment structure ===
204204

205-
The new commitment in coinbase transaction is a hash of the witness root hash and a witness nonce. The nonce currently has no consensus meaning, but in the future allows new commitment values for future softforks. For example, if a new consensus-critical commitment is required in the future, the commitment in
206-
coinbase becomes:
205+
The new commitment in coinbase transaction is a hash of the <code>witness root hash</code> and a <code>witness reserved value</code>. The <code>witness reserved value</code> currently has no consensus meaning, but in the future allows new commitment values for future softforks. For example, if a new consensus-critical commitment is required in the future, the commitment in coinbase becomes:
207206

208-
Double-SHA256(Witness root hash|Hash(new commitment|witness nonce))
207+
Double-SHA256(Witness root hash|Hash(new commitment|witness reserved value))
209208
210-
For backward compatibility, the Hash(new commitment|witness nonce) will go to the coinbase witness, and the witness nonce will be recorded in another location specified by the future softfork. Any number of new commitment could be added in this way.
209+
For backward compatibility, the <code>Hash(new commitment|witness reserved value)</code> will go to the coinbase witness, and the <code>witness reserved value</code> will be recorded in another location specified by the future softfork. Any number of new commitment could be added in this way.
211210

212-
Any commitments that are not consensus-critical to Bitcoin, such as merge-mining, MUST NOT use the witness nonce to preserve the ability to do upgrades of the Bitcoin consensus protocol.
211+
Any commitments that are not consensus-critical to Bitcoin, such as merge-mining, MUST NOT use the <code>witness reserved value</code> to preserve the ability to do upgrades of the Bitcoin consensus protocol.
213212

214213
The optional data space following the commitment also leaves room for metadata of future softforks, and MUST NOT be used for other purpose.
215214

@@ -283,9 +282,13 @@ For Bitcoin testnet, the BIP9 starttime will be midnight TBD UTC (Epoch timestam
283282

284283
Special thanks to Gregory Maxwell for originating many of the ideas in this BIP and Luke-Jr for figuring out how to deploy this as a soft fork.
285284

285+
== Footnotes ==
286+
287+
<references />
288+
286289
== Reference Implementation ==
287290

288-
https://github.com/sipa/bitcoin/commits/segwit
291+
https://github.com/bitcoin/bitcoin/pull/7910
289292

290293
== References ==
291294

0 commit comments

Comments
 (0)