Skip to content

Commit

Permalink
refactor: rm boxed errors (opaque) (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto authored Jun 9, 2024
1 parent f5f8ef5 commit c97ff84
Show file tree
Hide file tree
Showing 35 changed files with 1,314 additions and 1,076 deletions.
6 changes: 3 additions & 3 deletions examples/notebooks/set_membership.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
"source": [
"import pytest\n",
"def test_verification():\n",
" with pytest.raises(RuntimeError, match='Failed to run verify: The constraint system is not satisfied'):\n",
" with pytest.raises(RuntimeError, match='Failed to run verify: \\\\[halo2\\\\] The constraint system is not satisfied'):\n",
" ezkl.verify(\n",
" proof_path_faulty,\n",
" settings_path,\n",
Expand Down Expand Up @@ -514,9 +514,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}
7 changes: 3 additions & 4 deletions examples/notebooks/solvency.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,11 @@
"import pytest\n",
"\n",
"def test_verification():\n",
" with pytest.raises(RuntimeError, match='Failed to run verify: The constraint system is not satisfied'):\n",
" with pytest.raises(RuntimeError, match='Failed to run verify: \\\\[halo2\\\\] The constraint system is not satisfied'):\n",
" ezkl.verify(\n",
" proof_path,\n",
" settings_path,\n",
" vk_path,\n",
" \n",
" )\n",
"\n",
"# Run the test function\n",
Expand All @@ -510,9 +509,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}
15 changes: 11 additions & 4 deletions src/bin/ezkl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ pub async fn main() {
);
let res = run(command).await;
match &res {
Ok(_) => info!("succeeded"),
Err(e) => error!("failed: {}", e),
};
Ok(_) => {
info!("succeeded");
}
Err(e) => {
error!("{}", e);
std::process::exit(1)
}
}
} else {
error!("no command provided");
init_logger();
error!("No command provided");
std::process::exit(1)
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/circuit/modules/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use halo2_proofs::plonk::Error as PlonkError;
use thiserror::Error;

/// Error type for the circuit module
#[derive(Error, Debug)]
pub enum ModuleError {
/// Halo 2 error
#[error("[halo2] {0}")]
Halo2Error(#[from] PlonkError),
/// Wrong input type for a module
#[error("wrong input type {0} must be {1}")]
WrongInputType(String, String),
/// A constant was not previously assigned
#[error("constant was not previously assigned")]
ConstantNotAssigned,
/// Input length is wrong
#[error("input length is wrong {0}")]
InputWrongLength(usize),
}

impl From<ModuleError> for PlonkError {
fn from(_e: ModuleError) -> PlonkError {
PlonkError::Synthesis
}
}
15 changes: 8 additions & 7 deletions src/circuit/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ pub mod polycommit;

///
pub mod planner;
use halo2_proofs::{
circuit::Layouter,
plonk::{ConstraintSystem, Error},
};

///
pub mod errors;

use halo2_proofs::{circuit::Layouter, plonk::ConstraintSystem};
use halo2curves::ff::PrimeField;
pub use planner::*;

Expand All @@ -35,22 +36,22 @@ pub trait Module<F: PrimeField + TensorType + PartialOrd> {
/// Name
fn name(&self) -> &'static str;
/// Run the operation the module represents
fn run(input: Self::RunInputs) -> Result<Vec<Vec<F>>, Box<dyn std::error::Error>>;
fn run(input: Self::RunInputs) -> Result<Vec<Vec<F>>, errors::ModuleError>;
/// Layout inputs
fn layout_inputs(
&self,
layouter: &mut impl Layouter<F>,
input: &[ValTensor<F>],
constants: &mut ConstantsMap<F>,
) -> Result<Self::InputAssignments, Error>;
) -> Result<Self::InputAssignments, errors::ModuleError>;
/// Layout
fn layout(
&self,
layouter: &mut impl Layouter<F>,
input: &[ValTensor<F>],
row_offset: usize,
constants: &mut ConstantsMap<F>,
) -> Result<ValTensor<F>, Error>;
) -> Result<ValTensor<F>, errors::ModuleError>;
/// Number of instance values the module uses every time it is applied
fn instance_increment_input(&self) -> Vec<usize>;
/// Number of rows used by the module
Expand Down
37 changes: 20 additions & 17 deletions src/circuit/modules/polycommit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use halo2curves::CurveAffine;
use crate::circuit::region::ConstantsMap;
use crate::tensor::{Tensor, ValTensor, ValType, VarTensor};

use super::errors::ModuleError;
use super::Module;

/// The number of instance columns used by the PolyCommit hash function
Expand Down Expand Up @@ -110,7 +111,7 @@ impl Module<Fp> for PolyCommitChip {
_: &mut impl Layouter<Fp>,
_: &[ValTensor<Fp>],
_: &mut ConstantsMap<Fp>,
) -> Result<Self::InputAssignments, Error> {
) -> Result<Self::InputAssignments, ModuleError> {
Ok(())
}

Expand All @@ -123,28 +124,30 @@ impl Module<Fp> for PolyCommitChip {
input: &[ValTensor<Fp>],
_: usize,
constants: &mut ConstantsMap<Fp>,
) -> Result<ValTensor<Fp>, Error> {
) -> Result<ValTensor<Fp>, ModuleError> {
assert_eq!(input.len(), 1);

let local_constants = constants.clone();
layouter.assign_region(
|| "PolyCommit",
|mut region| {
let mut local_inner_constants = local_constants.clone();
let res = self.config.inputs.assign(
&mut region,
0,
&input[0],
&mut local_inner_constants,
)?;
*constants = local_inner_constants;
Ok(res)
},
)
layouter
.assign_region(
|| "PolyCommit",
|mut region| {
let mut local_inner_constants = local_constants.clone();
let res = self.config.inputs.assign(
&mut region,
0,
&input[0],
&mut local_inner_constants,
)?;
*constants = local_inner_constants;
Ok(res)
},
)
.map_err(|e| e.into())
}

///
fn run(message: Vec<Fp>) -> Result<Vec<Vec<Fp>>, Box<dyn std::error::Error>> {
fn run(message: Vec<Fp>) -> Result<Vec<Vec<Fp>>, ModuleError> {
Ok(vec![message])
}

Expand Down
Loading

0 comments on commit c97ff84

Please sign in to comment.