Skip to content

Commit 0405015

Browse files
committed
Revert a change
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent afd78fe commit 0405015

File tree

8 files changed

+78
-65
lines changed

8 files changed

+78
-65
lines changed

bbs_plus/src/proof.rs

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub struct PoKOfSignatureG1Proof<E: Pairing> {
152152
/// Proof of relation `g1 + h1*m1 + h2*m2 +.... + h_i*m_i` = `d*r3 + {h_0}*{-s'} + h1*{-m1} + h2*{-m2} + .... + h_j*{-m_j}` for all disclosed messages `m_i` and for all undisclosed messages `m_j`
153153
#[serde_as(as = "ArkObjectBytes")]
154154
pub T2: E::G1Affine,
155+
/// The following could be achieved by using Either<SchnorrResponse, PartialSchnorrResponse> but serialization
156+
/// for Either is not supported out of the box and had to be implemented
155157
pub sc_resp_2: Option<SchnorrResponse<E::G1Affine>>,
156158
pub sc_partial_resp_2: Option<PartialSchnorrResponse<E::G1Affine>>,
157159
}

bbs_plus/src/proof_23_cdl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub struct PoKOfSignature23G1Proof<E: Pairing> {
104104
/// Proof of relation `g1 + h1*m1 + h2*m2 +.... + h_i*m_i` = `d*r3 + h1*{-m1} + h2*{-m2} + .... + h_j*{-m_j}` for all disclosed messages `m_i` and for all undisclosed messages `m_j`
105105
#[serde_as(as = "ArkObjectBytes")]
106106
pub T2: E::G1Affine,
107+
/// The following could be achieved by using Either<SchnorrResponse, PartialSchnorrResponse> but serialization
108+
/// for Either is not supported out of the box and had to be implemented
107109
pub sc_resp_2: Option<SchnorrResponse<E::G1Affine>>,
108110
pub sc_partial_resp_2: Option<PartialSchnorrResponse<E::G1Affine>>,
109111
}

bbs_plus/src/proof_23_ietf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub struct PoKOfSignature23G1Proof<E: Pairing> {
8787
/// Proof of relation `\sum_{j \notin D}{h_j * m_j} - B_bar * 1/r - A_bar * e * 1/r = g + \sum_{i \in D}{h_i * m_i}`
8888
#[serde_as(as = "ArkObjectBytes")]
8989
pub T: E::G1Affine,
90+
/// The following could be achieved by using Either<SchnorrResponse, PartialSchnorrResponse> but serialization
91+
/// for Either is not supported out of the box and had to be implemented
9092
pub sc_resp: Option<SchnorrResponse<E::G1Affine>>,
9193
pub sc_partial_resp: Option<PartialSchnorrResponse<E::G1Affine>>,
9294
}

kvac/src/bbdt_2016/proof_cdh.rs

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub struct PoKOfMAC<G: AffineRepr> {
101101
pub sc_C: PokTwoDiscreteLogs<G>,
102102
#[serde_as(as = "ArkObjectBytes")]
103103
pub t_msgs: G,
104+
/// The following could be achieved by using Either<SchnorrResponse, PartialSchnorrResponse> but serialization
105+
/// for Either is not supported out of the box and had to be implemented
104106
pub sc_resp_msgs: Option<SchnorrResponse<G>>,
105107
pub sc_partial_resp_msgs: Option<PartialSchnorrResponse<G>>,
106108
}

proof_system/src/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub enum ProofSystemError {
110110
UnequalCiphertextChunksAndSchnorrResponses(usize, usize),
111111
UnequalResponseOfSaverCiphertextAndChunk(usize),
112112
ResponseForWitnessNotFoundForStatement(usize),
113+
NoResponseFoundForWitnessRef(usize, usize),
113114
}
114115

