perf(commitments): generate sapling point outside the method (#4799)

* move generated point to a lazy_static

* move lazy static out of method
This commit is contained in:
Alfredo Garcia 2022-07-21 20:17:09 -03:00 committed by GitHub
parent 394d16a5a5
commit 1b17c57bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View File

@ -301,17 +301,16 @@ impl ValueCommitment {
/// <https://zips.z.cash/protocol/nu5.pdf#concretehomomorphiccommit> /// <https://zips.z.cash/protocol/nu5.pdf#concretehomomorphiccommit>
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn new(rcv: pallas::Scalar, value: Amount) -> Self { pub fn new(rcv: pallas::Scalar, value: Amount) -> Self {
lazy_static! {
static ref V: pallas::Point = pallas_group_hash(b"z.cash:Orchard-cv", b"v");
static ref R: pallas::Point = pallas_group_hash(b"z.cash:Orchard-cv", b"r");
}
let v = pallas::Scalar::from(value); let v = pallas::Scalar::from(value);
Self::from(*V * v + *R * rcv) Self::from(*V * v + *R * rcv)
} }
} }
lazy_static! {
static ref V: pallas::Point = pallas_group_hash(b"z.cash:Orchard-cv", b"v");
static ref R: pallas::Point = pallas_group_hash(b"z.cash:Orchard-cv", b"r");
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -12,6 +12,7 @@ use std::{
use bitvec::prelude::*; use bitvec::prelude::*;
use jubjub::ExtendedPoint; use jubjub::ExtendedPoint;
use lazy_static::lazy_static;
use rand_core::{CryptoRng, RngCore}; use rand_core::{CryptoRng, RngCore};
use crate::{ use crate::{
@ -279,16 +280,15 @@ impl ValueCommitment {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn new(rcv: jubjub::Fr, value: Amount) -> Self { pub fn new(rcv: jubjub::Fr, value: Amount) -> Self {
let v = jubjub::Fr::from(value); let v = jubjub::Fr::from(value);
Self::from(*V * v + *R * rcv)
// TODO: These generator points can be generated once somewhere else to
// avoid having to recompute them on every new commitment.
let V = find_group_hash(*b"Zcash_cv", b"v");
let R = find_group_hash(*b"Zcash_cv", b"r");
Self::from(V * v + R * rcv)
} }
} }
lazy_static! {
static ref V: ExtendedPoint = find_group_hash(*b"Zcash_cv", b"v");
static ref R: ExtendedPoint = find_group_hash(*b"Zcash_cv", b"r");
}
/// A Homomorphic Pedersen commitment to the value of a note, used in Spend and /// A Homomorphic Pedersen commitment to the value of a note, used in Spend and
/// Output descriptions. /// Output descriptions.
/// ///