4

I need a bitcoin lock script that will require my key and 1 of 4 other people.

For example, If my key is present and one of the 4 other keys are also present, transaction can be claimed. If my key is not present, even the presence of all of the other 4 keys will not be enough to claim the transaction.

I have created a script like below but I couldnt figure out how to convert it to a lock script.

my_key OP_CHECKSIGVERIFY OP_1 key1 key2 key3 key4 OP_4 OP_CHECKMULTISIGVERIFY

Michael Folkson
  • 14,337
  • 3
  • 11
  • 45
Anıl
  • 41
  • 1

2 Answers2

3

The most straightforward (and safe) way is to use a Miniscript output descriptor. You can generate one using a Miniscript policy compiler.

For instance with your key A, and 4 other keys B C D and E the Miniscript policy could be and(pk(A),thresh(1,pk(B),pk(C),pk(D),pk(E))).

Using @sipa's online Miniscript policy compiler, this compiles to and_v(v:pk(A),c:or_i(pk_k(B),or_i(pk_h(C),or_i(pk_h(D),pk_h(E))))). You can then use the wsh(and_v(v:pk(A),c:or_i(pk_k(B),or_i(pk_h(C),or_i(pk_h(D),pk_h(E)))))) output descriptor in a wallet that supports it (for instance Bitcoin Core), to receive and send funds using this policy.


For what it's worth, the Bitcoin Script corresponding to the above Miniscript is:

<A> OP_CHECKSIGVERIFY OP_IF
  <B>
OP_ELSE
  OP_IF
    OP_DUP OP_HASH160 <HASH160(C)> OP_EQUALVERIFY
  OP_ELSE
    OP_IF
      OP_DUP OP_HASH160 <HASH160(D)> OP_EQUALVERIFY
    OP_ELSE
      OP_DUP OP_HASH160 <HASH160(E)> OP_EQUALVERIFY
    OP_ENDIF
  OP_ENDIF
OP_ENDIF
OP_CHECKSIG
Antoine Poinsot
  • 5,881
  • 2
  • 11
  • 28
1

You just have to modify your script a little like that <my_key> OP_CHECKSIG OP_IFDUP OP_NOTIF OP_1 <key1> <key2> <key3> <key4> OP_4 OP_CHECKMULTISIG OP_ENDIF

It will require two signatures to unlock the transaction output, one from your key and one from the other four key.

To use this as a Bitcoin lock script you will have to create a P2SH address that will contain the hash of your script, also notice that this script is pre Taproot since it use CHECKMULTISIG(VERIFY) . And of course dont forget to test heavily all this on a testnet if you want to use real fund for it.

Saxtheowl
  • 2,760
  • 8
  • 16
  • 34
  • 1
    Thanks, but how do you make sure that my key is always present? As far as i understand, with your script, any combination of 5 keys can claim this transaction. – Anıl Apr 10 '23 at 09:10
  • 1
    I think the question asker wants their key to be used for all spends with an additional key from the 4. Your script would allow spends without the question asker's key – Michael Folkson Apr 10 '23 at 09:11
  • I modified my answer, now it ensure that your key have to be present – Saxtheowl Apr 10 '23 at 09:16
  • 1
    Perhaps also state that this is pre Taproot and that with Taproot you'd use CHECKSIGADD rather than CHECKMULTISIG(VERIFY) that was disabled for Taproot addresses – Michael Folkson Apr 10 '23 at 09:24