Skip to content

Commit 9a7dfbc

Browse files
committed
impl Add for FeldmanCommitment and leverage batch_norm
1 parent 4715c52 commit 9a7dfbc

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

timeboost-crypto/src/feldman.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use derive_more::{Deref, From, IntoIterator};
99
use rayon::prelude::*;
1010
use serde::{Deserialize, Serialize};
1111
use serde_with::serde_as;
12-
use std::{iter::successors, num::NonZeroUsize};
12+
use std::{iter::successors, num::NonZeroUsize, ops::Add};
1313

1414
use crate::{
1515
interpolation::{interpolate, interpolate_in_exponent},
@@ -211,6 +211,30 @@ impl<C: CurveGroup> FeldmanCommitment<C> {
211211
}
212212
}
213213

214+
// Implementation of Add trait for FeldmanCommitment + &FeldmanCommitment
215+
impl<C: CurveGroup> Add<&FeldmanCommitment<C>> for FeldmanCommitment<C> {
216+
type Output = FeldmanCommitment<C>;
217+
218+
fn add(self, other: &FeldmanCommitment<C>) -> Self::Output {
219+
&self + other
220+
}
221+
}
222+
223+
// Implementation of Add trait for &FeldmanCommitment + &FeldmanCommitment
224+
impl<C: CurveGroup> Add<&FeldmanCommitment<C>> for &FeldmanCommitment<C> {
225+
type Output = FeldmanCommitment<C>;
226+
227+
fn add(self, other: &FeldmanCommitment<C>) -> Self::Output {
228+
let combined: Vec<C> = self
229+
.comm
230+
.iter()
231+
.zip(other.comm.iter())
232+
.map(|(x, y)| *x + y)
233+
.collect();
234+
C::normalize_batch(&combined).into()
235+
}
236+
}
237+
214238
impl<C: CurveGroup> KeyResharing<Self> for FeldmanVss<C> {
215239
fn reshare<R: Rng>(
216240
new_pp: &FeldmanVssPublicParam,

timeboost-types/src/decryption.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::{BTreeMap, btree_map};
22

33
use anyhow::anyhow;
4-
use ark_ec::{AffineRepr, CurveGroup};
4+
use ark_ec::AffineRepr;
55
use multisig::{Committee, CommitteeId, KeyId};
66
use rayon::prelude::*;
77
use serde::{Deserialize, Serialize};
@@ -60,16 +60,7 @@ impl DecryptionKey {
6060
let agg_comm = commitments
6161
.par_iter()
6262
.cloned()
63-
.reduce_with(|a, b| {
64-
let combined: Vec<_> = a
65-
.into_iter()
66-
.zip(b.into_iter())
67-
// NOTE: ideally we can use C::normalize_batch(), but C is not exposed,
68-
// minor optimization, so ignore for now.
69-
.map(|(x, y)| (x + y).into_affine())
70-
.collect();
71-
combined.into()
72-
})
63+
.reduce_with(|a, b| a + &b)
7364
.ok_or_else(|| anyhow!("no commitments provided"))?;
7465
let agg_key_share = key_shares.iter().sum();
7566

0 commit comments

Comments
 (0)