Skip to content

Commit ab14f0a

Browse files
committed
refactor: add allocation_id generate outside of precopute
Signed-off-by: pedro bufulin <pedro@semiotic.ai>
1 parent 448bea3 commit ab14f0a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

h2s2/src/holographic_homomorphic_signature_scheme.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub trait HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest + Send + S
1717

1818
/// Generate hash aggregate (H_a) with `tag` and `n` lanes, and a
1919
/// allocation_id as a ScalarField
20-
fn precompute<R: Rng>(
20+
fn precompute(
2121
pp: &Self::Parameters,
22-
rng: &mut R,
22+
tag: P::ScalarField,
2323
n: usize,
2424
) -> Result<(P::G1, P::ScalarField), Box<dyn Error>>;
2525

@@ -51,7 +51,6 @@ pub trait HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest + Send + S
5151
/// contained in [`AggregatedSignature`] with `tag` and `hash_aggregate` using `pp` parameter and `pk` public key
5252
fn verify_aggregate(
5353
pp: &Self::Parameters,
54-
// tag: &[u8],
5554
hash_aggregate: &P::G1,
5655
signature: &Self::AggregatedSignature,
5756
) -> Result<bool, Box<dyn Error>>;

h2s2/src/ncs.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,15 @@ impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<
9595
//TODO: allocationn_ids (tag in this case) must be unpredictable
9696
// some random value has to be appended during initialization, prior
9797
// to the precompute in this function
98-
fn precompute<R: Rng>(
98+
fn precompute(
9999
_pp: &Self::Parameters,
100-
rng: &mut R,
100+
tag: P::ScalarField,
101101
n: usize,
102102
) -> Result<(P::G1, P::ScalarField), Box<dyn Error>> {
103-
let allocation_id = P::ScalarField::rand(rng);
104103
let hash_vec = (0..n)
105104
.into_iter()
106105
.map(|lane_id| {
107-
let mut message_data = allocation_id.into_bigint().to_bytes_be();
106+
let mut message_data = tag.into_bigint().to_bytes_be();
108107
message_data.append(&mut lane_id.to_be_bytes().to_vec());
109108
hash_to_g1::<P, D>(message_data)
110109
})
@@ -113,7 +112,7 @@ impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<
113112
for hash_val in hash_vec {
114113
allocation_hash += hash_val;
115114
}
116-
Ok((allocation_hash, allocation_id))
115+
Ok((allocation_hash, tag))
117116
}
118117

119118
fn keygen<R: Rng>(
@@ -212,6 +211,7 @@ impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<
212211

213212
#[cfg(test)]
214213
mod tests {
214+
215215
use super::*;
216216
use ark_bn254::Bn254;
217217
//we could also use the ark_bls12_381 curve which was intended to substitute this one:
@@ -270,9 +270,10 @@ mod tests {
270270
#[test]
271271
fn test_precompute() {
272272
let params = &*PARAMS;
273-
let mut rng = test_rng();
273+
274+
let allocation_id = ark_bn254::Fr::from_be_bytes_mod_order(&Hasher::digest(&b"test"));
274275
let (hash_aggregate, alloc_id) =
275-
NCS::<Curve, Hasher>::precompute(&params, &mut rng, N).expect("Precompute failed");
276+
NCS::<Curve, Hasher>::precompute(&params, allocation_id, N).expect("Precompute failed");
276277

277278
println!("Precomputed Hash Aggregate: {:?}", hash_aggregate);
278279
println!("allocation_id {:?}", alloc_id);
@@ -284,8 +285,9 @@ mod tests {
284285
let params = &*PARAMS;
285286

286287
// Precompute the hash aggregate and allocation ID
288+
let allocation_id = ark_bn254::Fr::from_be_bytes_mod_order(&Hasher::digest(&b"test"));
287289
let (_, allocation_id) =
288-
NCS::<Curve, Hasher>::precompute(&params, &mut rng, N).expect("Precompute failed");
290+
NCS::<Curve, Hasher>::precompute(&params, allocation_id, N).expect("Precompute failed");
289291

290292
// Generate messages for each lane/index
291293
let messages: Vec<Fr> = (0..N).map(|_| Fr::rand(&mut rng)).collect();
@@ -326,8 +328,9 @@ mod tests {
326328
let messages: Vec<Fr> = (0..N).map(|_| Fr::rand(&mut rng)).collect();
327329

328330
// Precompute the hash aggregate and allocation ID
331+
let allocation_id = ark_bn254::Fr::from_be_bytes_mod_order(&Hasher::digest(&b"test"));
329332
let (hash_aggregate, allocation_id) =
330-
NCS::<Curve, Hasher>::precompute(&params, &mut rng, N).expect("Precompute failed");
333+
NCS::<Curve, Hasher>::precompute(&params, allocation_id, N).expect("Precompute failed");
331334

332335
// Generate individual signatures for each message
333336
let mut signatures: Vec<_> = (0..N)

0 commit comments

Comments
 (0)