send taproot multisig withdraw tx,got:Operation not valid with the current stack size

I create a taproot multisig script,and send some satoshi to the script address. then,withdaw satoshi from the script with 2 signatures,but got error:{"code":-26,"message":"mandatory-script-verify-flag-failed (Operation not valid with the current stack size)"} but if with 3 signatures,it's ok.tx:https://mempool.space/testnet/tx/c1b7a044776beb21856c91f7d3d688a91011f4321c6348c8c981c26082074341

script:key1 OP_CHECKSIG key2 OP_CHECKSIGADD key3 OP_CHECKSIGADD OP_2 OP_GREATERTHANOREQUAL my js code: const leafKeysWif = [ '---', '---', '---', ] const leafKeys = [] const leafPubkeys = [] for (const leafKeyWif of leafKeysWif) { const leafKey = ECPair.fromWIF(leafKeyWif, network) leafKeys.push(leafKey) leafPubkeys.push(toXOnly(leafKey.publicKey)) }

leafPubkeys.sort((a, b) => a.compare(b)) leafPubkeys.forEach((pubkey) => { console.log(pubkey.toString('hex')) })

const ops = [] leafPubkeys.forEach((pubkey) => { if (ops.length === 0) { ops.push(pubkey) ops.push(bitcoin.opcodes.OP_CHECKSIG) } else { ops.push(pubkey) ops.push(bitcoin.opcodes.OP_CHECKSIGADD) } }) ops.push(bitcoin.opcodes.OP_2) ops.push(bitcoin.opcodes.OP_GREATERTHANOREQUAL) const leafScript = bitcoin.script.compile(ops)

const internalPubkey = makeUnspendableInternalKey(undefined) const payment = bitcoin.payments.p2tr({ internalPubkey: internalPubkey, scriptTree: { output: leafScript, }, redeem: { output: leafScript, redeemVersion: LEAF_VERSION_TAPSCRIPT, // 0xc0 }, network: network, })

console.log(payment.address) //tb1pp33rqchke8lh3425uunvtuq0kcrslupwm7kxf9rcap6s05k3ukhqmcplhw console.log(payment.output.toString('hex'))// 51200c623062f6c9ff78d554e726c5f00fb6070ff02edfac649478e87507d2d1e5ae

// controlBlock const witness = payment.witness const controlBlock = witness[witness.length - 1] console.log('controlBlock', controlBlock.toString('hex'))// c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0

const psbt = new bitcoin.Psbt({ network: network }) const utxoHash = '83c307875653061a6574f8956c86efe69a86f7a671dfea3078b2bb434fcfb84b' const utxoVout = 0 const utxoAmount = 100000 const sendAmount = utxoAmount - 80000 psbt.addOutput({ value: sendAmount, address: 'tb1ph8jzyv68rwx436wtnr760tsg3ut07ml8zueuqcwww04fdmrp8ntqaqjmsp' }) psbt.addInput({ hash: utxoHash, index: utxoVout, witnessUtxo: { value: utxoAmount, script: payment.output }, })

psbt.updateInput(0, { tapLeafScript: [ { leafVersion: LEAF_VERSION_TAPSCRIPT, script: leafScript, controlBlock: controlBlock, }, ], })

console.log(psbt.toHex())

psbt.signInput(0, leafKeys[0]) psbt.signInput(0, leafKeys[1]) // psbt.signInput(0, leafKeys[2]) // if add the third signature,tx is ok psbt.finalizeAllInputs() console.log(psbt.toHex()) const tx = psbt.extractTransaction() const rawTx = tx.toBuffer() const hex = rawTx.toString('hex') console.log(hex)

const broadcast = async () => { const baseURLs = 'https://mempool.space:443/testnet/api/' const cli = new BitcoinClient(baseURLs, 30000) const rsp = await cli.postTransaction(hex) console.log(rsp) }

broadcast()



from Recent Questions - Bitcoin Stack Exchange https://ift.tt/EFIt3xm
via IFTTT

Popular posts from this blog

Bitcoin Mining Could Be Strengthening The Ruble, Russian Central Bank Says

Crypto Exec Warns Tokenization Is Moving Faster Than Expected

Bitwise Clients Pour $69M Into Solana as Bulls Fight to Reclaim $200 Resistance Zone