• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

multi signature – How “addDummySigs” in golang when send satoshi from p2tr multisig script?

Moussa by Moussa
November 18, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I have a 2-of-3 multisig taproot script,create like bitcoinjs-lib:https://github.com/bitcoinjs/bitcoinjs-lib/blob/8d9775c20da03ab40ccbb1971251e71d117bcd8b/test/integration/taproot.spec.ts#L531-L593:

builder := txscript.NewScriptBuilder()
for i, pk := range leafPubkeys {
    if i == 0 {
        builder.AddData(pk)
        builder.AddOp(byte(txscript.OP_CHECKSIG))
    } else {
        builder.AddData(pk)
        builder.AddOp(byte(txscript.OP_CHECKSIGADD))
    }
}
builder.AddOp(byte(txscript.OP_1 - 1 + 2))
builder.AddOp(byte(txscript.OP_GREATERTHANOREQUAL))

then create a tx(send satoshi from the script),and two keys sign it.but got “invalid schnorr signatures” when sent to bitcoind.
my golang code:

func TestGenTapscript(t *testing.T) {
    signpks := []string{
...
    }
    pks := []string{...}
    tapscript := NewMultisigTaprootScript(pks, 2, 3, &chaincfg.TestNet3Params)

    // build tx
    const utxoHash = "..."
    const utxoVout = 0
    const utxoAmount = 1000000
    const sendAmount = utxoAmount - 1000

    var (
        inputs     []*wire.OutPoint
        nSequences []uint32
        outputs    []*wire.TxOut
    )
    { // output
        ...
        outputs = append(outputs, redeemTxOut)
    }
    { // input
        ...
    }

    // Build PSBT
    packet, err := psbt.New(inputs, outputs, 2, 0, nSequences)
    if err != nil {
        t.Fatal(err)
    }
    packet.Inputs[0].TaprootLeafScript = []*psbt.TaprootTapLeafScript{
        &psbt.TaprootTapLeafScript{
            ControlBlock: tapscript.controlBlock,
            Script:       tapscript.leafScript,
            LeafVersion:  0xc0,
        },
    }

    // update
    updater, err := psbt.NewUpdater(packet)
    if err != nil {
        t.Fatal(err)
    }
    if err := updater.AddInWitnessUtxo(wire.NewTxOut(utxoAmount, tapscript.output), 0); err != nil {
        t.Fatal(err)
    }

    var serializedTx bytes.Buffer
    if err := packet.Serialize(&serializedTx); err != nil {
        t.Fatal(err)
    }
    psbtHex := hex.EncodeToString(serializedTx.Bytes())
    t.Log("psbtHex before sign:", psbtHex)

    // signit
    cu := cuabs.New()
    signedPsbtHex, err := cu.PsbtSign(context.Background(), signpks[0], psbtHex)
    if err != nil {
        t.Fatal(err)
    }
    signedPsbtHex, err = cu.PsbtSign(context.Background(), signpks[2], signedPsbtHex)
    if err != nil {
        t.Fatal(err)
    }
    t.Log("psbtHex after sign:", signedPsbtHex)

    // addDummySigs like bitcoinjs-lib
    psbtBz, _ := hex.DecodeString(signedPsbtHex)
    packet, err = psbt.NewFromRawBytes(bytes.NewReader(psbtBz), false)
    if err != nil {
        t.Fatal(err)
    }

    for index, input := range packet.Inputs {
        for _, pk := range pks {
            pkbz, _ := hex.DecodeString(pk)
            var signed bool
            for _, x := range input.TaprootScriptSpendSig {
                if bytes.Equal(pkbz, x.XOnlyPubKey) {
                    signed = true
                    break
                }
            }
            if !signed {
                packet.Inputs[index].TaprootScriptSpendSig = append(packet.Inputs[index].TaprootScriptSpendSig, &psbt.TaprootScriptSpendSig{
                    XOnlyPubKey: pkbz,
                    LeafHash:    tapscript.tapleafHash,
                    Signature:   nil,
                    SigHash:     0,
                })
            }
        }

        // sigs := packet.Inputs[index].TaprootScriptSpendSig

        // sort.Slice(sigs, func(i, j int) bool {
        //  return bytes.Compare(sigs[i].XOnlyPubKey, sigs[j].XOnlyPubKey) < 0
        // })
        // packet.Inputs[index].TaprootScriptSpendSig = sigs
    }

    {
        var serializedTx bytes.Buffer
        if err := packet.Serialize(&serializedTx); err != nil {
            t.Fatal(err)
        }
        t.Log("psbtHex before finalize", hex.EncodeToString(serializedTx.Bytes()))
    }

    if err = psbt.MaybeFinalizeAll(packet); err != nil {
        t.Fatal(err)
    }
    {
        var serializedTx bytes.Buffer
        if err := packet.Serialize(&serializedTx); err != nil {
            t.Fatal(err)
        }
        t.Log("psbtHex after finalize", hex.EncodeToString(serializedTx.Bytes()))
        
    }
    //extract()
    //broadcast()
}

