Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions payjoin/src/receive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,28 +337,13 @@ pub struct InputContributionError(InternalInputContributionError);

#[derive(Debug)]
pub(crate) enum InternalInputContributionError {
/// The address type could not be determined
AddressType(crate::psbt::AddressTypeError),
/// The original PSBT has no inputs
NoSenderInputs,
/// The proposed receiver inputs would introduce mixed input script types
MixedInputScripts(bitcoin::AddressType, bitcoin::AddressType),
/// Total input value is not enough to cover additional output value
ValueTooLow,
}

impl fmt::Display for InputContributionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.0 {
InternalInputContributionError::AddressType(e) =>
write!(f, "The address type could not be determined: {}", e),
InternalInputContributionError::NoSenderInputs =>
write!(f, "The original PSBT has no inputs"),
InternalInputContributionError::MixedInputScripts(type_a, type_b) => write!(
f,
"The proposed receiver inputs would introduce mixed input script types: {}; {}.",
type_a, type_b
),
InternalInputContributionError::ValueTooLow =>
write!(f, "Total input value is not enough to cover additional output value"),
}
Expand Down
6 changes: 0 additions & 6 deletions payjoin/src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ impl InputPair {
Ok(input_pair)
}

pub(crate) fn address_type(&self) -> AddressType {
InternalInputPair::from(self)
.address_type()
.expect("address type should have been validated in InputPair::new")
}

