Skip to content

Commit

Permalink
chore: error bubbling (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: jason <[email protected]>
  • Loading branch information
alexander-camuto and jasonmorton authored Jan 15, 2023
1 parent cc2cb51 commit 16f746b
Show file tree
Hide file tree
Showing 27 changed files with 1,055 additions and 951 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ on:
pull_request:
branches: [ "main" ]


concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


env:
CARGO_TERM_COLOR: always

Expand Down Expand Up @@ -60,7 +58,7 @@ jobs:

library-tests:

runs-on: ubuntu-latest-16-cores
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -108,9 +106,9 @@ jobs:
components: rustfmt, clippy

- name: IPA full-prove tests
run: cargo test --release --verbose tests::ipa_fullprove_ -- --test-threads 1
run: cargo test --release --verbose tests::ipa_fullprove_ -- --test-threads 4
- name: KZG full-prove tests
run: cargo test --release --verbose tests::kzg_fullprove_ -- --test-threads 1
run: cargo test --release --verbose tests::kzg_fullprove_ -- --test-threads 4

full-proving-evm-tests:

Expand All @@ -129,7 +127,7 @@ jobs:
- name: Install solc
run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.17 && solc --version
- name: KZG full-prove tests (EVM)
run: cargo test --release --verbose tests_evm::kzg_evm_fullprove_ -- --test-threads 1
run: cargo test --release --verbose tests_evm::kzg_evm_fullprove_ -- --test-threads 3

prove-and-verify-tests:

Expand All @@ -145,9 +143,9 @@ jobs:
components: rustfmt, clippy

- name: IPA prove and verify tests
run: cargo test --release --verbose tests::ipa_prove_and_verify_ -- --test-threads 1
run: cargo test --release --verbose tests::ipa_prove_and_verify_ -- --test-threads 4
- name: KZG prove and verify tests
run: cargo test --release --verbose tests::kzg_prove_and_verify_ -- --test-threads 1
run: cargo test --release --verbose tests::kzg_prove_and_verify_ -- --test-threads 4

examples:

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ halo2_wrong_ecc = { git = "https://github.com/zkonduit/halo2wrong", package = "e
plonk_verifier = { git = "https://github.com/zkonduit/plonk-verifier", branch = "main"}
colog = { version = "1.1.0", optional = true }
eq-float = "0.1.0"
thiserror = "1.0.38"

[dev-dependencies]
criterion = {version = "0.3", features = ["html_reports"]}
Expand Down
18 changes: 10 additions & 8 deletions benches/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ impl<F: FieldExt + TensorType> Circuit<F> for MyCircuit<F> {
mut config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
config.layout(
&mut layouter,
&[
self.input.clone(),
self.l0_params[0].clone(),
self.l0_params[1].clone(),
],
);
config
.layout(
&mut layouter,
&[
self.input.clone(),
self.l0_params[0].clone(),
self.l0_params[1].clone(),
],
)
.unwrap();
Ok(())
}
}
Expand Down
12 changes: 7 additions & 5 deletions benches/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ impl<F: FieldExt + TensorType> Circuit<F> for MyCircuit<F> {
config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
config.layout(
layouter.namespace(|| "Assign value"),
self.input.clone(),
self.output.clone(),
);
config
.layout(
layouter.namespace(|| "Assign value"),
self.input.clone(),
self.output.clone(),
)
.unwrap();

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion benches/relu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<F: FieldExt + TensorType> Circuit<F> for NLCircuit<F> {
config: Self::Config,
mut layouter: impl Layouter<F>, // layouter is our 'write buffer' for the circuit
) -> Result<(), Error> {
config.layout(&mut layouter, &self.input);
config.layout(&mut layouter, &self.input).unwrap();

Ok(())
}
Expand Down
47 changes: 26 additions & 21 deletions examples/conv2d_mnist/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,30 @@ where
mut config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let x = config.l0.layout(
&mut layouter,
&[
self.input.clone(),
self.l0_params[0].clone(),
self.l0_params[1].clone(),
],
);
let mut x = config.l1.layout(&mut layouter, &x);
let x = config
.l0
.layout(
&mut layouter,
&[
self.input.clone(),
self.l0_params[0].clone(),
self.l0_params[1].clone(),
],
)
.unwrap();
let mut x = config.l1.layout(&mut layouter, &x).unwrap();
x.flatten();
let l2out = config.l2.layout(
&mut layouter,
&[x, self.l2_params[0].clone(), self.l2_params[1].clone()],
);
let l2out = config
.l2
.layout(
&mut layouter,
&[x, self.l2_params[0].clone(), self.l2_params[1].clone()],
)
.unwrap();

match l2out {
ValTensor::PrevAssigned { inner: v, dims: _ } => v
.enum_map(|i, x| {
layouter
.constrain_instance(x.cell(), config.public_output, i)
.unwrap()
})
.enum_map(|i, x| layouter.constrain_instance(x.cell(), config.public_output, i))
.unwrap(),
_ => panic!("Should be assigned"),
};
Expand Down Expand Up @@ -310,10 +312,11 @@ pub fn runconv() {

let mut input: ValTensor<F> = train_data
.get_slice(&[0..1, 0..28, 0..28])
.unwrap()
.map(Value::known)
.into();

input.reshape(&[1, 28, 28]);
input.reshape(&[1, 28, 28]).unwrap();

let myparams = params::Params::new();
let mut l0_kernels: ValTensor<F> = Tensor::<Value<F>>::from(
Expand All @@ -334,7 +337,9 @@ pub fn runconv() {
)
.into();

l0_kernels.reshape(&[OUT_CHANNELS, IN_CHANNELS, KERNEL_HEIGHT, KERNEL_WIDTH]);
l0_kernels
.reshape(&[OUT_CHANNELS, IN_CHANNELS, KERNEL_HEIGHT, KERNEL_WIDTH])
.unwrap();

let l0_bias: ValTensor<F> = Tensor::<Value<F>>::from(
(0..OUT_CHANNELS).map(|_| Value::known(fieldutils::i32_to_felt(0))),
Expand All @@ -360,7 +365,7 @@ pub fn runconv() {
}))
.into();

l2_weights.reshape(&[CLASSES, LEN]);
l2_weights.reshape(&[CLASSES, LEN]).unwrap();

let circuit = MyCircuit::<
F,
Expand Down
45 changes: 24 additions & 21 deletions examples/mlp_4d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl<F: FieldExt + TensorType, const LEN: usize, const BITS: usize> Circuit<F>
&output,
BITS,
&[LookupOp::ReLU { scale: 1 }],
);
)
.unwrap();

// sets up a new Divide by table
let l4 =
Expand All @@ -107,28 +108,30 @@ impl<F: FieldExt + TensorType, const LEN: usize, const BITS: usize> Circuit<F>
mut config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let x = config.l0.layout(
&mut layouter,
&[
self.input.clone(),
self.l0_params[0].clone(),
self.l0_params[1].clone(),
],
);
let x = config.l1.layout(&mut layouter, &x);
let x = config.l2.layout(
&mut layouter,
&[x, self.l2_params[0].clone(), self.l2_params[1].clone()],
);
let x = config.l3.layout(&mut layouter, &x);
let x = config.l4.layout(&mut layouter, &x);
let x = config
.l0
.layout(
&mut layouter,
&[
self.input.clone(),
self.l0_params[0].clone(),
self.l0_params[1].clone(),
],
)
.unwrap();
let x = config.l1.layout(&mut layouter, &x).unwrap();
let x = config
.l2
.layout(
&mut layouter,
&[x, self.l2_params[0].clone(), self.l2_params[1].clone()],
)
.unwrap();
let x = config.l3.layout(&mut layouter, &x).unwrap();
let x = config.l4.layout(&mut layouter, &x).unwrap();
match x {
ValTensor::PrevAssigned { inner: v, dims: _ } => v
.enum_map(|i, x| {
layouter
.constrain_instance(x.cell(), config.public_output, i)
.unwrap()
})
.enum_map(|i, x| layouter.constrain_instance(x.cell(), config.public_output, i))
.unwrap(),
_ => panic!("Should be assigned"),
};
Expand Down
14 changes: 10 additions & 4 deletions src/bin/ezkl.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use ezkl::commands::Cli;
use ezkl::execute::run;
use log::info;
use log::{error, info};
use rand::seq::SliceRandom;
use std::error::Error;

pub fn main() {
pub fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::create();
colog::init();
banner();
info!("{}", &args.as_json());
run(args)
info!("{}", &args.as_json()?);
let res = run(args);
match &res {
Ok(_) => info!("verify succeeded"),
Err(e) => error!("verify failed: {}", e),
};
res
}

fn banner() {
Expand Down
Loading

0 comments on commit 16f746b

Please sign in to comment.