Skip to content

Commit d6a917b

Browse files
mmaker=?UTF-8?q?GOURIOU=20L=C3=A9na=C3=AFck?=
andcommitted
fix(fiat_shamir): refuse malformed proofs
This is part of #58. Co-Authored-By: =?UTF-8?q?GOURIOU=20L=C3=A9na=C3=AFck?= <[email protected]>
1 parent 6be467f commit d6a917b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/fiat_shamir.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,13 @@ where
117117
.prover_response(prover_state, &challenge)?;
118118

119119
// Local verification of the proof
120-
debug_assert!(self
120+
if self
121121
.interactive_proof
122122
.verifier(&commitment, &challenge, &response)
123-
.is_ok());
123+
.is_err()
124+
{
125+
return Err(Error::VerificationFailure);
126+
}
124127
Ok((commitment, challenge, response))
125128
}
126129

@@ -211,6 +214,13 @@ where
211214
return Err(Error::VerificationFailure);
212215
}
213216

217+
// Assert correct proof size
218+
let total_expected_len =
219+
commitment_size + self.interactive_proof.serialize_response(&response).len();
220+
if proof.len() != total_expected_len {
221+
return Err(Error::VerificationFailure);
222+
}
223+
214224
let mut hash_state = self.hash_state.clone();
215225

216226
// Recompute the challenge
@@ -283,6 +293,13 @@ where
283293
return Err(Error::VerificationFailure);
284294
}
285295

296+
// Assert correct proof size
297+
let total_expected_len =
298+
challenge_size + self.interactive_proof.serialize_response(&response).len();
299+
if proof.len() != total_expected_len {
300+
return Err(Error::VerificationFailure);
301+
}
302+
286303
// Compute the commitments
287304
let commitment = self
288305
.interactive_proof

0 commit comments

Comments
 (0)