Skip to content

Commit 29c9a34

Browse files
committed
Integrate verifiable encryption using TZ21 in proof system
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent 9c5002d commit 29c9a34

25 files changed

+1091
-76
lines changed

legogroth16/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
// #[macro_use]
1111
// extern crate bench_utils;
1212

13-
#[cfg(feature = "r1cs")]
14-
#[macro_use]
15-
extern crate derivative;
16-
1713
/// Reduce an R1CS instance to a *Quadratic Arithmetic Program* instance.
1814
pub(crate) mod r1cs_to_qap;
1915

proof_system/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ bulletproofs_plus_plus = { version = "0.6.0", default-features = false, path = "
3939
smc_range_proof = { version = "0.6.0", default-features = false, path = "../smc_range_proof" }
4040
short_group_sig = { version = "0.4.0", default-features = false, path = "../short_group_sig" }
4141
kvac = { version = "0.5.0", default-features = false, path = "../kvac" }
42+
verifiable_encryption = { version = "0.1.0", default-features = false, path = "../verifiable_encryption" }
43+
sha3 = { version = "0.10.6", default-features = false }
4244

4345
[dev-dependencies]
4446
ark-bls12-381.workspace = true
@@ -49,8 +51,8 @@ test_utils = { default-features = false, path = "../test_utils" }
4951

5052
[features]
5153
default = ["parallel"]
52-
std = ["ark-ff/std", "ark-ec/std", "ark-std/std", "ark-serialize/std", "schnorr_pok/std", "dock_crypto_utils/std", "serde/std", "saver/std", "ark-groth16/std", "legogroth16/std", "ark-r1cs-std/std", "ark-relations/std", "merlin/std", "coconut-crypto/std", "bulletproofs_plus_plus/std", "smc_range_proof/std", "short_group_sig/std", "kvac/std"]
54+
std = ["ark-ff/std", "ark-ec/std", "ark-std/std", "ark-serialize/std", "schnorr_pok/std", "dock_crypto_utils/std", "serde/std", "saver/std", "ark-groth16/std", "legogroth16/std", "ark-r1cs-std/std", "ark-relations/std", "merlin/std", "coconut-crypto/std", "bulletproofs_plus_plus/std", "smc_range_proof/std", "short_group_sig/std", "kvac/std", "verifiable_encryption/std"]
5355
print-trace = ["ark-std/print-trace", "schnorr_pok/print-trace", "bbs_plus/print-trace", "vb_accumulator/print-trace", "dock_crypto_utils/print-trace"]
54-
parallel = ["std", "ark-ff/parallel", "ark-ec/parallel", "ark-std/parallel", "rayon", "schnorr_pok/parallel", "bbs_plus/parallel", "vb_accumulator/parallel", "saver/parallel", "ark-groth16/parallel", "legogroth16/parallel", "ark-r1cs-std/parallel", "dock_crypto_utils/parallel", "coconut-crypto/parallel", "bulletproofs_plus_plus/parallel", "smc_range_proof/parallel", "short_group_sig/parallel", "kvac/parallel"]
56+
parallel = ["std", "ark-ff/parallel", "ark-ec/parallel", "ark-std/parallel", "rayon", "schnorr_pok/parallel", "bbs_plus/parallel", "vb_accumulator/parallel", "saver/parallel", "ark-groth16/parallel", "legogroth16/parallel", "ark-r1cs-std/parallel", "dock_crypto_utils/parallel", "coconut-crypto/parallel", "bulletproofs_plus_plus/parallel", "smc_range_proof/parallel", "short_group_sig/parallel", "kvac/parallel", "verifiable_encryption/parallel"]
5557
wasmer-js = ["legogroth16/wasmer-js"]
5658
wasmer-sys = ["legogroth16/wasmer-sys"]

proof_system/src/constants.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ pub const KB_POS_ACCUM_MEM_LABEL: &'static [u8; 34] = b"KB-positive-accumulator-
2222
pub const KB_POS_ACCUM_CDH_MEM_LABEL: &'static [u8; 38] = b"KB-positive-accumulator-CDH-membership";
2323

2424
pub const BBDT16_KVAC_LABEL: &'static [u8; 14] = b"BDDT-2016-KVAC";
25+
pub const VE_TZ_21_LABEL: &'static [u8; 8] = b"VE-TZ-21";
26+
pub const VE_TZ_21_ROBUST_LABEL: &'static [u8; 15] = b"VE-TZ-21-Robust";

proof_system/src/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use saver::error::SaverError;
99
use schnorr_pok::error::SchnorrError;
1010
use smc_range_proof::prelude::SmcRangeProofError;
1111
use vb_accumulator::error::VBAccumulatorError;
12+
use verifiable_encryption::error::VerifiableEncryptionError;
1213

1314
#[derive(Debug)]
1415
pub enum ProofSystemError {
@@ -111,6 +112,10 @@ pub enum ProofSystemError {
111112
UnequalResponseOfSaverCiphertextAndChunk(usize),
112113
ResponseForWitnessNotFoundForStatement(usize),
113114
NoResponseFoundForWitnessRef(usize, usize),
115+
MissingBlindingForStatementAtIndex(usize, usize),
116+
VerifiableEncryption(u32, VerifiableEncryptionError),
117+
NotALegoGroth16StatementProof,
118+
NotAVeTZ21StatementProof,
114119
}
115120

116121
impl From<SchnorrError> for ProofSystemError {

proof_system/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ extern crate core;
164164
pub mod setup_params;
165165
#[macro_use]
166166
mod derived_params;
167-
mod constants;
167+
pub mod constants;
168168
pub mod error;
169169
mod macros;
170170
pub mod meta_statement;

proof_system/src/prover.rs

+72-26
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use crate::{
2626
COMPOSITE_PROOF_LABEL, CONTEXT_LABEL, KB_POS_ACCUM_CDH_MEM_LABEL, KB_POS_ACCUM_MEM_LABEL,
2727
KB_UNI_ACCUM_CDH_MEM_LABEL, KB_UNI_ACCUM_CDH_NON_MEM_LABEL, KB_UNI_ACCUM_MEM_LABEL,
2828
KB_UNI_ACCUM_NON_MEM_LABEL, NONCE_LABEL, PS_LABEL, VB_ACCUM_CDH_MEM_LABEL,
29-
VB_ACCUM_CDH_NON_MEM_LABEL, VB_ACCUM_MEM_LABEL, VB_ACCUM_NON_MEM_LABEL,
29+
VB_ACCUM_CDH_NON_MEM_LABEL, VB_ACCUM_MEM_LABEL, VB_ACCUM_NON_MEM_LABEL, VE_TZ_21_LABEL,
30+
VE_TZ_21_ROBUST_LABEL,
3031
},
3132
meta_statement::{EqualWitnesses, WitnessRef},
3233
prelude::SnarkpackSRS,
@@ -63,9 +64,11 @@ use crate::{
6364
r1cs_legogorth16::R1CSLegogroth16Protocol,
6465
saver::SaverProtocol,
6566
schnorr::SchnorrProtocol,
67+
verifiable_encryption_tz_21::VeTZ21Protocol,
6668
},
6769
};
6870
use dock_crypto_utils::{
71+
aliases::FullDigest,
6972
expect_equality,
7073
hashing_utils::field_elem_from_try_and_incr,
7174
signature::MultiMessageSignatureParams,
@@ -136,7 +139,7 @@ impl<E: Pairing> Proof<E> {
136139
/// Also returns the randomness used by statements using SAVER and LegoGroth16 proofs which can
137140
/// then be used as helpers in subsequent proof creations where these proofs are reused than
138141
/// creating fresh proofs.
139-
pub fn new<R: RngCore, D: Digest>(
142+
pub fn new<R: RngCore, D: FullDigest + Digest>(
140143
rng: &mut R,
141144
proof_spec: ProofSpec<E>,
142145
witnesses: Witnesses<E>,
@@ -248,6 +251,36 @@ impl<E: Pairing> Proof<E> {
248251
}};
249252
}
250253

254+
macro_rules! ve_tz_21_init {
255+
($rng: ident, $s_idx: ident, $s: ident, $w: ident, $init_name: ident, $label: ident) => {{
256+
let witness_count = $w.len();
257+
let comm_key = $s.get_comm_key(&proof_spec.setup_params, $s_idx)?;
258+
// +1 since commitment includes randomness as well to make it perfectly hiding
259+
if comm_key.len() < (witness_count + 1) {
260+
return Err(ProofSystemError::IncompatiblePedCommSetupParamAtIndex(
261+
$s_idx,
262+
));
263+
}
264+
// Get blindings for all the witnesses
265+
let mut b = Vec::with_capacity(witness_count);
266+
for i in 0..witness_count {
267+
if let Some(blinding) = blindings.remove(&($s_idx, i)) {
268+
b.push(blinding);
269+
} else {
270+
return Err(ProofSystemError::MissingBlindingForStatementAtIndex(
271+
$s_idx, i,
272+
));
273+
}
274+
}
275+
let enc_params = $s.get_enc_params(&proof_spec.setup_params, $s_idx)?;
276+
let mut sp = VeTZ21Protocol::new($s_idx, comm_key, enc_params);
277+
sp.$init_name::<R, D>($rng, $w, b)?;
278+
transcript.set_label($label);
279+
sp.challenge_contribution(&mut transcript)?;
280+
sub_protocols.push(SubProtocol::VeTZ21(sp));
281+
}};
282+
}
283+
251284
/// Build a map of blindings for witnesses of given the statement index. The key is the witness
252285
/// index and value is the blinding. Also removes that blinding from the global blindings map
253286
/// containing blinding for each witness reference.
@@ -771,6 +804,18 @@ impl<E: Pairing> Proof<E> {
771804
}
772805
_ => err_incompat_witness!(s_idx, s, witness),
773806
},
807+
Statement::VeTZ21(s) => match witness {
808+
Witness::VeTZ21(w) => {
809+
ve_tz_21_init!(rng, s_idx, s, w, init, VE_TZ_21_LABEL);
810+
}
811+
_ => err_incompat_witness!(s_idx, s, witness),
812+
},
813+
Statement::VeTZ21Robust(s) => match witness {
814+
Witness::VeTZ21Robust(w) => {
815+
ve_tz_21_init!(rng, s_idx, s, w, init_robust, VE_TZ_21_ROBUST_LABEL);
816+
}
817+
_ => err_incompat_witness!(s_idx, s, witness),
818+
},
774819
_ => return Err(ProofSystemError::InvalidStatement),
775820
}
776821
}
@@ -979,6 +1024,13 @@ impl<E: Pairing> Proof<E> {
9791024
SubProtocol::KBUniversalAccumulatorNonMembershipKV(mut sp) => {
9801025
sp.gen_proof_contribution(&challenge)?
9811026
}
1027+
SubProtocol::VeTZ21(mut sp) => {
1028+
if sp.ve_proof.is_some() {
1029+
sp.gen_proof_contribution(&challenge)?
1030+
} else {
1031+
sp.gen_proof_contribution_robust(&challenge)?
1032+
}
1033+
}
9821034
});
9831035
}
9841036