115116
impl From<SchnorrError> for ProofSystemError {

proof_system/src/statement_proof.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,17 @@ pub struct BoundCheckLegoGroth16ProofWhenAggregatingSnarks<E: Pairing> {
284284
pub struct R1CSLegoGroth16Proof<E: Pairing> {
285285
#[serde_as(as = "ArkObjectBytes")]
286286
pub snark_proof: legogroth16::Proof<E>,
287-
pub sp: PedersenCommitmentPartialProof<E::G1Affine>,
287+
pub sp: PedersenCommitmentProof<E::G1Affine>,
288288
}
289289

290290
impl<E: Pairing> R1CSLegoGroth16Proof<E> {
291+
pub fn get_schnorr_response_for_message(
292+
&self,
293+
index: usize,
294+
) -> Result<&E::ScalarField, ProofSystemError> {
295+
self.sp.response.get_response(index).map_err(|e| e.into())
296+
}
297+
291298
pub fn for_aggregation(&self) -> R1CSLegoGroth16ProofWhenAggregatingSnarks<E> {
292299
R1CSLegoGroth16ProofWhenAggregatingSnarks {
293300
commitment: self.snark_proof.d,
@@ -304,7 +311,16 @@ impl<E: Pairing> R1CSLegoGroth16Proof<E> {
304311
pub struct R1CSLegoGroth16ProofWhenAggregatingSnarks<E: Pairing> {
305312
#[serde_as(as = "ArkObjectBytes")]
306313
pub commitment: E::G1Affine,
307-
pub sp: PedersenCommitmentPartialProof<E::G1Affine>,
314+
pub sp: PedersenCommitmentProof<E::G1Affine>,
315+
}
316+
317+
impl<E: Pairing> R1CSLegoGroth16ProofWhenAggregatingSnarks<E> {
318+
pub fn get_schnorr_response_for_message(
319+
&self,
320+
index: usize,
321+
) -> Result<&E::ScalarField, ProofSystemError> {
322+
self.sp.response.get_response(index).map_err(|e| e.into())
323+
}
308324
}
309325

310326
#[serde_as]

proof_system/src/sub_protocols/r1cs_legogorth16.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ use crate::{
77
};
88
use ark_ec::pairing::Pairing;
99
use ark_serialize::CanonicalSerialize;
10-
use ark_std::{
11-
collections::{BTreeMap, BTreeSet},
12-
io::Write,
13-
rand::RngCore,
14-
vec::Vec,
15-
UniformRand,
16-
};
10+
use ark_std::{collections::BTreeMap, io::Write, rand::RngCore, vec::Vec, UniformRand};
1711
use dock_crypto_utils::randomized_pairing_check::RandomizedPairingChecker;
1812
use legogroth16::{
1913
calculate_d,
@@ -156,15 +150,13 @@ impl<'a, E: Pairing> R1CSLegogroth16Protocol<'a, E> {
156150
self.id,
157151
));
158152
}
159-
let comm_wit_count = self.proving_key.as_ref().unwrap().vk.commit_witness_count as usize;
160-
let skip_responses_for = BTreeSet::from_iter(0..comm_wit_count);
161153
Ok(StatementProof::R1CSLegoGroth16(R1CSLegoGroth16Proof {
162154
snark_proof: self.snark_proof.take().unwrap(),
163155
sp: self
164156
.sp
165157
.take()
166158
.unwrap()
167-
.gen_partial_proof_contribution_as_struct(challenge, &skip_responses_for)?,
159+
.gen_proof_contribution_as_struct(challenge)?,
168160
}))
169161
}
170162

@@ -177,7 +169,6 @@ impl<'a, E: Pairing> R1CSLegogroth16Protocol<'a, E> {
177169
comm_key: &[E::G1Affine],
178170
pvk: &PreparedVerifyingKey<E>,
179171
pairing_checker: &mut Option<RandomizedPairingChecker<E>>,
180-
missing_responses: BTreeMap<usize, E::ScalarField>,
181172
) -> Result<(), ProofSystemError> {
182173
let snark_proof = &proof.snark_proof;
183174
match pairing_checker {
@@ -201,7 +192,7 @@ impl<'a, E: Pairing> R1CSLegogroth16Protocol<'a, E> {
201192
// NOTE: value of id is dummy
202193
let sp = SchnorrProtocol::new(10000, comm_key, proof.snark_proof.d);
203194

204-
sp.verify_partial_proof_contribution(challenge, &proof.sp, missing_responses)
195+
sp.verify_proof_contribution(challenge, &proof.sp)
205196
.map_err(|e| ProofSystemError::SchnorrProofContributionFailed(self.id as u32, e))
206197
}
207198

@@ -210,11 +201,10 @@ impl<'a, E: Pairing> R1CSLegogroth16Protocol<'a, E> {
210201
challenge: &E::ScalarField,
211202
proof: &R1CSLegoGroth16ProofWhenAggregatingSnarks<E>,
212203
comm_key: &[E::G1Affine],
213-
missing_responses: BTreeMap<usize, E::ScalarField>,
214204
) -> Result<(), ProofSystemError> {
215205
// NOTE: value of id is dummy
216206
let sp = SchnorrProtocol::new(10000, comm_key, proof.commitment);
217-
sp.verify_partial_proof_contribution(challenge, &proof.sp, missing_responses)
207+
sp.verify_proof_contribution(challenge, &proof.sp)
218208
.map_err(|e| ProofSystemError::SchnorrProofContributionFailed(self.id as u32, e))
219209
}
220210

proof_system/src/verifier.rs

+47-49
Original file line numberDiff line numberDiff line change
@@ -505,27 +505,6 @@ impl<E: Pairing> Proof<E> {
505505
StatementProof::PoKPSSignature(p) => {
506506
let sig_params = s.get_params(&proof_spec.setup_params, s_idx)?;
507507
let pk = s.get_public_key(&proof_spec.setup_params, s_idx)?;
508-
// // Check witness equalities for this statement.
509-
// let revealed_msg_ids: Vec<_> =
510-
// s.revealed_messages.keys().copied().collect();
511-
// for i in 0..sig_params.supported_message_count() {
512-
// let w_ref = (s_idx, i);
513-
// for j in 0..witness_equalities.len() {
514-
// if witness_equalities[j].contains(&w_ref) {
515-
// let resp = p.response_for_message(
516-
// i,
517-
// revealed_msg_ids.iter().copied(),
518-
// )?;
519-
// Self::check_response_for_equality(
520-
// s_idx,
521-
// i,
522-
// j,
523-
// &mut responses_for_equalities,
524-
// resp,
525-
// )?;
526-
// }
527-
// }
528-
// }
529508
transcript.set_label(PS_LABEL);
530509
p.challenge_contribution(&mut transcript, pk, sig_params)?;
531510
}
@@ -1295,49 +1274,70 @@ impl<E: Pairing> Proof<E> {
12951274
let pub_inp = s
12961275
.get_public_inputs(&proof_spec.setup_params, s_idx)?
12971276
.to_vec();
1298-
let mut resp = BTreeMap::new();
1299-
for i in 0..verifying_key.commit_witness_count as usize {
1300-
let wit_ref = (s_idx, i);
1301-
for (i, eq) in disjoint_equalities.iter().enumerate() {
1302-
if eq.has_wit_ref(&wit_ref) {
1303-
if let Some(r) = resp_for_equalities.get(&i) {
1304-
resp.insert(i, *r);
1305-
} else {
1306-
return Err(
1307-
ProofSystemError::ResponseForWitnessNotFoundForStatement(
1308-
s_idx,
1309-
),
1310-
);
1311-
}
1312-
// Exit loop because equalities are disjoint
1313-
break;
1314-
}
1315-
}
1316-
}
13171277

13181278
match proof {
1319-
StatementProof::R1CSLegoGroth16(ref r1cs_proof) => sp
1320-
.verify_proof_contribution(
1279+
StatementProof::R1CSLegoGroth16(ref r1cs_proof) => {
1280+
for w_id in 0..verifying_key.commit_witness_count as usize {
1281+
let w_ref = (s_idx, w_id);
1282+
for (i, eq) in disjoint_equalities.iter().enumerate() {
1283+
if eq.has_wit_ref(&w_ref) {
1284+
let resp =
1285+
r1cs_proof.get_schnorr_response_for_message(w_id)?;
1286+
if let Some(r) = resp_for_equalities.get(&i) {
1287+
if resp != r {
1288+
return Err(
1289+
ProofSystemError::WitnessResponseNotEqual(
1290+
s_idx, w_id,
1291+
),
1292+
);
1293+
}
1294+
} else {
1295+
resp_for_equalities.insert(i, *resp);
1296+
}
1297+
}
1298+
}
1299+
}
1300+
sp.verify_proof_contribution(
13211301
&challenge,
13221302
&pub_inp,
13231303
r1cs_proof,
13241304
r1cs_comm_keys.get(s_idx).unwrap(),
13251305
derived_lego_vk.get(s_idx).unwrap(),
13261306
&mut pairing_checker,
1327-
resp,
1328-
)?,
1307+
)?
1308+
}
13291309
StatementProof::R1CSLegoGroth16WithAggregation(ref r1cs_proof) => {
13301310
let agg_idx = agg_lego_stmts.get(&s_idx).ok_or_else(|| {
13311311
ProofSystemError::InvalidStatementProofIndex(s_idx)
13321312
})?;
13331313
agg_lego[*agg_idx].0.push(r1cs_proof.commitment);
13341314
agg_lego[*agg_idx].1.push(pub_inp);
13351315

1316+
for w_id in 0..verifying_key.commit_witness_count as usize {
1317+
let w_ref = (s_idx, w_id);
1318+
for (i, eq) in disjoint_equalities.iter().enumerate() {
1319+
if eq.has_wit_ref(&w_ref) {
1320+
let resp =
1321+
r1cs_proof.get_schnorr_response_for_message(w_id)?;
1322+
if let Some(r) = resp_for_equalities.get(&i) {
1323+
if resp != r {
1324+
return Err(
1325+
ProofSystemError::WitnessResponseNotEqual(
1326+
s_idx, w_id,
1327+
),
1328+
);
1329+
}
1330+
} else {
1331+
resp_for_equalities.insert(i, *resp);
1332+
}
1333+
}
1334+
}
1335+
}
1336+
13361337
sp.verify_proof_contribution_using_prepared_when_aggregating_snark(
13371338
&challenge,
13381339
r1cs_proof,
13391340
r1cs_comm_keys.get(s_idx).unwrap(),
1340-
resp,
13411341
)?
13421342
}
13431343
_ => {
@@ -1774,14 +1774,12 @@ impl<E: Pairing> Proof<E> {
17741774
if let Some(r) = resp_for_equalities.get(&i) {
17751775
resp = Some(*r);
17761776
} else {
1777-
return Err(ProofSystemError::ResponseForWitnessNotFoundForStatement(
1778-
s_idx,
1779-
));
1777+
return Err(ProofSystemError::NoResponseFoundForWitnessRef(s_idx, 0));
17801778
}
17811779
// Exit loop because equalities are disjoint
17821780
break;
17831781
}
17841782
}
1785-
resp.ok_or_else(|| ProofSystemError::ResponseForWitnessNotFoundForStatement(s_idx))
1783+
resp.ok_or_else(|| ProofSystemError::NoResponseFoundForWitnessRef(s_idx, 0))
17861784
}
17871785
}

0 commit comments

Comments
 (0)