Skip to content

Commit

Permalink
move utils
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed May 22, 2023
1 parent 7cfe558 commit 98c49d1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 0 additions & 2 deletions ferveo-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub mod keypair;
pub mod serialization;
pub mod utils;

pub use keypair::*;
pub use serialization::*;
pub use utils::*;
8 changes: 5 additions & 3 deletions ferveo/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use std::{cmp::Ordering, collections::BTreeMap};

use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup, Group};
use ark_poly::EvaluationDomain;
use ferveo_common::{is_power_of_2, is_sorted, PublicKey};
use ferveo_common::PublicKey;
use measure_time::print_time;
use rand::RngCore;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_with::serde_as;

use crate::{
aggregate, AggregatedPvss, Error, EthereumAddress,
PubliclyVerifiableParams, PubliclyVerifiableSS, Pvss, Result, Validator,
aggregate,
utils::{is_power_of_2, is_sorted},
AggregatedPvss, Error, EthereumAddress, PubliclyVerifiableParams,
PubliclyVerifiableSS, Pvss, Result, Validator,
};

#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod primitives;
pub mod pvss;
pub mod validator;

mod utils;

pub use dkg::*;
pub use primitives::*;
pub use pvss::*;
Expand Down
8 changes: 3 additions & 5 deletions ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ark_poly::{
polynomial::univariate::DensePolynomial, DenseUVPolynomial,
EvaluationDomain,
};
use ferveo_common::is_sorted;
use group_threshold_cryptography as tpke;
use itertools::Itertools;
use rand::RngCore;
Expand All @@ -21,8 +20,8 @@ use tpke::{
use zeroize::{self, Zeroize, ZeroizeOnDrop};

use crate::{
batch_to_projective_g1, batch_to_projective_g2, Error, PVSSMap,
PubliclyVerifiableDkg, Result, Validator,
batch_to_projective_g1, batch_to_projective_g2, utils::is_sorted, Error,
PVSSMap, PubliclyVerifiableDkg, Result, Validator,
};

/// These are the blinded evaluations of shares of a single random polynomial
Expand Down Expand Up @@ -487,11 +486,10 @@ mod test_pvss {
use ark_bls12_381::Bls12_381 as EllipticCurve;
use ark_ec::AffineRepr;
use ark_ff::UniformRand;
use ferveo_common::is_sorted;
use rand::seq::SliceRandom;

use super::*;
use crate::dkg::test_common::*;
use crate::{dkg::test_common::*, utils::is_sorted};

type ScalarField = <EllipticCurve as Pairing>::ScalarField;
type G1 = <EllipticCurve as Pairing>::G1Affine;
Expand Down
22 changes: 22 additions & 0 deletions ferveo/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub fn is_power_of_2(n: u32) -> bool {
n != 0 && (n & (n - 1)) == 0
}

pub fn is_sorted<I>(data: I) -> bool
where
I: IntoIterator,
I::Item: Ord,
{
let mut data = data.into_iter();
let mut prev = match data.next() {
None => return true,
Some(x) => x,
};
for x in data {
if prev > x {
return false;
}
prev = x;
}
true
}

0 comments on commit 98c49d1

Please sign in to comment.