@@ -1086,30 +1138,6 @@ impl<E: Pairing> Proof<E> {
10861138
field_elem_from_try_and_incr::<E::ScalarField, D>(bytes)
10871139
}
10881140

1089-
pub fn get_saver_ciphertext_and_proof(
1090-
&self,
1091-
index: usize,
1092-
) -> Result<(&Ciphertext<E>, &ark_groth16::Proof<E>), ProofSystemError> {
1093-
let st = self.statement_proof(index)?;
1094-
if let StatementProof::Saver(s) = st {
1095-
Ok((&s.ciphertext, &s.snark_proof))
1096-
} else {
1097-
Err(ProofSystemError::NotASaverStatementProof)
1098-
}
1099-
}
1100-
1101-
pub fn get_legogroth16_proof(
1102-
&self,
1103-
index: usize,
1104-
) -> Result<&legogroth16::Proof<E>, ProofSystemError> {
1105-
let st = self.statement_proof(index)?;
1106-
match st {
1107-
StatementProof::BoundCheckLegoGroth16(s) => Ok(&s.snark_proof),
1108-
StatementProof::R1CSLegoGroth16(s) => Ok(&s.snark_proof),
1109-
_ => Err(ProofSystemError::NotASaverStatementProof),
1110-
}
1111-
}
1112-
11131141
pub fn for_aggregate(&self) -> Self {
11141142
let mut statement_proofs = vec![];
11151143
for sp in self.statement_proofs() {
@@ -1177,4 +1205,22 @@ impl<E: Pairing> Proof<E> {
11771205
}
11781206
}
11791207
}
1208+
1209+
// fn get_ve_func_args<'a, 'b: 'a>(s_idx: usize, s: &'a VerifiableEncryptionTZ21<E::G1Affine>, proof_spec: &'b ProofSpec<E>, witness_count: usize, blindings: &'b mut BTreeMap<WitnessRef, E::ScalarField>) -> Result<(Vec<E::ScalarField>, &'a [E::G1Affine], &'a ElgamalEncryptionParams<E::G1Affine>), ProofSystemError> {
1210+
// let comm_key = s.get_comm_key(&proof_spec.setup_params, s_idx)?;
1211+
// // +1 since commitment includes randomness as well to make it perfectly hiding
1212+
// if comm_key.len() < (witness_count + 1) {
1213+
// return Err(ProofSystemError::IncompatiblePedCommSetupParamAtIndex(s_idx))
1214+
// }
1215+
// let mut b = Vec::with_capacity(witness_count);
1216+
// for i in 0..witness_count {
1217+
// if let Some(blinding) = blindings.remove(&(s_idx, i)) {
1218+
// b.push(blinding);
1219+
// } else {
1220+
// return Err(ProofSystemError::MissingBlindingForStatementAtIndex(s_idx, i))
1221+
// }
1222+
// }
1223+
// let enc_params = s.get_enc_params(&proof_spec.setup_params, s_idx)?;
1224+
// Ok((b, comm_key.as_slice(), enc_params))
1225+
// }
11801226
}

