Skip to content

Commit cc883dd

Browse files
committed
feat: use scalar weights in evaluate
Signed-off-by: pedro bufulin <pedro@semiotic.ai>
1 parent 7244f27 commit cc883dd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

h2s2/src/ncs.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,18 @@ impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<
190190
signatures: &[Self::Signature],
191191
weights: &[Self::Weight],
192192
) -> Result<Self::AggregatedSignature, Box<dyn Error>> {
193+
// Ensure that the lengths of the inputs match
194+
if signatures.len() != weights.len() {
195+
return Err("Signatures and weights must have the same length".into());
196+
}
197+
193198
let mut aggregate_signature = P::G1::zero();
194199
let mut total_value = P::ScalarField::zero();
195-
for sig in signatures {
196-
aggregate_signature += sig.signature;
197-
total_value += sig.value;
200+
201+
for (sig, &wt) in signatures.iter().zip(weights.iter()) {
202+
let weight_scalar = P::ScalarField::from(wt as u64);
203+
aggregate_signature += sig.signature.mul(weight_scalar);
204+
total_value += weight_scalar * sig.value;
198205
}
199206

200207
Ok(AggregatedSignature {
@@ -348,6 +355,8 @@ mod tests {
348355
let random_index = rng.gen_range(0..N);
349356
let duplicate_signature = signatures[random_index].clone();
350357
signatures.push(duplicate_signature);
358+
// adds 1 more weight to match the added signature
359+
let weights: Vec<usize> = vec![1; N + 1];
351360

352361
// Aggregate the signatures, including the duplicate
353362
let tampered_aggregate_signature =

0 commit comments

Comments
 (0)