• 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

ZachXBT Exposes US Law Firm Gerstein Harrow’s $71M Grab of Stolen Lazarus Funds

ZachXBT Exposes US Law Firm Gerstein Harrow’s $71M Grab of Stolen Lazarus Funds

May 2, 2026
Bitcoin Price Prediction: BTC is Pentagon “National Security Asset”

Bitcoin Price Prediction: BTC is Pentagon “National Security Asset”

May 2, 2026
Share76Tweet47

Related Posts

ZachXBT Exposes US Law Firm Gerstein Harrow’s $71M Grab of Stolen Lazarus Funds

ZachXBT Exposes US Law Firm Gerstein Harrow’s $71M Grab of Stolen Lazarus Funds

by Moussa
May 2, 2026
0

Key Takeaways: ZachXBT named Gerstein Harrow LLP for filing fake DPRK claims to seize $71M in frozen KelpDAO funds. Lazarus...

Bitcoin Price Prediction: BTC is Pentagon “National Security Asset”

Bitcoin Price Prediction: BTC is Pentagon “National Security Asset”

by Moussa
May 2, 2026
0

US Secretary of War Pete Hegseth told the House Armed Services Committee this week that the Pentagon is running classified...

Brazil Tightens Grip On Crypto As Central Bank Blocks Cross-Border Settlement Use

Brazil Tightens Grip On Crypto As Central Bank Blocks Cross-Border Settlement Use

by Moussa
May 2, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure About 90% of crypto flows in Brazil...

Here’s How High The XRP Price Will Be If It Repeats The 2017 Surge

Here’s How High The XRP Price Will Be If It Repeats The 2017 Surge

by Moussa
May 2, 2026
0

Crypto pundit Crypto Dyl has revealed how high the XRP price could reach if it replicates its historical surge in...

El Salvador Crypto Remittances Reach $17.38M

El Salvador Crypto Remittances Reach $17.38M

by Moussa
May 2, 2026
0

Key Takeaways: El Salvador’s Central Bank reported Q1 crypto remittances hit $17.38M, a $5.77M rise from 2025. Despite Bukele’s hopes...

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

© 2024 APPROX FOUNDATION - The Crypto Currency News