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
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,9 +57,13 @@ If there are more than one scriptPubKey matching the pattern, the one with highe
57
57
58
58
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".
59
59
60
+
Witness verification logic is either
61
+
# triggered by a scriptPubKey that is exactly a push of a version byte, plus a push of a witness program, or
62
+
# 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.
63
+
60
64
New rules for scriptSig:
61
-
* In case the scriptPubKey pushes a version byte and witness program directly, the scriptSig must be exactly empty.
62
-
* In case the redeemScript pushes a version byte and witness program, the scriptSig must be exactly the single push of the redeemScript.
65
+
* In case 1, the scriptSig must be exactly empty.
66
+
* In case 2, the scriptSig must be exactly a push of the BIP16 redeemScript.
63
67
64
68
If the version byte is 0, and the witness program is 20 bytes,
65
69
* It is interpreted as a pay-to-witness-public-key-hash (P2WPKH) program.
@@ -69,9 +73,9 @@ If the version byte is 0, and the witness program is 20 bytes,
69
73
70
74
If the version byte is 0, and the witness program is 32 bytes,
71
75
* It is interpreted as a pay-to-witness-script-hash (P2WSH) program.
72
-
* The witness must consist of an input stack to feed to the script, followed by a serialized script.
73
-
* The serialized script is popped off the initial witness stack. SHA256 of the serialized script must match the 32-byte witness program.
74
-
* The serialized script is deserialized, and executed after normal script evaluation with the remaining witness stack.
76
+
* The witness must consist of an input stack to feed to the script, followed by a serialized script ("witnessScript").
77
+
* The witnessScript is popped off the initial witness stack. SHA256 of the witnessScript must match the 32-byte witness program.
78
+
* The witnessScript is deserialized, and executed after normal script evaluation with the remaining witness stack.
75
79
* The script must not fail, and result in exactly a single TRUE on the stack.
76
80
77
81
If the version byte is 0, but the witness program is neither 20 nor 32 bytes, the script must fail.
@@ -124,7 +128,7 @@ The following example is an 1-of-2 multi-signature version 0 pay-to-witness-scri
124
128
scriptPubKey: 0 <32-byte-hash>
125
129
(0x0020{32-byte-hash})
126
130
127
-
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 P2WSH type. The last item in the witness is popped off, hashed with SHA256, compared against the 32-byte-hash in scriptPubKey, and deserialized:
131
+
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 P2WSH type. The last item in the witness (the "witnessScript") is popped off, hashed with SHA256, compared against the 32-byte-hash in scriptPubKey, and deserialized:
128
132
129
133
1 <pubkey1> <pubkey2> 2 CHECKMULTISIG
130
134
@@ -150,7 +154,7 @@ The only item in scriptSig is hashed with HASH160, compared against the 20-byte-
150
154
151
155
0 <32-byte-hash>
152
156
153
-
The P2WSH witness program is then executed as described in the previous example
157
+
The P2WSH witness program is then executed as described in the previous example.
154
158
155
159
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.
0 commit comments