Skip to content

Commit bb6850c

Browse files
committed
Upgrade wasmer to 3.0, add serializations and use forked merlin with
serialization Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent 15640a4 commit bb6850c

Some content is hidden

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

51 files changed

+2191
-527
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ members = [
1414
"delegatable_credentials",
1515
"secret_sharing_and_dkg",
1616
"legogroth16",
17-
"oblivious_transfer"
17+
"oblivious_transfer",
18+
"merlin"
1819
]
1920
resolver = "2"
2021

@@ -40,8 +41,8 @@ serde_with = { version = "1.10.0", default-features = false, features = ["macros
4041
zeroize = { version = "1.6.0", features = ["derive"] }
4142
blake2 = { version = "0.10", default-features = false }
4243
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
43-
merlin = { version = "^3.0", default-features = false }
44-
legogroth16 = { version = "0.6.0" , default-features = false }
44+
merlin = { package = "dock_merlin", version = "1.0", default-features = false, path = "./merlin" }
45+
legogroth16 = { version = "0.8.0" , default-features = false }
4546

4647
[profile.release]
4748
lto = true

bbs_plus/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bbs_plus"
3-
version = "0.14.0"
3+
version = "0.15.0"
44
edition.workspace = true
55
authors.workspace = true
66
license.workspace = true
@@ -19,10 +19,10 @@ ark-std.workspace = true
1919
digest.workspace = true
2020
rayon = {workspace = true, optional = true}
2121
itertools = "0.10.5"
22-
schnorr_pok = { version = "0.11.0", default-features = false, path = "../schnorr_pok" }
23-
dock_crypto_utils = { version = "0.12.0", default-features = false, path = "../utils" }
24-
oblivious_transfer_protocols = { version = "0.1.0", default-features = false, path = "../oblivious_transfer" }
25-
secret_sharing_and_dkg = { version = "0.4.0", default-features = false, path = "../secret_sharing_and_dkg" }
22+
schnorr_pok = { version = "0.12.0", default-features = false, path = "../schnorr_pok" }
23+
dock_crypto_utils = { version = "0.13.0", default-features = false, path = "../utils" }
24+
oblivious_transfer_protocols = { version = "0.2.0", default-features = false, path = "../oblivious_transfer" }
25+
secret_sharing_and_dkg = { version = "0.6.0", default-features = false, path = "../secret_sharing_and_dkg" }
2626
sha3 = { version = "0.10.6", default-features = false }
2727
serde.workspace = true
2828
serde_with.workspace = true

bbs_plus/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub enum BBSPlusError {
4848
UnexpectedMultiplicationParty2(ParticipantId),
4949
IncorrectEByParticipant(ParticipantId),
5050
IncorrectSByParticipant(ParticipantId),
51+
ParticipantCannotBePresentInOthers(ParticipantId),
5152
NotABaseOTSender(ParticipantId),
5253
NotABaseOTReceiver(ParticipantId),
5354
AlreadyHaveSenderPubkeyFrom(ParticipantId),

bbs_plus/src/threshold/base_ot_phase.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use crate::error::BBSPlusError;
55
use ark_ec::AffineRepr;
6+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
67
use ark_std::{
78
collections::{BTreeMap, BTreeSet},
89
rand::RngCore,
@@ -18,10 +19,14 @@ use oblivious_transfer_protocols::{
1819
},
1920
Bit, ParticipantId,
2021
};
22+
use serde::{Deserialize, Serialize};
2123

2224
/// The participant runs an independent base OT with each participant and stores each OT's state. If
2325
/// its id is less than other's then it acts as an OT sender else it acts as a receiver
24-
#[derive(Clone, Debug, PartialEq)]
26+
#[derive(
27+
Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
28+
)]
29+
#[serde(bound = "")]
2530
pub struct BaseOTPhase<G: AffineRepr> {
2631
pub id: ParticipantId,
2732
/// Number of base OTs to perform
@@ -36,35 +41,37 @@ pub struct BaseOTPhase<G: AffineRepr> {
3641
pub receiver_responder: BTreeMap<ParticipantId, VSROTResponder>,
3742
}
3843

39-
#[derive(Clone, Debug, PartialEq)]
44+
#[derive(
45+
Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
46+
)]
4047
pub struct BaseOTPhaseOutput {
4148
pub id: ParticipantId,
4249
pub sender_keys: BTreeMap<ParticipantId, OneOfTwoROTSenderKeys>,
4350
pub receiver: BTreeMap<ParticipantId, (Vec<Bit>, ROTReceiverKeys)>,
4451
}
4552

