<p>I believe it could work with a RedeemScript like this (haven't tested the scripts):  </p>

<pre><code>OP_IF
  3 &lt;pub_A&gt;&lt;pub_B&gt;&lt;pub_C&gt; 3 OP_CheckMultiSig
OP_ELSE
  1 &lt;pub_A&gt;&lt;pub_B&gt;&lt;pub_C&gt; 3 OP_CheckMultiSigVerify
  4 &lt;pub_S1&gt;&lt;pub_S2&gt;&lt;pub_S3&gt;&lt;pub_S4&gt;&lt;pub_S5&gt; 5 OP_CheckMultiSig
</code></pre>

<p><strong>Explanation:</strong> The redeem script has two parts:<br>
- <code>OP_IF</code>: this part could be removed, it is there to allow the "leaders" to spend the funds without needing the "shareholders" signatures. Depending on the purpose it could be removed (remove first 3 lines of RedeemScript and signature doesn't require <code>OP_TRUE/OP_FALSE</code> in it).<br>
- <code>OP_ELSE</code>: this provides what you need with 2 multi-signature operations. The first one requires at least one signature out of 3 "leaders" signatures and performs a OP_CheckMultiSig<strong>Verify</strong> (there is no true/false remaining on the stack after the execution) and the second one requires 4 of 5 signatures from "shareholders".  </p>

<p>To spend, either one of these signature scripts should be provided (<code>OP_0</code> is mandatory due to the bug in <code>CheckMultiSig</code> OPs):</p>

<pre><code>OP_0 &lt;sig_A&gt;&lt;sig_B&gt;&lt;sig_C&gt; OP_TRUE &lt;RedeemScript&gt;
</code></pre>

<p>or</p>

<pre><code>OP_0 &lt;sig_S1&gt;&lt;sig_S2&gt;&lt;sig_S4&gt;&lt;sig_S5&gt; OP_0 &lt;sig_A or B or C&gt; OP_FALSE &lt;RedeemScript&gt;
</code></pre>

CC BY-SA 4.0
2019-12-22T15:32:43.943Z
How about first checking with  all the public key of shareholders with checkmultisig, if the result was true we know that in signatures provided there is not exist either of leaders, if that was not true we could check for 4 s1, s2, .. ,s5, a, b, c 8 checkmultisig.
Parsa Rahimi
CC BY-SA 4.0
2019-12-23T06:05:35.777Z
That would require each shareholder to sign the transaction twice, it also increases the size of the signature (and transaction) by a lot.
Coding Enthusiast
CC BY-SA 4.0
2019-12-23T08:55:59.020Z
Instead of twice signature, we could duplicate it in the lucking script.
Parsa Rahimi
CC BY-SA 4.0
2019-12-22T06:03:52.250Z
2019-12-22T06:03:52.250Z
Coding Enthusiast
<p>Suppose you have a company which has three main leaders called A, B and C also the company have 5 shareholders called S1 to S5. The decision rule for spending any coin from company's address is to either we present 1 of the main leaders signature and three other signature from shareholders. 
For example following unlocking script works (since it contains one of the leaders):</p>

<pre><code>&lt;sig_S1&gt; &lt;sig_A&gt; &lt;sig_S2&gt; &lt;sig_S5&gt; 
</code></pre>

<p>but not this one:</p>

<pre><code>&lt;sig_S1&gt; &lt;sig_S4&gt; &lt;sig_S3&gt; &lt;sig_S5&gt; 
</code></pre>

<p>How I can check if amongst multi signatures there exist a signature which corresponds to a specific public key, in this case, I will learn that a leader's signature surely exists. for example, if we find out from 5 signatures provided the signature of A exists, and the locking code will look like follows:</p>

<pre><code>(3 times duplicate of all signatures provided)
(check for the existence of A in signatures)
OP_IF 
   4 &lt;pub_A&gt; &lt;pub_S1&gt; &lt;pub_S2&gt; ... &lt;pub_S5&gt; 5 OP_CHECKMULTISIG
OP_ENDIF
(the same as above for B)
(the same as above for C)
</code></pre>

<script><multi-signature>
Check if multiple signatures match a specific public key
Parsa Rahimi
# Check if multiple signatures match a specific public key

(Asked by: username_0 on 2019-12-21)

Suppose you have a company which has three main leaders called A, B and C also the company have 5 shareholders called S1 to S5. The decision rule for spending any coin from company's address is to either we present 1 of the main leaders signature and three other signature from shareholders. 
For example following unlocking script works (since it contains one of the leaders):
    

but not this one:
    

How I can check if amongst multi signatures there exist a signature which corresponds to a specific public key, in this case, I will learn that a leader's signature surely exists. for example, if we find out from 5 signatures provided the signature of A exists, and the locking code will look like follows:
(3 times duplicate of all signatures provided)
(check for the existence of A in signatures)
OP_IF 
   4    ...  5 OP_CHECKMULTISIG
OP_ENDIF
(the same as above for B)
(the same as above for C)

**Tags:** script, multi-signature


---

## 1 answers

### Answer by username_1 on 2019-12-22. Score: 1

I believe it could work with a RedeemScript like this (haven't tested the scripts):  
OP_IF
  3  3 OP_CheckMultiSig
OP_ELSE
  1  3 OP_CheckMultiSigVerify
  4  5 OP_CheckMultiSig

Explanation: The redeem script has two parts:
- OP_IF: this part could be removed, it is there to allow the "leaders" to spend the funds without needing the "shareholders" signatures. Depending on the purpose it could be removed (remove first 3 lines of RedeemScript and signature doesn't require OP_TRUE/OP_FALSE in it).
- OP_ELSE: this provides what you need with 2 multi-signature operations. The first one requires at least one signature out of 3 "leaders" signatures and performs a OP_CheckMultiSigVerify (there is no true/false remaining on the stack after the execution) and the second one requires 4 of 5 signatures from "shareholders".  
To spend, either one of these signature scripts should be provided (OP_0 is mandatory due to the bug in CheckMultiSig OPs):
OP_0  OP_TRUE 

or
OP_0  OP_0  OP_FALSE

> **Comments:**
> **username_0**: How about first checking with  all the public key of shareholders with checkmultisig, if the result was true we know that in signatures provided there is not exist either of leaders, if that was not true we could check for 4 s1, s2, .. ,s5, a, b, c 8 checkmultisig.  
> **username_1**: That would require each shareholder to sign the transaction twice, it also increases the size of the signature (and transaction) by a lot.  
> **username_0**: Instead of twice signature, we could duplicate it in the lucking script.  

---

