diff --git a/secret_sharing_and_dkg/src/feldman_dvss_dkg.rs b/secret_sharing_and_dkg/src/feldman_dvss_dkg.rs index fc70b53a..24da7afe 100644 --- a/secret_sharing_and_dkg/src/feldman_dvss_dkg.rs +++ b/secret_sharing_and_dkg/src/feldman_dvss_dkg.rs @@ -169,7 +169,7 @@ impl SharesAccumulator { } /// 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( public_keys: Vec<(ShareId, G)>, threshold: ShareId, diff --git a/secret_sharing_and_dkg/src/shamir_ss.rs b/secret_sharing_and_dkg/src/shamir_ss.rs index 10bf181f..a36df7c7 100644 --- a/secret_sharing_and_dkg/src/shamir_ss.rs +++ b/secret_sharing_and_dkg/src/shamir_ss.rs @@ -35,6 +35,9 @@ pub fn deal_secret( 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)); } @@ -68,18 +71,16 @@ impl Shares { 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 = ::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![ @@ -87,6 +88,7 @@ pub mod tests { (2, 3), (2, 4), (2, 5), + (1, 3), (3, 3), (3, 4), (3, 5), diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 00000000..b210ff61 --- /dev/null +++ b/utils/README.md @@ -0,0 +1,8 @@ + + +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. + + diff --git a/utils/src/commitment.rs b/utils/src/commitment.rs index cc10f6f2..ec993440 100644 --- a/utils/src/commitment.rs +++ b/utils/src/commitment.rs @@ -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, diff --git a/utils/src/lib.rs b/utils/src/lib.rs index 7c151312..7418a83b 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -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; @@ -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; diff --git a/utils/src/macros.rs b/utils/src/macros.rs index a00d0bda..dac0e305 100644 --- a/utils/src/macros.rs +++ b/utils/src/macros.rs @@ -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) => { @@ -225,6 +226,7 @@ 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) => { @@ -232,6 +234,7 @@ macro_rules! pair_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) => { diff --git a/utils/src/transcript.rs b/utils/src/transcript.rs index ef24154e..6420d937 100644 --- a/utils/src/transcript.rs +++ b/utils/src/transcript.rs @@ -1,3 +1,5 @@ +//! Merlin transcripts + use ark_ec::AffineRepr; use ark_ff::fields::Field; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};