Skip to content

Commit 0c54a1c

Browse files
committedMar 4, 2024·
Split prover and verifier statements for BBS and BBS+
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent 9e075a1 commit 0c54a1c

29 files changed

+1178
-449
lines changed
 

‎Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ rayon = { version = "1" }
4242
digest = { version = "0.10", default-features = false, features = ["alloc"] }
4343
serde = { version = "1.0", default-features = false, features = ["derive"] }
4444
serde_with = { version = "1.10.0", default-features = false, features = ["macros"] }
45-
zeroize = { version = "1.6.0", features = ["derive"] }
45+
zeroize = { version = "1.7.0", features = ["derive"] }
4646
blake2 = { version = "0.10", default-features = false }
4747
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
48-
itertools = "0.10.5"
48+
itertools = "0.12.1"
4949

5050
[profile.release]
5151
lto = true

‎kvac/src/bddt_2016/setup.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use ark_ec::{AffineRepr, CurveGroup, VariableBaseMSM};
2-
use ark_ff::PrimeField;
2+
use ark_ff::{
3+
field_hashers::{DefaultFieldHasher, HashToField},
4+
PrimeField,
5+
};
36
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
4-
use ark_std::{rand::RngCore, vec::Vec};
7+
use ark_std::{cfg_iter, rand::RngCore, vec::Vec};
58
use core::iter::once;
6-
use digest::Digest;
9+
use digest::{Digest, DynDigest};
710
use dock_crypto_utils::{
811
affine_group_element_from_byte_slices, concat_slices, join,
912
misc::{n_projective_group_elements, seq_pairs_satisfy},
@@ -143,6 +146,13 @@ impl<G: AffineRepr> MACParams<G> {
143146
let commitment = self.commit_to_messages(indexed_messages_sorted_by_index, s)?;
144147
Ok(commitment + self.h)
145148
}
149+
150+
pub fn is_valid(&self) -> bool {
151+
!(self.g_0.is_zero()
152+
|| self.g.is_zero()
153+
|| self.h.is_zero()
154+
|| cfg_iter!(self.g_vec).any(|v| v.is_zero()))
155+
}
146156
}
147157

