I have a Multisignature address 1-3 with a verification of OP_3, just a simple script to understand custom scripts in Bitcoin

Script definition

#OP_1 <Public Key> <Public Key> <Public Key> 3 OP_CHECKMULTISIGVERIFY OP_3 OP_EQUAL
SCRIPT="5121"$(cat compressed_public_key_1.txt)"21"$(cat compressed_public_key_2.txt)"21"$(cat compressed_public_key_3.txt)"53AF5387"

Now, I want to import my address using descriptor

PK1=`cat compressed_private_key_WIF_1.txt`
PK2=`cat compressed_private_key_WIF_2.txt`
PK3=`cat compressed_private_key_WIF_3.txt`
CHECKSUM=$(bitcoin-cli getdescriptorinfo "sh(multi(1,$PK1,$PK2,$PK3))" | jq -r .checksum)
bitcoin-cli importdescriptors '[{ "desc": "sh(multi(1,'$PK1','$PK2','$PK3'))#'$CHECKSUM'", "timestamp": "now", "internal": true }]'

The problem is I can't have the same address because the script is different. I will do the signature manually, only for study purposes. I read https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md but I didn't find any help about my problem.

Using Legacy code, I was able to import

bitcoin-cli importaddress $ADDR_P2SH

Where $ADDR_P2SH is the result of my address 1-3.

Is it possible to use a custom script using a descriptor? If I understand, a descriptor is "like a function," so I don't know if a "custom" function is available.


Thanks to Antoine Poinsot, I am posting the solution. Maybe it could be useful to someone.

ADDR_P2SH=`cat address_P2SH.txt`
bitcoin-cli -named createwallet wallet_name="bia" disable_private_keys=true

CHECKSUM=$(bitcoin-cli getdescriptorinfo "addr($(cat address_P2SH.txt))" | jq -r .checksum)
bitcoin-cli -rpcwallet=bia importdescriptors '[{ "desc": "addr('$(cat address_P2SH.txt)')#'$CHECKSUM'", "timestamp": "now", "internal": true }]'

and I get the UTXO with

UTXO=`bitcoin-cli -rpcwallet=bia listunspent 1 101 '["'$ADDR_P2SH'"]'`
  • 1
    Please open a new thread for new questions instead of updating the OP. Dec 9, 2023 at 15:36
  • Now resolved, I appreciate your time. I've posted the solution to help someone in a similar situation.
    – monkeyUser
    Dec 9, 2023 at 15:49

1 Answer 1

OP_1 <Public Key hash> <Public Key hash> <Public Key hash> 3 OP_CHECKMULTISIGVERIFY OP_3 OP_EQUAL

This is not a valid use of CHECKMULTISIGVERIFY. This script would not be spendable.

Is it possible to use a custom script using a descriptor? If I understand, a descriptor is "like a function," so I don't know if a "custom" function is available.

Under tr() and wsh() you can import more complex scripts but those have to be valid Miniscripts. Otherwise, the modern equivalent of the importaddress you were using on legacy wallets would be to use an addr() descriptor. In this case however Bitcoin Core won't know how to spend an output with the corresponding scriptPubKey.

  • Hello, thanks for your reply. This script is for study purposes only. Anyway, I will build the scriptsig properly in order to spend the transaction. It works with legacy commands. you are talking about "addr(ADDR) (top level only): the script which ADDR expands to." correct? what does mean Top Level only? Maybe I could use even raw(hex)
    – monkeyUser
    Dec 9, 2023 at 13:08
  • Top-level means that you can't use it inside another desc. Yes you could use raw() too. What are you trying to achieve? If you want to play with the Script interpreter there are tools out there you might be interested in trying out, such as github.com/bitcoin-core/btcdeb Dec 9, 2023 at 13:09
  • Yes, I love btcdeb, and I use it. My purpose is just for study. I want to import a multisignature 1-3, sign it, and check that OP_3 is equal to OP_3 that I put in my scriptsig. I create the signature manually. I repeat, it's just for fun and understanding what happens under the hood. With the legacy core, it works properly, but I updated to version 26, and I want to migrate it.
    – monkeyUser
    Dec 9, 2023 at 13:16
  • I see. Note this won't work because as i put in my answer your use of CMS is invalid. If you pass it public key hashes it'll just fail at VERIFY and never get to execute OP_3 OP_EQUAL. :) Dec 9, 2023 at 13:18
  • the public key hashes form the redeem script and in scriptSig I put Signature and and OP_3. the script works as you can see in testnet tbtc.bitaps.com/…
    – monkeyUser
    Dec 9, 2023 at 14:03

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.