Skip to content

Commit f286cf4

Browse files
committed
refactor: use generator() instead of random point in the curve
Signed-off-by: pedro bufulin <pedro@semiotic.ai>
1 parent cc883dd commit f286cf4

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

h2s2/src/holographic_homomorphic_signature_scheme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub trait HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest + Send + S
1313
type AggregatedSignature;
1414

1515
/// Generate one G2 element and `n` G1 elements
16-
fn setup<R: Rng>(rng: &mut R, n: usize) -> Result<Self::Parameters, Box<dyn Error>>;
16+
fn setup(n: usize) -> Result<Self::Parameters, Box<dyn Error>>;
1717

1818
/// Generate hash aggregate (H_a) with `tag` and `n` lanes, and a
1919
/// allocation_id as a ScalarField

h2s2/src/ncs.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{error::Error, marker::PhantomData};
44
use crate::holographic_homomorphic_signature_scheme::HolographicHomomorphicSignatureScheme;
55
use ark_ec::pairing::Pairing;
66
use ark_ec::AffineRepr;
7+
use ark_ec::PrimeGroup;
78
use ark_ff::PrimeField;
89
use ark_ff::{BigInteger, UniformRand, Zero};
910
use ark_std::rand::Rng;
@@ -69,27 +70,25 @@ impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<
6970
type AggregatedSignature = AggregatedSignature<P>;
7071

7172
// n represents the max_lanes amount
72-
fn setup<R: Rng>(rng: &mut R, n: usize) -> Result<Self::Parameters, Box<dyn Error>> {
73-
// Generate the G2 generator
74-
let g2_generator = P::G2::rand(rng);
73+
fn setup(n: usize) -> Result<Self::Parameters, Box<dyn Error>> {
74+
// Use the hardcoded G2 generator from the Pairing trait
75+
let g2_generator = P::G2::generator();
76+
77+
// Generate a deterministic set of G1 generators based on the hardcoded G1 generator
78+
let g1_base_generator = P::G1::generator();
79+
let g1_generators: Vec<P::G1> = (0..=n)
80+
.map(|i| g1_base_generator.mul(&P::ScalarField::from(i as u64)))
81+
.collect();
7582

76-
// Prepare the parameters without the secret/public keys
77-
let g1_generators: Vec<P::G1> = (0..=n).map(|_| P::G1::rand(rng)).collect();
78-
let mut pp: H2S2Parameters<P> = H2S2Parameters {
83+
// Initialize parameters without secret/public keys
84+
let pp: H2S2Parameters<P> = H2S2Parameters {
7985
g1_generators,
8086
g2_generator,
8187
secret_key: Some(P::ScalarField::zero()), // Temporary placeholder
8288
public_key: P::G2::zero(), // Temporary placeholder
8389
max_lanes: n,
8490
};
8591

86-
// Use the keygen function to generate the secret/public key pair
87-
let (public_key, secret_key) = Self::keygen(&pp, rng)?;
88-
89-
// Update the parameters with the generated keys
90-
pp.secret_key = Some(secret_key);
91-
pp.public_key = public_key;
92-
9392
Ok(pp)
9493
}
9594

@@ -201,7 +200,7 @@ impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<
201200
for (sig, &wt) in signatures.iter().zip(weights.iter()) {
202201
let weight_scalar = P::ScalarField::from(wt as u64);
203202
aggregate_signature += sig.signature.mul(weight_scalar);
204-
total_value += weight_scalar * sig.value;
203+
total_value += weight_scalar.mul(sig.value);
205204
}
206205

207206
Ok(AggregatedSignature {
@@ -221,10 +220,8 @@ mod tests {
221220

222221
static N: usize = 10; // Define the number of generators
223222

224-
static PARAMS: Lazy<H2S2Parameters<Bn254>> = Lazy::new(|| {
225-
let mut rng = test_rng();
226-
NCS::<Bn254, Blake2b512>::setup(&mut rng, N).expect("Setup failed")
227-
});
223+
static PARAMS: Lazy<H2S2Parameters<Bn254>> =
224+
Lazy::new(|| NCS::<Bn254, Blake2b512>::setup(N).expect("Setup failed"));
228225

229226
#[test]
230227
fn test_setup() {

0 commit comments

Comments
 (0)