Skip to content

Commit

Permalink
Not allowing zero as an x-coordinate in lagrange basis evaluation, ad…
Browse files Browse the repository at this point in the history
…ding a check for total > 1, and some docs.

Signed-off-by: lovesh <[email protected]>
  • Loading branch information
lovesh committed May 17, 2024
1 parent c985419 commit 1ceec9a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion secret_sharing_and_dkg/src/feldman_dvss_dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<G: AffineRepr> SharesAccumulator<G> {
}

/// Reconstruct threshold key using the individual public keys. Multiplies each public key with its
/// Lagrange coefficient and adds the result
/// Lagrange coefficient and adds the result. Assumes that public key ids are unique
pub fn reconstruct_threshold_public_key<G: AffineRepr>(
public_keys: Vec<(ShareId, G)>,
threshold: ShareId,
Expand Down
10 changes: 6 additions & 4 deletions secret_sharing_and_dkg/src/shamir_ss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub fn deal_secret<R: RngCore, F: PrimeField>(
if threshold > total {
return Err(SSError::InvalidThresholdOrTotal(threshold, total));
}
if total < 2 {
return Err(SSError::InvalidThresholdOrTotal(threshold, total));
}
if threshold < 1 {
return Err(SSError::InvalidThresholdOrTotal(threshold, total));
}
Expand Down Expand Up @@ -68,25 +71,24 @@ impl<F: PrimeField> Shares<F> {
pub mod tests {
use super::*;
use crate::common::Share;
use ark_bls12_381::Bls12_381;
use ark_ec::pairing::Pairing;
use ark_bls12_381::{Bls12_381, Fr};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::{rngs::StdRng, SeedableRng};
use test_utils::test_serialization;

type Fr = <Bls12_381 as Pairing>::ScalarField;

#[test]
fn shamir_secret_sharing() {
let mut rng = StdRng::seed_from_u64(0u64);

assert!(deal_random_secret::<_, Fr>(&mut rng, 1, 1).is_err());
assert!(deal_random_secret::<_, Fr>(&mut rng, 5, 4).is_err());

for (threshold, total) in vec![
(2, 2),
(2, 3),
(2, 4),
(2, 5),
(1, 3),
(3, 3),
(3, 4),
(3, 5),
Expand Down
8 changes: 8 additions & 0 deletions utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- cargo-rdme start -->

A collection of utilities used by our other crypto libraries. Some examples are Pedersen commitment,
Elgamal encryption, some finite field utilities like inner product, weighted inner product, hadamard product,
etc, multiscalar multiplication (MSM) like Fixed Base MSM, polynomial utilities like multiplying polynomials,
creating polynomial from roots, etc, efficient way of checking several pairing relations in a single multi-pairing.

<!-- cargo-rdme end -->
2 changes: 1 addition & 1 deletion utils/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use digest::Digest;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

/// A Pedersen commitment key. The Pedersen commitment will be `g * m + h * r` with opening `(m, r)`
/// A Pedersen commitment key `(g, h)`. The Pedersen commitment will be `g * m + h * r` with opening `(m, r)`
#[serde_as]
#[derive(
Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
Expand Down
18 changes: 18 additions & 0 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! A collection of utilities used by our other crypto libraries. Some examples are Pedersen commitment,
//! Elgamal encryption, some finite field utilities like inner product, weighted inner product, hadamard product,
//! etc, multiscalar multiplication (MSM) like Fixed Base MSM, polynomial utilities like multiplying polynomials,
//! creating polynomial from roots, etc, efficient way of checking several pairing relations in a single multi-pairing.
//!
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand All @@ -9,18 +15,30 @@ pub mod extend_some;
#[macro_use]
pub mod serde_utils;
pub mod ecies;

/// Elgamal encryption
pub mod elgamal;

/// Finite field utilities like inner product, weighted inner product, hadamard product, etc
#[macro_use]
pub mod ff;

/// Pedersen commitment
pub mod commitment;

/// Hashing utilities like hashing arbitrary bytes to field element or group element
pub mod hashing_utils;
pub mod iter;
pub mod macros;
pub mod misc;
/// Multiscalar multiplication (MSM) like Fixed Base MSM
pub mod msm;
pub mod owned_pairs;
pub mod pairs;
/// Polynomial utilities like multiplying polynomials, creating polynomial from roots, etc
pub mod poly;
/// An efficient way to check several equality relations involving pairings by combining the relations
/// in a random linear combination and doing a multi-pairing check. Relies on Schwartz–Zippel lemma.
pub mod randomized_pairing_check;
pub mod signature;
pub mod transcript;
Expand Down
3 changes: 3 additions & 0 deletions utils/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ macro_rules! try_pairs {
};
}

/// Return `$error` if `$left` not equals `$right`
#[macro_export]
macro_rules! expect_equality {
($left: expr, $right: expr, $error: expr) => {
Expand All @@ -225,13 +226,15 @@ macro_rules! expect_equality {
};
}

/// Return pairing where `$pairing_func` is the pairing function, `$g1` is/are group G1 elements and `$g2` is/are group G2 elements
#[macro_export]
macro_rules! pair_g1_g2 {
($pairing_func: path, $g1: expr, $g2: expr) => {
$pairing_func($g1, $g2)
};
}

/// Return pairing where `$pairing_func` is the pairing function, `$g1` is/are group G1 elements and `$g2` is/are group G2 elements
#[macro_export]
macro_rules! pair_g2_g1 {
($pairing_func: path, $g2: expr, $g1: expr) => {
Expand Down
2 changes: 2 additions & 0 deletions utils/src/transcript.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Merlin transcripts
use ark_ec::AffineRepr;
use ark_ff::fields::Field;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
Expand Down

0 comments on commit 1ceec9a

Please sign in to comment.