Skip to content

Commit

Permalink
Release 0.1.1 (#19)
Browse files Browse the repository at this point in the history
* Rollback to pse halo2 and halo2wrong for first release (#5)

* feat: move `Accumulator` to `accumulator.rs`

* feat: update due to halo2

* feat: upgrade to use branch `feature/generic-instructions` of `halo2wrong`

* refactor: rollback to `{halo2,halo2_wrong}` without challenge API and cleanup dependencies

* chore: rename statement to instance and auxliary to witness

* chore: use `finalize` instead of `code`

* feat: add `Code::deployment` and `EvmLoader::deployment_code`; add example `evm-verifier-codegen`

* fix: typo

* feat: reduce generated evm verifier size; rename to `evm-verifier` and add another example `evm-verifier-with-accumulator`

* fix: due to `halo2wrong`

* feat: reorganize mods and traits

* fix: allow empty `values` in `sum_*` and move them under `ScalarLoader`

* ci: use `--all-features` for `cargo test`

* fix: use same strategy for aggregation testing

* fix: simplify trait `PlonkVerifier` again

* fix: move system specified transcript under mod `system`

* feat: add `quotient_poly` info in `Protocol`

* feat: implement linearization for circom integration

* feat: re-export loader's dependency for consumer

* refactor: for circom's integration

* tmp: pin `revm` to rev

* fix: remove parentheses

* fix: upgrade for multi-phase halo2

* feat: improve error reporting

* chore: rename crate to snake case

* feat: add `Domain` as an input of `PolynomialCommitmentScheme::read_proof`

* refactor: for further integration

* feat: generalize to suppoer also ipa and add builder fns to `system::halo2::Config`

* feat: add `KzgDecider` for simple evm verifier

* refactor: split `AccumulationScheme` and `AccumulatorEncoding`

* refactor: split `PolynomialCommitmentScheme` and `MultiOpenScheme`

* fix: not need sealed actually

* fix: `chunk_size` should be `LIMBS` when recovering accumulator

* feat: add `Expression::DistributePowers` to avoid stack overflow

* fix: update and pin foundry

* fix: move testing circuits under `system/halo2`

* fix: allow accumulate single accumulator

* feat: remove all patch and make less depending `halo2wrong`

* Generalized `Halo2Loader` (#12)

* feat: generalize `Protocol` for further usage

* feat: add `EccInstruction::{fixed_base_msm,variable_base_msm,sum_with_const}`

* chore: move `rand_chacha` as dev dependency

* General refactor for further integration (#13)

* feat: remove dev-dependency `foundry` and vendor necessary part of it

* refactor: simplify traits and remove unused stuff

* refactor: much less clone

* feat: generalized `AccumulatorEncoding` for `EccInstructions`

* feat: implement ipa pcs and accumulation (#14)

* ci: add `svm-rs` and install `[email protected]` in job `test` (#16)

* Update `EvmLoader` to generate Yul code instead of bytecode (#15)

* Update `EvmLoader` to generate Yul instead of bytecode

* feat: simplify

* feat: Add missing end_gas_metering impl

Co-authored-by: Han <[email protected]>

Co-authored-by: Han <[email protected]>

* fix: pin all `revm` dependencies (#18)

* fix: looser trait bound on impl `CostEstimation` for `Plonk` (#20)

* Restructure for more kind of verifier (#21)

* feat: restructure to monorepo and expand the project scope to be generic (s)nark verifier

* feat: reorganize mods and traits for further new features

* refactor: simplify trait bounds

* chore: use hyphen case for crate name (`snark_verifier` -> `snark-verifier`)

* docs: add `#![deny(missing_docs)]` and simple documents

* refactor: remove redudant check `validate_ec_point` (still doesn not support identity)

* feat: expand more things and fix typos

Co-authored-by: Chih Cheng Liang <[email protected]>
Co-authored-by: Carlos Pérez <[email protected]>

* fix: rustdoc warnings

* chore: update dependencies (#24)

* chore: update `halo2` and `halo2wrong` version (#25)

* fix: enable `util::hash::poseidon` only when `feature = loader_halo2` (#27)

* feat: working update to halo2-lib v0.3.0

* feat: update zkevm bench

* feat: update recursion example

* feat: switch poseidon native implementation to Scroll's audited version

* fix: invert determinant only once in Cramer's rule

* chore: fix doc

* chore

* chore: forgot to update halo2-base dependency in snark-verifier-sdk

* Minor update (#8)

* feat(sdk): remove duplicate code in
`RangeWithInstanceCircuitBuilder::synthesize`

* feat(sdk): Proof caching when using feature 'halo2-pse'

* chore: sync with halo2-lib

* chore: switch to halo2-lib release-0.3.0 branch

* Moved `RangeWithInstanceCircuitBuilder` to halo2-lib (#9)

* chore: sync with halo2-lib

* fix: clippy

* chore: fix halo2-base branch in sdk

* feat: update to halo2-lib new types (#10)

* feat: add `assert` for non-empty accumulators in `decide_all` (#11)

* feat: use `zip_eq` for `Polynomial` add/sub (#12)

* fix: git CI turn off all features

* fix: `rotate_scalar` misbehaves on `i32::MIN` (#13)

Should never actually be callable with such a large negative rotation

* fix: cleanup code quality (#14)

* fix: `split_by_ascii_whitespace` (#15)

* fix: `batch_invert_and_mul` do not allow zeros (#16)

* feat: verify proof in release mode (#17)

Verify proof before caching it as extra safety

* fix: add better error messages/docs for catching empty inputs (#18)

* chore: add Cargo.lock

* chore: update Cargo dependencies

* feat: fix versions and tags for dependencies

---------

Co-authored-by: Han <[email protected]>
Co-authored-by: DoHoon Kim <[email protected]>
Co-authored-by: Chih Cheng Liang <[email protected]>
Co-authored-by: Carlos Pérez <[email protected]>
Co-authored-by: dante <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
  • Loading branch information
7 people authored Jun 20, 2023
1 parent c36ff8c commit 43e95ce
Show file tree
Hide file tree
Showing 83 changed files with 3,597 additions and 5,754 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
pull_request:
push:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: false

- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: Install solc
run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.17 && solc --version

- name: Run test
run: cargo test --all -- --nocapture


lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: false
components: rustfmt, clippy

- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: Run fmt
run: cargo fmt --all -- --check

- name: Run clippy
run: cargo clippy --all --all-targets -- -D warnings
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
/target
testdata

Cargo.lock
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ incremental = false
[profile.flamegraph]
inherits = "release"
debug = true

# patch until PR https://github.com/privacy-scaling-explorations/halo2/pull/111 is merged
[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/axiom-crypto/halo2.git", branch = "feat/serde-raw" }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# PLONK Verifier
# SNARK Verifier

Generic PLONK verifier.
Generic (S)NARK verifier.
28 changes: 14 additions & 14 deletions snark-verifier-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "snark-verifier-sdk"
version = "0.0.1"
version = "0.1.1"
edition = "2021"

[dependencies]
itertools = "0.10.3"
itertools = "0.10.5"
lazy_static = "1.4.0"
num-bigint = "0.4.3"
num-integer = "0.1.45"
Expand All @@ -14,24 +14,24 @@ rand_chacha = "0.3.1"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = { version = "2.2", optional = true }
bincode = "1.3.3"
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }

halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false }
halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.3.0", default-features = false }
snark-verifier = { path = "../snark-verifier", default-features = false }

# loader_evm
ethereum-types = { version = "0.14", default-features = false, features = ["std"], optional = true }
ethereum-types = { version = "=0.14.1", default-features = false, features = ["std"], optional = true }
# sha3 = { version = "0.10", optional = true }
# revm = { version = "2.3.1", optional = true }
# bytes = { version = "1.2", optional = true }
# rlp = { version = "0.5", default-features = false, features = ["std"], optional = true }

# zkevm benchmarks
zkevm-circuits = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", features = ["test"], optional = true }
bus-mapping = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
eth-types = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
mock = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
zkevm-circuits = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits.git", rev = "f834e61", features = ["test"], optional = true }
bus-mapping = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits.git", rev = "f834e61", optional = true }
eth-types = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits.git", rev = "f834e61", optional = true }
mock = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits.git", rev = "f834e61", optional = true }

[dev-dependencies]
ark-std = { version = "0.3.0", features = ["print-trace"] }
Expand All @@ -44,13 +44,13 @@ crossterm = { version = "0.25" }
tui = { version = "0.19", default-features = false, features = ["crossterm"] }

[features]
default = ["loader_halo2", "loader_evm", "halo2-axiom", "halo2-base/jemallocator"]
default = ["loader_halo2", "loader_evm", "halo2-axiom", "halo2-base/jemallocator", "display"]
display = ["snark-verifier/display", "dep:ark-std"]
loader_evm = ["snark-verifier/loader_evm", "dep:ethereum-types"]
loader_halo2 = ["snark-verifier/loader_halo2"]
parallel = ["snark-verifier/parallel"]
# EXACTLY one of halo2-pse / halo2-axiom should always be turned on; not sure how to enforce this with Cargo
halo2-pse = ["snark-verifier/halo2-pse"]
halo2-pse = ["snark-verifier/halo2-pse", "dep:serde_with"]
halo2-axiom = ["snark-verifier/halo2-axiom"]

zkevm = ["dep:zkevm-circuits", "dep:bus-mapping", "dep:mock", "dep:eth-types"]
Expand All @@ -62,10 +62,10 @@ harness = false

[[bench]]
name = "zkevm"
required-features = ["loader_halo2", "zkevm", "halo2-pse", "halo2-base/jemallocator"]
required-features = ["loader_halo2", "loader_evm", "zkevm", "halo2-pse"]
harness = false

[[bench]]
name = "zkevm_plus_state"
required-features = ["loader_halo2", "zkevm", "halo2-pse", "halo2-base/jemallocator"]
harness = false
required-features = ["loader_halo2", "loader_evm", "zkevm", "halo2-pse"]
harness = false
83 changes: 56 additions & 27 deletions snark-verifier-sdk/benches/standard_plonk.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
use criterion::{criterion_group, criterion_main};
use criterion::{BenchmarkId, Criterion};
use halo2_base::gates::builder::CircuitBuilderStage;
use halo2_base::utils::fs::gen_srs;
use pprof::criterion::{Output, PProfProfiler};

use rand::rngs::OsRng;
use std::path::Path;
use ark_std::{end_timer, start_timer};
use halo2_base::halo2_proofs;
use halo2_proofs::halo2curves as halo2_curves;
use halo2_proofs::{
halo2curves::bn256::Bn256,
poly::{commitment::Params, kzg::commitment::ParamsKZG},
};
use rand::rngs::OsRng;
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use snark_verifier_sdk::CircuitExt;
use snark_verifier_sdk::evm::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier_shplonk};
use snark_verifier_sdk::halo2::aggregation::AggregationConfigParams;
use snark_verifier_sdk::{
gen_pk,
halo2::{aggregation::AggregationCircuit, gen_proof_shplonk, gen_snark_shplonk},
Snark,
};
use snark_verifier_sdk::{CircuitExt, SHPLONK};

mod application {
use super::halo2_curves::bn256::Fr;
Expand Down Expand Up @@ -145,9 +147,9 @@ mod application {
}
#[cfg(feature = "halo2-axiom")]
{
region.assign_advice(config.a, 0, Value::known(self.0))?;
region.assign_advice(config.a, 0, Value::known(self.0));
region.assign_fixed(config.q_a, 0, -Fr::one());
region.assign_advice(config.a, 1, Value::known(-Fr::from(5u64)))?;
region.assign_advice(config.a, 1, Value::known(-Fr::from(5u64)));
for (idx, column) in (1..).zip([
config.q_a,
config.q_b,
Expand All @@ -158,7 +160,7 @@ mod application {
region.assign_fixed(column, 1, Fr::from(idx as u64));
}

let a = region.assign_advice(config.a, 2, Value::known(Fr::one()))?;
let a = region.assign_advice(config.a, 2, Value::known(Fr::one()));
a.copy_advice(&mut region, config.b, 3);
a.copy_advice(&mut region, config.c, 4);
}
Expand All @@ -173,42 +175,69 @@ mod application {
fn gen_application_snark(params: &ParamsKZG<Bn256>) -> Snark {
let circuit = application::StandardPlonk::rand(OsRng);

let pk = gen_pk(params, &circuit, None);
gen_snark_shplonk(params, &pk, circuit, &mut OsRng, None::<&str>)
let pk = gen_pk(params, &circuit, Some(Path::new("app.pk")));
gen_snark_shplonk(params, &pk, circuit, Some(Path::new("app.snark")))
}

fn bench(c: &mut Criterion) {
std::env::set_var("VERIFY_CONFIG", "./configs/example_evm_accumulator.config");
let k = 21;
let params = halo2_base::utils::fs::gen_srs(k);
let params_app = {
let mut params = params.clone();
params.downsize(8);
params
};
let path = "./configs/example_evm_accumulator.json";
let params_app = gen_srs(8);

let snarks = [(); 3].map(|_| gen_application_snark(&params_app));
let agg_config = AggregationConfigParams::from_path(path);
let params = gen_srs(agg_config.degree);
let lookup_bits = params.k() as usize - 1;

let start1 = start_timer!(|| "Create aggregation circuit");
let mut rng = ChaCha20Rng::from_entropy();
let agg_circuit = AggregationCircuit::new(&params, snarks, &mut rng);
end_timer!(start1);
let agg_circuit = AggregationCircuit::keygen::<SHPLONK>(&params, snarks.clone());

let pk = gen_pk(&params, &agg_circuit, None);
let start0 = start_timer!(|| "gen vk & pk");
let pk = gen_pk(&params, &agg_circuit, Some(Path::new("agg.pk")));
end_timer!(start0);
let break_points = agg_circuit.break_points();

let mut group = c.benchmark_group("plonk-prover");
group.sample_size(10);
group.bench_with_input(
BenchmarkId::new("standard-plonk-agg", k),
&(&params, &pk, &agg_circuit),
|b, &(params, pk, agg_circuit)| {
BenchmarkId::new("standard-plonk-agg", params.k()),
&(&params, &pk, &break_points, &snarks),
|b, &(params, pk, break_points, snarks)| {
b.iter(|| {
let agg_circuit = AggregationCircuit::new::<SHPLONK>(
CircuitBuilderStage::Prover,
Some(break_points.clone()),
lookup_bits,
params,
snarks.clone(),
);
let instances = agg_circuit.instances();
gen_proof_shplonk(params, pk, agg_circuit.clone(), instances, &mut rng, None)
gen_proof_shplonk(params, pk, agg_circuit, instances, None)
})
},
);
group.finish();

#[cfg(feature = "loader_evm")]
{
// do one more time to verify
let agg_circuit = AggregationCircuit::new::<SHPLONK>(
CircuitBuilderStage::Prover,
Some(break_points),
lookup_bits,
&params,
snarks.clone(),
);
let num_instances = agg_circuit.num_instance();
let instances = agg_circuit.instances();
let proof = gen_evm_proof_shplonk(&params, &pk, agg_circuit, instances.clone());

let deployment_code = gen_evm_verifier_shplonk::<AggregationCircuit>(
&params,
pk.get_vk(),
num_instances,
None,
);
evm_verify(deployment_code, instances, proof);
}
}

criterion_group! {
Expand Down
Loading

0 comments on commit 43e95ce

Please sign in to comment.