Skip to content

Commit 0d3bc3a

Browse files
authored
Integrate Coconut - an Attribute-Based Credential Scheme with Threshold Issuance based on the modified Pointcheval-Sanders signature (#10)
* Integrate `ps-signature` implementation * Enable CI on PR * Fix feature gates * Update comments * Sync * `ps-signature` -> `coconut` * Bump up versions * `CommitmentsPoK` -> `MessagesPoK` * Stylistic
1 parent 38069c2 commit 0d3bc3a

File tree

118 files changed

+8466
-1524
lines changed

Some content is hidden

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

118 files changed

+8466
-1524
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"bbs_plus",
77
"vb_accumulator",
88
"proof_system",
9+
"coconut",
910
"saver",
1011
"compressed_sigma",
1112
"benches",

bbs_plus/src/proof.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<E: Pairing> PoKOfSignatureG1Protocol<E> {
339339
params.h[*i].serialize_compressed(&mut writer)?;
340340
bases_revealed.push(params.h[*i]);
341341
msg.serialize_compressed(&mut writer)?;
342-
exponents.push(msg.clone());
342+
exponents.push(*msg);
343343
}
344344
E::G1::msm_unchecked(&bases_revealed, &exponents).serialize_compressed(&mut writer)?;
345345
T2.serialize_compressed(&mut writer).map_err(|e| e.into())
@@ -495,7 +495,7 @@ where
495495
if revealed_msgs.contains_key(&i) {
496496
let message = revealed_msgs.get(&i).unwrap();
497497
bases_revealed.push(h[i]);
498-
exponents.push(message.clone());
498+
exponents.push(*message);
499499
} else {
500500
bases_2.push(h[i]);
501501
}
@@ -557,10 +557,7 @@ mod tests {
557557
KeypairG2<Bls12_381>,
558558
SignatureG1<Bls12_381>,
559559
) {
560-
let messages: Vec<Fr> = (0..message_count)
561-
.into_iter()
562-
.map(|_| Fr::rand(rng))
563-
.collect();
560+
let messages: Vec<Fr> = (0..message_count).map(|_| Fr::rand(rng)).collect();
564561
let params = SignatureParamsG1::<Bls12_381>::generate_using_rng(rng, message_count);
565562
let keypair = KeypairG2::<Bls12_381>::generate_using_rng(rng, &params);
566563
let sig =
@@ -669,18 +666,16 @@ mod tests {
669666
let keypair_2 = KeypairG2::<Bls12_381>::generate_using_rng(&mut rng, &params_2);
670667

671668
let mut messages_1: Vec<Fr> = (0..message_1_count - 1)
672-
.into_iter()
673669
.map(|_| Fr::rand(&mut rng))
674670
.collect();
675671
let mut messages_2: Vec<Fr> = (0..message_2_count - 1)
676-
.into_iter()
677672
.map(|_| Fr::rand(&mut rng))
678673
.collect();
679674

680675
let same_msg_idx = 4;
681676
let same_msg = Fr::rand(&mut rng);
682-
messages_1.insert(same_msg_idx, same_msg.clone());
683-
messages_2.insert(same_msg_idx, same_msg.clone());
677+
messages_1.insert(same_msg_idx, same_msg);
678+
messages_2.insert(same_msg_idx, same_msg);
684679

685680
// A particular message is same
686681
assert_eq!(messages_1[same_msg_idx], messages_2[same_msg_idx]);
@@ -704,10 +699,10 @@ mod tests {
704699
let same_blinding = Fr::rand(&mut rng);
705700

706701
let mut blindings_1 = BTreeMap::new();
707-
blindings_1.insert(same_msg_idx, same_blinding.clone());
702+
blindings_1.insert(same_msg_idx, same_blinding);
708703

709704
let mut blindings_2 = BTreeMap::new();
710-
blindings_2.insert(same_msg_idx, same_blinding.clone());
705+
blindings_2.insert(same_msg_idx, same_blinding);
711706

712707
// Add some more blindings randomly,
713708
blindings_1.insert(0, Fr::rand(&mut rng));
@@ -854,7 +849,7 @@ mod tests {
854849
*proof_2
855850
.get_resp_for_message(1, &revealed_indices_2)
856851
.unwrap(),
857-
proof_2.sc_resp_2.0[2 + 0]
852+
proof_2.sc_resp_2.0[2]
858853
);
859854
assert_eq!(
860855
*proof_2
@@ -896,7 +891,7 @@ mod tests {
896891
*proof_3
897892
.get_resp_for_message(1, &revealed_indices_3)
898893
.unwrap(),
899-
proof_3.sc_resp_2.0[2 + 0]
894+
proof_3.sc_resp_2.0[2]
900895
);
901896
assert_eq!(
902897
*proof_3
@@ -972,7 +967,6 @@ mod tests {
972967
for i in 0..sig_count {
973968
msgs.push(
974969
(0..message_count)
975-
.into_iter()
976970
.map(|_| Fr::rand(&mut rng))
977971
.collect::<Vec<Fr>>(),
978972
);

bbs_plus/src/signature.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,7 @@ mod tests {
410410
// Test signing and verification
411411
let mut rng = StdRng::seed_from_u64(0u64);
412412
let message_count = 20;
413-
let messages: Vec<Fr> = (0..message_count)
414-
.into_iter()
415-
.map(|_| Fr::rand(&mut rng))
416-
.collect();
413+
let messages: Vec<Fr> = (0..message_count).map(|_| Fr::rand(&mut rng)).collect();
417414

418415
{
419416
test_sig_verif!(

benches/Cargo.toml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
[package]
22
name = "benches"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
edition.workspace = true
55
authors.workspace = true
66
license.workspace = true
77

88
[dependencies]
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" }
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 }
1212
test_utils = { version = "0.1.0", default-features = false, path = "../test_utils" }
1313
ark-ff.workspace = true
1414
ark-ec.workspace = true
1515
ark-std.workspace = true
1616
ark-bls12-381.workspace = true
1717
serde.workspace = true
1818
serde_with.workspace = true
19+
blake2 = { version = "0.10", default-features = false }
20+
itertools = "0.10.5"
21+
coconut = { version = "0.1.0", default-features = false, path = "../coconut" }
1922
dock_crypto_utils = { default-features = false, path = "../utils" }
2023
zeroize.workspace = true
2124

@@ -33,11 +36,21 @@ name = "bbs_plus_signature"
3336
path = "benches/bbs_plus_signature.rs"
3437
harness = false
3538

39+
[[bench]]
40+
name = "ps_signature"
41+
path = "benches/ps_signature.rs"
42+
harness = false
43+
3644
[[bench]]
3745
name = "bbs_plus_proof"
3846
path = "benches/bbs_plus_proof.rs"
3947
harness = false
4048

49+
[[bench]]
50+
name = "ps_proof"
51+
path = "benches/ps_proof.rs"
52+
harness = false
53+
4154
[[bench]]
4255
name = "positive_accumulator"
4356
path = "benches/positive_accumulator.rs"

benches/benches/accum_witness_updates.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn non_membership_update_batch_using_public_info(c: &mut Criterion) {
7272

7373
let mut old_accums = Vec::with_capacity(iters as usize);
7474
let mut omegas = Vec::with_capacity(iters as usize);
75-
old_accums.push((*accumulator.value()).clone());
75+
old_accums.push(*accumulator.value());
7676

7777
for i in 0..iters as usize {
7878
accumulator = accumulator
@@ -85,7 +85,7 @@ fn non_membership_update_batch_using_public_info(c: &mut Criterion) {
8585
)
8686
.unwrap();
8787
if i < (iters - 1) as usize {
88-
old_accums.push((*accumulator.value()).clone());
88+
old_accums.push(*accumulator.value());
8989
let omega = Omega::new(
9090
&elems_batches[i + 1],
9191
&elems_batches[i],
@@ -137,7 +137,7 @@ fn membership_update_batch_using_public_info(c: &mut Criterion) {
137137
b.iter_custom(|iters| {
138138
let member = Fr::rand(&mut rng);
139139
accumulator = accumulator
140-
.add(member.clone(), &keypair.secret_key, &mut state)
140+
.add(member, &keypair.secret_key, &mut state)
141141
.unwrap();
142142

143143
let elems_batches = (0..iters + 1)
@@ -158,7 +158,7 @@ fn membership_update_batch_using_public_info(c: &mut Criterion) {
158158

159159
let mut old_accums = Vec::with_capacity(iters as usize);
160160
let mut omegas = Vec::with_capacity(iters as usize);
161-
old_accums.push((*accumulator.value()).clone());
161+
old_accums.push(*accumulator.value());
162162

163163
for i in 0..iters as usize {
164164
accumulator = accumulator
@@ -170,7 +170,7 @@ fn membership_update_batch_using_public_info(c: &mut Criterion) {
170170
)
171171
.unwrap();
172172
if i < (iters - 1) as usize {
173-
old_accums.push((*accumulator.value()).clone());
173+
old_accums.push(*accumulator.value());
174174
}
175175
let omega = Omega::new(
176176
&elems_batches[i + 1],
@@ -239,13 +239,13 @@ fn non_membership_update_batch_using_secret_key(c: &mut Criterion) {
239239
.collect::<Vec<_>>();
240240

241241
let mut old_accums = Vec::with_capacity(iters as usize);
242-
old_accums.push((*accumulator.value()).clone());
242+
old_accums.push(*accumulator.value());
243243
for i in 0..iters as usize {
244244
accumulator = accumulator
245245
.add_batch(elems_batches[i].clone(), &keypair.secret_key, &initial_elements, &mut state)
246246
.unwrap();
247247
if i < (iters - 1) as usize {
248-
old_accums.push((*accumulator.value()).clone());
248+
old_accums.push(*accumulator.value());
249249
}
250250
}
251251

@@ -306,7 +306,7 @@ fn non_membership_update_batch_using_secret_key(c: &mut Criterion) {
306306
accumulator = accumulator
307307
.remove_batch(&elems_batches[i], &keypair.secret_key, &initial_elements, &mut state)
308308
.unwrap();
309-
new_accums.push((*accumulator.value()).clone());
309+
new_accums.push(*accumulator.value());
310310
}
311311

312312
let start = Instant::now();
@@ -361,14 +361,14 @@ fn non_membership_update_batch_using_secret_key(c: &mut Criterion) {
361361
.unwrap();
362362

363363
let mut old_accums = Vec::with_capacity(iters as usize);
364-
old_accums.push((*accumulator.value()).clone());
364+
old_accums.push(*accumulator.value());
365365

366366
for i in 0..iters as usize {
367367
accumulator = accumulator
368368
.batch_updates(elems_batches[i+1].clone(), &elems_batches[i], &keypair.secret_key, &initial_elements, &mut state)
369369
.unwrap();
370370
if i < (iters - 1) as usize {
371-
old_accums.push((*accumulator.value()).clone());
371+
old_accums.push(*accumulator.value());
372372
}
373373
}
374374

@@ -435,13 +435,13 @@ fn membership_update_batch_using_secret_key(c: &mut Criterion) {
435435
.collect::<Vec<_>>();
436436

437437
let mut old_accums = Vec::with_capacity(iters as usize);
438-
old_accums.push((*pos_accumulator_1.value()).clone());
438+
old_accums.push(*pos_accumulator_1.value());
439439
for i in 0..iters as usize {
440440
pos_accumulator_1 = pos_accumulator_1
441441
.add_batch(elems_batches[i].clone(), &pos_keypair.secret_key, &mut pos_state)
442442
.unwrap();
443443
if i < (iters - 1) as usize {
444-
old_accums.push((*pos_accumulator_1.value()).clone());
444+
old_accums.push(*pos_accumulator_1.value());
445445
}
446446
}
447447

@@ -505,7 +505,7 @@ fn membership_update_batch_using_secret_key(c: &mut Criterion) {
505505
pos_accumulator_1 = pos_accumulator_1
506506
.remove_batch(&elems_batches[i], &pos_keypair.secret_key, &mut pos_state)
507507
.unwrap();
508-
new_accums.push((*pos_accumulator_1.value()).clone());
508+
new_accums.push(*pos_accumulator_1.value());
509509
}
510510

511511
let start = Instant::now();
@@ -563,14 +563,14 @@ fn membership_update_batch_using_secret_key(c: &mut Criterion) {
563563
.unwrap();
564564

565565
let mut old_accums = Vec::with_capacity(iters as usize);
566-
old_accums.push((*pos_accumulator_1.value()).clone());
566+
old_accums.push(*pos_accumulator_1.value());
567567

568568
for i in 0..iters as usize {
569569
pos_accumulator_1 = pos_accumulator_1
570570
.batch_updates(elems_batches[i+1].clone(), &elems_batches[i], &pos_keypair.secret_key, &mut pos_state)
571571
.unwrap();
572572
if i < (iters - 1) as usize {
573-
old_accums.push((*pos_accumulator_1.value()).clone());
573+
old_accums.push(*pos_accumulator_1.value());
574574
}
575575
}
576576

@@ -606,11 +606,11 @@ fn membership_update_single(c: &mut Criterion) {
606606

607607
let elem = Fr::rand(&mut rng);
608608
let pos_accumulator_1 = pos_accumulator
609-
.add(elem.clone(), &pos_keypair.secret_key, &mut pos_state)
609+
.add(elem, &pos_keypair.secret_key, &mut pos_state)
610610
.unwrap();
611611
let uni_accumulator_1 = uni_accumulator
612612
.add(
613-
elem.clone(),
613+
elem,
614614
&uni_keypair.secret_key,
615615
&initial_elements,
616616
&mut uni_state,
@@ -619,15 +619,11 @@ fn membership_update_single(c: &mut Criterion) {
619619

620620
let elem_to_update_with = Fr::rand(&mut rng);
621621
let pos_accumulator_2 = pos_accumulator_1
622-
.add(
623-
elem_to_update_with.clone(),
624-
&pos_keypair.secret_key,
625-
&mut pos_state,
626-
)
622+
.add(elem_to_update_with, &pos_keypair.secret_key, &mut pos_state)
627623
.unwrap();
628624
let uni_accumulator_2 = uni_accumulator_1
629625
.add(
630-
elem_to_update_with.clone(),
626+
elem_to_update_with,
631627
&uni_keypair.secret_key,
632628
&initial_elements,
633629
&mut uni_state,
@@ -730,7 +726,7 @@ fn non_membership_update_single(c: &mut Criterion) {
730726
let elem_to_update_with = Fr::rand(&mut rng);
731727
let accumulator_1 = accumulator
732728
.add(
733-
elem_to_update_with.clone(),
729+
elem_to_update_with,
734730
&keypair.secret_key,
735731
&initial_elements,
736732
&mut state,
@@ -744,7 +740,7 @@ fn non_membership_update_single(c: &mut Criterion) {
744740
wit_1.update_after_addition(
745741
black_box(&non_member),
746742
black_box(&elem_to_update_with),
747-
black_box(&accumulator.value()),
743+
black_box(accumulator.value()),
748744
);
749745
})
750746
},
@@ -771,7 +767,7 @@ fn non_membership_update_single(c: &mut Criterion) {
771767
.update_after_removal(
772768
black_box(&non_member),
773769
black_box(&elem_to_update_with),
774-
black_box(&accumulator_2.value()),
770+
black_box(accumulator_2.value()),
775771
)
776772
.unwrap();
777773
})

benches/benches/bbs_plus_proof.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ fn pok_sig_benchmark(c: &mut Criterion) {
8484
b.iter(|| {
8585
let pok = PoKOfSignatureG1Protocol::init(
8686
&mut rng,
87-
black_box(&sig),
88-
black_box(&params),
87+
black_box(sig),
88+
black_box(params),
8989
black_box(messages),
9090
black_box(BTreeMap::new()),
9191
black_box(revealed_indices[j].clone()),
@@ -117,8 +117,8 @@ fn pok_sig_benchmark(c: &mut Criterion) {
117117
for j in 0..revealed_indices_range[i].len() {
118118
let pok = PoKOfSignatureG1Protocol::init(
119119
&mut rng,
120-
&sig,
121-
&params,
120+
sig,
121+
params,
122122
messages,
123123
BTreeMap::new(),
124124
revealed_indices_range[i][j].clone(),
@@ -155,8 +155,8 @@ fn pok_sig_benchmark(c: &mut Criterion) {
155155
.verify(
156156
black_box(&revealed_msgs_range[i][j]),
157157
black_box(&challenges_range[i][j]),
158-
black_box(&keypair.public_key),
159-
black_box(&params),
158+
black_box(keypair.public_key.clone()),
159+
black_box(params.clone()),
160160
)
161161
.unwrap();
162162
});

0 commit comments

Comments
 (0)