From 344040ac7322bae5604aa9db48d4194c1b3779fa Mon Sep 17 00:00:00 2001 From: Hansie Odendaal <39146854+hansieodendaal@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:43:50 +0200 Subject: [PATCH] feat: fix rpc transaction conversion (#5304) Description --- Fixed RPC transaction proto conversion Motivation and Context --- With the RPC conversion `minimum_value_promise` was zeroed instead of assigned See #5295 How Has This Been Tested? --- What process can a PR reviewer use to test or verify this change? --- Run a system-level test to submit a transaction via gRPC to a base node where an output has `minimum_value_promise != 0` and then mine the transaction Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify --- base_layer/core/src/proto/transaction.rs | 2 +- .../transaction_output.rs | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/base_layer/core/src/proto/transaction.rs b/base_layer/core/src/proto/transaction.rs index ee783f5c78..2e1b7c1e56 100644 --- a/base_layer/core/src/proto/transaction.rs +++ b/base_layer/core/src/proto/transaction.rs @@ -259,7 +259,7 @@ impl TryFrom for TransactionOutput { let encrypted_value = EncryptedValue::from_bytes(&output.encrypted_value).map_err(|err| err.to_string())?; - let minimum_value_promise = MicroTari::zero(); + let minimum_value_promise = output.minimum_value_promise.into(); Ok(Self::new( TransactionOutputVersion::try_from( diff --git a/base_layer/core/src/transactions/transaction_components/transaction_output.rs b/base_layer/core/src/transactions/transaction_components/transaction_output.rs index ca1e769e79..fa69c012ae 100644 --- a/base_layer/core/src/transactions/transaction_components/transaction_output.rs +++ b/base_layer/core/src/transactions/transaction_components/transaction_output.rs @@ -567,8 +567,35 @@ pub fn batch_verify_range_proofs( }); proofs.push(output.proof.to_vec().clone()); } - prover.verify_batch(proofs.iter().collect(), statements.iter().collect())?; - Ok(()) + match prover.verify_batch(proofs.iter().collect(), statements.iter().collect()) { + Ok(_) => Ok(()), + Err(err_1) => { + for output in outputs.iter() { + match output.verify_range_proof(prover) { + Ok(_) => {}, + Err(err_2) => { + let proof = output.proof.to_hex(); + let proof = if proof.len() > 32 { + format!("{}..{}", &proof[0..16], &proof[proof.len() - 16..proof.len()]) + } else { + proof + }; + return Err(RangeProofError::InvalidRangeProof(format!( + "commitment {}, minimum_value_promise {}, proof {} ({:?})", + output.commitment.to_hex(), + output.minimum_value_promise, + proof, + err_2, + ))); + }, + } + } + Err(RangeProofError::InvalidRangeProof(format!( + "Batch verification failed, but individual verification passed - {:?}", + err_1 + ))) + }, + } } #[cfg(test)]