From: Duncan Dean Date: Tue, 26 Mar 2024 10:15:37 +0000 (+0200) Subject: Abort if we add a duplicate input X-Git-Tag: v0.0.123-rc1~7^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=62d4952348ecf70e3c4b8cd0400158a603b37708;p=rust-lightning Abort if we add a duplicate input --- diff --git a/lightning/src/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs index 33a8bfc2f..836258b58 100644 --- a/lightning/src/ln/interactivetxs.rs +++ b/lightning/src/ln/interactivetxs.rs @@ -308,7 +308,10 @@ impl NegotiationContext { }; let prev_output = tx.output.get(msg.prevtx_out as usize).ok_or(AbortReason::PrevTxOutInvalid)?.clone(); - self.prevtx_outpoints.insert(input.previous_output); + if !self.prevtx_outpoints.insert(input.previous_output) { + // We have added an input that already exists + return Err(AbortReason::PrevTxOutInvalid); + } self.inputs.insert(msg.serial_id, TxInputWithPrevOutput { input, prev_output }); Ok(()) } @@ -1253,7 +1256,7 @@ mod tests { outputs_a: generate_outputs(&[1_000_000]), inputs_b: vec![], outputs_b: vec![], - expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeA)), + expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeB)), }); // Non-initiator uses same prevout as initiator. let duplicate_input = TxIn { @@ -1266,7 +1269,7 @@ mod tests { outputs_a: generate_outputs(&[1_000_000]), inputs_b: vec![(duplicate_input.clone(), tx.clone())], outputs_b: vec![], - expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeB)), + expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeA)), }); // Initiator sends too many TxAddInputs do_test_interactive_tx_constructor(TestSession {