<p>I have a scenario as follows:</p>
<ul>
<li>In a company, there is a manager and three employees. The multisig signature will be redeemed by the manager combined with one of the employees.</li>
<li>However, only the manager, or only the employees with enough number of signatures will not be able to redeem the transaction</li>
<li>The order of the signatures should not matter</li>
<li>Assume my_public_key is manager_public_key</li>
</ul>
<p>My solution was: <code>[OP_2DUP, my_public_key, OP_CHECKSIG, OP_IF, OP_DROP, OP_ELSE, my_public_key, OP_CHECKSIGVERIFY, OP_SWAP, OP_ENDIF, OP_DROP, OP_1, employee1_public_key, employee2_public_key, employee3_public_key, OP_3, OP_CHECKMULTISIG] </code></p>
<p>So I tried to shorten the script in order to have less bit in a transaction by using alt-stack.</p>
<p>My suggested solution is just to duplicate the my_public_key and push it into the alt-stack and whenever I need it later, I can pop it from the alt-stack and use it. So by the final script I should deduct the script by one public key.</p>
<p>Suggested solution: <code>[OP_2DUP, my_public_key, OP_DUP, OP_TOALTSTACK, OP_CHECKSIG, OP_IF, OP_DROP, OP_ELSE, OP_FROMALTSTACK, OP_CHECKSIGVERIFY, OP_SWAP, OP_ENDIF, OP_DROP, OP_1, employee1_public_key, employee2_public_key, employee3_public_key, OP_3, OP_CHECKMULTISIG]</code></p>
<p>My suggested solution gives reference error.
I would be happy if anyone can help me.</p>
<p>Error:
{&quot;error&quot;: &quot;Error validating transaction: Rejected script for input 0 referencing 5f026fb3260c809d446740917bca4aa0e8633f64ec86fc8a4c5e23979f1578ba at 0..&quot;}</p>
<p>Input script:
[OP_0, manager_sig,employee_sig]</p>

CC BY-SA 4.0
2021-04-08T23:30:05.120Z
Is the script you are looking for just doing `manager AND (employee_1 OR employee_2 OR employee_3)`? If so, you don't need to make such a complicated script or use the altstack. Is allowing any order a hard requirement? That severely complicates things, whereas if the scriptSig is just a template with signatures in a particular order, everything is a lot easier.
Ava Chow
CC BY-SA 4.0
2021-04-09T01:44:29.903Z
The order of signatures should not matter. So, the script should accept any order of signatures.
cavitcakir
CC BY-SA 4.0
2021-04-13T16:43:19.577Z
@cavitcakir OP_CHECKMULTISIG requires the signatures to be in the same order as the keys (though in case of a k-of-n, obviously sigs for some keys have to be omitted). Still, the remaining ones must be right.
Pieter Wuille
CC BY-SA 4.0
2021-04-13T19:34:28.327Z
@PieterWuille Yes, I know how it works so that's why I first check the order and do required manipulations. The first script works well when input is not ordered. But I used 2 my_public_key and I want to reduce the number of keys in the locking script.
cavitcakir
CC BY-SA 4.0
2021-04-13T19:35:33.103Z
@AndrewChow I forgot to mention you in the previous comment.
cavitcakir
<script>
Alt Stack is not working as expected
cavitcakir
# Alt Stack is not working as expected

(Asked by: username_0 on 2021-04-02)

I have a scenario as follows:

* In a company, there is a manager and three employees. The multisig signature will be redeemed by the manager combined with one of the employees.
* However, only the manager, or only the employees with enough number of signatures will not be able to redeem the transaction
* The order of the signatures should not matter
* Assume my\_public\_key is manager\_public\_key

My solution was: `[OP_2DUP, my_public_key, OP_CHECKSIG, OP_IF, OP_DROP, OP_ELSE, my_public_key, OP_CHECKSIGVERIFY, OP_SWAP, OP_ENDIF, OP_DROP, OP_1, employee1_public_key, employee2_public_key, employee3_public_key, OP_3, OP_CHECKMULTISIG]`

So I tried to shorten the script in order to have less bit in a transaction by using alt-stack.

My suggested solution is just to duplicate the my\_public\_key and push it into the alt-stack and whenever I need it later, I can pop it from the alt-stack and use it. So by the final script I should deduct the script by one public key.

Suggested solution: `[OP_2DUP, my_public_key, OP_DUP, OP_TOALTSTACK, OP_CHECKSIG, OP_IF, OP_DROP, OP_ELSE, OP_FROMALTSTACK, OP_CHECKSIGVERIFY, OP_SWAP, OP_ENDIF, OP_DROP, OP_1, employee1_public_key, employee2_public_key, employee3_public_key, OP_3, OP_CHECKMULTISIG]`

My suggested solution gives reference error.
I would be happy if anyone can help me.

Error:
{"error": "Error validating transaction: Rejected script for input 0 referencing 5f026fb3260c809d446740917bca4aa0e8633f64ec86fc8a4c5e23979f1578ba at 0.."}

Input script:
[OP\_0, manager\_sig,employee\_sig]

**Tags:** script

> **Comments:**
> **username_1**: Is the script you are looking for just doing `manager AND (employee_1 OR employee_2 OR employee_3)`? If so, you don't need to make such a complicated script or use the altstack. Is allowing any order a hard requirement? That severely complicates things, whereas if the scriptSig is just a template with signatures in a particular order, everything is a lot easier.  
> **username_0**: The order of signatures should not matter. So, the script should accept any order of signatures.  
> **username_2**: @username_0 OP_CHECKMULTISIG requires the signatures to be in the same order as the keys (though in case of a k-of-n, obviously sigs for some keys have to be omitted). Still, the remaining ones must be right.  
> **username_0**: @PieterWuille Yes, I know how it works so that's why I first check the order and do required manipulations. The first script works well when input is not ordered. But I used 2 my_public_key and I want to reduce the number of keys in the locking script.  
> **username_0**: @AndrewChow I forgot to mention you in the previous comment.  

---

## 0 answers

