Skip to content

Commit fc97fb9

Browse files
olegnnlovesh
authored andcommitted
Move some of coconut helpers to dock_crypto_utils
1 parent da6a04b commit fc97fb9

File tree

33 files changed

+265
-266
lines changed

33 files changed

+265
-266
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ zeroize = { version = "1.5.5", features = ["derive"] }
4040
blake2 = { version = "0.10", default-features = false }
4141
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
4242
merlin = { version = "^3.0", default-features = false }
43-
legogroth16 = { version = "0.6.0" , default-features = false }
43+
legogroth16 = { version = "0.6.0" , default-features = false, path = "../legogroth16" }
4444

4545
[profile.release]
4646
lto = true

benches/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ authors.workspace = true
66
license.workspace = true
77

88
[dependencies]
9-
bbs_plus = { version = "0.11.0", default-features = false }
10-
schnorr_pok = { version = "0.9.0", default-features = false }
11-
vb_accumulator = { version = "0.12.0", default-features = false }
9+
bbs_plus = { version = "0.11.0", default-features = false, path = "../bbs_plus" }
10+
schnorr_pok = { version = "0.9.0", default-features = false, path = "../schnorr_pok" }
11+
vb_accumulator = { version = "0.12.0", default-features = false, path = "../vb_accumulator" }
1212
test_utils = { version = "0.1.0", default-features = false, path = "../test_utils" }
1313
ark-ff.workspace = true
1414
ark-ec.workspace = true

coconut/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ ark-std = { version = "0.4.0", default-features = false }
1717
ark-poly = { version = "0.4.1", default-features = false }
1818
ark-serialize = { version = "0.4.1", default-features = false, features = [ "derive" ] }
1919
serde = { version = "1.0.156", default-features = false, features = ["derive"] }
20-
dock_crypto_utils = { version = "0.9.0", default-features = false }
20+
dock_crypto_utils = { version = "0.9.0", default-features = false, path = "../utils" }
2121
digest = "0.10.6"
2222
zeroize = { version = "1.5.7", features = ["derive"] }
2323
rayon = { version = "1.7.0", optional = true }
24-
schnorr_pok = { version = "0.9.0", default-features = false }
24+
schnorr_pok = { version = "0.9.0", default-features = false, path = "../schnorr_pok" }
2525
itertools = "0.10.5"
2626
secret_sharing_and_dkg = { version = "0.2.0", default-features = false }
2727
serde_with = { version = "1.10.0", default-features = false, features = ["macros"] }

coconut/src/helpers/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,23 @@ use dock_crypto_utils::msm::multiply_field_elems_with_same_group_elem;
1212

1313
use schnorr_pok::error::SchnorrError;
1414

15-
pub mod aliases;
16-
pub mod extend_some;
17-
pub mod iter;
1815
pub mod owned_pairs;
1916
pub mod pairs;
20-
pub mod try_iter;
2117
pub mod with_schnorr_and_blindings;
2218
pub mod with_schnorr_response;
2319

24-
pub use aliases::*;
25-
pub use extend_some::*;
20+
pub use dock_crypto_utils::aliases::*;
21+
pub use dock_crypto_utils::extend_some::*;
22+
pub use dock_crypto_utils::iter::{self, *};
23+
pub use dock_crypto_utils::try_iter::{self, *};
2624
pub use iter::*;
2725
pub use owned_pairs::*;
2826
pub use pairs::*;
2927
pub use try_iter::*;
3028
pub use with_schnorr_and_blindings::*;
3129
pub use with_schnorr_response::*;
3230

33-
use crate::{impl_indexed_iter, impl_into_indexed_iter, join};
31+
use dock_crypto_utils::{impl_indexed_iter, impl_into_indexed_iter, join};
3432

