Skip to content

Commit 1ceec9a

Browse files
committedMay 17, 2024·
Not allowing zero as an x-coordinate in lagrange basis evaluation, adding a check for total > 1, and some docs.
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent c985419 commit 1ceec9a

File tree

7 files changed

+39
-6
lines changed

7 files changed

+39
-6
lines changed
 

‎secret_sharing_and_dkg/src/feldman_dvss_dkg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<G: AffineRepr> SharesAccumulator<G> {
169169
}
170170

171171
/// Reconstruct threshold key using the individual public keys. Multiplies each public key with its
172-
/// Lagrange coefficient and adds the result
172+
/// Lagrange coefficient and adds the result. Assumes that public key ids are unique
173173
pub fn reconstruct_threshold_public_key<G: AffineRepr>(
174174
public_keys: Vec<(ShareId, G)>,
175175
threshold: ShareId,

‎secret_sharing_and_dkg/src/shamir_ss.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pub fn deal_secret<R: RngCore, F: PrimeField>(
3535
if threshold > total {
3636
return Err(SSError::InvalidThresholdOrTotal(threshold, total));
3737
}
38+
if total < 2 {
39+
return Err(SSError::InvalidThresholdOrTotal(threshold, total));
40+
}
3841
if threshold < 1 {
3942
return Err(SSError::InvalidThresholdOrTotal(threshold, total));
4043
}
@@ -68,25 +71,24 @@ impl<F: PrimeField> Shares<F> {
6871
pub mod tests {
6972
use super::*;
7073
use crate::common::Share;
71-
use ark_bls12_381::Bls12_381;
72-
use ark_ec::pairing::Pairing;
74+
use ark_bls12_381::{Bls12_381, Fr};
7375
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
7476
use ark_std::rand::{rngs::StdRng, SeedableRng};
7577
use test_utils::test_serialization;
7678

77-
type Fr = <Bls12_381 as Pairing>::ScalarField;
78-
7979
#[test]
8080
fn shamir_secret_sharing() {
8181
let mut rng = StdRng::seed_from_u64(0u64);
8282

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

8586
for (threshold, total) in vec![
8687
(2, 2),
8788
(2, 3),
8889
(2, 4),
8990
(2, 5),
91+
(1, 3),
9092
(3, 3),
9193
(3, 4),
9294
(3, 5),

‎utils/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- cargo-rdme start -->
2+
3+
A collection of utilities used by our other crypto libraries. Some examples are Pedersen commitment,
4+
Elgamal encryption, some finite field utilities like inner product, weighted inner product, hadamard product,
5+
etc, multiscalar multiplication (MSM) like Fixed Base MSM, polynomial utilities like multiplying polynomials,
6+
creating polynomial from roots, etc, efficient way of checking several pairing relations in a single multi-pairing.
7+
8+
<!-- cargo-rdme end -->

‎utils/src/commitment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use digest::Digest;
88
use serde::{Deserialize, Serialize};
99
use serde_with::serde_as;
1010

11-
/// A Pedersen commitment key. The Pedersen commitment will be `g * m + h * r` with opening `(m, r)`
11+
/// A Pedersen commitment key `(g, h)`. The Pedersen commitment will be `g * m + h * r` with opening `(m, r)`
1212
#[serde_as]
1313
#[derive(
1414
Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,

‎utils/src/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! A collection of utilities used by our other crypto libraries. Some examples are Pedersen commitment,
2+
//! Elgamal encryption, some finite field utilities like inner product, weighted inner product, hadamard product,
3+
//! etc, multiscalar multiplication (MSM) like Fixed Base MSM, polynomial utilities like multiplying polynomials,
4+
//! creating polynomial from roots, etc, efficient way of checking several pairing relations in a single multi-pairing.
5+
//!
6+
17
#![cfg_attr(not(feature = "std"), no_std)]
28

39
extern crate alloc;
@@ -9,18 +15,30 @@ pub mod extend_some;
915
#[macro_use]
1016
pub mod serde_utils;
1117
pub mod ecies;
18+
19+
/// Elgamal encryption
1220
pub mod elgamal;
21+
22+
/// Finite field utilities like inner product, weighted inner product, hadamard product, etc
1323
#[macro_use]
1424
pub mod ff;
25+
26+
/// Pedersen commitment
1527
pub mod commitment;
28+
29+
/// Hashing utilities like hashing arbitrary bytes to field element or group element
1630
pub mod hashing_utils;
1731
pub mod iter;
1832
pub mod macros;
1933
pub mod misc;
34+
/// Multiscalar multiplication (MSM) like Fixed Base MSM
2035
pub mod msm;
2136
pub mod owned_pairs;
2237
pub mod pairs;
38+
/// Polynomial utilities like multiplying polynomials, creating polynomial from roots, etc
2339
pub mod poly;
40+
/// An efficient way to check several equality relations involving pairings by combining the relations
41+
/// in a random linear combination and doing a multi-pairing check. Relies on Schwartz–Zippel lemma.
2442
pub mod randomized_pairing_check;
2543
pub mod signature;
2644
pub mod transcript;

‎utils/src/macros.rs

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ macro_rules! try_pairs {
216216
};
217217
}
218218

219+
/// Return `$error` if `$left` not equals `$right`
219220
#[macro_export]
220221
macro_rules! expect_equality {
221222
($left: expr, $right: expr, $error: expr) => {
@@ -225,13 +226,15 @@ macro_rules! expect_equality {
225226
};
226227
}
227228

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

237+
/// Return pairing where `$pairing_func` is the pairing function, `$g1` is/are group G1 elements and `$g2` is/are group G2 elements
235238
#[macro_export]
236239
macro_rules! pair_g2_g1 {
237240
($pairing_func: path, $g2: expr, $g1: expr) => {

‎utils/src/transcript.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Merlin transcripts
2+
13
use ark_ec::AffineRepr;
24
use ark_ff::fields::Field;
35
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};

0 commit comments

Comments
 (0)