1
0
mirror of https://github.com/bitcoin/bips.git synced 2024-11-19 09:50:06 +01:00

Merge pull request #289 from jl2012/patch-6

Tidy up Witness Program section
This commit is contained in:
Luke-Jr 2016-01-20 16:56:10 +00:00
commit ae9947f98d

View File

@ -57,21 +57,17 @@ If there are more than one scriptPubKey matching the pattern, the one with highe
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".
Witness verification logic is either
# triggered by a scriptPubKey that is exactly a push of a version byte, plus a push of a witness program, or
# 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.
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:
# 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.
# 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.
New rules for scriptSig:
* In case 1, the scriptSig must be exactly empty.
* In case 2, the scriptSig must be exactly a push of the BIP16 redeemScript.
If the version byte is 0, and the witness program is 20 bytes,
If the version byte is 0, and the witness program is 20 bytes:
* It is interpreted as a pay-to-witness-public-key-hash (P2WPKH) program.
* The witness must consist of exactly 2 items. The first one is a signature, and the second one is a public key.
* HASH160 of the public key must match the 20-byte witness program.
* The witness must consist of exactly 2 items. The first one a signature, and the second one a public key.
* The HASH160 of the public key must match the 20-byte witness program.
* After normal script evaluation, the signature is verified against the public key with CHECKSIG operation. The verification must result in a single TRUE on the stack.
If the version byte is 0, and the witness program is 32 bytes,
If the version byte is 0, and the witness program is 32 bytes:
* It is interpreted as a pay-to-witness-script-hash (P2WSH) program.
* The witness must consist of an input stack to feed to the script, followed by a serialized script ("witnessScript").
* The witnessScript is popped off the initial witness stack. SHA256 of the witnessScript must match the 32-byte witness program.