Skip to content

Commit

Permalink
Fix build, simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Mar 27, 2023
1 parent 1f8c436 commit 12ff67e
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 42 deletions.
8 changes: 4 additions & 4 deletions coconut/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ ark-std = { version = "0.4.0", default-features = false }
ark-poly = { version = "0.4.1", default-features = false }
ark-serialize = { version = "0.4.1", default-features = false, features = [ "derive" ] }
serde = { version = "1.0.156", default-features = false, features = ["derive"] }
dock_crypto_utils = { version = "0.9.0", default-features = false, path = "../utils" }
utils = { package = "dock_crypto_utils", version = "0.9.0", default-features = false, path = "../utils" }
digest = "0.10.6"
zeroize = { version = "1.5.7", features = ["derive"] }
rayon = { version = "1.7.0", optional = true }
schnorr_pok = { version = "0.9.0", default-features = false, path = "../schnorr_pok" }
itertools = "0.10.5"
secret_sharing_and_dkg = { version = "0.2.0", default-features = false }
secret_sharing_and_dkg = { version = "0.2.0", default-features = false, path = "../secret_sharing_and_dkg" }
serde_with = { version = "1.10.0", default-features = false, features = ["macros"] }

[dev-dependencies]
Expand All @@ -32,5 +32,5 @@ ark-bls12-381 = { version = "0.4.0", default-features = false, features = [ "cur

[features]
default = ["std", "parallel"]
parallel = ["ark-std/parallel", "ark-ec/parallel", "ark-poly/parallel", "ark-ff/parallel", "ark-std/parallel", "dock_crypto_utils/parallel", "schnorr_pok/parallel", "secret_sharing_and_dkg/parallel", "rayon"]
std = ["serde/std", "ark-serialize/std", "ark-std/std", "ark-poly/std", "ark-ec/std", "ark-ff/std", "dock_crypto_utils/std", "schnorr_pok/std", "secret_sharing_and_dkg/std"]
parallel = ["ark-std/parallel", "ark-ec/parallel", "ark-poly/parallel", "ark-ff/parallel", "ark-std/parallel", "utils/parallel", "schnorr_pok/parallel", "secret_sharing_and_dkg/parallel", "rayon"]
std = ["serde/std", "ark-serialize/std", "ark-std/std", "ark-poly/std", "ark-ec/std", "ark-ff/std", "utils/std", "schnorr_pok/std", "secret_sharing_and_dkg/std"]
12 changes: 6 additions & 6 deletions coconut/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ pub mod pairs;
pub mod with_schnorr_and_blindings;
pub mod with_schnorr_response;

pub use dock_crypto_utils::aliases::*;
pub use dock_crypto_utils::extend_some::*;
pub use dock_crypto_utils::iter::{self, *};
pub use dock_crypto_utils::misc::*;
pub use dock_crypto_utils::try_iter::{self, *};
pub use iter::*;
pub use owned_pairs::*;
pub use pairs::*;
pub use try_iter::*;
pub use utils::aliases::*;
pub use utils::extend_some::*;
pub use utils::iter::{self, *};
pub use utils::misc::*;
pub use utils::try_iter::{self, *};
pub use with_schnorr_and_blindings::*;
pub use with_schnorr_response::*;

use dock_crypto_utils::{impl_indexed_iter, impl_into_indexed_iter, join};
use utils::{impl_indexed_iter, impl_into_indexed_iter, join};

/// TODO remove when `SchnorrError` will derive `Eq`, `PartialEq`, `Clone`
pub fn schnorr_error(err: SchnorrError) -> String {
Expand Down
4 changes: 2 additions & 2 deletions coconut/src/helpers/with_schnorr_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use alloc::vec::Vec;
use ark_ec::AffineRepr;
use ark_serialize::*;
use core::{cmp::Ordering, ops::Range};
use dock_crypto_utils::serde_utils::ArkObjectBytes;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_with::serde_as;
use utils::serde_utils::ArkObjectBytes;

use schnorr_pok::{
error::SchnorrError, SchnorrChallengeContributor, SchnorrCommitment, SchnorrResponse,
Expand All @@ -28,7 +28,7 @@ pub struct WithSchnorrResponse<G: AffineRepr, V: CanonicalSerialize + CanonicalD

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct IndiceRange(Range<usize>);
dock_crypto_utils::impl_deref! { IndiceRange(Range<usize>) }
utils::impl_deref! { IndiceRange(Range<usize>) }

impl CanonicalSerialize for IndiceRange {
fn serialized_size(&self, compress: Compress) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion coconut/src/proof/messages_pok/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use ark_ec::pairing::Pairing;
use ark_serialize::{CanonicalSerialize, Write};
use ark_std::{cfg_iter, rand::RngCore};

use dock_crypto_utils::join;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use schnorr_pok::{error::SchnorrError, SchnorrChallengeContributor};
use utils::join;

use super::UnpackedBlindedMessages;
use crate::{
Expand Down
4 changes: 2 additions & 2 deletions coconut/src/proof/messages_pok/multi_message_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use core::{borrow::Borrow, iter::once};
use ark_ec::{pairing::Pairing, CurveGroup};
use ark_serialize::*;
use ark_std::rand::RngCore;
use dock_crypto_utils::serde_utils::ArkObjectBytes;
use schnorr_pok::{error::SchnorrError, SchnorrCommitment};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use utils::serde_utils::ArkObjectBytes;

use crate::{
helpers::{rand, OwnedPairs, Pairs, WithSchnorrAndBlindings, WithSchnorrResponse},
Expand All @@ -22,7 +22,7 @@ use crate::{
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
)]
pub struct MultiMessageCommitment<E: Pairing>(#[serde_as(as = "ArkObjectBytes")] E::G1Affine);
dock_crypto_utils::impl_deref! { MultiMessageCommitment<E: Pairing>(E::G1Affine) }
utils::impl_deref! { MultiMessageCommitment<E: Pairing>(E::G1Affine) }

impl<E: Pairing> MultiMessageCommitment<E> {
/// `g * o + \sum_{i}(h_{i} * m_{i})`
Expand Down
4 changes: 2 additions & 2 deletions coconut/src/proof/signature_pok/k.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use alloc::vec::Vec;
use ark_serialize::*;
use core::{borrow::Borrow, iter::once};
use dock_crypto_utils::serde_utils::ArkObjectBytes;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use utils::serde_utils::ArkObjectBytes;

use ark_ec::{pairing::Pairing, CurveGroup};

Expand Down Expand Up @@ -32,7 +32,7 @@ use crate::{
Deserialize,
)]
pub struct K<E: Pairing>(#[serde_as(as = "ArkObjectBytes")] E::G2Affine);
dock_crypto_utils::impl_deref! { K<E: Pairing>(E::G2Affine) }
utils::impl_deref! { K<E: Pairing>(E::G2Affine) }

impl<E: Pairing> K<E> {
/// `\sum_{j}(beta_tilde_{j} * m_{l}{j} + g_tilde * r_{l})`
Expand Down
2 changes: 1 addition & 1 deletion coconut/src/proof/signature_pok/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
setup::{PublicKey, SignatureParams},
CommitMessage, Signature,
};
use dock_crypto_utils::join;
use utils::join;

pub use error::*;
use k::*;
Expand Down
4 changes: 2 additions & 2 deletions coconut/src/proof/signature_pok/proof.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alloc::vec::Vec;
use ark_ec::pairing::Pairing;
use ark_serialize::*;
use dock_crypto_utils::join;
use dock_crypto_utils::randomized_pairing_check::RandomizedPairingChecker;
use serde::{Deserialize, Serialize};
use utils::join;
use utils::randomized_pairing_check::RandomizedPairingChecker;

use crate::{
helpers::{pluck_missed, take_while_pairs_unique_sorted, SendIfParallel, WithSchnorrResponse},
Expand Down
2 changes: 1 addition & 1 deletion coconut/src/proof/signature_pok/randomized_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use alloc::vec::Vec;
use ark_ec::{pairing::Pairing, AffineRepr, Group};
use ark_ff::PrimeField;
use ark_serialize::*;
use dock_crypto_utils::join;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use utils::join;

use crate::{
helpers::{pair_valid_pairs_with_slice, IdxAsc, OwnedPairs},
Expand Down
4 changes: 2 additions & 2 deletions coconut/src/setup/keypair/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use alloc::vec::Vec;
use ark_ec::{pairing::Pairing, AffineRepr};
use ark_ff::PrimeField;

use dock_crypto_utils::serde_utils::ArkObjectBytes;
use utils::serde_utils::ArkObjectBytes;

use ark_serialize::*;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

use crate::{helpers::points, setup::SignatureParams};
use dock_crypto_utils::join;
use utils::join;

use super::SecretKey;

Expand Down
2 changes: 1 addition & 1 deletion coconut/src/setup/keypair/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ark_std::rand::RngCore;
use zeroize::{Zeroize, ZeroizeOnDrop};

use crate::helpers::{n_rand, rand, FullDigest};
use dock_crypto_utils::join;
use utils::join;

/// `SecretKey` used in Pointcheval-Sanders signature scheme.
#[derive(
Expand Down
6 changes: 2 additions & 4 deletions coconut/src/setup/signature_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use alloc::vec::Vec;
use ark_ec::pairing::Pairing;
use ark_serialize::*;
use ark_std::cfg_into_iter;
use dock_crypto_utils::{
hashing_utils::affine_group_elem_from_try_and_incr, serde_utils::ArkObjectBytes,
};
use serde_with::serde_as;
use utils::{hashing_utils::affine_group_elem_from_try_and_incr, serde_utils::ArkObjectBytes};

#[cfg(feature = "parallel")]
use rayon::prelude::*;
use serde::{Deserialize, Serialize};

use dock_crypto_utils::{concat_slices, join};
use utils::{concat_slices, join};

/// Parameters generated by a random oracle.
#[serde_as]
Expand Down
2 changes: 1 addition & 1 deletion coconut/src/signature/aggregated_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Result<T, E = AggregatedPSError> = core::result::Result<T, E>;
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
)]
pub struct AggregatedSignature<E: Pairing>(Signature<E>);
dock_crypto_utils::impl_deref! { AggregatedSignature<E: Pairing>(Signature<E>) }
utils::impl_deref! { AggregatedSignature<E: Pairing>(Signature<E>) }

impl<E: Pairing> AggregatedSignature<E> {
/// Creates new `AggregatedSignature` using supplied signatures which must be provided
Expand Down
2 changes: 1 addition & 1 deletion coconut/src/signature/blind_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use ark_ec::pairing::Pairing;
use alloc::vec::Vec;
use ark_serialize::*;
use ark_std::cfg_into_iter;
use dock_crypto_utils::join;
use itertools::{process_results, Itertools};
use utils::join;

use super::{error::BlindPSError, ps_signature::Signature};
use crate::{
Expand Down
6 changes: 3 additions & 3 deletions coconut/src/signature/message_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use ark_ec::{pairing::Pairing, CurveGroup};

use ark_serialize::*;
use ark_std::{cfg_into_iter, rand::RngCore};
use dock_crypto_utils::serde_utils::ArkObjectBytes;
use utils::serde_utils::ArkObjectBytes;

#[cfg(feature = "parallel")]
use rayon::prelude::*;
use schnorr_pok::{error::SchnorrError, SchnorrCommitment};

use dock_crypto_utils::{impl_indexed_iter, impl_into_indexed_iter};
use utils::{impl_indexed_iter, impl_into_indexed_iter};

use crate::{
helpers::{n_rand, WithSchnorrAndBlindings, WithSchnorrResponse},
Expand All @@ -27,7 +27,7 @@ use crate::{
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
)]
pub struct MessageCommitment<E: Pairing>(#[serde_as(as = "ArkObjectBytes")] E::G1Affine);
dock_crypto_utils::impl_deref! { MessageCommitment<E: Pairing>(E::G1Affine) }
utils::impl_deref! { MessageCommitment<E: Pairing>(E::G1Affine) }

impl<E: Pairing> MessageCommitment<E> {
/// `g * o + h * m`.
Expand Down
6 changes: 3 additions & 3 deletions coconut/src/signature/ps_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use ark_ff::{BigInteger, PrimeField};
use ark_serialize::*;
use ark_std::{cfg_into_iter, rand::RngCore, UniformRand, Zero};
use digest::Digest;
use dock_crypto_utils::serde_utils::ArkObjectBytes;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use utils::serde_utils::ArkObjectBytes;

use dock_crypto_utils::hashing_utils::projective_group_elem_from_try_and_incr;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use utils::hashing_utils::projective_group_elem_from_try_and_incr;

use crate::{
helpers::Pairs,
setup::{PublicKey, SecretKey, SignatureParams},
try_pairs, PSError,
};
use dock_crypto_utils::multi_pairing;
use utils::multi_pairing;

type Result<T, E = PSError> = core::result::Result<T, E>;

Expand Down
2 changes: 1 addition & 1 deletion secret_sharing_and_dkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ark-std.workspace = true
ark-serialize.workspace = true
ark-poly.workspace = true
digest.workspace = true
rayon = {workspace = true, optional = true}
rayon = { workspace = true, optional = true }
serde.workspace = true
serde_with.workspace = true
zeroize.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion utils/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ pub trait PairValidator<I> {
fn validate(&self, previous: &Self::MappedItem, current: &Self::MappedItem) -> bool;
}

impl<I, M, MapF: Fn(&I) -> M, CmpF: Fn(&M, &M) -> bool> PairValidator<I> for (MapF, CmpF) {
impl<I, M, MapF, ValidateF> PairValidator<I> for (MapF, ValidateF)
where
MapF: Fn(&I) -> M,
ValidateF: Fn(&M, &M) -> bool,
{
type MappedItem = M;

fn map(&self, item: &I) -> M {
Expand Down
10 changes: 6 additions & 4 deletions utils/src/misc.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use crate::msm::multiply_field_elems_with_same_group_elem;
use crate::{
aliases::DoubleEndedExactSizeIterator, msm::multiply_field_elems_with_same_group_elem,
};
use alloc::vec::Vec;
use ark_ec::{AffineRepr, CurveGroup};
use ark_std::{rand::RngCore, UniformRand};
use core::cmp::Ord;

/// Returns `true` is `first` is less than `second`.
/// Returns `true` if `first` is less than `second`.
pub fn is_lt<I: Ord>(first: &I, second: &I) -> bool {
Ord::cmp(first, second).is_lt()
first.cmp(second).is_lt()
}

/// Generates an iterator of randoms producing `count` elements using the supplied `rng`.
pub fn n_rand<T: UniformRand, R: RngCore>(
rng: &'_ mut R,
count: usize,
) -> impl Iterator<Item = T> + '_ {
) -> impl DoubleEndedExactSizeIterator<Item = T> + '_ {
(0..count).map(move |_| rand(rng))
}

Expand Down

0 comments on commit 12ff67e

Please sign in to comment.