proof_system/src/setup_params.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::{
99
prelude::bound_check_smc::SmcParamsAndCommitmentKey,
1010
statement::bound_check_smc_with_kv::SmcParamsAndCommitmentKeyAndSecretKey,
1111
};
12-
use ark_ec::pairing::Pairing;
12+
use ark_ec::{pairing::Pairing, AffineRepr};
13+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
1314
use ark_std::vec::Vec;
1415
use bbs_plus::prelude::{
1516
PublicKeyG2 as BBSPublicKeyG2, SignatureParams23G1 as BBSSignatureParams23G1,
@@ -74,6 +75,7 @@ pub enum SetupParams<E: Pairing> {
7475
BBDT16MACParams(MACParams<E::G1Affine>),
7576
PedersenCommitmentKeyG2(#[serde_as(as = "Vec<ArkObjectBytes>")] Vec<E::G2Affine>),
7677
CommitmentKeyG2(#[serde_as(as = "ArkObjectBytes")] PedersenCommitmentKey<E::G2Affine>),
78+
ElgamalEncryption(ElgamalEncryptionParams<E::G1Affine>),
7779
}
7880

7981
macro_rules! delegate {
@@ -109,7 +111,8 @@ macro_rules! delegate {
109111
KBPositiveAccumulatorPublicKey,
110112
BBDT16MACParams,
111113
PedersenCommitmentKeyG2,
112-
CommitmentKeyG2
114+
CommitmentKeyG2,
115+
ElgamalEncryption
113116
: $($tt)+
114117
}
115118
}};
@@ -148,7 +151,8 @@ macro_rules! delegate_reverse {
148151
KBPositiveAccumulatorPublicKey,
149152
BBDT16MACParams,
150153
PedersenCommitmentKeyG2,
151-
CommitmentKeyG2
154+
CommitmentKeyG2,
155+
ElgamalEncryption
152156
: $($tt)+
153157
}
154158

@@ -176,6 +180,19 @@ macro_rules! extract_param {
176180
}};
177181
}
178182

