Skip to content

Commit 7d1b001

Browse files
committed
Make serde optional feature
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent 0023be5 commit 7d1b001

162 files changed

Lines changed: 2504 additions & 2856 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ jobs:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v2
27+
- name: Cache cargo registry
28+
uses: actions/cache@v3
29+
with:
30+
path: ~/.cargo/registry
31+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
32+
- name: Cache cargo index
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/.cargo/git
36+
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
2737
- name: Install rust toolchain
2838
uses: actions-rs/toolchain@v1
2939
with:
@@ -34,36 +44,51 @@ jobs:
3444
- name: Build
3545
run: cargo build
3646

37-
build-no-std:
47+
build-matrix:
3848
runs-on: ubuntu-latest
49+
strategy:
50+
matrix:
51+
target:
52+
- ""
53+
- "--no-default-features --features=wasmer-sys"
54+
- "--no-default-features --features=wasmer-js --target wasm32-unknown-unknown"
55+
- "--no-default-features --features=serde,wasmer-js --target wasm32-unknown-unknown"
3956
steps:
4057
- uses: actions/checkout@v2
41-
- name: Install rust toolchain
42-
uses: actions-rs/toolchain@v1
58+
- name: Cache cargo registry
59+
uses: actions/cache@v3
4360
with:
44-
toolchain: stable
45-
override: true
46-
- name: Build without default features
47-
run: cargo build --no-default-features --features=wasmer-sys
48-
49-
build-wasm:
50-
runs-on: ubuntu-latest
51-
steps:
52-
- uses: actions/checkout@v2
61+
path: ~/.cargo/registry
62+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
63+
- name: Cache cargo index
64+
uses: actions/cache@v3
65+
with:
66+
path: ~/.cargo/git
67+
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
5368
- name: Install rust toolchain
5469
uses: actions-rs/toolchain@v1
5570
with:
5671
toolchain: stable
5772
override: true
58-
- name: Install WASM
59-
run: rustup target add wasm32-unknown-unknown
60-
- name: Build for WASM target
61-
run: cargo build --no-default-features --features=wasmer-js --target wasm32-unknown-unknown
73+
- name: Install WASM (if needed)
74+
run: rustup target add wasm32-unknown-unknown || true
75+
- name: Build (matrix)
76+
run: cargo build ${{ matrix.target }}
6277

6378
test:
6479
runs-on: ubuntu-latest
6580
steps:
6681
- uses: actions/checkout@v2
82+
- name: Cache cargo registry
83+
uses: actions/cache@v3
84+
with:
85+
path: ~/.cargo/registry
86+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
87+
- name: Cache cargo index
88+
uses: actions/cache@v3
89+
with:
90+
path: ~/.cargo/git
91+
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
6792
- name: Install rust toolchain
6893
uses: actions-rs/toolchain@v1
6994
with:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "cu
5151
ark-secp256r1 = { version = "^0.4.0", default-features = false }
5252
itertools = "0.14.0"
5353
sha3 = { version = "0.10.6", default-features = false }
54+
cfg_eval = { version = "0.1"}
5455

5556
[profile.release]
5657
lto = true

bbs_plus/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ ark-std.workspace = true
2020
digest.workspace = true
2121
rayon = {workspace = true, optional = true}
2222
itertools.workspace = true
23-
serde.workspace = true
24-
serde_with.workspace = true
23+
serde = { workspace = true, optional = true, default-features = false, features = ["derive"] }
24+
serde_with = { workspace = true, optional = true }
25+
cfg_eval.workspace = true
2526
zeroize.workspace = true
2627
schnorr_pok = { version = "0.23.0", default-features = false, path = "../schnorr_pok" }
2728
dock_crypto_utils = { version = "0.23.0", default-features = false, path = "../utils" }
@@ -37,7 +38,8 @@ test_utils = { path = "../test_utils" }
3738
sha3.workspace = true
3839

