Skip to content

Commit 5c2bda7

Browse files
committed
f shuffle inputs/outputs before sending to peer
1 parent 2c37cd3 commit 5c2bda7

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -659,20 +659,27 @@ impl InteractiveTxConstructor {
659659
{
660660
let state_machine =
661661
StateMachine::new(feerate_sat_per_kw, is_initiator, tx_locktime, to_remote_value);
662-
let inputs_to_contribute = inputs_to_contribute
663-
.into_iter()
664-
.map(|(input, tx)| {
665-
let serial_id = generate_local_serial_id(entropy_source, is_initiator);
666-
(serial_id, input, tx)
667-
})
668-
.collect();
669-
let outputs_to_contribute = outputs_to_contribute
662+
let mut inputs_to_contribute: Vec<(SerialId, TxIn, TransactionU16LenLimited)> =
663+
inputs_to_contribute
664+
.into_iter()
665+
.map(|(input, tx)| {
666+
let serial_id = generate_local_serial_id(entropy_source, is_initiator);
667+
(serial_id, input, tx)
668+
})
669+
.collect();
670+
// We'll sort by the randomly generated serial IDs, effectively shuffling the order of the inputs
671+
// as the user passed them to us to avoid leaking any potential categorization of transactions
672+
// before we pass any of the inputs to the counterparty.
673+
inputs_to_contribute.sort_unstable_by_key(|(serial_id, _, _)| *serial_id);
674+
let mut outputs_to_contribute: Vec<(SerialId, TxOut)> = outputs_to_contribute
670675
.into_iter()
671676
.map(|output| {
672677
let serial_id = generate_local_serial_id(entropy_source, is_initiator);
673678
(serial_id, output)
674679
})
675680
.collect();
681+
// In the same manner and for the same rationale as the inputs above, we'll shuffle the outputs.
682+
outputs_to_contribute.sort_unstable_by_key(|(serial_id, _)| *serial_id);
676683
let mut constructor =
677684
Self { state_machine, channel_id, inputs_to_contribute, outputs_to_contribute };
678685
let message_send = if is_initiator {

0 commit comments

Comments
 (0)