@@ -659,20 +659,27 @@ impl InteractiveTxConstructor {
659
659
{
660
660
let state_machine =
661
661
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
670
675
. into_iter ( )
671
676
. map ( |output| {
672
677
let serial_id = generate_local_serial_id ( entropy_source, is_initiator) ;
673
678
( serial_id, output)
674
679
} )
675
680
. 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) ;
676
683
let mut constructor =
677
684
Self { state_machine, channel_id, inputs_to_contribute, outputs_to_contribute } ;
678
685
let message_send = if is_initiator {
0 commit comments