3940
[features]
40-
default = [ "parallel" ]
41-
std = [ "ark-ff/std", "ark-ec/std", "ark-std/std", "ark-serialize/std", "schnorr_pok/std", "dock_crypto_utils/std", "serde/std", "oblivious_transfer_protocols/std", "secret_sharing_and_dkg/std"]
41+
default = [ "parallel", "serde" ]
42+
serde = ["dep:serde", "serde_with", "dock_crypto_utils/serde", "schnorr_pok/serde", "oblivious_transfer_protocols/serde", "secret_sharing_and_dkg/serde"]
43+
std = [ "ark-ff/std", "ark-ec/std", "ark-std/std", "ark-serialize/std", "schnorr_pok/std", "dock_crypto_utils/std", "oblivious_transfer_protocols/std", "secret_sharing_and_dkg/std"]
4244
print-trace = [ "ark-std/print-trace", "schnorr_pok/print-trace", "dock_crypto_utils/print-trace" ]
4345
parallel = [ "std", "ark-ff/parallel", "ark-ec/parallel", "ark-std/parallel", "rayon", "schnorr_pok/parallel", "dock_crypto_utils/parallel", "oblivious_transfer_protocols/parallel", "secret_sharing_and_dkg/parallel"]

bbs_plus/src/error.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
use ark_serialize::SerializationError;
44
use ark_std::fmt::Debug;
5-
use dock_crypto_utils::{
6-
serde_utils::ArkSerializationError,
7-
try_iter::{IndexIsOutOfBounds, InvalidPair},
8-
};
5+
#[cfg(feature = "serde")]
6+
use dock_crypto_utils::serde_utils::ArkSerializationError;
7+
use dock_crypto_utils::try_iter::{IndexIsOutOfBounds, InvalidPair};
98
use oblivious_transfer_protocols::{error::OTError, ParticipantId};
109
use schnorr_pok::error::SchnorrError;
1110
use secret_sharing_and_dkg::error::SSError;
11+
#[cfg(feature = "serde")]
1212
use serde::Serialize;
1313

