Make Amount opaque, and use it more

This helps to ensure type-safety of values that are required to satisfy
zatoshi range bounds.
This commit is contained in:
Jack Grigg
2019-07-27 00:35:29 +01:00
parent ab60b8804a
commit 59ed258c7f
12 changed files with 203 additions and 89 deletions
+3 -2
View File
@@ -2,6 +2,7 @@ use pairing::bls12_381::Bls12;
use sapling_crypto::jubjub::{
edwards, fs::FsRepr, FixedGenerators, JubjubBls12, JubjubParams, Unknown,
};
use zcash_primitives::transaction::components::Amount;
mod prover;
mod verifier;
@@ -11,12 +12,12 @@ pub use self::verifier::SaplingVerificationContext;
// This function computes `value` in the exponent of the value commitment base
fn compute_value_balance(
value: i64,
value: Amount,
params: &JubjubBls12,
) -> Option<edwards::Point<Bls12, Unknown>> {
// Compute the absolute value (failing if -i64::MAX is
// the value)
let abs = match value.checked_abs() {
let abs = match i64::from(value).checked_abs() {
Some(a) => a as u64,
None => return None,
};