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

2 Answers 2

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
1
  • Ha beat me to it. Deleting my answer :) Commented Apr 10, 2023 at 9:35
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.

4
  • 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
    Commented Apr 10, 2023 at 9: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 Commented Apr 10, 2023 at 9:11
  • I modified my answer, now it ensure that your key have to be present
    – Saxtheowl
    Commented Apr 10, 2023 at 9: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 Commented Apr 10, 2023 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.