Move Sapling verification checks into zcash_proofs crate
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
use pairing::bls12_381::Bls12;
|
||||
use sapling_crypto::jubjub::{
|
||||
edwards, fs::FsRepr, FixedGenerators, JubjubBls12, JubjubParams, Unknown,
|
||||
};
|
||||
|
||||
mod verifier;
|
||||
|
||||
pub use self::verifier::SaplingVerificationContext;
|
||||
|
||||
// This function computes `value` in the exponent of the value commitment base
|
||||
pub fn compute_value_balance(
|
||||
value: i64,
|
||||
params: &JubjubBls12,
|
||||
) -> Option<edwards::Point<Bls12, Unknown>> {
|
||||
// Compute the absolute value (failing if -i64::MAX is
|
||||
// the value)
|
||||
let abs = match value.checked_abs() {
|
||||
Some(a) => a as u64,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
// Is it negative? We'll have to negate later if so.
|
||||
let is_negative = value.is_negative();
|
||||
|
||||
// Compute it in the exponent
|
||||
let mut value_balance = params
|
||||
.generator(FixedGenerators::ValueCommitmentValue)
|
||||
.mul(FsRepr::from(abs), params);
|
||||
|
||||
// Negate if necessary
|
||||
if is_negative {
|
||||
value_balance = value_balance.negate();
|
||||
}
|
||||
|
||||
// Convert to unknown order point
|
||||
Some(value_balance.into())
|
||||
}
|
||||
Reference in New Issue
Block a user