14-
#[derive(Debug, Serialize)]
14+
#[derive(Debug)]
15+
#[cfg_attr(feature = "serde", derive(Serialize))]
1516
pub enum BBSPlusError {
1617
CannotInvert0,
1718
NoMessageToSign,
@@ -26,7 +27,7 @@ pub enum BBSPlusError {
2627
/// 2nd schnorr proof failed during verification of proof of knowledge of signature
2728
SecondSchnorrVerificationFailed,
2829
InvalidMsgIdxForResponse(usize),
29-
#[serde(with = "ArkSerializationError")]
30+
#[cfg_attr(feature = "serde", serde(with = "ArkSerializationError"))]
3031
Serialization(SerializationError),
3132
SchnorrError(SchnorrError),
3233
MessageIndicesMustBeUniqueAndSorted(InvalidPair<usize>),

bbs_plus/src/proof.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ use ark_std::{
7373
UniformRand,
7474
};
7575
use core::mem;
76+
#[cfg(feature = "serde")]
77+
use dock_crypto_utils::serde_utils::*;
7678
use dock_crypto_utils::{
7779
misc::rand,
7880
randomized_pairing_check::RandomizedPairingChecker,
79-
serde_utils::*,
8081
signature::{
8182
msg_index_map_to_schnorr_response_map, msg_index_to_schnorr_response_index,
8283
schnorr_responses_to_msg_index_map, split_messages_and_blindings, MessageOrBlinding,
@@ -90,7 +91,9 @@ use schnorr_pok::{
9091
partial::PartialSchnorrResponse,
9192
SchnorrCommitment, SchnorrResponse,
9293
};
94+
#[cfg(feature = "serde")]
9395
use serde::{Deserialize, Serialize};
96+
#[cfg(feature = "serde")]
9497
use serde_with::serde_as;
9598
use zeroize::{Zeroize, ZeroizeOnDrop};
9699

@@ -103,54 +106,45 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
103106
/// pre-challenge (`init`) which is used to create the challenge and post-challenge (`gen_proof`). Thus, several instances of
104107
/// the protocol can be used together where the pre-challenge phase of all protocols is used to create a combined challenge
105108
/// and then that challenge is used in post-challenge phase of all protocols.
106-
#[serde_as]
109+
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_with::serde_as)]
107110
#[derive(
108-
Clone,
109-
PartialEq,
110-
Eq,
111-
Debug,
112-
Zeroize,
113-
ZeroizeOnDrop,
114-
CanonicalSerialize,
115-
CanonicalDeserialize,
116-
Serialize,
117-
Deserialize,
111+
Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize, Zeroize, ZeroizeOnDrop,
118112
)]
113+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
119114
pub struct PoKOfSignatureG1Protocol<E: Pairing> {
120115
#[zeroize(skip)]
121-
#[serde_as(as = "ArkObjectBytes")]
116+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
122117
pub A_prime: E::G1Affine,
123118
#[zeroize(skip)]
124-
#[serde_as(as = "ArkObjectBytes")]
119+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
125120
pub A_bar: E::G1Affine,
126121
#[zeroize(skip)]
127-
#[serde_as(as = "ArkObjectBytes")]
122+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
128123
pub d: E::G1Affine,
129124
/// For proving relation `A_bar - d = A_prime * -e + h_0 * r2`
130125
pub sc_comm_1: PokPedersenCommitmentProtocol<E::G1Affine>,
131126
/// For proving relation `g1 + \sum_{i in D}(h_i*m_i)` = `d*r3 + {h_0}*{-s'} + sum_{j notin D}(h_j*m_j)`
132127
pub sc_comm_2: SchnorrCommitment<E::G1Affine>,
133-
#[serde_as(as = "Vec<ArkObjectBytes>")]
128+
#[cfg_attr(feature = "serde", serde_as(as = "Vec<ArkObjectBytes>"))]
134129
sc_wits_2: Vec<E::ScalarField>,
135130
}
136131

137132
/// Proof of knowledge of BBS+ signature in G1. It contains the randomized signature, commitment (Schnorr step 1)
138133
/// and response (Schnorr step 3) to both Schnorr protocols in `T_` and `sc_resp_`
139-
#[serde_as]
140-
#[derive(
141-
Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
142-
)]
134+
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_with::serde_as)]
135+
#[derive(Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize)]
136+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
143137
pub struct PoKOfSignatureG1Proof<E: Pairing> {
144-
#[serde_as(as = "ArkObjectBytes")]
138+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
145139
pub A_prime: E::G1Affine,
146-
#[serde_as(as = "ArkObjectBytes")]
140+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
147141
pub A_bar: E::G1Affine,
148-
#[serde_as(as = "ArkObjectBytes")]
142+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
149143
pub d: E::G1Affine,
150144
/// Proof of relation `A_bar - d = A_prime * -e + h_0 * r2`
151145
pub sc_resp_1: PokPedersenCommitment<E::G1Affine>,
152146
/// Proof of relation `g1 + h1*m1 + h2*m2 +.... + h_i*m_i` = `d*r3 + {h_0}*{-s'} + h1*{-m1} + h2*{-m2} + .... + h_j*{-m_j}` for all disclosed messages `m_i` and for all undisclosed messages `m_j`
153-
#[serde_as(as = "ArkObjectBytes")]
147+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
154148
pub T2: E::G1Affine,
155149
/// The following could be achieved by using Either<SchnorrResponse, PartialSchnorrResponse> but serialization
156150
/// for Either is not supported out of the box and had to be implemented

bbs_plus/src/proof_23.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
use crate::{
2424
error::BBSPlusError,
25-
setup::{PreparedPublicKeyG2, SignatureParams23G1},
25+
setup::{PreparedPublicKeyG2, PreparedSignatureParams23G1, SignatureParams23G1},
2626
signature_23::Signature23G1,
2727
};
2828
use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup, Group, VariableBaseMSM};
@@ -34,62 +34,54 @@ use ark_std::{
3434
rand::RngCore,
3535
vec::Vec,
3636
};
37-
use itertools::{multiunzip, MultiUnzip};
38-
39-
use crate::setup::PreparedSignatureParams23G1;
37+
#[cfg(feature = "serde")]
38+
use dock_crypto_utils::serde_utils::ArkObjectBytes;
4039
use dock_crypto_utils::{
4140
expect_equality,
4241
extend_some::ExtendSome,
4342
misc::rand,
4443
randomized_pairing_check::RandomizedPairingChecker,
45-
serde_utils::ArkObjectBytes,
4644
signature::{MessageOrBlinding, MultiMessageSignatureParams},
4745
};
46+
use itertools::{multiunzip, MultiUnzip};
4847
use schnorr_pok::{error::SchnorrError, SchnorrCommitment, SchnorrResponse};
48+
#[cfg(feature = "serde")]
4949
use serde::{Deserialize, Serialize};
50+
#[cfg(feature = "serde")]
5051
use serde_with::serde_as;
5152
use zeroize::{Zeroize, ZeroizeOnDrop};
5253