3533
/// Generates an iterator of randoms producing `count` elements using the supplied `rng`.
3634
pub fn n_rand<T: UniformRand, R: RngCore>(

coconut/src/helpers/with_schnorr_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct WithSchnorrResponse<G: AffineRepr, V: CanonicalSerialize + CanonicalD
2828

2929
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
3030
pub struct IndiceRange(Range<usize>);
31-
crate::impl_deref! { IndiceRange(Range<usize>) }
31+
dock_crypto_utils::impl_deref! { IndiceRange(Range<usize>) }
3232

3333
impl CanonicalSerialize for IndiceRange {
3434
fn serialized_size(&self, compress: Compress) -> usize {

coconut/src/macros.rs

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
/// Concatenates supplied slices into one continuous vector.
2-
#[macro_export]
3-
macro_rules! concat_slices {
4-
($($slice: expr),+) => {
5-
[$(&$slice[..]),+].concat()
6-
}
7-
}
8-
9-
/// Implements `Deref`/`DeferMut` traits for the supplied wrapper and type.
10-
#[macro_export]
11-
macro_rules! impl_deref {
12-
($wrapper: ident$(<$($ty: ident: $($by: path),+),*>)?($type: path)) => {
13-
impl$(<$($ty: $($by)++),+>)* core::ops::Deref for $wrapper$(<$($ty),+>)* {
14-
type Target = $type;
15-
16-
fn deref(&self) -> &Self::Target {
17-
&self.0
18-
}
19-
}
20-
21-
impl$(<$($ty: $($by)++),+>)* core::ops::DerefMut for $wrapper$(<$($ty),+>)* {
22-
fn deref_mut(&mut self) -> &mut Self::Target {
23-
&mut self.0
24-
}
25-
}
26-
};
27-
}
28-
291
/// Convert given slices to `OwnedPairs`, panics in case of error.
302
#[macro_export]
313
macro_rules! owned_pairs {
@@ -61,185 +33,3 @@ macro_rules! try_pairs {
6133
$crate::helpers::Pairs::try_from((&$left[..], &$right[..]))
6234
};
6335
}
64-
65-
/// Calculates the product of pairing for supplied pairs.
66-
/// ```compile_fail
67-
/// multi_pairing! {
68-
/// a, c,
69-
/// b, d
70-
/// }
71-
/// ```
72-
/// Will be transformed to:
73-
/// ```compile_fail
74-
/// E::multi_pairing([a, b], [c, d])
75-
/// ```
76-
#[macro_export]
77-
macro_rules! multi_pairing {
78-
($($g1: expr, $g2: expr);+) => {
79-
$crate::multi_pairing! { using E: $($g1, $g2);+ }
80-
};
81-
(using $pairing_engine: path: $($g1: expr, $g2: expr);+) => {
82-
<$pairing_engine>::multi_pairing(
83-
[
84-
$($g1.into()),+
85-
],
86-
[
87-
$($g2.into()),+
88-
]
89-
)
90-
}
91-
}
92-
93-
/// Flattened `rayon::join(|| expr1, || rayon::join(|| expr2, || ...))`
94-
#[cfg(feature = "parallel")]
95-
#[macro_export]
96-
macro_rules! join {
97-
(@ $a: expr) => { $a };
98-
(@ $a: expr, $b: expr) => {
99-
rayon::join(|| $a, || $b)
100-
};
101-
(@ $a: expr, $b: expr, $($c: expr),+) => {{
102-
join!(@ $a, join!(@ $b, $($c),+))
103-
}};
104-
($($e: expr),+) => {{
105-
$crate::unnest_tuple!(
106-
$($e),+
107-
=>
108-
join!(@ $($e),+)
109-
)
110-
}}
111-
}
112-
113-
/// `(expr1, expr2, expr3...)`
114-
#[cfg(not(feature = "parallel"))]
115-
#[macro_export]
116-
macro_rules! join {
117-
($($e: expr),+) => {
118-
($($e),+)
119-
};
120-
}
121-
122-
/// `(a, (b, c)) => (a, b, c)`
123-
#[macro_export]
124-
macro_rules! unnest_tuple {
125-
($a: expr => $v: expr) => {{
126-
$v
127-
}};
128-
($a: expr, $b: expr => $v: expr) => {{
129-
let (_a, _b) = $v;
130-
131-
(_a, _b)
132-
}};
133-
($a: expr, $b: expr, $c: expr => $v: expr) => {{
134-
let (_a, (_b, _c)) = $v;
135-
136-
(_a, _b, _c)
137-
}};
138-
($a: expr, $b: expr, $c: expr, $d: expr => $v: expr) => {{
139-
let (_a, (_b, (_c, _d))) = $v;
140-
141-
(_a, _b, _c, _d)
142-
}};
143-
($a: expr, $b: expr, $c: expr, $d: expr, $e: expr => $v: expr) => {{
144-
let (_a, (_b, (_c, (_d, _e)))) = $v;
145-
146-
(_a, _b, _c, _d, _e)
147-
}};
148-
($a: expr, $b: expr, $c: expr, $d: expr, $e: expr, $f: expr => $v: expr) => {{
149-
let (_a, (_b, (_c, (_d, (_e, _f))))) = $v;
150-
151-
(_a, _b, _c, _d, _e, _f)
152-
}};
153-
}
154-
155-
/// `impl Iterator` or `impl ParallelIterator` depending on the `parallel` feature.
156-
#[macro_export]
157-
#[cfg(feature = "parallel")]
158-
macro_rules! impl_iter {
159-
(<Item = $item: ty> $($tt: tt)*) => { impl rayon::prelude::ParallelIterator<Item = $item> $($tt)* }
160-
}
161-
162-
/// `impl Iterator` or `impl ParallelIterator` depending on the `parallel` feature.
163-
#[macro_export]
164-
#[cfg(not(feature = "parallel"))]
165-
macro_rules! impl_iter {
166-
(<Item = $item: ty> $($tt: tt)*) => { impl core::iter::Iterator<Item = $item> $($tt)* }
167-
}
168-
169-
/// `impl IntoIterator` or `impl IntoParallelIterator` depending on the `parallel` feature.
170-
#[macro_export]
171-
#[cfg(feature = "parallel")]
172-
macro_rules! impl_into_iter {
173-
(<Item = $item: ty> $($tt: tt)*) => { impl rayon::prelude::IntoParallelIterator<Item = $item> $($tt)* }
174-
}
175-
176-
/// `impl IntoIterator` or `impl IntoParallelIterator` depending on the `parallel` feature.
177-
#[macro_export]
178-
#[cfg(not(feature = "parallel"))]
179-
macro_rules! impl_into_iter {
180-
(<Item = $item: ty> $($tt: tt)*) => { impl core::iter::IntoIterator<Item = $item> $($tt)* }
181-
}
182-
183-
/// `impl DoubleEndedIterator + ExactSizeIterator` or `impl IndexedParallelIterator` depending on the `parallel` feature.
184-
#[macro_export]
185-
#[cfg(feature = "parallel")]
186-
macro_rules! impl_indexed_iter {
187-
(<Item = $item: ty> $($tt: tt)*) => { impl rayon::prelude::IndexedParallelIterator<Item = $item> $($tt)* }
188-
}
189-
190-
/// `impl DoubleEndedIterator + ExactSizeIterator` or `impl IndexedParallelIterator` depending on the `parallel` feature.
191-
#[macro_export]
192-
#[cfg(not(feature = "parallel"))]
193-
macro_rules! impl_indexed_iter {
194-
(<Item = $item: ty> $($tt: tt)*) => { impl $crate::helpers::DoubleEndedExactSizeIterator<Item = $item> $($tt)* }
195-
}
196-
197-
/// `impl IntoIterator` where `IntoIter: DoubleEndedIterator + ExactSizeIterator` or `impl IntoParallelIterator` where `Iter: IndexedParallelIterator` depending on the `parallel` feature.
198-
#[macro_export]
199-
#[cfg(feature = "parallel")]
200-
macro_rules! impl_into_indexed_iter {
201-
(<Item = $item: ty> $($tt: tt)*) => { impl rayon::prelude::IntoParallelIterator<Item = $item, Iter = impl rayon::prelude::IndexedParallelIterator<Item = $item> $($tt)*> $($tt)* }
202-
}
203-
204-
/// `impl IntoIterator` where `IntoIter: DoubleEndedIterator + ExactSizeIterator` or `impl IntoParallelIterator` where `Iter: IndexedParallelIterator` depending on the `parallel` feature.
205-
#[macro_export]
206-
#[cfg(not(feature = "parallel"))]
207-
macro_rules! impl_into_indexed_iter {
208-
(<Item = $item: ty> $($tt: tt)*) => { impl core::iter::IntoIterator<Item = $item, IntoIter = impl $crate::helpers::DoubleEndedExactSizeIterator<Item = $item> $($tt)*> $($tt)* }
209-
}
210-
211-
#[cfg(test)]
212-
mod tests {
213-
#[test]
214-
fn unnest_tuple() {
215-
let a = unnest_tuple!(1 => 1);
216-
assert_eq!([a], [1]);
217-
let (a, b) = unnest_tuple!(_a, _b => (1, 2));
218-
assert_eq!([a, b], [1, 2]);
219-
let (a, b, c) = unnest_tuple!(_a, _b, _c => (1, (2, 3)));
220-
assert_eq!([a, b, c], [1, 2, 3]);
221-
let (a, b, c, d) = unnest_tuple!(_a, _b, _c, _d => (1, (2, (3, 4))));
222-
assert_eq!([a, b, c, d], [1, 2, 3, 4]);
223-
let (a, b, c, d, e) = unnest_tuple!(_a, _b, _c, _d, _e => (1, (2, (3, (4, 5)))));
224-
assert_eq!([a, b, c, d, e], [1, 2, 3, 4, 5]);
225-
let (a, b, c, d, e, f) =
226-
unnest_tuple!(_a, _b, _c, _d, _e, _f => (1, (2, (3, (4, (5, 6))))));
227-
assert_eq!([a, b, c, d, e, f], [1, 2, 3, 4, 5, 6]);
228-
}
229-
230-
#[test]
231-
fn join() {
232-
let a = join!(1);
233-
assert_eq!([a], [1]);
234-
let (a, b) = join!(1, 2);
235-
assert_eq!([a, b], [1, 2]);
236-
let (a, b, c) = join!(1, 2, 3);
237-
assert_eq!([a, b, c], [1, 2, 3]);
238-
let (a, b, c, d) = join!(1, 2, 3, 4);
239-
assert_eq!([a, b, c, d], [1, 2, 3, 4]);
240-
let (a, b, c, d, e) = join!(1, 2, 3, 4, 5);
241-
assert_eq!([a, b, c, d, e], [1, 2, 3, 4, 5]);
242-
let (a, b, c, d, e, f) = join!(1, 2, 3, 4, 5, 6);
243-
assert_eq!([a, b, c, d, e, f], [1, 2, 3, 4, 5, 6]);
244-
}
245-
}

coconut/src/proof/messages_pok/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use ark_ec::pairing::Pairing;
77
use ark_serialize::{CanonicalSerialize, Write};
88
use ark_std::{cfg_iter, rand::RngCore};
99

10+
use dock_crypto_utils::join;
1011
#[cfg(feature = "parallel")]
1112
use rayon::prelude::*;
1213
use schnorr_pok::{error::SchnorrError, SchnorrChallengeContributor};
1314

1415
use super::UnpackedBlindedMessages;
1516
use crate::{
1617
helpers::{schnorr_error, DoubleEndedExactSizeIterator, WithSchnorrAndBlindings},
17-
join, pairs,
18+
pairs,
1819
setup::SignatureParams,
1920
signature::message_commitment::MessageCommitmentRandomness,
2021
CommitMessage,

coconut/src/proof/messages_pok/multi_message_commitment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
2323
)]
2424
pub struct MultiMessageCommitment<E: Pairing>(#[serde_as(as = "ArkObjectBytes")] E::G1Affine);
25-
crate::impl_deref! { MultiMessageCommitment<E: Pairing>(E::G1Affine) }
25+
dock_crypto_utils::impl_deref! { MultiMessageCommitment<E: Pairing>(E::G1Affine) }
2626

2727
impl<E: Pairing> MultiMessageCommitment<E> {
2828
/// `g * o + \sum_{i}(h_{i} * m_{i})`

coconut/src/proof/signature_pok/k.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
Deserialize,
3333
)]
3434
pub struct K<E: Pairing>(#[serde_as(as = "ArkObjectBytes")] E::G2Affine);
35-
crate::impl_deref! { K<E: Pairing>(E::G2Affine) }
35+
dock_crypto_utils::impl_deref! { K<E: Pairing>(E::G2Affine) }
3636

3737
impl<E: Pairing> K<E> {
3838
/// `\sum_{j}(beta_tilde_{j} * m_{l}{j} + g_tilde * r_{l})`

coconut/src/proof/signature_pok/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ mod witnesses;
1616
use super::UnpackedBlindedMessages;
1717
use crate::{
1818
helpers::{schnorr_error, WithSchnorrAndBlindings},
19-
join, pairs,
19+
pairs,
2020
setup::{PublicKey, SignatureParams},
2121
CommitMessage, Signature,
2222
};
23+
use dock_crypto_utils::join;
2324

2425
pub use error::*;
2526
use k::*;

0 commit comments

Comments
 (0)