Skip to content

Commit e65dc59

Browse files
committed
fix on OP_CHECKMULTISIG per #606
1 parent 0649608 commit e65dc59

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

10_2_Building_the_Structure_of_P2SH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ Here's what the individual parts mean:
106106

107107
* 0x52 = OP_2
108108
* 0x21 = OP_PUSHDATA 33 bytes (hex: 0x21)
109-
* 0x02da2f10746e9778dd57bd0276a4f84101c4e0a711f9cfd9f09cde55acbdd2d191 = the next 33 bytes (public-key hash)
109+
* 0x02da2f10746e9778dd57bd0276a4f84101c4e0a711f9cfd9f09cde55acbdd2d191 = the next 33 bytes (public key)
110110
* 0x21 = OP_PUSHDATA 33 bytes (hex: 0x21)
111-
* 0x02bfde48be4aa8f4bf76c570e98a8d287f9be5638412ab38dede8e78df82f33fa3 = the next 33 bytes (public-key hash)
111+
* 0x02bfde48be4aa8f4bf76c570e98a8d287f9be5638412ab38dede8e78df82f33fa3 = the next 33 bytes (public key)
112112
* 0x52 = OP_2
113113
* 0xae = OP_CHECKMULTISIG
114114

10_4_Scripting_a_Multisig.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ Before we close out this intro to P2SH scripting, it's worth examining a more re
44

55
## Understand the Multisig Code
66

7-
Multisig transactions are created in Bitcoin using the `OP_CHECKMULTISIG` code. `OP_CHECKMULTISIG` expects a long string of arguments that looks like this: `0 ... sigs ... <m> ... addresses ... <n> OP_CHECKMULTISIG`. When `OP_CHECKMULTISIG` is run, it does the following:
7+
Multisig transactions are created in Bitcoin using the `OP_CHECKMULTISIG` code. `OP_CHECKMULTISIG` expects a long string of arguments that looks like this: `0 ... sigs ... <m> ... public keys ... <n> OP_CHECKMULTISIG`. When `OP_CHECKMULTISIG` is run, it does the following:
88

99
1. Pop the first value from the stack (`<n>`).
10-
2. Pop "n" values from the stack as Bitcoin addresses (hashed public keys).
10+
2. Pop "n" values from the stack as public keys.
1111
3. Pop the next value from the stack (`<m>`).
1212
4. Pop "m" values from the stack as potential signatures.
1313
5. Pop a `0` from the stack due to a mistake in the original coding.
14-
6. Compare the signatures to the Bitcoin adddresses.
14+
6. Compare the signatures to the public keys.
1515
7. Push a `True` or `False` depending on the result.
1616

17-
The operands of `OP_MULTISIG` are typically divided, with the `0` and the signatures coming from the unlocking script and the "m", "n", and addresses being detailed by the locking script.
17+
The operands of `OP_MULTISIG` are typically divided, with the `0` and
18+
the signatures coming from the unlocking script and the "m", "n", and
19+
public keys being detailed by the locking script.
1820

1921
The requirement for that `0` as the first operand for `OP_CHECKMULTISIG` is a consensus rule. Because the original version of `OP_CHECKMULTISIG` accidentally popped an extra item off the stack, Bitcoin must forever follow that standard, lest complex redemption scripts from that time period accidentally be broken, rendering old funds unredeemable.
2022

@@ -24,11 +26,11 @@ The requirement for that `0` as the first operand for `OP_CHECKMULTISIG` is a co
2426

2527
As discussed in [§10.1: Understanding the Foundation of P2SH](10_1_Understanding_the_Foundation_of_P2SH.md), multisigs are one of the standard Bitcoin transaction types. A transaction can be created with a locking script that uses the raw `OP_CHECKMULTISIG` command, and it will be accepted into a block. This is the classic methodology for using multisigs in Bitcoin.
2628

27-
As an example, we will revisit the multisig created in [§6.1](06_1_Sending_a_Transaction_to_a_Multisig.md) one final time and build a new locking script for it using this methodology. As you may recall, that was a 2-of-2 multisig built from `$address1` and `$address2`.
29+
As an example, we will revisit the multisig created in [§6.1](06_1_Sending_a_Transaction_to_a_Multisig.md) one final time and build a new locking script for it using this methodology. As you may recall, that was a 2-of-2 multisig built from `$pubkey1` and `$pubkey2`.
2830

