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: 10_4_Scripting_a_Multisig.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,19 @@ Before we close out this intro to P2SH scripting, it's worth examining a more re
4
4
5
5
## Understand the Multisig Code
6
6
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:
8
8
9
9
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.
11
11
3. Pop the next value from the stack (`<m>`).
12
12
4. Pop "m" values from the stack as potential signatures.
13
13
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.
15
15
7. Push a `True` or `False` depending on the result.
16
16
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.
18
20
19
21
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.
20
22
@@ -24,11 +26,11 @@ The requirement for that `0` as the first operand for `OP_CHECKMULTISIG` is a co
24
26
25
27
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.
26
28
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`.
28
30
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`:
30
32
```
31
-
2 $address1 $address2 2 OP_CHECKMULTISIG
33
+
2 $pubkey1 $pubkey2 2 OP_CHECKMULTISIG
32
34
```
33
35
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).
34
36
```
@@ -48,20 +50,20 @@ The `scriptSig` for a standard multisig address must then submit the missing ope
48
50
49
51
In order to spend a multisig UTXO, you run the `scriptSig` and `scriptPubKey` as follows:
4. Succeed if the operands fulfill the deserialized `redeemScript`.
140
142
141
143
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