@@ -26,7 +26,8 @@ use crate::{
26
26
COMPOSITE_PROOF_LABEL , CONTEXT_LABEL , KB_POS_ACCUM_CDH_MEM_LABEL , KB_POS_ACCUM_MEM_LABEL ,
27
27
KB_UNI_ACCUM_CDH_MEM_LABEL , KB_UNI_ACCUM_CDH_NON_MEM_LABEL , KB_UNI_ACCUM_MEM_LABEL ,
28
28
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 ,
30
31
} ,
31
32
meta_statement:: { EqualWitnesses , WitnessRef } ,
32
33
prelude:: SnarkpackSRS ,
@@ -63,9 +64,11 @@ use crate::{
63
64
r1cs_legogorth16:: R1CSLegogroth16Protocol ,
64
65
saver:: SaverProtocol ,
65
66
schnorr:: SchnorrProtocol ,
67
+ verifiable_encryption_tz_21:: VeTZ21Protocol ,
66
68
} ,
67
69
} ;
68
70
use dock_crypto_utils:: {
71
+ aliases:: FullDigest ,
69
72
expect_equality,
70
73
hashing_utils:: field_elem_from_try_and_incr,
71
74
signature:: MultiMessageSignatureParams ,
@@ -136,7 +139,7 @@ impl<E: Pairing> Proof<E> {
136
139
/// Also returns the randomness used by statements using SAVER and LegoGroth16 proofs which can
137
140
/// then be used as helpers in subsequent proof creations where these proofs are reused than
138
141
/// creating fresh proofs.
139
- pub fn new < R : RngCore , D : Digest > (
142
+ pub fn new < R : RngCore , D : FullDigest + Digest > (
140
143
rng : & mut R ,
141
144
proof_spec : ProofSpec < E > ,
142
145
witnesses : Witnesses < E > ,
@@ -248,6 +251,36 @@ impl<E: Pairing> Proof<E> {
248
251
} } ;
249
252
}
250
253
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
+
251
284
/// Build a map of blindings for witnesses of given the statement index. The key is the witness
252
285
/// index and value is the blinding. Also removes that blinding from the global blindings map
253
286
/// containing blinding for each witness reference.
@@ -771,6 +804,18 @@ impl<E: Pairing> Proof<E> {
771
804
}
772
805
_ => err_incompat_witness ! ( s_idx, s, witness) ,
773
806
} ,
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
+ } ,
774
819
_ => return Err ( ProofSystemError :: InvalidStatement ) ,
775
820
}
776
821
}
@@ -979,6 +1024,13 @@ impl<E: Pairing> Proof<E> {
979
1024
SubProtocol :: KBUniversalAccumulatorNonMembershipKV ( mut sp) => {
980
1025
sp. gen_proof_contribution ( & challenge) ?
981
1026
}
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
+ }
982
1034
} ) ;
983
1035
}
984
1036
@@ -1086,30 +1138,6 @@ impl<E: Pairing> Proof<E> {
1086
1138
field_elem_from_try_and_incr :: < E :: ScalarField , D > ( bytes)
1087
1139
}
1088
1140
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
-
1113
1141
pub fn for_aggregate ( & self ) -> Self {
1114
1142
let mut statement_proofs = vec ! [ ] ;
1115
1143
for sp in self . statement_proofs ( ) {
@@ -1177,4 +1205,22 @@ impl<E: Pairing> Proof<E> {
1177
1205
}
1178
1206
}
1179
1207
}
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
+ // }
1180
1226
}
0 commit comments