diff --git a/.github/scripts/wasm-target-test-build.sh b/.github/scripts/wasm-target-test-build.sh index c8fa0371cd..eb486aed8e 100755 --- a/.github/scripts/wasm-target-test-build.sh +++ b/.github/scripts/wasm-target-test-build.sh @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 558785df5a..d3d0ce27d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/halo2_frontend/Cargo.toml b/halo2_frontend/Cargo.toml index 3714c7dca7..f9627bac28 100644 --- a/halo2_frontend/Cargo.toml +++ b/halo2_frontend/Cargo.toml @@ -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", @@ -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 diff --git a/halo2_frontend/src/plonk/circuit/constraint_system.rs b/halo2_frontend/src/plonk/circuit/constraint_system.rs index 5504f6a9a9..4c4d8cfd3f 100644 --- a/halo2_frontend/src/plonk/circuit/constraint_system.rs +++ b/halo2_frontend/src/plonk/circuit/constraint_system.rs @@ -402,50 +402,81 @@ impl ConstraintSystem { name: S, table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression, Expression)>, ) -> 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. diff --git a/halo2_proofs/Cargo.toml b/halo2_proofs/Cargo.toml index a68f422934..39d7d5f149 100644 --- a/halo2_proofs/Cargo.toml +++ b/halo2_proofs/Cargo.toml @@ -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", @@ -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