Skip to content

Commit

Permalink
mobilecoind: fix a bug in swap generation (#3232)
Browse files Browse the repository at this point in the history
The `SignedContingentInputBuilder` does not know the TxOut global
indices of the ring elements, they usually aren't supplied to it
unless merkle proofs of membership were supplied to it.
It usually ends up setting `tx_out_global_indices` to a list of zeroes,
and it falls to the counterparty to find proofs of membership.

I forgot to do this in `generate_swap_impl`, so `mobilecoind` was
leaving `tx_out_global_indices` with an incorrect setting. This
commit fixes it and adds a test.
  • Loading branch information
cbeck88 authored Mar 14, 2023
1 parent dd24518 commit dae30ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mobilecoind/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,12 @@ impl<T: BlockchainConnection + UserTxConnection + 'static, FPR: FogPubkeyResolve
}

// Build sci.
sci_builder
let mut result = sci_builder
.build(&NoKeysRingSigner {}, rng)
.map_err(|err| Error::TxBuild(format!("build tx failed: {err}")))
.map_err(|err| Error::TxBuild(format!("build tx failed: {err}")))?;

result.tx_out_global_indices = global_indices;
Ok(result)
}
}

Expand Down
6 changes: 6 additions & 0 deletions mobilecoind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3815,6 +3815,12 @@ mod test {
let sci = SignedContingentInput::try_from(sci).unwrap();

sci.validate().unwrap();
assert_eq!(sci.tx_out_global_indices.len(), 11);
// Indices should be distinct
assert_eq!(
HashSet::from_iter(sci.tx_out_global_indices.iter()).len(),
11
);

let unmasked_amount = sci.required_output_amounts[0].clone();
assert_eq!(unmasked_amount.value, 999_999);
Expand Down

0 comments on commit dae30ff

Please sign in to comment.