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

Implement BatchOpenScheme::Gwc19 #13

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ Note that function selector is already included.

## Limitations & Caveats

- It only allows circuit with **exact 1 instance column** and **no rotated query to this instance column**.
- It only allows circuit with **less or equal than 1 instance column** and **no rotated query to this instance column**.
- Currently even the `configure` is same, the [selector compression](https://github.com/privacy-scaling-explorations/halo2/blob/7a2165617195d8baa422ca7b2b364cef02380390/halo2_proofs/src/plonk/circuit/compress_selectors.rs#L51) might lead to different configuration when selector assignments are different. To avoid this, please use [`keygen_vk_custom`](https://github.com/privacy-scaling-explorations/halo2/blob/6fc6d7ca018f3899b030618cb18580249b1e7c82/halo2_proofs/src/plonk/keygen.rs#L223) with `compress_selectors: false` to do key generation without selector compression.
- Now it only supports BDFG21 batch open scheme (aka SHPLONK), GWC19 is not yet implemented.

## Compatibility

Expand Down
2 changes: 1 addition & 1 deletion examples/separately.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod application {
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
meta.set_minimum_degree(4);
meta.set_minimum_degree(5);
StandardPlonkConfig::configure(meta)
}

Expand Down
36 changes: 8 additions & 28 deletions src/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use crate::codegen::{
evaluator::Evaluator,
pcs::{
bdfg21_computations, queries, rotation_sets,
BatchOpenScheme::{Bdfg21, Gwc19},
},
template::{Halo2Verifier, Halo2VerifyingKey},
util::{fr_to_u256, g1_to_u256s, g2_to_u256s, ConstraintSystemMeta, Data, Ptr},
};
Expand Down Expand Up @@ -108,11 +104,6 @@ impl<'a> SolidityGenerator<'a> {
.any(|(_, rotation)| *rotation != Rotation::cur()),
"Rotated query to instance column is not yet implemented"
);
assert_eq!(
scheme,
BatchOpenScheme::Bdfg21,
"BatchOpenScheme::Gwc19 is not yet implemented"
);

Self {
params,
Expand Down Expand Up @@ -237,7 +228,7 @@ impl<'a> SolidityGenerator<'a> {

let vk = self.generate_vk();
let vk_len = vk.len();
let vk_mptr = Ptr::memory(self.estimate_static_working_memory_size(&vk, proof_cptr));
let vk_mptr = Ptr::memory(self.static_working_memory_size(&vk, proof_cptr));
let data = Data::new(&self.meta, &vk, vk_mptr, proof_cptr);

let evaluator = Evaluator::new(self.vk.cs(), &self.meta, &data);
Expand All @@ -260,10 +251,7 @@ impl<'a> SolidityGenerator<'a> {
})
.collect();

let pcs_computations = match self.scheme {
Bdfg21 => bdfg21_computations(&self.meta, &data),
Gwc19 => unimplemented!(),
};
let pcs_computations = self.scheme.computations(&self.meta, &data);

Halo2Verifier {
scheme: self.scheme,
Expand All @@ -273,6 +261,7 @@ impl<'a> SolidityGenerator<'a> {
num_neg_lagranges: self.meta.rotation_last.unsigned_abs() as usize,
num_advices: self.meta.num_advices(),
num_challenges: self.meta.num_challenges(),
num_rotations: self.meta.num_rotations,
num_evals: self.meta.num_evals,
num_quotients: self.meta.num_quotients,
proof_cptr,
Expand All @@ -285,20 +274,11 @@ impl<'a> SolidityGenerator<'a> {
}
}

fn estimate_static_working_memory_size(
&self,
vk: &Halo2VerifyingKey,
proof_cptr: Ptr,
) -> usize {
let pcs_computation = match self.scheme {
Bdfg21 => {
let mock_vk_mptr = Ptr::memory(0x100000);
let mock = Data::new(&self.meta, vk, mock_vk_mptr, proof_cptr);
let (superset, sets) = rotation_sets(&queries(&self.meta, &mock));
let num_coeffs = sets.iter().map(|set| set.rots().len()).sum::<usize>();
2 * (1 + num_coeffs) + 6 + 2 * superset.len() + 1 + 3 * sets.len()
}
Gwc19 => unimplemented!(),
fn static_working_memory_size(&self, vk: &Halo2VerifyingKey, proof_cptr: Ptr) -> usize {
let pcs_computation = {
let mock_vk_mptr = Ptr::memory(0x100000);
let mock = Data::new(&self.meta, vk, mock_vk_mptr, proof_cptr);
self.scheme.static_working_memory_size(&self.meta, &mock)
};

itertools::max([
Expand Down
Loading
Loading