diff --git a/Cargo.lock b/Cargo.lock index 3319b08c8..f23b6901a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -621,6 +621,7 @@ dependencies = [ "anyhow", "ark-std", "bitvec", + "cfg-if 1.0.0", "downcast-rs", "ff", "halo2_proofs", @@ -1481,9 +1482,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memmap" @@ -2039,9 +2040,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", @@ -2051,9 +2052,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -2062,9 +2063,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "resolv-conf" @@ -3016,6 +3017,7 @@ name = "wasmi" version = "0.11.0" dependencies = [ "parity-wasm", + "regex", "specs", "wasmi-validation", "wasmi_core", diff --git a/Cargo.toml b/Cargo.toml index 463a20284..7fecb380b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ exclude = ["third-party/wasmi", "crates/playground"] [workspace.dependencies] anyhow = { version = "1.0.68", features = ["backtrace"] } +cfg-if = "1.0.0" halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch = "main", features = ["unsafe"] } halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", default-features = true } parity-wasm = { version = "0.42.0", features = ["sign_ext"] } diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index fe1eca45e..31ebcb4eb 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -28,3 +28,4 @@ circuits-batcher = { git = "https://github.com/DelphinusLab/continuation-batcher [features] default = [] cuda = ["delphinus-zkwasm/cuda"] +uniform-circuit = ["delphinus-zkwasm/uniform-circuit"] \ No newline at end of file diff --git a/crates/playground/Cargo.lock b/crates/playground/Cargo.lock index cd0eb8643..08892f8e2 100644 --- a/crates/playground/Cargo.lock +++ b/crates/playground/Cargo.lock @@ -553,6 +553,7 @@ dependencies = [ "anyhow", "ark-std", "bitvec", + "cfg-if 1.0.0", "downcast-rs", "ff", "halo2_proofs", @@ -1352,9 +1353,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memmap" @@ -1900,9 +1901,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", @@ -1912,9 +1913,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.3" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -1923,9 +1924,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "resolv-conf" @@ -2853,6 +2854,7 @@ name = "wasmi" version = "0.11.0" dependencies = [ "parity-wasm", + "regex", "specs", "wasmi-validation", "wasmi_core", diff --git a/crates/zkwasm/Cargo.toml b/crates/zkwasm/Cargo.toml index 1393edbe7..194f38123 100644 --- a/crates/zkwasm/Cargo.toml +++ b/crates/zkwasm/Cargo.toml @@ -27,6 +27,7 @@ sha2 = "0.10.6" poseidon = { git = "https://github.com/lanbones/poseidon" } anyhow.workspace = true +cfg-if.workspace = true halo2aggregator-s.workspace = true halo2_proofs.workspace = true parity-wasm.workspace = true @@ -42,3 +43,4 @@ rusty-fork = "0.3.0" [features] default = [] cuda = ["halo2_proofs/cuda", "specs/cuda"] +uniform-circuit = [] \ No newline at end of file diff --git a/crates/zkwasm/src/circuits/image_table/assign.rs b/crates/zkwasm/src/circuits/image_table/assign.rs index bb9c5fe43..e1411be64 100644 --- a/crates/zkwasm/src/circuits/image_table/assign.rs +++ b/crates/zkwasm/src/circuits/image_table/assign.rs @@ -19,22 +19,44 @@ impl ImageTableChip { |region| { let mut ctx = Context::new(region); - macro_rules! assign_one_line { - ($v: expr) => {{ - let cell = ctx - .region - .assign_advice( - || "image table", - self.config.col, - ctx.offset, - || Ok($v), - )? - .cell(); + cfg_if::cfg_if! { + if #[cfg(feature="uniform-circuit")] { + macro_rules! assign_one_line { + ($v: expr) => {{ + let cell = ctx + .region + .assign_advice( + || "image table", + self.config.col, + ctx.offset, + || Ok($v), + )? + .cell(); - ctx.next(); + ctx.next(); - cell - }}; + cell + }}; + } + } else { + macro_rules! assign_one_line { + ($v: expr) => {{ + let cell = ctx + .region + .assign_fixed( + || "image table", + self.config.col, + ctx.offset, + || Ok($v), + )? + .cell(); + + ctx.next(); + + cell + }}; + } + } } let entry_fid_cell = assign_one_line!(image_table.entry_fid); diff --git a/crates/zkwasm/src/circuits/image_table/configure.rs b/crates/zkwasm/src/circuits/image_table/configure.rs index 02c36cc54..9ce7cd878 100644 --- a/crates/zkwasm/src/circuits/image_table/configure.rs +++ b/crates/zkwasm/src/circuits/image_table/configure.rs @@ -7,12 +7,26 @@ use halo2_proofs::plonk::VirtualCells; use specs::encode::image_table::ImageTableEncoder; use super::ImageTableConfig; -use super::IMAGE_COL_NAME; -use crate::curr; impl ImageTableConfig { + fn expr(&self, meta: &mut VirtualCells) -> Expression { + cfg_if::cfg_if! { + if #[cfg(feature="uniform-circuit")] { + crate::curr!(meta, self.col) + } else { + crate::fixed_curr!(meta, self.col) + } + } + } + pub(in crate::circuits) fn configure(meta: &mut ConstraintSystem) -> Self { - let col = meta.named_advice_column(IMAGE_COL_NAME.to_owned()); + cfg_if::cfg_if! { + if #[cfg(feature="uniform-circuit")] { + let col = meta.named_advice_column(super::IMAGE_COL_NAME.to_owned()); + } else { + let col = meta.fixed_column(); + } + } meta.enable_equality(col); Self { col, @@ -29,7 +43,7 @@ impl ImageTableConfig { meta.lookup_any(key, |meta| { vec![( ImageTableEncoder::Instruction.encode(expr(meta)), - curr!(meta, self.col), + self.expr(meta), )] }); } @@ -43,7 +57,7 @@ impl ImageTableConfig { meta.lookup_any(key, |meta| { vec![( ImageTableEncoder::InitMemory.encode(expr(meta)), - curr!(meta, self.col), + self.expr(meta), )] }); } @@ -57,7 +71,7 @@ impl ImageTableConfig { meta.lookup_any(key, |meta| { vec![( ImageTableEncoder::BrTable.encode(expr(meta)), - curr!(meta, self.col), + self.expr(meta), )] }); } diff --git a/crates/zkwasm/src/circuits/image_table/mod.rs b/crates/zkwasm/src/circuits/image_table/mod.rs index 777f2a8d6..a2239a63f 100644 --- a/crates/zkwasm/src/circuits/image_table/mod.rs +++ b/crates/zkwasm/src/circuits/image_table/mod.rs @@ -1,5 +1,4 @@ use halo2_proofs::arithmetic::FieldExt; -use halo2_proofs::plonk::Advice; use halo2_proofs::plonk::Column; use num_bigint::BigUint; use specs::brtable::BrTable; @@ -198,9 +197,17 @@ impl EncodeCompilationTableValues for CompilationTable { } } +#[cfg(feature = "uniform-circuit")] #[derive(Clone)] pub struct ImageTableConfig { - col: Column, + col: Column, + _mark: PhantomData, +} + +#[cfg(not(feature = "uniform-circuit"))] +#[derive(Clone)] +pub struct ImageTableConfig { + col: Column, _mark: PhantomData, } diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index a62ec0b09..9ca06ffc7 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -1,7 +1,6 @@ use anyhow::Result; use halo2_proofs::arithmetic::MultiMillerLoop; use halo2_proofs::dev::MockProver; -use halo2_proofs::plonk::get_advice_commitments_from_transcript; use halo2_proofs::plonk::keygen_vk; use halo2_proofs::plonk::verify_proof; use halo2_proofs::plonk::SingleVerifier; @@ -25,7 +24,6 @@ use crate::checksum::CompilationTableWithParams; use crate::checksum::ImageCheckSum; use crate::circuits::config::init_zkwasm_runtime; use crate::circuits::config::set_zkwasm_k; -use crate::circuits::image_table::IMAGE_COL_NAME; use crate::circuits::TestCircuit; use crate::circuits::ZkWasmCircuitBuilder; use crate::loader::err::Error; @@ -51,9 +49,7 @@ pub struct ZkWasmLoader, - _data_arg: PhantomData, - _data_builder: PhantomData, - _data_e: PhantomData, + _mark: PhantomData<(Arg, EnvBuilder, E)>, } impl> ZkWasmLoader { @@ -115,6 +111,11 @@ impl> ZkWasmLoader()) } + /// Create a ZkWasm Loader + /// Arguments: + /// - k: the size of circuit + /// - image: wasm binary + /// - phantom_functions: regular expressions of phantom function pub fn new(k: u32, image: Vec, phantom_functions: Vec) -> Result { set_zkwasm_k(k); @@ -124,9 +125,7 @@ impl> ZkWasmLoader> ZkWasmLoader