From 3337b7a030795547077e1920120bf0f82463bf8e Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 23 Jun 2025 20:13:55 +0000 Subject: [PATCH] psbt: introduce IncorrectNonWitnessUtxo error variant Putting this in its own commit so that the fix and the test can live in separate commits which reviewers can swap. --- bitcoin/src/psbt/error.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bitcoin/src/psbt/error.rs b/bitcoin/src/psbt/error.rs index 58338ab69..6095c85ff 100644 --- a/bitcoin/src/psbt/error.rs +++ b/bitcoin/src/psbt/error.rs @@ -80,6 +80,16 @@ pub enum Error { NegativeFee, /// Integer overflow in fee calculation FeeOverflow, + /// Non-witness UTXO (which is a complete transaction) has [`crate::Txid`] that + /// does not match the transaction input. + IncorrectNonWitnessUtxo { + /// The index of the input in question. + index: usize, + /// The outpoint of the input, as it appears in the unsigned transaction. + input_outpoint: crate::OutPoint, + /// The ['crate::Txid`] of the non-witness UTXO. + non_witness_utxo_txid: crate::Txid, + }, /// Parsing error indicating invalid public keys InvalidPublicKey(crate::crypto::key::FromSliceError), /// Parsing error indicating invalid secp256k1 public keys @@ -154,6 +164,13 @@ impl fmt::Display for Error { write_err!(f, "error parsing bitcoin consensus encoded object"; e), NegativeFee => f.write_str("PSBT has a negative fee which is not allowed"), FeeOverflow => f.write_str("integer overflow in fee calculation"), + IncorrectNonWitnessUtxo { index, input_outpoint, non_witness_utxo_txid } => { + write!( + f, + "non-witness utxo txid is {}, which does not match input {}'s outpoint {}", + non_witness_utxo_txid, index, input_outpoint + ) + } InvalidPublicKey(ref e) => write_err!(f, "invalid public key"; e), InvalidSecp256k1PublicKey(ref e) => write_err!(f, "invalid secp256k1 public key"; e), InvalidXOnlyPublicKey => f.write_str("invalid xonly public key"), @@ -200,6 +217,7 @@ impl std::error::Error for Error { | CombineInconsistentKeySources(_) | NegativeFee | FeeOverflow + | IncorrectNonWitnessUtxo { .. } | InvalidPublicKey(_) | InvalidSecp256k1PublicKey(_) | InvalidXOnlyPublicKey