Use js code,it work. “tapscript.tapleafHash” in golang is equal “leafHash” in js,and “pubkey” is equal.
After comparison, it was found that the “psbtHex before finalize” and “psbtHex after finalize” were different.
my js code:

const psbt = bitcoin.Psbt.fromHex(signedPsbtHex)
{
  const leafHash = tapleafHash({
    output: leafScript,
    version: LEAF_VERSION_TAPSCRIPT,
  })
  console.log(leafHash.toString('hex'))
  for (const input of psbt.data.inputs) {
    if (!input.tapScriptSig) continue
    const signedPubkeys = input.tapScriptSig.filter((ts) => ts.leafHash.equals(leafHash)).map((ts) => ts.pubkey)
    for (const pubkey of leafPubkeys) {
      if (signedPubkeys.some((sPub) => sPub.equals(pubkey))) continue
      input.tapScriptSig.push({
        // This can be reused for each dummy signature
        leafHash,
        // This is the pubkey that didn't sign
        pubkey,
        // This must be an empty Buffer.
        signature: Buffer.from([]),
      })
    }
  }
} // this code from bitcoinjs-lib

psbt.finalizeAllInputs()
const tx = psbt.extractTransaction()
broadcast(...)



Source link

Related articles

The ‘Anti-Christ Block’? Bitcoin’s 666,666 Block Carries This Powerful Message

The ‘Anti-Christ Block’? Bitcoin’s 666,666 Block Carries This Powerful Message

April 6, 2026
What Does The Japanese Bond Gap Have To Do With The XRP Price Reaching $150?

What Does The Japanese Bond Gap Have To Do With The XRP Price Reaching $150?

April 6, 2026
Share76Tweet47

Related Posts

The ‘Anti-Christ Block’? Bitcoin’s 666,666 Block Carries This Powerful Message

The ‘Anti-Christ Block’? Bitcoin’s 666,666 Block Carries This Powerful Message

by Moussa
April 6, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure The Bitcoin (BTC) history is filled with...

What Does The Japanese Bond Gap Have To Do With The XRP Price Reaching $150?

What Does The Japanese Bond Gap Have To Do With The XRP Price Reaching $150?

by Moussa
April 6, 2026
0

Crypto pundit Remi has explained the impact that the Japanese Bond gap could have on the XRP price reaching $150....

Strive (ASST) Adds 113 Bitcoin At An Average Price Of $68,584 Per BTC

Strive (ASST) Adds 113 Bitcoin At An Average Price Of $68,584 Per BTC

by Moussa
April 6, 2026
0

Strive has expanded its Bitcoin treasury with a new acquisition of 113 BTC, reinforcing a steady accumulation strategy among publicly...

South Korean Fintech Toss Targets Web3 Finance With Proprietary Mainnet and 24 Stablecoin Trademarks – Crypto News Bitcoin News

South Korean Fintech Toss Targets Web3 Finance With Proprietary Mainnet and 24 Stablecoin Trademarks – Crypto News Bitcoin News

by Moussa
April 6, 2026
0

Key Takeaways: Toss, operated by Viva Republica, is building an L1 blockchain mainnet and native coin to power its 30...

Trader Liquidated for the Sixth Time: How James Wynn From $100M to $900 in a Brutal Leverage Lesson

Trader Liquidated for the Sixth Time: How James Wynn From $100M to $900 in a Brutal Leverage Lesson

by Moussa
April 6, 2026
0

A trader named James Wynn turned $100 million into $900. Not over years of bad decisions, over a concentrated stretch...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSU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NFJTNDaW5wdXQlMjB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News