From 7da5605f513787d68d2abba7465019ade84e1603 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 26 May 2021 23:55:40 +0100 Subject: [PATCH] Remove redundant Error suffix from Error cases --- CHANGELOG.md | 5 +++- benches/plonk.rs | 24 +++++++++--------- examples/circuit-layout.rs | 32 ++++++++++++------------ examples/simple-example.rs | 8 +++--- examples/two-chip.rs | 14 +++++------ src/circuit/floor_planner/single_pass.rs | 8 +++--- src/circuit/floor_planner/v1.rs | 4 +-- src/dev.rs | 6 ++--- src/plonk/error.rs | 8 +++--- src/plonk/keygen.rs | 2 +- src/plonk/permutation/keygen.rs | 4 +-- src/plonk/prover.rs | 2 +- src/plonk/verifier.rs | 2 +- tests/plonk_api.rs | 32 ++++++++++++------------ 14 files changed, 77 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de649..49459e62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,10 @@ and this project adheres to Rust's notion of - `Error` no longer implements `PartialEq`. Tests can check for specific error cases with `assert!(matches!(..))`. - `Error::IncompatibleParams` is now `Error::InvalidInstances`. - - `Error::TranscriptError` stores the underlying `io::Error`. + - `Error::OpeningError` is now `Error::Opening`. + - `Error::SynthesisError` is now `Error::Synthesis`. + - `Error::TranscriptError` is now `Error::Transcript`, and stores the + underlying `io::Error`. ### Removed - `halo2::arithmetic::BatchInvert` (use `ff::BatchInvert` instead). diff --git a/benches/plonk.rs b/benches/plonk.rs index 3106b72c..15528d48 100644 --- a/benches/plonk.rs +++ b/benches/plonk.rs @@ -90,20 +90,20 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) { 0, || { value = Some(f()?); - Ok(value.ok_or(Error::SynthesisError)?.0) + Ok(value.ok_or(Error::Synthesis)?.0) }, )?; let rhs = region.assign_advice( || "rhs", self.config.b, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1), + || Ok(value.ok_or(Error::Synthesis)?.1), )?; let out = region.assign_advice( || "out", self.config.c, 0, - || Ok(value.ok_or(Error::SynthesisError)?.2), + || Ok(value.ok_or(Error::Synthesis)?.2), )?; region.assign_fixed(|| "a", self.config.sa, 0, || Ok(FF::zero()))?; @@ -132,20 +132,20 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) { 0, || { value = Some(f()?); - Ok(value.ok_or(Error::SynthesisError)?.0) + Ok(value.ok_or(Error::Synthesis)?.0) }, )?; let rhs = region.assign_advice( || "rhs", self.config.b, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1), + || Ok(value.ok_or(Error::Synthesis)?.1), )?; let out = region.assign_advice( || "out", self.config.c, 0, - || Ok(value.ok_or(Error::SynthesisError)?.2), + || Ok(value.ok_or(Error::Synthesis)?.2), )?; region.assign_fixed(|| "a", self.config.sa, 0, || Ok(FF::one()))?; @@ -226,17 +226,17 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) { let (a0, _, c0) = cs.raw_multiply(&mut layouter, || { a_squared = self.a.map(|a| a.square()); Ok(( - self.a.ok_or(Error::SynthesisError)?, - self.a.ok_or(Error::SynthesisError)?, - a_squared.ok_or(Error::SynthesisError)?, + self.a.ok_or(Error::Synthesis)?, + self.a.ok_or(Error::Synthesis)?, + a_squared.ok_or(Error::Synthesis)?, )) })?; let (a1, b1, _) = cs.raw_add(&mut layouter, || { let fin = a_squared.and_then(|a2| self.a.map(|a| a + a2)); Ok(( - self.a.ok_or(Error::SynthesisError)?, - a_squared.ok_or(Error::SynthesisError)?, - fin.ok_or(Error::SynthesisError)?, + self.a.ok_or(Error::Synthesis)?, + a_squared.ok_or(Error::Synthesis)?, + fin.ok_or(Error::Synthesis)?, )) })?; cs.copy(&mut layouter, a0, a1)?; diff --git a/examples/circuit-layout.rs b/examples/circuit-layout.rs index 49035595..eed2816a 100644 --- a/examples/circuit-layout.rs +++ b/examples/circuit-layout.rs @@ -72,32 +72,32 @@ impl StandardCs for StandardPlonk { 0, || { value = Some(f()?); - Ok(value.ok_or(Error::SynthesisError)?.0) + Ok(value.ok_or(Error::Synthesis)?.0) }, )?; region.assign_advice( || "lhs^4", self.config.d, 0, - || Ok(value.ok_or(Error::SynthesisError)?.0.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.0.square().square()), )?; let rhs = region.assign_advice( || "rhs", self.config.b, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1), + || Ok(value.ok_or(Error::Synthesis)?.1), )?; region.assign_advice( || "rhs^4", self.config.e, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.1.square().square()), )?; let out = region.assign_advice( || "out", self.config.c, 0, - || Ok(value.ok_or(Error::SynthesisError)?.2), + || Ok(value.ok_or(Error::Synthesis)?.2), )?; region.assign_fixed(|| "a", self.config.sa, 0, || Ok(FF::zero()))?; @@ -117,32 +117,32 @@ impl StandardCs for StandardPlonk { 0, || { value = Some(f()?); - Ok(value.ok_or(Error::SynthesisError)?.0) + Ok(value.ok_or(Error::Synthesis)?.0) }, )?; region.assign_advice( || "lhs^4", self.config.d, 0, - || Ok(value.ok_or(Error::SynthesisError)?.0.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.0.square().square()), )?; let rhs = region.assign_advice( || "rhs", self.config.b, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1), + || Ok(value.ok_or(Error::Synthesis)?.1), )?; region.assign_advice( || "rhs^4", self.config.e, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.1.square().square()), )?; let out = region.assign_advice( || "out", self.config.c, 0, - || Ok(value.ok_or(Error::SynthesisError)?.2), + || Ok(value.ok_or(Error::Synthesis)?.2), )?; region.assign_fixed(|| "a", self.config.sa, 0, || Ok(FF::one()))?; @@ -259,17 +259,17 @@ impl Circuit for MyCircuit { let (a0, _, c0) = cs.raw_multiply(&mut region, || { a_squared = self.a.map(|a| a.square()); Ok(( - self.a.ok_or(Error::SynthesisError)?, - self.a.ok_or(Error::SynthesisError)?, - a_squared.ok_or(Error::SynthesisError)?, + self.a.ok_or(Error::Synthesis)?, + self.a.ok_or(Error::Synthesis)?, + a_squared.ok_or(Error::Synthesis)?, )) })?; let (a1, b1, _) = cs.raw_add(&mut region, || { let fin = a_squared.and_then(|a2| self.a.map(|a| a + a2)); Ok(( - self.a.ok_or(Error::SynthesisError)?, - a_squared.ok_or(Error::SynthesisError)?, - fin.ok_or(Error::SynthesisError)?, + self.a.ok_or(Error::Synthesis)?, + a_squared.ok_or(Error::Synthesis)?, + fin.ok_or(Error::Synthesis)?, )) })?; cs.copy(&mut region, a0, a1)?; diff --git a/examples/simple-example.rs b/examples/simple-example.rs index f3236b5f..56a6fd7e 100644 --- a/examples/simple-example.rs +++ b/examples/simple-example.rs @@ -172,7 +172,7 @@ impl NumericInstructions for FieldChip { || "private input", config.advice[0], 0, - || value.ok_or(Error::SynthesisError), + || value.ok_or(Error::Synthesis), )?; num = Some(Number { cell, value }); Ok(()) @@ -233,13 +233,13 @@ impl NumericInstructions for FieldChip { || "lhs", config.advice[0], 0, - || a.value.ok_or(Error::SynthesisError), + || a.value.ok_or(Error::Synthesis), )?; let rhs = region.assign_advice( || "rhs", config.advice[1], 0, - || b.value.ok_or(Error::SynthesisError), + || b.value.ok_or(Error::Synthesis), )?; region.constrain_equal(a.cell, lhs)?; region.constrain_equal(b.cell, rhs)?; @@ -250,7 +250,7 @@ impl NumericInstructions for FieldChip { || "lhs * rhs", config.advice[0], 1, - || value.ok_or(Error::SynthesisError), + || value.ok_or(Error::Synthesis), )?; // Finally, we return a variable representing the output, diff --git a/examples/two-chip.rs b/examples/two-chip.rs index a2adcea9..2f22cc0a 100644 --- a/examples/two-chip.rs +++ b/examples/two-chip.rs @@ -222,13 +222,13 @@ impl AddInstructions for AddChip { || "lhs", config.advice[0], 0, - || a.value.ok_or(Error::SynthesisError), + || a.value.ok_or(Error::Synthesis), )?; let rhs = region.assign_advice( || "rhs", config.advice[1], 0, - || b.value.ok_or(Error::SynthesisError), + || b.value.ok_or(Error::Synthesis), )?; region.constrain_equal(a.cell, lhs)?; region.constrain_equal(b.cell, rhs)?; @@ -239,7 +239,7 @@ impl AddInstructions for AddChip { || "lhs * rhs", config.advice[0], 1, - || value.ok_or(Error::SynthesisError), + || value.ok_or(Error::Synthesis), )?; // Finally, we return a variable representing the output, @@ -362,13 +362,13 @@ impl MulInstructions for MulChip { || "lhs", config.advice[0], 0, - || a.value.ok_or(Error::SynthesisError), + || a.value.ok_or(Error::Synthesis), )?; let rhs = region.assign_advice( || "rhs", config.advice[1], 0, - || b.value.ok_or(Error::SynthesisError), + || b.value.ok_or(Error::Synthesis), )?; region.constrain_equal(a.cell, lhs)?; region.constrain_equal(b.cell, rhs)?; @@ -379,7 +379,7 @@ impl MulInstructions for MulChip { || "lhs * rhs", config.advice[0], 1, - || value.ok_or(Error::SynthesisError), + || value.ok_or(Error::Synthesis), )?; // Finally, we return a variable representing the output, @@ -457,7 +457,7 @@ impl FieldInstructions for FieldChip { || "private input", config.advice[0], 0, - || value.ok_or(Error::SynthesisError), + || value.ok_or(Error::Synthesis), )?; num = Some(Number { cell, value }); Ok(()) diff --git a/src/circuit/floor_planner/single_pass.rs b/src/circuit/floor_planner/single_pass.rs index 37ac23de..68e35c00 100644 --- a/src/circuit/floor_planner/single_pass.rs +++ b/src/circuit/floor_planner/single_pass.rs @@ -180,7 +180,7 @@ impl<'a, F: Field, CS: Assignment + 'a> Layouter for SingleChipLayouter<'a _ => None, }) { Some(Some(len)) => len, - _ => return Err(Error::SynthesisError), // TODO better error + _ => return Err(Error::Synthesis), // TODO better error } }; @@ -320,7 +320,7 @@ impl<'r, 'a, F: Field, CS: Assignment + 'a> RegionLayouter let value = self.layouter.cs.query_instance(instance, row)?; let cell = self.assign_advice(annotation, advice, offset, &mut || { - value.ok_or(Error::SynthesisError).map(|v| v.into()) + value.ok_or(Error::Synthesis).map(|v| v.into()) })?; self.layouter.cs.copy( @@ -417,7 +417,7 @@ impl<'r, 'a, F: Field, CS: Assignment + 'a> TableLayouter to: &'v mut (dyn FnMut() -> Result, Error> + 'v), ) -> Result<(), Error> { if self.used_columns.contains(&column) { - return Err(Error::SynthesisError); // TODO better error + return Err(Error::Synthesis); // TODO better error } let entry = self.default_and_assigned.entry(column).or_default(); @@ -439,7 +439,7 @@ impl<'r, 'a, F: Field, CS: Assignment + 'a> TableLayouter (true, 0) => entry.0 = Some(value), // Since there is already an existing default value for this table column, // the caller should not be attempting to assign another value at offset 0. - (false, 0) => return Err(Error::SynthesisError), // TODO better error + (false, 0) => return Err(Error::Synthesis), // TODO better error _ => (), } if entry.1.len() <= offset { diff --git a/src/circuit/floor_planner/v1.rs b/src/circuit/floor_planner/v1.rs index 29c90c4b..2b7f8ae7 100644 --- a/src/circuit/floor_planner/v1.rs +++ b/src/circuit/floor_planner/v1.rs @@ -321,7 +321,7 @@ impl<'p, 'a, F: Field, CS: Assignment + 'a> AssignmentPass<'p, 'a, F, CS> { _ => None, }) { Some(Some(len)) => len, - _ => return Err(Error::SynthesisError), // TODO better error + _ => return Err(Error::Synthesis), // TODO better error } }; @@ -436,7 +436,7 @@ impl<'r, 'a, F: Field, CS: Assignment + 'a> RegionLayouter for V1Region<'r let value = self.plan.cs.query_instance(instance, row)?; let cell = self.assign_advice(annotation, advice, offset, &mut || { - value.ok_or(Error::SynthesisError).map(|v| v.into()) + value.ok_or(Error::Synthesis).map(|v| v.into()) })?; self.plan.cs.copy( diff --git a/src/dev.rs b/src/dev.rs index bc4085ff..7fda24c1 100644 --- a/src/dev.rs +++ b/src/dev.rs @@ -292,15 +292,15 @@ impl Mul for Value { /// layouter.assign_region(|| "Example region", |mut region| { /// config.s.enable(&mut region, 0)?; /// region.assign_advice(|| "a", config.a, 0, || { -/// self.a.map(|v| F::from(v)).ok_or(Error::SynthesisError) +/// self.a.map(|v| F::from(v)).ok_or(Error::Synthesis) /// })?; /// region.assign_advice(|| "b", config.b, 0, || { -/// self.b.map(|v| F::from(v)).ok_or(Error::SynthesisError) +/// self.b.map(|v| F::from(v)).ok_or(Error::Synthesis) /// })?; /// region.assign_advice(|| "c", config.c, 0, || { /// self.a /// .and_then(|a| self.b.map(|b| F::from(a * b))) -/// .ok_or(Error::SynthesisError) +/// .ok_or(Error::Synthesis) /// })?; /// Ok(()) /// }) diff --git a/src/plonk/error.rs b/src/plonk/error.rs index 419af1ca..7058f79b 100644 --- a/src/plonk/error.rs +++ b/src/plonk/error.rs @@ -6,7 +6,7 @@ use std::io; pub enum Error { /// This is an error that can occur during synthesis of the circuit, for /// example, when the witness is not present. - SynthesisError, + Synthesis, /// The provided instances do not match the circuit parameters. InvalidInstances, /// The constraint system is not satisfied. @@ -14,9 +14,9 @@ pub enum Error { /// Out of bounds index passed to a backend BoundsFailure, /// Opening error - OpeningError, + Opening, /// Transcript error - TranscriptError(io::Error), + Transcript(io::Error), /// Instance provided has more rows than supported by circuit NotEnoughRowsAvailable, /// Instance provided exceeds number of available rows @@ -29,6 +29,6 @@ pub enum Error { impl From for Error { fn from(error: io::Error) -> Self { // The only place we can get io::Error from is the transcript. - Error::TranscriptError(error) + Error::Transcript(error) } } diff --git a/src/plonk/keygen.rs b/src/plonk/keygen.rs index e52f2a03..fd280690 100644 --- a/src/plonk/keygen.rs +++ b/src/plonk/keygen.rs @@ -160,7 +160,7 @@ impl Assignment for Assembly { .ok_or(Error::BoundsFailure)?; for row in self.usable_rows.clone().skip(from_row) { - col[row] = to.ok_or(Error::SynthesisError)?; + col[row] = to.ok_or(Error::Synthesis)?; } Ok(()) diff --git a/src/plonk/permutation/keygen.rs b/src/plonk/permutation/keygen.rs index 1aa9c908..b0f9cba5 100644 --- a/src/plonk/permutation/keygen.rs +++ b/src/plonk/permutation/keygen.rs @@ -51,12 +51,12 @@ impl Assembly { .columns .iter() .position(|c| c == &left_column) - .ok_or(Error::SynthesisError)?; + .ok_or(Error::Synthesis)?; let right_column = self .columns .iter() .position(|c| c == &right_column) - .ok_or(Error::SynthesisError)?; + .ok_or(Error::Synthesis)?; // Check bounds if left_row >= self.mapping[left_column].len() diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index 77d91dc9..06200c75 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -599,5 +599,5 @@ pub fn create_proof< // We query the h(X) polynomial at x .chain(vanishing.open(x)); - multiopen::create_proof(params, transcript, instances).map_err(|_| Error::OpeningError) + multiopen::create_proof(params, transcript, instances).map_err(|_| Error::Opening) } diff --git a/src/plonk/verifier.rs b/src/plonk/verifier.rs index 33c5e0d6..639f7027 100644 --- a/src/plonk/verifier.rs +++ b/src/plonk/verifier.rs @@ -285,5 +285,5 @@ pub fn verify_proof<'params, C: CurveAffine, E: EncodedChallenge, T: Transcri // We are now convinced the circuit is satisfied so long as the // polynomial commitments open to the correct values. - multiopen::verify_proof(params, transcript, queries, msm).map_err(|_| Error::OpeningError) + multiopen::verify_proof(params, transcript, queries, msm).map_err(|_| Error::Opening) } diff --git a/tests/plonk_api.rs b/tests/plonk_api.rs index 5c0ddd1a..457da4fb 100644 --- a/tests/plonk_api.rs +++ b/tests/plonk_api.rs @@ -105,32 +105,32 @@ fn plonk_api() { 0, || { value = Some(f()?); - Ok(value.ok_or(Error::SynthesisError)?.0) + Ok(value.ok_or(Error::Synthesis)?.0) }, )?; region.assign_advice( || "lhs^4", self.config.d, 0, - || Ok(value.ok_or(Error::SynthesisError)?.0.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.0.square().square()), )?; let rhs = region.assign_advice( || "rhs", self.config.b, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1), + || Ok(value.ok_or(Error::Synthesis)?.1), )?; region.assign_advice( || "rhs^4", self.config.e, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.1.square().square()), )?; let out = region.assign_advice( || "out", self.config.c, 0, - || Ok(value.ok_or(Error::SynthesisError)?.2), + || Ok(value.ok_or(Error::Synthesis)?.2), )?; region.assign_fixed(|| "a", self.config.sa, 0, || Ok(FF::zero()))?; @@ -159,32 +159,32 @@ fn plonk_api() { 0, || { value = Some(f()?); - Ok(value.ok_or(Error::SynthesisError)?.0) + Ok(value.ok_or(Error::Synthesis)?.0) }, )?; region.assign_advice( || "lhs^4", self.config.d, 0, - || Ok(value.ok_or(Error::SynthesisError)?.0.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.0.square().square()), )?; let rhs = region.assign_advice( || "rhs", self.config.b, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1), + || Ok(value.ok_or(Error::Synthesis)?.1), )?; region.assign_advice( || "rhs^4", self.config.e, 0, - || Ok(value.ok_or(Error::SynthesisError)?.1.square().square()), + || Ok(value.ok_or(Error::Synthesis)?.1.square().square()), )?; let out = region.assign_advice( || "out", self.config.c, 0, - || Ok(value.ok_or(Error::SynthesisError)?.2), + || Ok(value.ok_or(Error::Synthesis)?.2), )?; region.assign_fixed(|| "a", self.config.sa, 0, || Ok(FF::one()))?; @@ -356,17 +356,17 @@ fn plonk_api() { let (a0, _, c0) = cs.raw_multiply(&mut layouter, || { a_squared = self.a.map(|a| a.square()); Ok(( - self.a.ok_or(Error::SynthesisError)?, - self.a.ok_or(Error::SynthesisError)?, - a_squared.ok_or(Error::SynthesisError)?, + self.a.ok_or(Error::Synthesis)?, + self.a.ok_or(Error::Synthesis)?, + a_squared.ok_or(Error::Synthesis)?, )) })?; let (a1, b1, _) = cs.raw_add(&mut layouter, || { let fin = a_squared.and_then(|a2| self.a.map(|a| a + a2)); Ok(( - self.a.ok_or(Error::SynthesisError)?, - a_squared.ok_or(Error::SynthesisError)?, - fin.ok_or(Error::SynthesisError)?, + self.a.ok_or(Error::Synthesis)?, + a_squared.ok_or(Error::Synthesis)?, + fin.ok_or(Error::Synthesis)?, )) })?; cs.copy(&mut layouter, a0, a1)?;