pub(crate) fn previous_txout(&self) -> TxOut {
InternalInputPair::from(self)
.previous_txout()
Expand Down
47 changes: 0 additions & 47 deletions payjoin/src/receive/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,11 @@ impl WantsInputs {
.first()
.map(|input| input.sequence)
.unwrap_or_default();
let uniform_sender_input_type = self.uniform_sender_input_type()?;

// Insert contributions at random indices for privacy
let mut rng = rand::thread_rng();
let mut receiver_input_amount = Amount::ZERO;
for input_pair in inputs.into_iter() {
let input_type = input_pair.address_type();
if self.params.v == 1 {
// v1 payjoin proposals must not introduce mixed input script types
self.check_mixed_input_types(input_type, uniform_sender_input_type)?;
}

receiver_input_amount += input_pair.previous_txout().value;
let index = rng.gen_range(0..=self.payjoin_psbt.unsigned_tx.input.len());
payjoin_psbt.inputs.insert(index, input_pair.psbtin);
Expand All @@ -533,46 +526,6 @@ impl WantsInputs {
})
}

/// Check for mixed input types and throw an error if conditions are met
fn check_mixed_input_types(
&self,
receiver_input_type: bitcoin::AddressType,
uniform_sender_input_type: Option<bitcoin::AddressType>,
) -> Result<(), InputContributionError> {
if let Some(uniform_sender_input_type) = uniform_sender_input_type {
if receiver_input_type != uniform_sender_input_type {
return Err(InternalInputContributionError::MixedInputScripts(
receiver_input_type,
uniform_sender_input_type,
)
.into());
}
}
Ok(())
}

/// Check if the sender's inputs are all of the same type
///
/// Returns `None` if the sender inputs are not all of the same type
fn uniform_sender_input_type(
&self,
) -> Result<Option<bitcoin::AddressType>, InputContributionError> {
let mut sender_inputs = self.original_psbt.input_pairs();
let first_input_type = sender_inputs
.next()
.ok_or(InternalInputContributionError::NoSenderInputs)?
.address_type()
.map_err(InternalInputContributionError::AddressType)?;
for input in sender_inputs {
if input.address_type().map_err(InternalInputContributionError::AddressType)?
!= first_input_type
{
return Ok(None);
}
}
Ok(Some(first_input_type))
}

// Compute the minimum amount that the receiver must contribute to the transaction as input
fn receiver_min_input_amount(&self) -> Amount {
let output_amount = self
Expand Down
11 changes: 1 addition & 10 deletions payjoin/src/send/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{self, Display};

use bitcoin::locktime::absolute::LockTime;
use bitcoin::transaction::Version;
use bitcoin::{AddressType, Sequence};
use bitcoin::Sequence;

/// Error building a Sender from a SenderBuilder.
///
Expand Down Expand Up @@ -147,16 +147,13 @@ pub(crate) enum InternalProposalError {
VersionsDontMatch { proposed: Version, original: Version },
LockTimesDontMatch { proposed: LockTime, original: LockTime },
SenderTxinSequenceChanged { proposed: Sequence, original: Sequence },
SenderTxinContainsNonWitnessUtxo,
SenderTxinContainsWitnessUtxo,
SenderTxinContainsFinalScriptSig,
SenderTxinContainsFinalScriptWitness,
TxInContainsKeyPaths,
ContainsPartialSigs,
ReceiverTxinNotFinalized,
ReceiverTxinMissingUtxoInfo,
MixedSequence,
MixedInputTypes { proposed: AddressType, original: AddressType },
MissingOrShuffledInputs,
TxOutContainsKeyPaths,
FeeContributionExceedsMaximum,
Expand Down Expand Up @@ -188,16 +185,13 @@ impl fmt::Display for InternalProposalError {
VersionsDontMatch { proposed, original, } => write!(f, "proposed transaction version {} doesn't match the original {}", proposed, original),
LockTimesDontMatch { proposed, original, } => write!(f, "proposed transaction lock time {} doesn't match the original {}", proposed, original),
SenderTxinSequenceChanged { proposed, original, } => write!(f, "proposed transaction sequence number {} doesn't match the original {}", proposed, original),
SenderTxinContainsNonWitnessUtxo => write!(f, "an input in proposed transaction belonging to the sender contains non-witness UTXO information"),
SenderTxinContainsWitnessUtxo => write!(f, "an input in proposed transaction belonging to the sender contains witness UTXO information"),
SenderTxinContainsFinalScriptSig => write!(f, "an input in proposed transaction belonging to the sender contains finalized non-witness signature"),
SenderTxinContainsFinalScriptWitness => write!(f, "an input in proposed transaction belonging to the sender contains finalized witness signature"),
TxInContainsKeyPaths => write!(f, "proposed transaction inputs contain key paths"),
ContainsPartialSigs => write!(f, "an input in proposed transaction belonging to the sender contains partial signatures"),
ReceiverTxinNotFinalized => write!(f, "an input in proposed transaction belonging to the receiver is not finalized"),
ReceiverTxinMissingUtxoInfo => write!(f, "an input in proposed transaction belonging to the receiver is missing UTXO information"),
MixedSequence => write!(f, "inputs of proposed transaction contain mixed sequence numbers"),
MixedInputTypes { proposed, original, } => write!(f, "proposed transaction contains input of type {:?} while original contains inputs of type {:?}", proposed, original),
MissingOrShuffledInputs => write!(f, "proposed transaction is missing inputs of the sender or they are shuffled"),
TxOutContainsKeyPaths => write!(f, "proposed transaction outputs contain key paths"),
FeeContributionExceedsMaximum => write!(f, "fee contribution exceeds allowed maximum"),
Expand Down Expand Up @@ -225,16 +219,13 @@ impl std::error::Error for InternalProposalError {
VersionsDontMatch { proposed: _, original: _ } => None,
LockTimesDontMatch { proposed: _, original: _ } => None,
SenderTxinSequenceChanged { proposed: _, original: _ } => None,
SenderTxinContainsNonWitnessUtxo => None,
SenderTxinContainsWitnessUtxo => None,
SenderTxinContainsFinalScriptSig => None,
SenderTxinContainsFinalScriptWitness => None,
TxInContainsKeyPaths => None,
ContainsPartialSigs => None,
ReceiverTxinNotFinalized => None,
ReceiverTxinMissingUtxoInfo => None,
MixedSequence => None,
MixedInputTypes { .. } => None,
MissingOrShuffledInputs => None,
TxOutContainsKeyPaths => None,
FeeContributionExceedsMaximum => None,
Expand Down
14 changes: 0 additions & 14 deletions payjoin/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub struct PsbtContext {
fee_contribution: Option<(bitcoin::Amount, usize)>,
min_fee_rate: FeeRate,
payee: ScriptBuf,
allow_mixed_input_scripts: bool,
}

macro_rules! check_eq {
Expand Down Expand Up @@ -145,11 +144,6 @@ impl PsbtContext {
original.txin.sequence,
SenderTxinSequenceChanged
);
ensure!(
proposed.psbtin.non_witness_utxo.is_none(),
SenderTxinContainsNonWitnessUtxo
);
ensure!(proposed.psbtin.witness_utxo.is_none(), SenderTxinContainsWitnessUtxo);
Comment thread
spacebear21 marked this conversation as resolved.
ensure!(
proposed.psbtin.final_script_sig.is_none(),
SenderTxinContainsFinalScriptSig
Expand Down Expand Up @@ -180,13 +174,6 @@ impl PsbtContext {
ReceiverTxinMissingUtxoInfo
);
ensure!(proposed.txin.sequence == original.txin.sequence, MixedSequence);
if !self.allow_mixed_input_scripts {
check_eq!(
proposed.address_type()?,
original.address_type()?,
MixedInputTypes
);
}
}
}
}
Expand Down Expand Up @@ -448,7 +435,6 @@ pub(crate) mod test {
fee_contribution: Some((bitcoin::Amount::from_sat(182), 0)),
min_fee_rate: FeeRate::ZERO,
payee,
allow_mixed_input_scripts: false,
}
}

Expand Down
1 change: 0 additions & 1 deletion payjoin/src/send/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ impl Sender {
fee_contribution: self.fee_contribution,
payee: self.payee.clone(),
min_fee_rate: self.min_fee_rate,
allow_mixed_input_scripts: false,
},
},
))
Expand Down
1 change: 0 additions & 1 deletion payjoin/src/send/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ impl Sender {
fee_contribution: self.v1.fee_contribution,
payee: self.v1.payee.clone(),
min_fee_rate: self.v1.min_fee_rate,
allow_mixed_input_scripts: true,
},
hpke_ctx,
ohttp_ctx,
Expand Down
Loading