29-
As `OP_CHECKMULTISIG` locking script requires the "m" (`2`), the addresses, and the "n" (`2`), you could write the following `scriptPubKey`:
31+
As `OP_CHECKMULTISIG` locking script requires the "m" (`2`), the public keys, and the "n" (`2`), you could write the following `scriptPubKey`:
3032
```
31-
2 $address1 $address2 2 OP_CHECKMULTISIG
33+
2 $pubkey1 $pubkey2 2 OP_CHECKMULTISIG
3234
```
3335
If this looks familiar, that's because it's the multisig that you deserialized in [§10.2: Building the Structure of P2SH](10_2_Building_the_Structure_of_P2SH.md).
3436
```
@@ -48,20 +50,20 @@ The `scriptSig` for a standard multisig address must then submit the missing ope
4850

4951
In order to spend a multisig UTXO, you run the `scriptSig` and `scriptPubKey` as follows:
5052
```
51-
Script: 0 $signature1 $signature2 2 $address1 $address2 2 OP_CHECKMULTISIG
53+
Script: 0 $signature1 $signature2 2 $pubkey1 $pubkey2 2 OP_CHECKMULTISIG
5254
Stack: [ ]
5355
```
5456
First, you place all the constants on the stack:
5557
```
5658
Script: OP_CHECKMULTISIG
57-
Stack: [ 0 $signature1 $signature2 2 $address1 $address2 2 ]
59+
Stack: [ 0 $signature1 $signature2 2 $pubkey1 $pubkey2 2 ]
5860
```
5961
Then, the `OP_CHECKMULTISIG` begins to run. First, the "2" is popped:
6062
```
6163
Running: OP_CHECKMULTISIG
62-
Stack: [ 0 $signature1 $signature2 2 $address1 $address2 ]
64+
Stack: [ 0 $signature1 $signature2 2 $pubkey1 $pubkey2 ]
6365
```
64-
Then, the "2" tells `OP_CHECKMULTISIG `to pop two addresses:
66+
Then, the "2" tells `OP_CHECKMULTISIG `to pop two public keys:
6567
```
6668
Running: OP_CHECKMULTISIG
6769
Stack: [ 0 $signature1 $signature2 2 ]
@@ -81,7 +83,7 @@ Then, one more item is mistakenly popped:
8183
Running: OP_CHECKMULTISIG
8284
Stack: [ ]
8385
```
84-
Then, `OP_CHECKMULTISIG` completes its operation by comparing the "m" signatures to the "n" addresses:
86+
Then, `OP_CHECKMULTISIG` completes its operation by comparing the "m" signatures to the "n" public keys:
8587
```
8688
Script:
8789
Stack: [ True ]
@@ -105,7 +107,7 @@ P2SH multisigs are the modern methodology for creating multisigs on the Blockcha
105107

106108
To create a P2SH multisig, follow the standard steps for creating a P2SH locking script:
107109

108-
1. Serialize `2 $address1 $address2 2 OP_CHECKMULTISIG`.
110+
1. Serialize `2 $pubkey1 $pubkey2 2 OP_CHECKMULTISIG`.
109111
1. `<serializedMultiSig>` = "522102da2f10746e9778dd57bd0276a4f84101c4e0a711f9cfd9f09cde55acbdd2d1912102bfde48be4aa8f4bf76c570e98a8d287f9be5638412ab38dede8e78df82f33fa352ae"
110112
2. Save `<serializedMultiSig>` for future reference as the redeemScript.
111113
1. `<redeemScript>` = "522102da2f10746e9778dd57bd0276a4f84101c4e0a711f9cfd9f09cde55acbdd2d1912102bfde48be4aa8f4bf76c570e98a8d287f9be5638412ab38dede8e78df82f33fa352ae"
@@ -133,9 +135,9 @@ To unlock the P2SH multisig, first confirm the script:
133135

134136
Then, run the multisig script:
135137

136-
1. Deserialize `<serializedMultiSig>` to `2 $address1 $address2 2 OP_CHECKMULTISIG`.
138+
1. Deserialize `<serializedMultiSig>` to `2 $pubkey1 $pubkey2 2 OP_CHECKMULTISIG`.
137139
2. Concatenate that with the earlier operands in the unlocking script, `0 $signature1 $signature2`.
138-
3. Validate `0 $signature1 $signature2 2 $address1 $address2 2 OP_CHECKMULTISIG`.
140+
3. Validate `0 $signature1 $signature2 2 $pubkey1 $pubkey2 2 OP_CHECKMULTISIG`.
139141
4. Succeed if the operands fulfill the deserialized `redeemScript`.
140142

141143
Now you know how the multisig transaction in [§6.1](06_1_Sending_a_Transaction_to_a_Multisig.md) was actually created, how it was validated for spending, and why that `redeemScript` was so important.

0 commit comments

Comments
 (0)