53+
#[derive(
54+
Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
55+
)]
56+
#[serde(bound = "")]
57+
pub struct SenderPubKeyAndProof<G: AffineRepr>(SenderPubKey<G>, SecretKnowledgeProof<G>);
58+
4659
impl<G: AffineRepr> BaseOTPhase<G> {
4760
pub fn init<R: RngCore, D: Digest>(
4861
rng: &mut R,
4962
id: ParticipantId,
5063
others: BTreeSet<ParticipantId>,
5164
num_base_ot: u16,
5265
B: &G,
53-
) -> Result<
54-
(
55-
Self,
56-
BTreeMap<ParticipantId, (SenderPubKey<G>, SecretKnowledgeProof<G>)>,
57-
),
58-
BBSPlusError,
59-
> {
66+
) -> Result<(Self, BTreeMap<ParticipantId, SenderPubKeyAndProof<G>>), BBSPlusError> {
6067
let mut base_ot_sender_setup = BTreeMap::new();
6168
let mut base_ot_receiver_choices = BTreeMap::new();
6269
let mut base_ot_s = BTreeMap::new();
6370
for other in others {
6471
if id < other {
6572
let (setup, S, proof) =
6673
ROTSenderSetup::new_verifiable::<R, D>(rng, num_base_ot, B)?;
67-
base_ot_s.insert(other, (S, proof));
74+
base_ot_s.insert(other, SenderPubKeyAndProof(S, proof));
6875
base_ot_sender_setup.insert(other, setup);
6976
} else {
7077
let base_ot_choices = (0..num_base_ot)
@@ -92,8 +99,7 @@ impl<G: AffineRepr> BaseOTPhase<G> {
9299
&mut self,
93100
rng: &mut R,
94101
sender_id: ParticipantId,
95-
S: SenderPubKey<G>,
96-
proof: SecretKnowledgeProof<G>,
102+
sender_pk_and_proof: SenderPubKeyAndProof<G>,
97103
B: &G,
98104
) -> Result<ReceiverPubKeys<G>, BBSPlusError> {
99105
if self.id == sender_id {
@@ -108,6 +114,7 @@ impl<G: AffineRepr> BaseOTPhase<G> {
108114
if self.receiver_keys.contains_key(&sender_id) {
109115
return Err(BBSPlusError::AlreadyHaveSenderPubkeyFrom(sender_id));
110116
}
117+
let SenderPubKeyAndProof(S, proof) = sender_pk_and_proof;
111118
let (receiver_keys, pub_key) = ROTReceiverKeys::new_verifiable::<_, _, D, KEY_SIZE>(
112119
rng,
113120
self.count,
@@ -276,9 +283,9 @@ pub mod tests {
276283
}
277284

278285
for (sender_id, pks) in sender_pks {
279-
for (id, (pk, proof)) in pks {
286+
for (id, pk) in pks {
280287
let recv_pk = base_ots[id as usize - 1]
281-
.receive_sender_pubkey::<_, Blake2b512, KEY_SIZE>(rng, sender_id, pk, proof, &B)
288+
.receive_sender_pubkey::<_, Blake2b512, KEY_SIZE>(rng, sender_id, pk, &B)
282289
.unwrap();
283290
receiver_pks.insert((id, sender_id), recv_pk);
284291
}

bbs_plus/src/threshold/cointoss.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Party<F: PrimeField, const SALT_SIZE: usize> {
2828
// pub own_shares_and_salts: Vec<(F, [u8; 2*SECURITY_PARAM])>,
2929
/// Stores commitments to shares received from other parties and used to verify against the
3030
/// shares received from them in a future round
31-
pub commitments: BTreeMap<ParticipantId, Commitments>,
31+
pub other_commitments: BTreeMap<ParticipantId, Commitments>,
3232
/// Stores shares received from other parties and used to compute the joint randomness
3333
pub other_shares: BTreeMap<ParticipantId, Vec<F>>,
3434
}
@@ -56,7 +56,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
5656
id,
5757
protocol_id,
5858
own_shares_and_salts: shares_and_salts,
59-
commitments: Default::default(),
59+
other_commitments: Default::default(),
6060
other_shares: Default::default(),
6161
},
6262
Commitments(commitments),
@@ -72,7 +72,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
7272
if self.id == sender_id {
7373
return Err(BBSPlusError::SenderIdCannotBeSameAsSelf(sender_id, self.id));
7474
}
75-
if self.commitments.contains_key(&sender_id) {
75+
if self.other_commitments.contains_key(&sender_id) {
7676
return Err(BBSPlusError::AlreadyHaveCommitmentFromParticipant(
7777
sender_id,
7878
));
@@ -83,7 +83,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
8383
commitments.0.len(),
8484
));
8585
}
86-
self.commitments.insert(sender_id, commitments);
86+
self.other_commitments.insert(sender_id, commitments);
8787
Ok(())
8888
}
8989

@@ -97,7 +97,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
9797
if self.id == sender_id {
9898
return Err(BBSPlusError::SenderIdCannotBeSameAsSelf(sender_id, self.id));
9999
}
100-
if !self.commitments.contains_key(&sender_id) {
100+
if !self.other_commitments.contains_key(&sender_id) {
101101
return Err(BBSPlusError::MissingCommitmentFromParticipant(sender_id));
102102
}
103103
if self.other_shares.contains_key(&sender_id) {
@@ -110,7 +110,7 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
110110
));
111111
}
112112
let expected_commitments = Self::compute_commitments(&shares_and_salts, &self.protocol_id);
113-
if expected_commitments != self.commitments.get(&sender_id).unwrap().0 {
113+
if expected_commitments != self.other_commitments.get(&sender_id).unwrap().0 {
114114
return Err(BBSPlusError::IncorrectCommitment);
115115
}
116116
self.other_shares.insert(
@@ -134,13 +134,18 @@ impl<F: PrimeField, const SALT_SIZE: usize> Party<F, SALT_SIZE> {
134134
}
135135

136136
pub fn has_commitment_from(&self, id: &ParticipantId) -> bool {
137-
self.commitments.contains_key(id)
137+
self.other_commitments.contains_key(id)
138138
}
139139

140140
pub fn has_shares_from(&self, id: &ParticipantId) -> bool {
141141
self.other_shares.contains_key(id)
142142
}
143143

144+
/// Returns true if it has got shares from all other participants that sent commitments.
145+
pub fn has_shares_from_all_who_committed(&self) -> bool {
146+
self.other_shares.len() == self.other_commitments.len()
147+
}
148+
144149
// pub const fn salt_size() -> usize {
145150
// 2 * SECURITY_PARAM
146151
// }
@@ -211,16 +216,23 @@ pub mod tests {
211216

212217
// All parties send their shares to others
213218
let start = Instant::now();
214-
for i in 1..=num_parties {
215-
for j in 1..=num_parties {
216-
if i != j {
217-
let share = parties[j as usize - 1].own_shares_and_salts.clone();
218-
parties[i as usize - 1].receive_shares(j, share).unwrap();
219+
for receiver_id in 1..=num_parties {
220+
for sender_id in 1..=num_parties {
221+
if receiver_id != sender_id {
222+
assert!(
223+
!parties[receiver_id as usize - 1].has_shares_from_all_who_committed()
224+
);
225+
let share = parties[sender_id as usize - 1].own_shares_and_salts.clone();
226+
parties[receiver_id as usize - 1]
227+
.receive_shares(sender_id, share)
228+
.unwrap();
219229
}
220230
}
231+
assert!(parties[receiver_id as usize - 1].has_shares_from_all_who_committed());
221232
}
222233
let process_shares_time = start.elapsed();
223234

235+
// Shares are received correctly
224236
for i in 1..=num_parties {
225237
for j in 1..=num_parties {
226238
if i != j {
@@ -237,6 +249,10 @@ pub mod tests {
237249
}
238250
}
239251

252+
for i in 0..num_parties as usize {
253+
assert!(parties[i].has_shares_from_all_who_committed());
254+
}
255+
240256
// All parties compute the joint randomness
241257
let start = Instant::now();
242258
let mut joint_randomness = vec![];

bbs_plus/src/threshold/multiplication_phase.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::{error::BBSPlusError, threshold::base_ot_phase::BaseOTPhaseOutput};
44
use ark_ff::PrimeField;
5+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
56
use ark_std::{
67
collections::{BTreeMap, BTreeSet},
78
rand::RngCore,
@@ -20,25 +21,35 @@ use oblivious_transfer_protocols::{
2021
};
2122

2223
/// The participant will acts as
23-
/// - a receiver in OT extension where its id is less than other participant
24-
/// - a sender in OT extension where its id is greater than other participant
25-
#[derive(Clone)]
24+
/// - a receiver in OT extension, also called Party2 in multiplication protocol, and its id is less than other participant
25+
/// - a sender in OT extension, also called Party1 in multiplication protocol, and its id is greater than other participant
26+
#[derive(Clone, CanonicalSerialize, CanonicalDeserialize)]
2627
pub struct Phase2<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16> {
2728
pub id: ParticipantId,
2829
/// Number of threshold signatures being generated in a single batch.
2930
pub batch_size: usize,
3031
/// Transcripts to record protocol interactions with each participant and later used to generate random challenges
3132
pub transcripts: BTreeMap<ParticipantId, Merlin>,
3233
pub ote_params: MultiplicationOTEParams<KAPPA, STATISTICAL_SECURITY_PARAMETER>,
34+
/// Map where this participant plays the role of sender, i.e Party1
3335
pub multiplication_party1:
3436
BTreeMap<ParticipantId, Party1<F, KAPPA, STATISTICAL_SECURITY_PARAMETER>>,
37+
/// Map where this participant plays the role of receiver, i.e Party2
3538
pub multiplication_party2:
3639
BTreeMap<ParticipantId, Party2<F, KAPPA, STATISTICAL_SECURITY_PARAMETER>>,
3740
pub z_A: BTreeMap<ParticipantId, (Vec<F>, Vec<F>)>,
3841
pub z_B: BTreeMap<ParticipantId, (Vec<F>, Vec<F>)>,
3942
}
4043

41-
#[derive(Clone, Debug, PartialEq)]
44+
/// Message sent from Party2 to Party1 of multiplication protocol
45+
#[derive(Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
46+
pub struct Message1<F: PrimeField>(BitMatrix, KOSRLC, MaskedInputs<F>);
47+
48+
/// Message sent from Party1 to Party2 of multiplication protocol. This message is created after Part1 processes `Message1`
49+
#[derive(Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
50+
pub struct Message2<F: PrimeField>(CorrelationTag<F>, RLC<F>, MaskedInputs<F>);
51+
52+
#[derive(Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize)]
4253
pub struct Phase2Output<F: PrimeField> {
4354
pub z_A: BTreeMap<ParticipantId, (Vec<F>, Vec<F>)>,
4455
pub z_B: BTreeMap<ParticipantId, (Vec<F>, Vec<F>)>,
@@ -56,13 +67,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
5667
others: BTreeSet<ParticipantId>,
5768
ote_params: MultiplicationOTEParams<KAPPA, STATISTICAL_SECURITY_PARAMETER>,
5869
gadget_vector: &GadgetVector<F, KAPPA, STATISTICAL_SECURITY_PARAMETER>,
59-
) -> Result<
60-
(
61-
Self,
62-
BTreeMap<ParticipantId, (BitMatrix, KOSRLC, MaskedInputs<F>)>,
63-
),
64-
BBSPlusError,
65-
> {
70+
) -> Result<(Self, BTreeMap<ParticipantId, Message1<F>>), BBSPlusError> {
6671
assert_eq!(masked_signing_key_share.len(), masked_r.len());
6772
let batch_size = masked_signing_key_share.len();
6873

@@ -108,7 +113,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
108113
&gadget_vector,
109114
)?;
110115
multiplication_party2.insert(other, party2);
111-
Us.insert(other, (U, rlc, gamma));
116+
Us.insert(other, Message1(U, rlc, gamma));
112117
} else {
113118
return Err(BBSPlusError::MissingOTSenderFor(other));
114119
}
@@ -130,20 +135,20 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
130135
))
131136
}
132137

133-
pub fn receive_u<D: Default + DynDigest + Clone>(
138+
/// Process received message from Party2 of multiplication protocol
139+
pub fn receive_message1<D: Default + DynDigest + Clone>(
134140
&mut self,
135141
sender_id: ParticipantId,
136-
U: BitMatrix,
137-
rlc: KOSRLC,
138-
gamma: MaskedInputs<F>,
142+
message: Message1<F>,
139143
gadget_vector: &GadgetVector<F, KAPPA, STATISTICAL_SECURITY_PARAMETER>,
140-
) -> Result<(CorrelationTag<F>, RLC<F>, MaskedInputs<F>), BBSPlusError> {
144+
) -> Result<Message2<F>, BBSPlusError> {
141145
if self.multiplication_party2.contains_key(&sender_id) {
142146
return Err(BBSPlusError::NotAMultiplicationParty2(sender_id));
143147
}
144148
if !self.multiplication_party1.contains_key(&sender_id) {
145149
return Err(BBSPlusError::NotAMultiplicationParty1(sender_id));
146150
}
151+
let Message1(U, rlc, gamma) = message;
147152
let party1 = self.multiplication_party1.remove(&sender_id).unwrap();
148153
let trans = self.transcripts.get_mut(&sender_id).unwrap();
149154

@@ -160,15 +165,14 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
160165
}
161166
}
162167
self.z_A.insert(sender_id, (z_A_0, z_A_1));
163-
Ok((tau, r, gamma_a))
168+
Ok(Message2(tau, r, gamma_a))
164169
}
165170

166-
pub fn receive_tau<D: Default + DynDigest + Clone>(
171+
/// Process received message from Party1 of multiplication protocol
172+
pub fn receive_message2<D: Default + DynDigest + Clone>(
167173
&mut self,
168174
sender_id: ParticipantId,
169-
tau: CorrelationTag<F>,
170-
rlc: RLC<F>,
171-
gamma: MaskedInputs<F>,
175+
message: Message2<F>,
172176
gadget_vector: &GadgetVector<F, KAPPA, STATISTICAL_SECURITY_PARAMETER>,
173177
) -> Result<(), BBSPlusError> {
174178
if self.multiplication_party1.contains_key(&sender_id) {
@@ -177,7 +181,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
177181
if !self.multiplication_party2.contains_key(&sender_id) {
178182
return Err(BBSPlusError::NotAMultiplicationParty2(sender_id));
179183
}
180-
184+
let Message2(tau, rlc, gamma) = message;
181185
let party2 = self.multiplication_party2.remove(&sender_id).unwrap();
182186
let trans = self.transcripts.get_mut(&sender_id).unwrap();
183187
let shares = party2.receive::<D>(tau, rlc, gamma, trans, &gadget_vector)?;

0 commit comments

Comments
 (0)