Skip to content

Commit

Permalink
feat: add new feature "lookup-any-sanity-checks"
Browse files Browse the repository at this point in the history
  • Loading branch information
guorong009 committed Jun 17, 2024
1 parent 20ca124 commit 6205dfc
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/wasm-target-test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cp "${GIT_ROOT}/rust-toolchain" .
rustup target add wasm32-unknown-unknown wasm32-wasi

# add dependencies
cargo add --path "${GIT_ROOT}/halo2_proofs" --features batch,dev-graph,gadget-traces
cargo add --path "${GIT_ROOT}/halo2_proofs" --features batch,dev-graph,gadget-traces,lookup-any-sanity-checks
cargo add getrandom --features js --target wasm32-unknown-unknown

# test build for wasm32-* targets
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- feature_set: basic
features: batch,dev-graph,gadget-traces
- feature_set: all
features: batch,dev-graph,gadget-traces,test-dev-graph,thread-safe-region,sanity-checks,circuit-params
features: batch,dev-graph,gadget-traces,test-dev-graph,thread-safe-region,sanity-checks,circuit-params,lookup-any-sanity-checks

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion halo2_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ serde_json = "1"
getrandom = { version = "0.2", features = ["js"] }

[features]
default = ["bits"]
default = ["bits", "lookup-any-sanity-checks"]
dev-graph = ["plotters", "tabbycat"]
test-dev-graph = [
"dev-graph",
Expand All @@ -63,6 +63,7 @@ circuit-params = []
heap-profiling = []
cost-estimator = ["serde", "serde_derive"]
derive_serde = ["halo2curves/derive_serde"]
lookup-any-sanity-checks = []

[lib]
bench = false
101 changes: 66 additions & 35 deletions halo2_frontend/src/plonk/circuit/constraint_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,50 +402,81 @@ impl<F: Field> ConstraintSystem<F> {
name: S,
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, Expression<F>)>,
) -> usize {
let mut cells = VirtualCells::new(self);
#[cfg(feature = "lookup-any-sanity-checks")]
{
let mut cells = VirtualCells::new(self);

let mut is_all_table_expr_single_fixed = true;
let mut is_all_table_expr_contain_fixed_or_selector = true;
let mut is_tagging_exprs_pair_exists = false;
let mut is_all_table_expr_single_fixed = true;
let mut is_all_table_expr_contain_fixed_or_selector = true;
let mut is_tagging_exprs_pair_exists = false;

let table_map = table_map(&mut cells)
.into_iter()
.map(|(mut input, mut table)| {
if input.contains_simple_selector() {
panic!("expression containing simple selector supplied to lookup argument");
}
if table.contains_simple_selector() {
panic!("expression containing simple selector supplied to lookup argument");
}
let table_map = table_map(&mut cells)
.into_iter()
.map(|(mut input, mut table)| {
if input.contains_simple_selector() {
panic!("expression containing simple selector supplied to lookup argument");
}
if table.contains_simple_selector() {
panic!("expression containing simple selector supplied to lookup argument");
}

is_all_table_expr_single_fixed &= table.degree() == 1 && table.contains_fixed_col();
is_all_table_expr_contain_fixed_or_selector &=
table.contains_fixed_col_or_selector();
is_tagging_exprs_pair_exists |=
table.contains_fixed_col_or_selector() && table.degree() == 1;
is_all_table_expr_single_fixed &=
table.degree() == 1 && table.contains_fixed_col();
is_all_table_expr_contain_fixed_or_selector &=
table.contains_fixed_col_or_selector();
is_tagging_exprs_pair_exists |=
table.contains_fixed_col_or_selector() && table.degree() == 1;

input.query_cells(&mut cells);
table.query_cells(&mut cells);
(input, table)
})
.collect();
input.query_cells(&mut cells);
table.query_cells(&mut cells);
(input, table)
})
.collect();

if is_all_table_expr_single_fixed {
panic!("all table expressions contain only fixed query, should use `lookup` api instead of `lookup_any`");
}
if !is_all_table_expr_contain_fixed_or_selector {
panic!("all table expressions need selector/fixed query for tagging");
}
if !is_tagging_exprs_pair_exists {
panic!("pair of tagging expressions(query of the tag columns or mutiple query combinations) should be included");
if is_all_table_expr_single_fixed {
panic!("all table expressions contain only fixed query, should use `lookup` api instead of `lookup_any`");
}
if !is_all_table_expr_contain_fixed_or_selector {
panic!("all table expressions need selector/fixed query for tagging");
}
if !is_tagging_exprs_pair_exists {
panic!("pair of tagging expressions(query of the tag columns or mutiple query combinations) should be included");
}

let index = self.lookups.len();

self.lookups
.push(lookup::Argument::new(name.as_ref(), table_map));

index
}
#[cfg(not(feature = "lookup-any-sanity-checks"))]
{
let mut cells = VirtualCells::new(self);

let index = self.lookups.len();
let table_map = table_map(&mut cells)
.into_iter()
.map(|(mut input, mut table)| {
if input.contains_simple_selector() {
panic!("expression containing simple selector supplied to lookup argument");
}
if table.contains_simple_selector() {
panic!("expression containing simple selector supplied to lookup argument");
}

self.lookups
.push(lookup::Argument::new(name.as_ref(), table_map));
input.query_cells(&mut cells);
table.query_cells(&mut cells);
(input, table)
})
.collect();

index
let index = self.lookups.len();

self.lookups
.push(lookup::Argument::new(name.as_ref(), table_map));

index
}
}

/// Add a shuffle argument for some input expressions and table expressions.
Expand Down
3 changes: 2 additions & 1 deletion halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ serde_json = "1"
getrandom = { version = "0.2", features = ["js"] }

[features]
default = ["batch", "bits", "halo2_frontend/default", "halo2_backend/default"]
default = ["batch", "bits", "halo2_frontend/default", "halo2_backend/default", "lookup-any-sanity-checks"]
dev-graph = ["halo2_frontend/dev-graph", "plotters"]
test-dev-graph = [
"halo2_frontend/test-dev-graph",
Expand All @@ -84,6 +84,7 @@ circuit-params = ["halo2_frontend/circuit-params"]
heap-profiling = ["halo2_frontend/heap-profiling"]
cost-estimator = ["halo2_frontend/cost-estimator"]
derive_serde = ["halo2curves/derive_serde", "halo2_frontend/derive_serde", "halo2_backend/derive_serde"]
lookup-any-sanity-checks = ["halo2_frontend/lookup-any-sanity-checks"]

[lib]
bench = false
Expand Down

0 comments on commit 6205dfc

Please sign in to comment.