Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions zebra-chain/src/orchard/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,16 @@ impl ValueCommitment {
/// <https://zips.z.cash/protocol/nu5.pdf#concretehomomorphiccommit>
#[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 {

Expand Down
14 changes: 7 additions & 7 deletions zebra-chain/src/sapling/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{

use bitvec::prelude::*;
use jubjub::ExtendedPoint;
use lazy_static::lazy_static;
use rand_core::{CryptoRng, RngCore};

use crate::{
Expand Down Expand Up @@ -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.
///
Expand Down