05 - Pay to MultiSignature Hash (P2MSH)

Stack
Script
Description

Empty.

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3> | |OP_3DUP OP_CAT OP_CAT OP_HASH160 <3pubkey_hash> OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

scriptSig and scriptPubKey are combined.

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3>

OP_3DUP OP_CAT OP_CAT OP_HASH160 <3pubkey_hash> OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Signatures and public keys are added to the stack

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3><pubkey_1> <pubkey_2> <pubkey_3>

OP_CAT OP_CAT OP_HASH160 <3pubkey_hash> OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

3 public keys are duplicated

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3><pubkey_1> <pubkey_2_3_cat>

OP_CAT OP_HASH160 <3pubkey_hash> OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Pubkey 2 and Pubkey 3 are concatenated

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3><pubkey_1_2_3_cat>

OP_HASH160 <3pubkey_hash> OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Pubkey 1 is concatenated with Pukey 2_3 concatenation

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3> <pubkey_1_2_3_hash>

<3pubkey_hash> OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Concatenated pubkeys are double hashed using OP_HASH160

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3> <pubkey_1_2_3_hash> <3pubkey_hash>

OP_EQUALVERIFY OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Expected 3 pubkey hash is pushed onto the stack

1 <signature_1> <signature_2> <pubkey_1> <pubkey_2> <pubkey_3>

OP_TOALTSTACK OP_TOALTSTACK OP_TOALTSTACK OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Generated hash is evaluated against expected hash

1 <signature_1> <signature_2>​Altstack:<pubkey_3> <pubkey_2> <pubkey_1>

OP_2 OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Pubkeys 3, 2 and 1 are pushed to altstack

1 <signature_1> <signature_2> 2​Altstack:<pubkey_3> <pubkey_2> <pubkey_1>

OP_FROMALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_3 OP_CHECKMULTISIG

Constant value '2' is pushed onto the stack

1 <signature_1> <signature_2> 2 <pubkey_1><pubkey_2><pubkey_3>

OP_3 OP_CHECKMULTISIG

Pubkeys 3, 2 and 1 are pulled from altstack

1 <signature_1> <signature_2> 2 <pubkey_1><pubkey_2><pubkey_3> 3

OP_CHECKMULTISIG

Constant value '3' is pushed onto the stack

true

Empty.

Multisignature evaluation is performed

As shown above, the spending parties must supply 2 valid signatures and the three public keys that correspond to the hash stored in the output. The 3 public keys are duplicated and hashed using the OP_HASH160 opcode, and the resultant data item is checked against a hash value stored in the output.

Following this, the three public keys are pushed to the ALTSTACK so that the 2 signature evaluation criteria can be inserted, and then pulled back to the main stack. The 3 pubkey evaluation criteria is then added and the multisig operation takes place.

These types of scripts can be applied in many ways to enable multi-party collaboration for a range of use cases.

Last updated

Was this helpful?