183+
/// Elgamal encryption parameters generated by the decryptor
184+
#[serde_as]
185+
#[derive(
186+
Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
187+
)]
188+
pub struct ElgamalEncryptionParams<G: AffineRepr> {
189+
/// Generator used in the scheme to generate public key and ephemeral public key by sender/encryptor
190+
#[serde_as(as = "ArkObjectBytes")]
191+
pub gen: G,
192+
#[serde_as(as = "ArkObjectBytes")]
193+
pub public_key: G,
194+
}
195+
179196
mod serialization {
180197
use super::*;
181198
use ark_serialize::{

proof_system/src/statement/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod ped_comm;
2121
pub mod ps_signature;
2222
pub mod r1cs_legogroth16;
2323
pub mod saver;
24+
pub mod verifiable_encryption_tz_21;
2425

2526
/// Type of relation being proved and the public values for the relation
2627
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -128,6 +129,12 @@ pub enum Statement<E: Pairing> {
128129
),
129130
PoKBBSSignature23IETFG1Prover(bbs_23_ietf::PoKBBSSignature23IETFG1Prover<E>),
130131
PoKBBSSignature23IETFG1Verifier(bbs_23_ietf::PoKBBSSignature23IETFG1Verifier<E>),
132+
/// Verifiable Encryption using DKGith protocol in the scheme TZ21
133+
// TODO: This should have the const generics used by the corresponding protocol
134+
VeTZ21(verifiable_encryption_tz_21::VerifiableEncryptionTZ21<E::G1Affine>),
135+
/// Verifiable Encryption using Robust DKGith protocol in the scheme TZ21
136+
// TODO: This should have the const generics used by the corresponding protocol
137+
VeTZ21Robust(verifiable_encryption_tz_21::VerifiableEncryptionTZ21<E::G1Affine>),
131138
}
132139

133140
/// A collection of statements
@@ -205,7 +212,9 @@ macro_rules! delegate {
205212
KBUniversalAccumulatorNonMembershipKV,
206213
KBUniversalAccumulatorNonMembershipKVFullVerifier,
207214
PoKBBSSignature23IETFG1Prover,
208-
PoKBBSSignature23IETFG1Verifier
215+
PoKBBSSignature23IETFG1Verifier,
216+
VeTZ21,
217+
VeTZ21Robust
209218
: $($tt)+
210219
}
211220
}}
@@ -260,7 +269,9 @@ macro_rules! delegate_reverse {
260269
KBUniversalAccumulatorNonMembershipKV,
261270
KBUniversalAccumulatorNonMembershipKVFullVerifier,
262271
PoKBBSSignature23IETFG1Prover,
263-
PoKBBSSignature23IETFG1Verifier
272+
PoKBBSSignature23IETFG1Verifier,
273+
VeTZ21,
274+
VeTZ21Robust
264275
: $($tt)+
265276
}
266277

0 commit comments

Comments
 (0)