Update error handling

This commit is contained in:
therealyingtong 2020-10-15 17:01:26 +08:00 committed by Jack Grigg
parent 43337dea1b
commit 2375507f4f
4 changed files with 48 additions and 16 deletions

View file

@ -105,7 +105,9 @@ impl<C: CurveAffine> Proof<C> {
drop(aux_commitments_projective); drop(aux_commitments_projective);
for commitment in &aux_commitments { for commitment in &aux_commitments {
transcript.absorb_point(commitment).ok(); transcript
.absorb_point(commitment)
.map_err(|_| Error::TranscriptError)?;
} }
let aux_polys: Vec<_> = aux let aux_polys: Vec<_> = aux
@ -143,7 +145,9 @@ impl<C: CurveAffine> Proof<C> {
drop(advice_commitments_projective); drop(advice_commitments_projective);
for commitment in &advice_commitments { for commitment in &advice_commitments {
transcript.absorb_point(commitment).ok(); transcript
.absorb_point(commitment)
.map_err(|_| Error::TranscriptError)?;
} }
let advice_polys: Vec<_> = witness let advice_polys: Vec<_> = witness
@ -277,7 +281,9 @@ impl<C: CurveAffine> Proof<C> {
// Hash each permutation product commitment // Hash each permutation product commitment
for c in &permutation_product_commitments { for c in &permutation_product_commitments {
transcript.absorb_point(c).ok(); transcript
.absorb_point(c)
.map_err(|_| Error::TranscriptError)?;
} }
// Obtain challenge for keeping all separate gates linearly independent // Obtain challenge for keeping all separate gates linearly independent
@ -385,7 +391,9 @@ impl<C: CurveAffine> Proof<C> {
// Hash each h(X) piece // Hash each h(X) piece
for c in h_commitments.iter() { for c in h_commitments.iter() {
transcript.absorb_point(c).ok(); transcript
.absorb_point(c)
.map_err(|_| Error::TranscriptError)?;
} }
let x_3: C::Scalar = get_challenge_scalar(Challenge(transcript.squeeze().get_lower_128())); let x_3: C::Scalar = get_challenge_scalar(Challenge(transcript.squeeze().get_lower_128()));

View file

@ -31,12 +31,16 @@ impl<'a, C: CurveAffine> Proof<C> {
// Hash the aux (external) commitments into the transcript // Hash the aux (external) commitments into the transcript
for commitment in aux_commitments { for commitment in aux_commitments {
transcript.absorb_point(commitment).ok(); transcript
.absorb_point(commitment)
.map_err(|_| Error::TranscriptError)?;
} }
// Hash the prover's advice commitments into the transcript // Hash the prover's advice commitments into the transcript
for commitment in &self.advice_commitments { for commitment in &self.advice_commitments {
transcript.absorb_point(commitment).ok(); transcript
.absorb_point(commitment)
.map_err(|_| Error::TranscriptError)?;
} }
// Sample x_0 challenge // Sample x_0 challenge
@ -47,7 +51,9 @@ impl<'a, C: CurveAffine> Proof<C> {
// Hash each permutation product commitment // Hash each permutation product commitment
for c in &self.permutation_product_commitments { for c in &self.permutation_product_commitments {
transcript.absorb_point(c).ok(); transcript
.absorb_point(c)
.map_err(|_| Error::TranscriptError)?;
} }
// Sample x_2 challenge, which keeps the gates linearly independent. // Sample x_2 challenge, which keeps the gates linearly independent.
@ -55,7 +61,9 @@ impl<'a, C: CurveAffine> Proof<C> {
// Obtain a commitment to h(X) in the form of multiple pieces of degree n - 1 // Obtain a commitment to h(X) in the form of multiple pieces of degree n - 1
for c in &self.h_commitments { for c in &self.h_commitments {
transcript.absorb_point(c).ok(); transcript
.absorb_point(c)
.map_err(|_| Error::TranscriptError)?;
} }
// Sample x_3 challenge, which is used to ensure the circuit is // Sample x_3 challenge, which is used to ensure the circuit is

View file

@ -96,8 +96,12 @@ impl<C: CurveAffine> Proof<C> {
// Feed L and R into the cloned transcript. // Feed L and R into the cloned transcript.
// We expect these to not be points at infinity due to the randomness. // We expect these to not be points at infinity due to the randomness.
transcript.absorb_point(&l).ok(); transcript
transcript.absorb_point(&r).ok(); .absorb_point(&l)
.map_err(|_| Error::SamplingError)?;
transcript
.absorb_point(&r)
.map_err(|_| Error::SamplingError)?;
// ... and get the squared challenge. // ... and get the squared challenge.
let challenge_sq_packed = transcript.squeeze().get_lower_128(); let challenge_sq_packed = transcript.squeeze().get_lower_128();
@ -121,8 +125,12 @@ impl<C: CurveAffine> Proof<C> {
let challenge_sq = challenge.square(); let challenge_sq = challenge.square();
// Feed L and R into the real transcript // Feed L and R into the real transcript
transcript.absorb_point(&l).ok(); transcript
transcript.absorb_point(&r).ok(); .absorb_point(&l)
.map_err(|_| Error::SamplingError)?;
transcript
.absorb_point(&r)
.map_err(|_| Error::SamplingError)?;
// And obtain the challenge, even though we already have it, since // And obtain the challenge, even though we already have it, since
// squeezing affects the transcript. // squeezing affects the transcript.
@ -168,7 +176,9 @@ impl<C: CurveAffine> Proof<C> {
let delta = best_multiexp(&[d, d * &b, s], &[g, u, params.h]).to_affine(); let delta = best_multiexp(&[d, d * &b, s], &[g, u, params.h]).to_affine();
// Feed delta into the transcript // Feed delta into the transcript
transcript.absorb_point(&delta).ok(); transcript
.absorb_point(&delta)
.map_err(|_| Error::SamplingError)?;
// Obtain the challenge c. // Obtain the challenge c.
let c_packed = transcript.squeeze().get_lower_128(); let c_packed = transcript.squeeze().get_lower_128();

View file

@ -114,8 +114,12 @@ impl<C: CurveAffine> Proof<C> {
if bool::from(l.get_xy().is_none() | r.get_xy().is_none()) { if bool::from(l.get_xy().is_none() | r.get_xy().is_none()) {
return Err(Error::OpeningError); return Err(Error::OpeningError);
} }
transcript.absorb_point(&l).ok(); transcript
transcript.absorb_point(&r).ok(); .absorb_point(&l)
.map_err(|_| Error::OpeningError)?;
transcript
.absorb_point(&r)
.map_err(|_| Error::OpeningError)?;
let challenge_sq_packed = transcript.squeeze().get_lower_128(); let challenge_sq_packed = transcript.squeeze().get_lower_128();
let challenge_sq: C::Scalar = get_challenge_scalar(Challenge(challenge_sq_packed)); let challenge_sq: C::Scalar = get_challenge_scalar(Challenge(challenge_sq_packed));
@ -154,7 +158,9 @@ impl<C: CurveAffine> Proof<C> {
} }
// Feed delta into the transcript // Feed delta into the transcript
transcript.absorb_point(&delta).ok(); transcript
.absorb_point(&delta)
.map_err(|_| Error::OpeningError)?;
// Get the challenge `c` // Get the challenge `c`
let c_packed = transcript.squeeze().get_lower_128(); let c_packed = transcript.squeeze().get_lower_128();