From f79c438ca4096d08ce27d720ee464631db934597 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 20 Jul 2022 12:39:35 -0300 Subject: [PATCH 1/2] move generated point to a lazy_static --- zebra-chain/src/sapling/commitment.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zebra-chain/src/sapling/commitment.rs b/zebra-chain/src/sapling/commitment.rs index 0f33cab1ac1..0a1d389129c 100644 --- a/zebra-chain/src/sapling/commitment.rs +++ b/zebra-chain/src/sapling/commitment.rs @@ -12,6 +12,7 @@ use std::{ use bitvec::prelude::*; use jubjub::ExtendedPoint; +use lazy_static::lazy_static; use rand_core::{CryptoRng, RngCore}; use crate::{ @@ -279,16 +280,15 @@ impl ValueCommitment { #[allow(non_snake_case)] pub fn new(rcv: jubjub::Fr, value: Amount) -> Self { let v = jubjub::Fr::from(value); - - // 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) + 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 /// Output descriptions. /// From 4cbe1fcd37f3d6035890c548ec47bfb6f946dace Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 20 Jul 2022 13:08:27 -0300 Subject: [PATCH 2/2] move lazy static out of method --- zebra-chain/src/orchard/commitment.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/zebra-chain/src/orchard/commitment.rs b/zebra-chain/src/orchard/commitment.rs index cc146ffbec6..b09721172e7 100644 --- a/zebra-chain/src/orchard/commitment.rs +++ b/zebra-chain/src/orchard/commitment.rs @@ -301,17 +301,16 @@ impl ValueCommitment { /// #[allow(non_snake_case)] 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); - 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)] mod tests {