You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bip-0141.mediawiki
+28-6Lines changed: 28 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,9 +108,13 @@ If the version byte is 1 to 16, no further interpretation of the witness program
108
108
109
109
Blocks are currently limited to 1,000,000 bytes (1MB) total size. We change this restriction as follows:
110
110
111
-
''Block cost'' is defined. The cost of each byte in the existing header and transactions is 4, while the cost of each byte in witness data is 1.
111
+
''Block cost'' is defined as ''Base size'' * 3 + ''Total size''.
112
112
113
-
The new rule is total ''block cost'' ≤ 4,000,000.
113
+
''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.
114
+
115
+
''Total size'' is the block size in bytes with transactions serialized as described in [[bip-0144.mediawiki|BIP144]], including base data and witness data.
116
+
117
+
The new rule is ''block cost'' ≤ 4,000,000.
114
118
115
119
==== Sigops ====
116
120
@@ -128,8 +132,8 @@ The following example is a version 0 pay-to-witness-public-key-hash (P2WPKH) wit
128
132
129
133
witness: <signature> <pubkey>
130
134
scriptSig: (empty)
131
-
scriptPubKey: 0 <20-byte-hash>
132
-
(0x0014{20-byte-hash})
135
+
scriptPubKey: 0 <20-byte-key-hash>
136
+
(0x0014{20-byte-key-hash})
133
137
134
138
The '0' in scriptPubKey indicates the following push is a version 0 witness program. The length of the witness program indicates that it is a P2WPKH type. The witness must consist of exactly 2 items. The HASH160 of the pubkey in witness must match the witness program.
135
139
@@ -139,6 +143,24 @@ The signature is verified as
139
143
140
144
Comparing with a traditional P2PKH output, the P2WPKH equivalent occupies 3 less bytes in the scriptPubKey, and moves the signature and public key from scriptSig to witness.
141
145
146
+
=== P2WPKH nested in BIP16 P2SH ===
147
+
148
+
The following example is the same P2WPKH witness program, but nested in a BIP16 P2SH output.
149
+
150
+
witness: <signature> <pubkey>
151
+
scriptSig: <0 <20-byte-key-hash>>
152
+
(0x160014{20-byte-key-hash})
153
+
scriptPubKey: HASH160 <20-byte-script-hash> EQUAL
154
+
(0xA914{20-byte-script-hash}87)
155
+
156
+
The only item in scriptSig is hashed with HASH160, compared against the 20-byte-script-hash in scriptPubKey, and interpreted as:
157
+
158
+
0 <20-byte-key-hash>
159
+
160
+
The P2WPKH witness program is then executed as described in the previous example.
161
+
162
+
Comparing with the previous example, the scriptPubKey is 1 byte bigger and the scriptSig is 23 bytes bigger. Although a nested witness program is less efficient, its payment address is fully transparent and backward compatible for all Bitcoin reference client since version 0.6.0.
163
+
142
164
=== P2WSH witness program ===
143
165
144
166
The following example is an 1-of-2 multi-signature version 0 pay-to-witness-script-hash (P2WSH) witness program.
@@ -160,7 +182,7 @@ A P2WSH witness program allows arbitrarily large script as the 520-byte push lim
160
182
161
183
The scriptPubKey occupies 34 bytes, as opposed to 23 bytes of BIP16 P2SH. The increased size improves security against possible collision attacks, as 2<sup>80</sup> work is not infeasible anymore (By the end of 2015, 2<sup>84</sup> hashes have been calculated in Bitcoin mining since the creation of Bitcoin). The spending script is same as the one for an equivalent BIP16 P2SH output but is moved to witness.
162
184
163
-
===Witness program nested in BIP16 P2SH ===
185
+
===P2WSH nested in BIP16 P2SH ===
164
186
165
187
The following example is the same 1-of-2 multi-signature P2WSH witness program, but nested in a BIP16 P2SH output.
166
188
@@ -176,7 +198,7 @@ The only item in scriptSig is hashed with HASH160, compared against the 20-byte-
176
198
177
199
The P2WSH witness program is then executed as described in the previous example.
178
200
179
-
Comparing with the previous example, the scriptPubKey is 11 bytes smaller (with reduced security) while witness is the same. However, it also requires 35 bytes in scriptSig, which is not prunable in transmission. Although a nested witness program is less efficient in many ways, its payment address is fully transparent and backward compatible for all Bitcoin reference client since version 0.6.0.
201
+
Comparing with the previous example, the scriptPubKey is 11 bytes smaller (with reduced security) while witness is the same. However, it also requires 35 bytes in scriptSig.
0 commit comments