• 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

Issue with constructing a correct Schnorr Signature for a Taproot transaction

Moussa by Moussa
February 16, 2026
in Bitcoin
0
How do Bitcoin mining pools typically handle payout frequency versus thresholds?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I’m experimenting with creating and sending Taproot transactions programmatically and encountered an issue with the Schnorr signature. I’m trying to send simple transaction with one V1_P2TR input and one V1_P2TR output, using what I understand to be a key path spend approach, without any scripts. However, when I attempt to send the transaction, my node rejects it with the error:
mandatory-script-verify-flag-failed (Invalid Schnorr signature)

I’m using the following dependencies in my Rust project:

bitcoin = { version = "0.30.1", features = ["rand"] }
ord-bitcoincore-rpc = "0.17.1"   # (a forked version of bitcoincore-rpc, though I believe this detail is not crucial to the issue).

Here’s the relevant part of my code:

fn create_and_send_tmp_tx(client: &Client, utxo: &ListUnspentResultEntry, fee_rate: f64, key_pair: &UntweakedKeyPair, address_to: &Address) -> Result {

    let secp256k1 = Secp256k1::new();

    // Verifying that UTXO can be spent by provided key pair
    let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair);
    let address = Address::p2tr(&secp256k1, public_key, None, Network::Bitcoin);
    let address_script_pubkey = address.script_pubkey();
    let utxo_script_pubkey = utxo.script_pub_key.clone();
    if ! (address_script_pubkey == utxo_script_pubkey) {
        bail!("Can't spend utxo");
    }

    let mut tx = Transaction {
        input: vec![TxIn {
            previous_output: OutPoint {
                txid: utxo.txid,
                vout: utxo.vout,
            },
            script_sig: Builder::new().into_script(),
            witness: Witness::new(),
            sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
        }],
        output: vec![TxOut {
            script_pubkey: address_to.script_pubkey(),
            value: 0,   // tmp value for estimation
        }],
        lock_time: LockTime::ZERO,
        version: 2,
    };

    tx.input[0].witness.push(
        Signature::from_slice(&[0; SCHNORR_SIGNATURE_SIZE])
            .unwrap()
            .to_vec(),
    );

    let fee = Amount::from_sat((fee_rate * tx.vsize()).round() as u64);
    info!("Fee: {:?}", fee.to_sat());
    tx.output[0].value = utxo.amount.to_sat() - fee.to_sat();
    tx.input[0].witness.clear();

    let prevouts = vec![TxOut {script_pubkey: utxo.script_pub_key.clone(), value: utxo.amount.to_sat()}];

    let mut sighash_cache = SighashCache::new(&tx);
    let sighash = sighash_cache.taproot_key_spend_signature_hash(
        0,
        &Prevouts::All(&prevouts),
        TapSighashType::Default,
    ).expect("Failed to compute sighash");

    let msg = secp256k1::Message::from_slice(sighash.as_ref()).expect("should be cryptographically secure hash");
    let sig = secp256k1.sign_schnorr(&msg, &key_pair);

    tx.input[0].witness.push(
        Signature {
            sig,
            hash_ty: TapSighashType::Default,
        }
            .to_vec(),
    );

    let signed_tx_bytes = consensus::encode::serialize(&tx);
    // let signed_tx_bytes = client.sign_raw_transaction_with_wallet(&tx, None, None)?.hex;

    let txid = match client.send_raw_transaction(&signed_tx_bytes) {
        Ok(txid) => txid,
        Err(err) => {
            return Err(anyhow!("Failed to send transaction: {err}\n"))
        }
    };
    info!("Tx sent: {:?}", txid);
    Ok(txid)
}

The wallet I’m using is connected to my node. If I use the
client.sign_raw_transaction_with_wallet(&tx, None, None)?.hex; function, which allows the node to replace my witness with a correct one, the transaction is accepted. This suggests that my inputs and outputs are constructed correctly, and the issue likely lies with how I’m generating the signature.

I’ve successfully sent transactions using a script path spend with a similar approach, using sighash_cache.taproot_script_spend_signature_hash, without the node’s intervention in signing.

Could someone help me identify what I’m doing wrong?



Source link

Related articles

One Move Could Trigger A Massive Shift

One Move Could Trigger A Massive Shift

April 12, 2026
Argentina Recognizes Crypto as Qualified Investors’ Net Worth – Regulation Bitcoin News

Argentina Recognizes Crypto as Qualified Investors’ Net Worth – Regulation Bitcoin News

April 12, 2026
Share76Tweet47

Related Posts

One Move Could Trigger A Massive Shift

One Move Could Trigger A Massive Shift

by Moussa
April 12, 2026
0

My name is Godspower Owie, and I was born and brought up in Edo State, Nigeria. I grew up with...

Argentina Recognizes Crypto as Qualified Investors’ Net Worth – Regulation Bitcoin News

Argentina Recognizes Crypto as Qualified Investors’ Net Worth – Regulation Bitcoin News

by Moussa
April 12, 2026
0

Key Takeaways: CNV Resolution 1125/2026 lets crypto count for the $479K investor limit, expanding future market access. A 2022 Central...

How do Bitcoin mining pools typically handle payout frequency versus thresholds?

lightning network – Why does MuSig2 partial signature pass local verification but get rejected by Bitcoin Core mempool when using python-bitcoinutils?

by Moussa
April 12, 2026
0

The problem is a double tweak. python-bitcoinutils applies a BIP86 tweak internally when you call get_taproot_address(). If you have already...

Crypto Derivatives Shakeout: Market Records Lowest Trading Volume In December 2025

Crypto Market Structure Bill Enters Crucial Stage, Coinbase CEO Says “It’s Time”

by Moussa
April 12, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure One of the major talking points in...

Dogecoin Cracks Again: BTC Pair Collapse Signals Imminent Drop To $0.07

Dogecoin Cracks Again: BTC Pair Collapse Signals Imminent Drop To $0.07

by Moussa
April 11, 2026
0

Dogecoin is flashing renewed signs of weakness as its BTC pair breaks down sharply, dragging the price structure into bearish...

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

© 2024 APPROX FOUNDATION - The Crypto Currency News