148158
impl<G: AffineRepr> MultiMessageSignatureParams for MACParams<G> {
@@ -161,6 +171,11 @@ impl<F: PrimeField> SecretKey<F> {
161171
pub fn new<R: RngCore>(rng: &mut R) -> Self {
162172
Self(F::rand(rng))
163173
}
174+
175+
pub fn generate_using_seed<D: DynDigest + Default + Clone>(seed: &[u8]) -> Self {
176+
let hasher = <DefaultFieldHasher<D> as HashToField<F>>::new(b"BDDT16-MAC-KEYGEN-SALT");
177+
Self(hasher.hash_to_field(seed, 1).pop().unwrap())
178+
}
164179
}
165180

166181
impl<G: AffineRepr> PublicKey<G> {

‎proof_system/src/proof_spec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<E: Pairing> ProofSpec<E> {
192192
// knowledge proof
193193
for (i, st) in self.statements.0.iter().enumerate() {
194194
match st {
195-
Statement::PoKBBSSignatureG1(s) => {
195+
Statement::PoKBBSSignatureG1Prover(s) => {
196196
for k in s.revealed_messages.keys() {
197197
revealed_wit_refs.insert((i, *k));
198198
}
@@ -433,14 +433,14 @@ impl<E: Pairing> ProofSpec<E> {
433433

434434
for (s_idx, statement) in self.statements.0.iter().enumerate() {
435435
match statement {
436-
Statement::PoKBBSSignatureG1(s) => {
436+
Statement::PoKBBSSignatureG1Verifier(s) => {
437437
let params = s.get_params(&self.setup_params, s_idx)?;
438438
derived_bbs_p.on_new_statement_idx(params, s_idx);
439439

440440
let pk = s.get_public_key(&self.setup_params, s_idx)?;
441441
derived_bbs_pk.on_new_statement_idx(pk, s_idx);
442442
}
443-
Statement::PoKBBSSignature23G1(s) => {
443+
Statement::PoKBBSSignature23G1Verifier(s) => {
444444
let params = s.get_params(&self.setup_params, s_idx)?;
445445
derived_bbs.on_new_statement_idx(params, s_idx);
446446

‎proof_system/src/prover.rs

+26-16
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,15 @@ impl<E: Pairing> Proof<E> {
200200
}
201201

202202
macro_rules! sig_protocol_init {
203-
($s: ident, $s_idx: ident, $w: ident, $protocol: ident, $protocol_variant: ident, $label: ident) => {{
203+
($s: ident, $s_idx: ident, $w: ident, $protocol: ident, $func_name: ident, $protocol_variant: ident, $label: ident) => {{
204204
// Prepare blindings for this signature proof
205205
let blindings_map = build_blindings_map::<E>(
206206
&mut blindings,
207207
$s_idx,
208208
$w.unrevealed_messages.keys().cloned(),
209209
);
210210
let sig_params = $s.get_params(&proof_spec.setup_params, $s_idx)?;
211-
let pk = $s.get_public_key(&proof_spec.setup_params, $s_idx)?;
212-
let mut sp = $protocol::new($s_idx, &$s.revealed_messages, sig_params, pk);
211+
let mut sp = $protocol::$func_name($s_idx, &$s.revealed_messages, sig_params);
213212
sp.init(rng, blindings_map, $w)?;
214213
transcript.set_label($label);
215214
sp.challenge_contribution(&mut transcript)?;
@@ -252,26 +251,28 @@ impl<E: Pairing> Proof<E> {
252251
.enumerate()
253252
{
254253
match statement {
255-
Statement::PoKBBSSignatureG1(s) => match witness {
254+
Statement::PoKBBSSignatureG1Prover(s) => match witness {
256255
Witness::PoKBBSSignatureG1(w) => {
257256
sig_protocol_init!(
258257
s,
259258
s_idx,
260259
w,
261260
PoKBBSPlusSigG1SubProtocol,
261+
new_for_prover,
262262
PoKBBSSignatureG1,
263263
BBS_PLUS_LABEL
264264
);
265265
}
266266
_ => err_incompat_witness!(s_idx, s, witness),
267267
},
268-
Statement::PoKBBSSignature23G1(s) => match witness {
268+
Statement::PoKBBSSignature23G1Prover(s) => match witness {
269269
Witness::PoKBBSSignature23G1(w) => {
270270
sig_protocol_init!(
271271
s,
272272
s_idx,
273273
w,
274274
PoKBBSSigG1SubProtocol,
275+
new_for_prover,
275276
PoKBBSSignature23G1,
276277
BBS_23_LABEL
277278
);
@@ -572,7 +573,19 @@ impl<E: Pairing> Proof<E> {
572573
},
573574
Statement::PoKPSSignature(s) => match witness {
574575
Witness::PoKPSSignature(w) => {
575-
sig_protocol_init!(s, s_idx, w, PSSignaturePoK, PSSignaturePoK, PS_LABEL);
576+
// Prepare blindings for this PS sig proof
577+
let blindings_map = build_blindings_map::<E>(
578+
&mut blindings,
579+
s_idx,
580+
w.unrevealed_messages.keys().cloned(),
581+
);
582+
let params = s.get_params(&proof_spec.setup_params, s_idx)?;
583+
let pk = s.get_public_key(&proof_spec.setup_params, s_idx)?;
584+
let mut sp = PSSignaturePoK::new(s_idx, &s.revealed_messages, params, pk);
585+
sp.init::<R>(rng, blindings_map, w)?;
586+
transcript.set_label(PS_LABEL);
587+
sp.challenge_contribution(&mut transcript)?;
588+
sub_protocols.push(SubProtocol::PSSignaturePoK(sp));
576589
}
577590
_ => err_incompat_witness!(s_idx, s, witness),
578591
},
@@ -667,18 +680,15 @@ impl<E: Pairing> Proof<E> {
667680
},
668681
Statement::PoKBDDT16MAC(s) => match witness {
669682
Witness::PoKOfBDDT16MAC(w) => {
670-
// Prepare blindings for this BDDT16 MAC proof
671-
let blindings_map = build_blindings_map::<E>(
672-
&mut blindings,
683+
sig_protocol_init!(
684+
s,
673685
s_idx,
674-
w.unrevealed_messages.keys().cloned(),
686+
w,
687+
PoKOfMACSubProtocol,
688+
new,
689+
PoKOfBDDT16MAC,
690+
BDDT16_KVAC_LABEL
675691
);
676-
let params = s.get_params(&proof_spec.setup_params, s_idx)?;
677-
let mut sp = PoKOfMACSubProtocol::new(s_idx, &s.revealed_messages, params);
678-
sp.init::<R>(rng, blindings_map, w)?;
679-
transcript.set_label(BDDT16_KVAC_LABEL);
680-
sp.challenge_contribution(&mut transcript)?;
681-
sub_protocols.push(SubProtocol::PoKOfBDDT16MAC(sp));
682692
}
683693
_ => err_incompat_witness!(s_idx, s, witness),
684694
},

‎proof_system/src/statement/bbs_23.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use serde::{Deserialize, Serialize};
55
use serde_with::{serde_as, Same};
66

77
use crate::{
8-
error::ProofSystemError, impl_bbs_statement, setup_params::SetupParams, statement::Statement,
8+
error::ProofSystemError, impl_bbs_prover_statement, impl_bbs_verifier_statement,
9+
setup_params::SetupParams, statement::Statement,
910
};
1011
use bbs_plus::prelude::{PublicKeyG2, SignatureParams23G1};
1112
use dock_crypto_utils::serde_utils::*;
@@ -16,7 +17,22 @@ use dock_crypto_utils::serde_utils::*;
1617
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
1718
)]
1819
#[serde(bound = "")]
19-
pub struct PoKBBSSignature23G1<E: Pairing> {
20+
pub struct PoKBBSSignature23G1Prover<E: Pairing> {
21+
/// Messages being revealed.
22+
#[serde_as(as = "BTreeMap<Same, ArkObjectBytes>")]
23+
pub revealed_messages: BTreeMap<usize, E::ScalarField>,
24+
/// If the statement was created by passing the signature params directly, then it will not be None
25+
pub signature_params: Option<SignatureParams23G1<E>>,
26+
/// If the statement was created by passing the index of signature params in `SetupParams`, then it will not be None
27+
pub signature_params_ref: Option<usize>,
28+
}
29+
30+
#[serde_as]
31+
#[derive(
32+
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
33+
)]
34+
#[serde(bound = "")]
35+
pub struct PoKBBSSignature23G1Verifier<E: Pairing> {
2036
/// Messages being revealed.
2137
#[serde_as(as = "BTreeMap<Same, ArkObjectBytes>")]
2238
pub revealed_messages: BTreeMap<usize, E::ScalarField>,
@@ -30,10 +46,18 @@ pub struct PoKBBSSignature23G1<E: Pairing> {
3046
pub public_key_ref: Option<usize>,
3147
}
3248

33-
impl<E: Pairing> PoKBBSSignature23G1<E> {
34-
impl_bbs_statement!(
49+
impl<E: Pairing> PoKBBSSignature23G1Prover<E> {
50+
impl_bbs_prover_statement!(
51+
SignatureParams23G1,
52+
PoKBBSSignature23G1Prover,
53+
BBSSignatureParams23
54+
);
55+
}
56+
57+
impl<E: Pairing> PoKBBSSignature23G1Verifier<E> {
58+
impl_bbs_verifier_statement!(
3559
SignatureParams23G1,
36-
PoKBBSSignature23G1,
60+
PoKBBSSignature23G1Verifier,
3761
BBSSignatureParams23
3862
);
3963
}

‎proof_system/src/statement/bbs_plus.rs

+77-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,29 @@ use crate::{error::ProofSystemError, setup_params::SetupParams, statement::State
88
use bbs_plus::prelude::{PublicKeyG2, SignatureParamsG1};
99
use dock_crypto_utils::serde_utils::*;
1010

11+
/// Public values like setup params and revealed messages for proving knowledge of BBS+ signature.
12+
#[serde_as]
13+
#[derive(
14+
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
15+
)]
16+
#[serde(bound = "")]
17+
pub struct PoKBBSSignatureG1Prover<E: Pairing> {
18+
/// Messages being revealed.
19+
#[serde_as(as = "BTreeMap<Same, ArkObjectBytes>")]
20+
pub revealed_messages: BTreeMap<usize, E::ScalarField>,
21+
/// If the statement was created by passing the signature params directly, then it will not be None
22+
pub signature_params: Option<SignatureParamsG1<E>>,
23+
/// If the statement was created by passing the index of signature params in `SetupParams`, then it will not be None
24+
pub signature_params_ref: Option<usize>,
25+
}
26+
1127
/// Public values like setup params, public key and revealed messages for proving knowledge of BBS+ signature.
1228
#[serde_as]
1329
#[derive(
1430
Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
1531
)]
1632
#[serde(bound = "")]
17-
pub struct PoKBBSSignatureG1<E: Pairing> {
33+
pub struct PoKBBSSignatureG1Verifier<E: Pairing> {
1834
/// Messages being revealed.
1935
#[serde_as(as = "BTreeMap<Same, ArkObjectBytes>")]
2036
pub revealed_messages: BTreeMap<usize, E::ScalarField>,
@@ -29,7 +45,52 @@ pub struct PoKBBSSignatureG1<E: Pairing> {
2945
}
3046

3147
#[macro_export]
32-
macro_rules! impl_bbs_statement {
48+
macro_rules! impl_bbs_prover_statement {
49+
($params: ident, $stmt: ident, $setup_param_name: ident) => {
50+
/// Create a statement by passing the signature parameters directly.
51+
pub fn new_statement_from_params(
52+
signature_params: $params<E>,
53+
revealed_messages: BTreeMap<usize, E::ScalarField>,
54+
) -> Statement<E> {
55+
Statement::$stmt(Self {
56+
revealed_messages,
57+
signature_params: Some(signature_params),
58+
signature_params_ref: None,
59+
})
60+
}
61+
62+
/// Create a statement by passing the index of signature parameters in `SetupParams`.
63+
pub fn new_statement_from_params_ref(
64+
signature_params_ref: usize,
65+
revealed_messages: BTreeMap<usize, E::ScalarField>,
66+
) -> Statement<E> {
67+
Statement::$stmt(Self {
68+
revealed_messages,
69+
signature_params: None,
70+
signature_params_ref: Some(signature_params_ref),
71+
})
72+
}
73+
74+
/// Get signature params for the statement index `s_idx` either from `self` or from given `setup_params`.
75+
pub fn get_params<'a>(
76+
&'a self,
77+
setup_params: &'a [SetupParams<E>],
78+
st_idx: usize,
79+
) -> Result<&'a $params<E>, ProofSystemError> {
80+
extract_param!(
81+
setup_params,
82+
&self.signature_params,
83+
self.signature_params_ref,
84+
$setup_param_name,
85+
IncompatibleBBSPlusSetupParamAtIndex,
86+
st_idx
87+
)
88+
}
89+
};
90+
}
91+
92+
#[macro_export]
93+
macro_rules! impl_bbs_verifier_statement {
3394
($params: ident, $stmt: ident, $setup_param_name: ident) => {
3495
/// Create a statement by passing the signature parameters and public key directly.
3596
pub fn new_statement_from_params(
@@ -95,6 +156,18 @@ macro_rules! impl_bbs_statement {
95156
};
96157
}
97158

98-
impl<E: Pairing> PoKBBSSignatureG1<E> {
99-
impl_bbs_statement!(SignatureParamsG1, PoKBBSSignatureG1, BBSPlusSignatureParams);
159+
impl<E: Pairing> PoKBBSSignatureG1Prover<E> {
160+
impl_bbs_prover_statement!(
161+
SignatureParamsG1,
162+
PoKBBSSignatureG1Prover,
163+
BBSPlusSignatureParams
164+
);
165+
}
166+
167+
impl<E: Pairing> PoKBBSSignatureG1Verifier<E> {
168+
impl_bbs_verifier_statement!(
169+
SignatureParamsG1,
170+
PoKBBSSignatureG1Verifier,
171+
BBSPlusSignatureParams
172+
);
100173
}

0 commit comments

Comments
 (0)
Please sign in to comment.