Skip to content

Commit

Permalink
Check stored transaction for payment proof when checking proof (mimbl…
Browse files Browse the repository at this point in the history
…ewimble#266)

* check original transaction when checking payment proof

* rustfmt

* tweak to trigger build
  • Loading branch information
yeastplume authored Dec 3, 2019
1 parent 56396b8 commit 0d77282
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ Full documentation outlining how to use the command line wallet can be found on
# License

Apache License v2.0

39 changes: 24 additions & 15 deletions libwallet/src/internal/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,30 @@ where
C: NodeClient + 'a,
K: Keychain + 'a,
{
let tx_vec = updater::retrieve_txs(wallet, None, Some(slate.id), Some(parent_key_id), false)?;
if tx_vec.len() == 0 {
return Err(ErrorKind::PaymentProof(
"TxLogEntry with original proof info not found (is account correct?)".to_owned(),
))?;
}

let orig_proof_info = tx_vec[0].clone().payment_proof;

if orig_proof_info.is_some() && slate.payment_proof.is_none() {
return Err(ErrorKind::PaymentProof(
"Expected Payment Proof for this Transaction is not present".to_owned(),
))?;
}

if let Some(ref p) = slate.payment_proof {
let orig_proof_info = match orig_proof_info {
Some(p) => p,
None => {
return Err(ErrorKind::PaymentProof(
"Original proof info not stored in tx".to_owned(),
))?;
}
};
let keychain = wallet.keychain(keychain_mask)?;
let index = match context.payment_proof_derivation_index {
Some(i) => i,
Expand All @@ -492,21 +515,7 @@ where
"Sender address on slate does not match original sender address".to_owned(),
))?;
}
let tx_vec =
updater::retrieve_txs(wallet, None, Some(slate.id), Some(&parent_key_id), false)?;
if tx_vec.len() != 1 {
return Err(ErrorKind::PaymentProof(
"TxLogEntry with original proof info not found".to_owned(),
))?;
}
let orig_proof_info = match tx_vec[0].clone().payment_proof {
Some(o) => o,
None => {
return Err(ErrorKind::PaymentProof(
"Original proof info not stored in tx".to_owned(),
))?;
}
};

if orig_proof_info.receiver_address != p.receiver_address {
return Err(ErrorKind::PaymentProof(
"Recipient address on slate does not match original recipient address".to_owned(),
Expand Down
4 changes: 4 additions & 0 deletions tests/cmd_line_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::

let arg_vec = vec![
"grin-wallet",
"-a",
"mining",
"-p",
"password",
"finalize",
Expand Down Expand Up @@ -307,6 +309,8 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::

let arg_vec = vec![
"grin-wallet",
"-a",
"mining",
"-p",
"password",
"finalize",
Expand Down

0 comments on commit 0d77282

Please sign in to comment.