Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache lookup consts vk #17

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
de1326d
feat: chunked lookup verifier (#1)
alexander-camuto Nov 19, 2023
1f7315b
feat: lookup modularity (#2)
alexander-camuto Jan 22, 2024
bf2c640
Merge remote-tracking branch 'upstream/main'
alexander-camuto Jan 22, 2024
366c0d5
Merge branch 'main' of https://github.com/alexander-camuto/halo2-soli…
alexander-camuto Jan 22, 2024
eb04be1
fix: tests
alexander-camuto Jan 22, 2024
fd74f1d
chore: update readme (#4)
alexander-camuto May 2, 2024
2701125
append lookup consts to VK memory.
ethan-crypto Jun 24, 2024
32b59b1
* finish up tests
ethan-crypto Jun 24, 2024
0aa84ea
*pass none to `evaluator.lookup_computations` when building conjoined…
ethan-crypto Jun 25, 2024
e649d02
check rust version of CI.
ethan-crypto Jun 25, 2024
8e8e5d3
*setup toolchain for rust v 1.77.2 for revm compatibility.
ethan-crypto Jun 25, 2024
a35d857
*new template for reusable verifier.
ethan-crypto Jul 1, 2024
54c088d
*fix clippy warnings and vk loading bug.
ethan-crypto Jul 1, 2024
164fa25
*cache proof_len_cptr in vk.
ethan-crypto Jul 2, 2024
aea26a6
*cache quotient x's
ethan-crypto Jul 2, 2024
25f27ab
*cache all vk_ptr offset solidity constants in vk.
ethan-crypto Jul 3, 2024
f5c3dbc
*half way caching theta vars
ethan-crypto Jul 3, 2024
85a0d2c
*cache all theta constants in vk.
ethan-crypto Jul 4, 2024
57a969b
*set delta as a constant
ethan-crypto Jul 7, 2024
9331a92
*consolidate all expression
ethan-crypto Jul 9, 2024
591389d
*layout encoded gate computation expressions in VK.
ethan-crypto Jul 11, 2024
37945c1
*cfg feat not mv-lookup expression_consts.
ethan-crypto Jul 11, 2024
82d3033
*don't reset const cache between code blocks in gate computations.
ethan-crypto Jul 11, 2024
f9149c7
*test gate_computation encoding
ethan-crypto Jul 12, 2024
792d609
*hardcode R as a constant.
ethan-crypto Jul 13, 2024
d389492
*encode permutation columns.
ethan-crypto Jul 19, 2024
5c5f76d
*bump solc version to 0.8.26
ethan-crypto Jul 23, 2024
21a2444
* refactor generate_vk
ethan-crypto Jul 24, 2024
bf8e9f8
*add diagnostic_namespace feat
ethan-crypto Jul 24, 2024
34c27cb
*update rust toolchain config on yaml.
ethan-crypto Jul 24, 2024
4381645
Revert "*add diagnostic_namespace feat"
ethan-crypto Jul 24, 2024
c4915fd
*append solc install with hash svm 2>/dev/null
ethan-crypto Jul 24, 2024
428f39e
* updated estimate free static memory
ethan-crypto Jul 24, 2024
78456c4
gate_computations struct.
ethan-crypto Jul 25, 2024
c6a19a5
*packed expression words
ethan-crypto Jul 26, 2024
4c25caa
*revert to old solc version
ethan-crypto Jul 27, 2024
0654a72
*pack lookup input and table expressions.
ethan-crypto Jul 28, 2024
1f69bbb
set input_expressions_fsm_usage to 0x0 on None unwrap.
ethan-crypto Jul 29, 2024
a3ff8d5
*add reference to 0x0 unwrap or.
ethan-crypto Jul 29, 2024
2095a70
*fix bug with no lookup circuits.
ethan-crypto Jul 29, 2024
8e21bff
*pcs point_computations
ethan-crypto Jul 29, 2024
030051f
*vanishing_computations
ethan-crypto Jul 30, 2024
9fe8835
*coeff_computations.
ethan-crypto Jul 31, 2024
c4380e4
*normalized pcs
ethan-crypto Jul 31, 2024
bcb85f7
*r_evals_computations
ethan-crypto Aug 1, 2024
cfeea11
*coeff_sums_computation
ethan-crypto Aug 2, 2024
b2b636c
*r_eval + pairing computations
ethan-crypto Aug 3, 2024
7ceb2cc
*pack challenges
ethan-crypto Aug 5, 2024
27f6052
packed perm evaluations.
ethan-crypto Aug 7, 2024
18ed00a
hardcode coeff_ptr
ethan-crypto Aug 8, 2024
1d60e0c
*MV lookup packed
ethan-crypto Aug 9, 2024
3fac35c
refactor: verifier cache enum
ethan-crypto Aug 14, 2024
5a7ff4e
*update readme
ethan-crypto Aug 14, 2024
99b6548
*move encode mv lookup input table cache from metadata to lookup eval…
ethan-crypto Aug 16, 2024
3082fda
chore: update h2 curves
alexander-camuto Aug 18, 2024
fdfe5e4
*add compiler warning for non contigious table expressions across loo…
ethan-crypto Aug 21, 2024
bf04cd4
*bitmask constants
ethan-crypto Aug 25, 2024
b101da4
*optimization: enumerate set diff ptr at run time.
ethan-crypto Aug 25, 2024
659ad43
Update Cargo.toml
alexander-camuto Aug 30, 2024
b58b241
fix: patch tests
alexander-camuto Aug 30, 2024
a830dcf
fix: example
alexander-camuto Aug 30, 2024
b544e4b
h2 curve update + revm version bump
ethan-crypto Aug 31, 2024
d600b14
*load in all challenge related constants before performing challenge …
ethan-crypto Sep 5, 2024
d1464f9
*reduce `extcodecopy` call by one by only loading in vka data needed …
ethan-crypto Sep 6, 2024
d9d4b08
*fix logic bug in MV lookup and typo in last linear combine accum.
ethan-crypto Sep 9, 2024
853b960
*non mv lookups
ethan-crypto Sep 16, 2024
fa1c577
*bit flip fuzzing tests
ethan-crypto Oct 4, 2024
5e252d7
Merge branch 'ac/update-h2-curves' into cache-lookup-consts-vk
ethan-crypto Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.77.2
profile: minimal

- 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.21 && solc --version
run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.20 && svm use 0.8.20 && solc --version

- name: Run test
- name: Run test (mv lookups)
run: cargo test --workspace --all-features --all-targets -- --nocapture
- name: Run test (non-mv lookups)
run: cargo test --workspace --all-targets -- --nocapture
- name: Run separate example
run: cargo run --package halo2_solidity_verifier --example separately --all-features -- --nocapture

lint:
name: Lint
Expand Down
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ version = "0.1.0"
edition = "2021"

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/zkonduit/halo2?branch=ac/cache-lookup-commitments#8b13a0d2a7a34d8daab010dadb2c47dfa47d37d0", package = "halo2_proofs", branch = "ac/cache-lookup-commitments" }
askama = { version = "0.12.0", features = ["config"], default-features = false }
hex = "0.4.3"
ruint = "1"
ruint = "1.8.0"
sha3 = "0.10"
itertools = "0.11.0"

# Remove when `vk.transcript_repr()` is ready for usage.
blake2b_simd = "1"

# For feature = "evm"
revm = { version = "3.3.0", default-features = false, optional = true }
revm = { version = "14.0.1", default-features = false, optional = true }

[dev-dependencies]
rand = "0.8.5"
revm = { version = "3.3.0", default-features = false }
halo2_maingate = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20", package = "maingate" }
revm = { version = "14.0.1", default-features = false }
halo2_maingate = { git = "https://github.com/zkonduit/halo2wrong", branch = "ac/chunked-mv-lookup", package = "maingate" }


[features]
default = []
evm = ["dep:revm"]
mv-lookup = ["halo2_proofs/mv-lookup", "halo2_maingate/mv-lookup"]

[[example]]
name = "separately"
required-features = ["evm"]

[patch.'https://github.com/zkonduit/halo2']
halo2_proofs = { git = "https://github.com/zkonduit/halo2?branch=ac/cache-lookup-commitments#8b13a0d2a7a34d8daab010dadb2c47dfa47d37d0", package = "halo2_proofs", branch = "ac/cache-lookup-commitments" }
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For audited solidity verifier generator and proof aggregation toolkits, please r

## Usage

### Generate verifier and verifying key separately as 2 solidity contracts
### Generate fully reusable verifier and verifying artifact separately as 2 solidity contracts

```rust
let generator = SolidityGenerator::new(&params, &vk, Bdfg21, num_instances);
Expand Down Expand Up @@ -42,7 +42,7 @@ Note that function selector is already included.

The [`Keccak256Transcript`](./src/transcript.rs#L19) behaves exactly same as the `EvmTranscript` in `snark-verifier`.

## Design Rationale
## Design Rationale for Conjoined Verifier

The current solidity verifier generator within `snark-verifier` faces a couple of issues:

Expand All @@ -51,6 +51,21 @@ The current solidity verifier generator within `snark-verifier` faces a couple o

This repository is a ground-up rebuild, addressing these concerns while maintaining a focus on code size and readability. Remarkably, the gas cost is comparable, if not slightly lower, than the one generated by `snark-verifier`.

## Design Rationale for Reusable Verifier

The previous `render_separately` solidity verifier, although granted some degree of reusability, was still dependent on a given circuit's configuation despite being independent of the verifying key. We wanted to reengineer the separate verifier to be completely independent of the circuit configuration, allowing for a single verifier to be used across multiple circuits.

In the process we created two new types of contracts--`Halo2VerifierReusable` and `Halo2VerifierArtifact`-- that replaced the previous `Halo2Verifier` and `Halo2VerifierKey` contracts generated by the `render_seperately` compilation respectively.

The `Halo2VerifierArtifact` extends the original `Halo2VerifierKey` by encoding all of the circuit configuration data that was hardcoded in the original separate `Halo2Verifier` into memory. The `Halo2VerifierReusable` then loads this configuration data dynamicaly from the `Halo2VerifierArtifact` at runtime, decodes it and executes the verification computation in a functionally identical manner to the conjoined version.

For large circuits, this reduces deployment costs by 77 percent enabling the deployment of circuits that were previously infeasible due to the contract size limit, requiring an aggregation to get below the limit.

## Acknowledgement

The template is heavily inspired by Aztec's [`BaseUltraVerifier.sol`](https://github.com/AztecProtocol/barretenberg/blob/4c456a2b196282160fd69bead6a1cea85289af37/sol/src/ultra/BaseUltraVerifier.sol).


## Lookup Modularity

Note that we have extended the verifier to include the ability to verify mvlookup / logup lookups. This is hidden behind the `mvlookup` feature flag.
12 changes: 7 additions & 5 deletions examples/separately.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use application::StandardPlonk;
use prelude::*;

use halo2_proofs::poly::commitment::Params;
use halo2_solidity_verifier::{
compile_solidity, encode_calldata, BatchOpenScheme::Bdfg21, Evm, Keccak256Transcript,
SolidityGenerator,
Expand All @@ -16,14 +17,14 @@ fn main() {
let vk = keygen_vk(&params[&K_RANGE.start], &StandardPlonk::default()).unwrap();
let generator = SolidityGenerator::new(&params[&K_RANGE.start], &vk, Bdfg21, 0);
let (verifier_solidity, _) = generator.render_separately().unwrap();
save_solidity("Halo2Verifier.sol", &verifier_solidity);
save_solidity("Halo2VerifierReusable.sol", &verifier_solidity);

let verifier_creation_code = compile_solidity(&verifier_solidity);
let verifier_creation_code_size = verifier_creation_code.len();
println!("Verifier creation code size: {verifier_creation_code_size}");

let mut evm = Evm::default();
let verifier_address = evm.create(verifier_creation_code);
let (verifier_address, _) = evm.create(verifier_creation_code);

let deployed_verifier_solidity = verifier_solidity;

Expand All @@ -35,12 +36,12 @@ fn main() {
let pk = keygen_pk(&params[&k], vk, &circuit).unwrap();
let generator = SolidityGenerator::new(&params[&k], pk.get_vk(), Bdfg21, num_instances);
let (verifier_solidity, vk_solidity) = generator.render_separately().unwrap();
save_solidity(format!("Halo2VerifyingKey-{k}.sol"), &vk_solidity);
save_solidity(format!("Halo2VerifyingArtifact-{k}.sol"), &vk_solidity);

assert_eq!(deployed_verifier_solidity, verifier_solidity);

let vk_creation_code = compile_solidity(&vk_solidity);
let vk_address = evm.create(vk_creation_code);
let (vk_address, _) = evm.create(vk_creation_code);

let calldata = {
let instances = circuit.instances();
Expand Down Expand Up @@ -75,7 +76,7 @@ fn create_proof_checked(
pk: &ProvingKey<G1Affine>,
circuit: impl Circuit<Fr>,
instances: &[Fr],
mut rng: impl RngCore,
mut rng: impl RngCore + Send + Sync,
) -> Vec<u8> {
use halo2_proofs::{
poly::kzg::{
Expand Down Expand Up @@ -107,6 +108,7 @@ fn create_proof_checked(
SingleStrategy::new(params),
&[&[instances]],
&mut transcript,
params.n(),
)
};
assert!(result.is_ok());
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2024-07-18"
Loading