5354
/// Protocol to prove knowledge of BBS signature in group G1.
54-
#[serde_as]
55+
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_with::serde_as)]
5556
#[derive(
56-
Clone,
57-
PartialEq,
58-
Eq,
59-
Debug,
60-
Zeroize,
61-
ZeroizeOnDrop,
62-
CanonicalSerialize,
63-
CanonicalDeserialize,
64-
Serialize,
65-
Deserialize,
57+
Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize, Zeroize, ZeroizeOnDrop,
6658
)]
59+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6760
pub struct PoKOfSignature23G1Protocol<E: Pairing> {
6861
#[zeroize(skip)]
69-
#[serde_as(as = "ArkObjectBytes")]
62+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
7063
pub A_bar: E::G1Affine,
7164
#[zeroize(skip)]
72-
#[serde_as(as = "ArkObjectBytes")]
65+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
7366
pub B_bar: E::G1Affine,
7467
/// For proving relation `g1 + \sum_{i in D}(h_i*m_i)` = `sum_{j notin D}(h_j*m_j)`
7568
pub sc_comm: SchnorrCommitment<E::G1Affine>,
76-
#[serde_as(as = "Vec<ArkObjectBytes>")]
69+
#[cfg_attr(feature = "serde", serde_as(as = "Vec<ArkObjectBytes>"))]
7770
sc_wits: Vec<E::ScalarField>,
7871
}
7972

8073
/// Proof of knowledge of BBS signature in G1. It contains the randomized signature, commitment (Schnorr step 1)
8174
/// and response (Schnorr step 3) to the Schnorr protocol in `T` and `sc_resp`
82-
#[serde_as]
83-
#[derive(
84-
Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
85-
)]
75+
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_with::serde_as)]
76+
#[derive(Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize)]
77+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8678
pub struct PoKOfSignature23G1Proof<E: Pairing> {
87-
#[serde_as(as = "ArkObjectBytes")]
79+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
8880
pub A_bar: E::G1Affine,
89-
#[serde_as(as = "ArkObjectBytes")]
81+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
9082
pub B_bar: E::G1Affine,
9183
/// Proof of relation `g1 + h1*m1 + h2*m2 +.... + h_i*m_i` = `h1*{-m1} + h2*{-m2} + .... + h_j*{-m_j}` for all disclosed messages `m_i` and for all undisclosed messages `m_j`
92-
#[serde_as(as = "ArkObjectBytes")]
84+
#[cfg_attr(feature = "serde", serde_as(as = "ArkObjectBytes"))]
9385
pub T: E::G1Affine,
9486
pub sc_resp: SchnorrResponse<E::G1Affine>,
9587
}

0 commit comments

Comments
 (0)