Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/provider/hyperkzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,25 @@ where

Commitment { comm }
}

fn commit_sparse(
ck: &Self::CommitmentKey,
indices: &[usize],
scalars: &[E::Scalar],
r: &E::Scalar,
) -> Self::Commitment {
assert_eq!(indices.len(), scalars.len());

let bases: Vec<_> = indices.par_iter().map(|&i| ck.ck[i]).collect();

let mut comm = E::GE::vartime_multiscalar_mul(scalars, &bases);

if r != &E::Scalar::ZERO {
comm += <E::GE as DlogGroup>::group(&ck.h) * r;
}

Commitment { comm }
}
}

/// Provides an implementation of generators for proving evaluations
Expand Down
19 changes: 19 additions & 0 deletions src/provider/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,25 @@ where

Commitment { comm }
}

fn commit_sparse(
ck: &Self::CommitmentKey,
indices: &[usize],
scalars: &[E::Scalar],
r: &E::Scalar,
) -> Self::Commitment {
assert_eq!(indices.len(), scalars.len());

let bases: Vec<_> = indices.par_iter().map(|&i| ck.ck[i]).collect();

let mut comm = E::GE::vartime_multiscalar_mul(scalars, &bases);

if r != &E::Scalar::ZERO {
comm += <E::GE as DlogGroup>::group(&ck.h) * r;
}

Commitment { comm }
}
}

/// A trait listing properties of a commitment key that can be managed in a divide-and-conquer fashion
Expand Down
9 changes: 9 additions & 0 deletions src/traits/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ pub trait CommitmentEngineTrait<E: Engine>: Clone + Send + Sync {
r: &E::Scalar,
) -> Self::Commitment;

/// Commits to the provided vector of sparse scalars given by (indices, scalars),
/// using the provided generators and random blind
fn commit_sparse(
ck: &Self::CommitmentKey,
indices: &[usize],
scalars: &[E::Scalar],
r: &E::Scalar,
) -> Self::Commitment;

/// Commits to the provided vector of "small" scalars (at most 64 bits) using the provided generators and random blind
fn commit_small<T: Integer + Into<u64> + Copy + Sync + ToPrimitive>(
ck: &Self::CommitmentKey,
Expand Down
Loading