Skip to content

Commit

Permalink
feat: fix rpc transaction conversion (#5304)
Browse files Browse the repository at this point in the history
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

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
hansieodendaal committed Apr 11, 2023
1 parent 23d882e commit 344040a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base_layer/core/src/proto/transaction.rs
Expand Up @@ -259,7 +259,7 @@ impl TryFrom<proto::types::TransactionOutput> 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(
Expand Down
Expand Up @@ -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)]
Expand Down

0 comments on commit 344040a

Please sign in to comment.