From 7adb3f5e1b33576b962b10d308483b6f4a5a5c6a Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Tue, 22 Jul 2025 20:02:02 -0400 Subject: [PATCH 01/24] Resolve current compilation issues --- Cargo.lock | 37 +++++++++------- Cargo.toml | 2 + src/arithmetics/mod.rs | 2 +- src/e2e/mod.rs | 2 + src/extensions/mod.rs | 2 +- src/tower_verifier/binding.rs | 2 +- src/tower_verifier/program.rs | 2 +- src/transcript/mod.rs | 2 +- src/zkvm_verifier/binding.rs | 81 ++++++++++++++++++++++++++++++++--- src/zkvm_verifier/verifier.rs | 7 ++- 10 files changed, 110 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a62a669..67cf4da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,8 +517,10 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" version = "1.2.30" +version = "1.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" dependencies = [ "shlex", ] @@ -526,7 +528,7 @@ dependencies = [ [[package]] name = "ceno-examples" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "glob", ] @@ -577,7 +579,7 @@ dependencies = [ [[package]] name = "ceno_emul" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "anyhow", "ceno_rt", @@ -600,7 +602,7 @@ dependencies = [ [[package]] name = "ceno_host" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "anyhow", "ceno_emul", @@ -613,7 +615,7 @@ dependencies = [ [[package]] name = "ceno_rt" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "getrandom 0.2.16", "rkyv", @@ -622,7 +624,7 @@ dependencies = [ [[package]] name = "ceno_zkvm" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "base64", "bincode", @@ -1141,7 +1143,7 @@ dependencies = [ [[package]] name = "ff_ext" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "once_cell", "p3", @@ -1231,17 +1233,20 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gkr_iop" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "ark-std 0.5.0", "bincode", "ceno_emul", + "ceno_emul", "clap", "either", "ff_ext", "itertools 0.13.0", "mpcs", + "mpcs", "multilinear_extensions", + "ndarray", "p3", "p3-field", "p3-goldilocks", @@ -1718,7 +1723,7 @@ dependencies = [ [[package]] name = "mpcs" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "aes", "bincode", @@ -1749,7 +1754,7 @@ dependencies = [ [[package]] name = "multilinear_extensions" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "either", "ff_ext", @@ -2311,7 +2316,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "p3-baby-bear", "p3-challenger", @@ -2769,7 +2774,7 @@ dependencies = [ [[package]] name = "poseidon" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "criterion", "ff_ext", @@ -3378,7 +3383,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sumcheck" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "crossbeam-channel", "either", @@ -3397,7 +3402,7 @@ dependencies = [ [[package]] name = "sumcheck_macro" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "itertools 0.13.0", "p3", @@ -3671,7 +3676,7 @@ dependencies = [ [[package]] name = "transcript" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "crossbeam-channel", "ff_ext", @@ -3849,7 +3854,7 @@ dependencies = [ [[package]] name = "whir" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "bincode", "blake2", @@ -4085,7 +4090,7 @@ dependencies = [ [[package]] name = "witness" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" dependencies = [ "ff_ext", "multilinear_extensions", diff --git a/Cargo.toml b/Cargo.toml index 41488ea..0f3c426 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.g openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } +openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } +openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } rand = { version = "0.8.5", default-features = false } itertools = { version = "0.13.0", default-features = false } diff --git a/src/arithmetics/mod.rs b/src/arithmetics/mod.rs index c79494d..a8a7bbe 100644 --- a/src/arithmetics/mod.rs +++ b/src/arithmetics/mod.rs @@ -11,7 +11,7 @@ use openvm_native_recursion::challenger::ChallengerVariable; use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; -use p3_field::{FieldAlgebra, FieldExtensionAlgebra}; +use openvm_stark_backend::p3_field::{FieldAlgebra, FieldExtensionAlgebra, extension::BinomialExtensionField}; type E = BabyBearExt4; const HASH_RATE: usize = 8; const MAX_NUM_VARS: usize = 25; diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index b707d72..be7c1b1 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -214,6 +214,7 @@ pub fn parse_zkvm_proof_import( } } + pub fn inner_test_thread() { setup_tracing_with_log_level(tracing::Level::WARN); @@ -290,3 +291,4 @@ pub fn test_zkvm_proof_verifier_from_bincode_exports() { handler.join().expect("Thread panicked"); } +*/ diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 347f556..6042866 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -29,7 +29,7 @@ mod tests { use openvm_stark_sdk::{ config::baby_bear_poseidon2::BabyBearPoseidon2Config, p3_baby_bear::BabyBear, }; - use p3_field::{Field, FieldAlgebra, FieldExtensionAlgebra}; + use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; type Pcs = Basefold; const NUM_FANIN: usize = 2; diff --git a/src/tower_verifier/binding.rs b/src/tower_verifier/binding.rs index 26c888a..1e750f9 100644 --- a/src/tower_verifier/binding.rs +++ b/src/tower_verifier/binding.rs @@ -10,7 +10,7 @@ pub type E = BinomialExtensionField; pub type InnerConfig = AsmConfig; use openvm_stark_sdk::p3_baby_bear::BabyBear; -use p3_field::extension::BinomialExtensionField; +use openvm_stark_backend::p3_field::extension::BinomialExtensionField; use serde::{Deserialize, Serialize}; #[derive(DslVariable, Clone)] diff --git a/src/tower_verifier/program.rs b/src/tower_verifier/program.rs index 85d097b..c97e795 100644 --- a/src/tower_verifier/program.rs +++ b/src/tower_verifier/program.rs @@ -13,7 +13,7 @@ use openvm_native_recursion::challenger::ChallengerVariable; use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; -use p3_field::FieldAlgebra; +use openvm_stark_backend::p3_field::FieldAlgebra; pub(crate) fn interpolate_uni_poly( builder: &mut Builder, diff --git a/src/transcript/mod.rs b/src/transcript/mod.rs index 45af2e2..7007aa8 100644 --- a/src/transcript/mod.rs +++ b/src/transcript/mod.rs @@ -4,7 +4,7 @@ use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; use openvm_native_recursion::challenger::{CanSampleBitsVariable, ChallengerVariable}; -use p3_field::FieldAlgebra; +use openvm_stark_backend::p3_field::{FieldAlgebra, FieldExtensionAlgebra}; pub fn transcript_observe_label( builder: &mut Builder, diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index 5e35664..b176a8e 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -20,7 +20,7 @@ use openvm_native_compiler::{ use openvm_native_compiler_derive::iter_zip; use openvm_native_recursion::hints::{Hintable, VecAutoHintable}; use openvm_stark_sdk::p3_baby_bear::BabyBear; -use p3_field::{extension::BinomialExtensionField, FieldAlgebra}; +use openvm_stark_backend::p3_field::{FieldAlgebra, extension::BinomialExtensionField}; pub type F = BabyBear; pub type E = BinomialExtensionField; @@ -147,12 +147,79 @@ impl Hintable for ZKVMProofInput { stream.extend(self.raw_pi.write()); stream.extend(raw_pi_num_variables.write()); stream.extend(self.pi_evals.write()); - stream.extend(self.chip_proofs.write()); - stream.extend(>::write(&max_num_var)); - stream.extend(self.witin_commit.write()); - stream.extend(witin_perm.write()); - stream.extend(fixed_perm.write()); - stream.extend(self.pcs_proof.write()); + stream.extend(self.opcode_proofs.write()); + stream.extend(self.table_proofs.write()); + + // Write in witin_commit + let mut cmt_vec: Vec = vec![]; + self.witin_commit.commit().iter().for_each(|x| { + let f: F = serde_json::from_value(serde_json::to_value(&x).unwrap()).unwrap(); + cmt_vec.push(f); + }); + let mut witin_commit_trivial_commits: Vec> = vec![]; + /* _debug + for trivial_commit in &self.witin_commit.trivial_commits { + let mut t_cmt_vec: Vec = vec![]; + trivial_commit.iter().for_each(|x| { + let f: F = + serde_json::from_value(serde_json::to_value(x.clone()).unwrap()).unwrap(); + t_cmt_vec.push(f); + }); + witin_commit_trivial_commits.push(t_cmt_vec); + } + */ + let witin_commit_log2_max_codeword_size = + F::from_canonical_u32(self.witin_commit.log2_max_codeword_size as u32); + stream.extend(cmt_vec.write()); + stream.extend(witin_commit_trivial_commits.write()); + stream.extend(witin_commit_log2_max_codeword_size.write()); + + // Write in fixed_commit + let has_fixed_commit: usize = if self.fixed_commit.is_some() { 1 } else { 0 }; + let mut fixed_commit_vec: Vec = vec![]; + let mut fixed_commit_trivial_commits: Vec> = vec![]; + let mut fixed_commit_log2_max_codeword_size: F = F::ZERO.clone(); + if has_fixed_commit > 0 { + self.fixed_commit + .as_ref() + .unwrap() + .commit() + .iter() + .for_each(|x| { + let f: F = + serde_json::from_value(serde_json::to_value(x.clone()).unwrap()).unwrap(); + fixed_commit_vec.push(f); + }); + + /* _debug + for trivial_commit in &self.fixed_commit.as_ref().unwrap().trivial_commits { + let mut t_cmt_vec: Vec = vec![]; + trivial_commit.iter().for_each(|x| { + let f: F = + serde_json::from_value(serde_json::to_value(x.clone()).unwrap()).unwrap(); + t_cmt_vec.push(f); + }); + fixed_commit_trivial_commits.push(t_cmt_vec); + } + */ + fixed_commit_log2_max_codeword_size = F::from_canonical_u32( + self.fixed_commit.as_ref().unwrap().log2_max_codeword_size as u32, + ); + } + stream.extend(>::write(&has_fixed_commit)); + stream.extend(fixed_commit_vec.write()); + stream.extend(fixed_commit_trivial_commits.write()); + stream.extend(fixed_commit_log2_max_codeword_size.write()); + + // Write num_instances + let mut num_instances_vec: Vec> = vec![]; + for (circuit_size, num_var) in &self.num_instances { + num_instances_vec.push(vec![ + F::from_canonical_usize(*circuit_size), + F::from_canonical_usize(*num_var), + ]); + } + stream.extend(num_instances_vec.write()); stream } diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 2fabd37..6d330bf 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -34,7 +34,7 @@ use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; use p3_baby_bear::BabyBear; -use p3_field::{Field, FieldAlgebra}; +use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; type F = BabyBear; type E = BabyBearExt4; @@ -82,6 +82,7 @@ pub fn verify_zkvm_proof>( zkvm_proof_input: ZKVMProofInputVariable, vk: &ZKVMVerifier, ) { + /* _debug let mut challenger = DuplexChallengerVariable::new(builder); transcript_observe_label(builder, &mut challenger, b"riscv"); @@ -376,8 +377,11 @@ pub fn verify_zkvm_proof>( /* TODO: Temporarily disable product check for missing subcircuits builder.assert_ext_eq(prod_r, prod_w); */ + + */ } +/* _debug pub fn verify_opcode_proof( builder: &mut Builder, challenger: &mut DuplexChallengerVariable, @@ -834,3 +838,4 @@ pub fn verify_table_proof( rt_tower.fs } +*/ From f0f0e181743d1b8e274087c63acfcbab5a49bdbf Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 23 Jul 2025 18:34:27 -0400 Subject: [PATCH 02/24] Binding, Parsing and GKR entry --- Cargo.lock | 34 +++---- Cargo.toml | 1 + src/e2e/mod.rs | 165 ++++++++++++++++++++++++++++++++-- src/zkvm_verifier/binding.rs | 94 +++++++++++++++++++ src/zkvm_verifier/verifier.rs | 15 ++++ 5 files changed, 286 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67cf4da..674235b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "ceno-examples" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "glob", ] @@ -545,6 +545,7 @@ dependencies = [ "ceno_emul", "ceno_zkvm", "ff_ext", + "gkr_iop", "itertools 0.13.0", "mpcs", "multilinear_extensions", @@ -579,7 +580,7 @@ dependencies = [ [[package]] name = "ceno_emul" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "anyhow", "ceno_rt", @@ -602,7 +603,7 @@ dependencies = [ [[package]] name = "ceno_host" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "anyhow", "ceno_emul", @@ -615,7 +616,7 @@ dependencies = [ [[package]] name = "ceno_rt" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "getrandom 0.2.16", "rkyv", @@ -624,7 +625,7 @@ dependencies = [ [[package]] name = "ceno_zkvm" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "base64", "bincode", @@ -1143,7 +1144,7 @@ dependencies = [ [[package]] name = "ff_ext" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "once_cell", "p3", @@ -1233,7 +1234,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gkr_iop" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "ark-std 0.5.0", "bincode", @@ -1246,7 +1247,6 @@ dependencies = [ "mpcs", "mpcs", "multilinear_extensions", - "ndarray", "p3", "p3-field", "p3-goldilocks", @@ -1723,7 +1723,7 @@ dependencies = [ [[package]] name = "mpcs" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "aes", "bincode", @@ -1754,7 +1754,7 @@ dependencies = [ [[package]] name = "multilinear_extensions" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "either", "ff_ext", @@ -2316,7 +2316,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "p3-baby-bear", "p3-challenger", @@ -2774,7 +2774,7 @@ dependencies = [ [[package]] name = "poseidon" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "criterion", "ff_ext", @@ -3383,7 +3383,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sumcheck" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "crossbeam-channel", "either", @@ -3402,7 +3402,7 @@ dependencies = [ [[package]] name = "sumcheck_macro" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "itertools 0.13.0", "p3", @@ -3676,7 +3676,7 @@ dependencies = [ [[package]] name = "transcript" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "crossbeam-channel", "ff_ext", @@ -3854,7 +3854,7 @@ dependencies = [ [[package]] name = "whir" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "bincode", "blake2", @@ -4090,7 +4090,7 @@ dependencies = [ [[package]] name = "witness" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#df4a6114179bce80c971dac00cf4c7651c22bc9e" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "ff_ext", "multilinear_extensions", diff --git a/Cargo.toml b/Cargo.toml index 0f3c426..5f98c58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "b ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "witness" } ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } +gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } serde = { version = "1.0", features = ["derive"] } diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index be7c1b1..07d4a6d 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -1,11 +1,14 @@ use crate::basefold_verifier::basefold::BasefoldCommitment; use crate::basefold_verifier::query_phase::QueryPhaseVerifierInput; use crate::tower_verifier::binding::IOPProverMessage; -use crate::zkvm_verifier::binding::ZKVMProofInput; -use crate::zkvm_verifier::binding::{TowerProofInput, ZKVMChipProofInput, E, F}; -use crate::zkvm_verifier::verifier::verify_zkvm_proof; +use crate::zkvm_verifier::binding::{ + ZKVMProofInput, TowerProofInput, ZKVMOpcodeProofInput, ZKVMTableProofInput, E, F, + GKRProofInput, LayerProofInput, SumcheckLayerProofInput, +}; +use crate::zkvm_verifier::verifier::{verify_zkvm_proof, verify_precompile}; use ceno_mle::util::ceil_log2; use ff_ext::BabyBearExt4; +use gkr_iop::gkr::layer::sumcheck_layer::{SumcheckLayer, SumcheckLayerProof}; use itertools::Itertools; use mpcs::{Basefold, BasefoldRSParams}; use openvm_circuit::arch::{instructions::program::Program, SystemConfig, VmExecutor}; @@ -28,7 +31,7 @@ type EF = ::Challenge; use ceno_zkvm::{ scheme::{verifier::ZKVMVerifier, ZKVMProof}, - structs::ZKVMVerifyingKey, + structs::{ComposedConstrainSystem, ZKVMVerifyingKey}, }; pub fn parse_zkvm_proof_import( @@ -214,7 +217,6 @@ pub fn parse_zkvm_proof_import( } } - pub fn inner_test_thread() { setup_tracing_with_log_level(tracing::Level::WARN); @@ -291,4 +293,155 @@ pub fn test_zkvm_proof_verifier_from_bincode_exports() { handler.join().expect("Thread panicked"); } -*/ + +pub fn parse_precompile_proof_variables( + zkvm_proof: ZKVMProof>, + verifier: &ZKVMVerifier>, +) -> (GKRCircuit, GKRProofInput) { + let index: usize = 18; + let proof = &zkvm_proof.chip_proofs[&index]; + + let circuit_name = &verifier.vk.circuit_index_to_name[&index]; + let circuit_vk = &verifier.vk.circuit_vks[circuit_name]; + + let composed_cs = circuit_vk.get_cs(); + let ComposedConstrainSystem { + zkvm_v1_css: _, + gkr_circuit, + } = &composed_cs; + let gkr_circuit = gkr_circuit.clone().unwrap(); + let num_instances = proof.num_instances; + let next_pow2_instance = num_instances.next_power_of_two().max(2); + let log2_num_instances = ceil_log2(next_pow2_instance); + let num_var_with_rotation = log2_num_instances + composed_cs.rotation_vars().unwrap_or(0); + let gkr_proof = proof.gkr_iop_proof.clone().unwrap(); + + let mut gkr_proof_input = GKRProofInput { + num_var_with_rotation, + layer_proofs: vec![], + }; + + for layer_proof in gkr_proof.0 { + // rotation + let (has_rotation, rotation): (usize, SumcheckLayerProofInput) = if let Some(p) = layer_proof.rotation { + let mut iop_messages: Vec = vec![]; + for m in p.proof.proofs { + let mut evaluations: Vec = vec![]; + for e in m.evaluations { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evaluations.push(v_e); + } + iop_messages.push(IOPProverMessage { evaluations }); + } + let mut evals: Vec = vec![]; + for e in p.evals { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evals.push(v_e); + } + + (1, SumcheckLayerProofInput { proof: iop_messages, evals }) + } else { + (0, SumcheckLayerProofInput::default()) + }; + + // main sumcheck + let mut iop_messages: Vec = vec![]; + let mut evals: Vec = vec![]; + for m in layer_proof.main.proof.proofs { + let mut evaluations: Vec = vec![]; + for e in m.evaluations { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evaluations.push(v_e); + } + iop_messages.push(IOPProverMessage { evaluations }); + } + for e in layer_proof.main.evals { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evals.push(v_e); + } + + let main = SumcheckLayerProofInput { + proof: iop_messages, + evals, + }; + + gkr_proof_input.layer_proofs.push(LayerProofInput { has_rotation, rotation, main }); + } + + (gkr_circuit, gkr_proof_input) +} + +pub fn precompile_test_thread() { + setup_tracing_with_log_level(tracing::Level::WARN); + + let proof_path = "./src/e2e/encoded/proof.bin"; + let vk_path = "./src/e2e/encoded/vk.bin"; + + let zkvm_proof: ZKVMProof> = + bincode::deserialize_from(File::open(proof_path).expect("Failed to open proof file")) + .expect("Failed to deserialize proof file"); + + let vk: ZKVMVerifyingKey> = + bincode::deserialize_from(File::open(vk_path).expect("Failed to open vk file")) + .expect("Failed to deserialize vk file"); + + let verifier = ZKVMVerifier::new(vk); + + let (circuit, gkr_proof) = parse_precompile_proof_variables(zkvm_proof, &verifier); + + // OpenVM DSL + let mut builder = AsmBuilder::::default(); + + // Obtain witness inputs + let gkr_proof_input = GKRProofInput::read(&mut builder); + verify_precompile(&mut builder, circuit, gkr_proof_input); + builder.halt(); + + // Pass in witness stream + let mut witness_stream: Vec< + Vec>, + > = Vec::new(); + + witness_stream.extend(gkr_proof.write()); + + // Compile program + let options = CompilerOptions::default().with_cycle_tracker(); + let mut compiler = AsmCompiler::new(options.word_size); + compiler.build(builder.operations); + let asm_code = compiler.code(); + + let program: Program< + p3_monty_31::MontyField31, + > = convert_program(asm_code, options); + let mut system_config = SystemConfig::default() + .with_public_values(4) + .with_max_segment_len((1 << 25) - 100); + system_config.profiling = true; + let config = NativeConfig::new(system_config, Native); + + let executor = VmExecutor::::new(config); + + let res = executor + .execute_and_then(program, witness_stream, |_, seg| Ok(seg), |err| err) + .unwrap(); + + for (i, seg) in res.iter().enumerate() { + println!("=> segment {:?} metrics: {:?}", i, seg.metrics); + } +} + +#[test] +pub fn test_precompile_verification_from_bincode_exports() { + let stack_size = 64 * 1024 * 1024; // 64 MB + + let handler = thread::Builder::new() + .stack_size(stack_size) + .spawn(precompile_test_thread) + .expect("Failed to spawn thread"); + + handler.join().expect("Thread panicked"); +} diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index b176a8e..f8bfb1d 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -12,6 +12,7 @@ use crate::{ use ark_std::iterable::Iterable; use ff_ext::BabyBearExt4; use itertools::Itertools; +use openvm_circuit::derive; use openvm_native_compiler::{ asm::AsmConfig, ir::{Array, Builder, Config, Felt}, @@ -403,3 +404,96 @@ impl Hintable for ZKVMChipProofInput { stream } } + +#[derive(Default)] +pub(crate) struct SumcheckLayerProofInput { + pub proof: Vec, + pub evals: Vec, +} +#[derive(DslVariable, Clone)] +pub(crate) struct SumcheckLayerProofVariable { + pub proof: Array>, + pub evals: Array>, +} +impl VecAutoHintable for SumcheckLayerProofInput {} +impl Hintable for SumcheckLayerProofInput { + type HintVariable = SumcheckLayerProofVariable; + + fn read(builder: &mut Builder) -> Self::HintVariable { + let proof = Vec::::read(builder); + let evals = Vec::::read(builder); + Self::HintVariable { + proof, + evals + } + } + fn write(&self) -> Vec::N>> { + let mut stream = Vec::new(); + stream.extend(self.proof.write()); + stream.extend(self.evals.write()); + stream + } +} + +pub(crate) struct LayerProofInput { + pub has_rotation: usize, + pub rotation: SumcheckLayerProofInput, + pub main: SumcheckLayerProofInput, +} +#[derive(DslVariable, Clone)] +pub(crate) struct LayerProofVariable { + pub has_rotation: Var, + pub rotation: SumcheckLayerProofVariable, + pub main: SumcheckLayerProofVariable, +} +impl VecAutoHintable for LayerProofInput {} +impl Hintable for LayerProofInput { + type HintVariable = LayerProofVariable; + + fn read(builder: &mut Builder) -> Self::HintVariable { + let has_rotation = usize::read(builder); + let rotation = SumcheckLayerProofInput::read(builder); + let main = SumcheckLayerProofInput::read(builder); + + Self::HintVariable { + has_rotation, + rotation, + main, + } + } + fn write(&self) -> Vec::N>> { + let mut stream = Vec::new(); + stream.extend(>::write(&self.has_rotation)); + stream.extend(self.rotation.write()); + stream.extend(self.main.write()); + stream + } +} +#[derive(Default)] +pub(crate) struct GKRProofInput { + pub num_var_with_rotation: usize, + pub layer_proofs: Vec, +} +#[derive(DslVariable, Clone)] +pub(crate) struct GKRProofVariable { + pub num_var_with_rotation: Var, + pub layer_proofs: Array>, +} +impl Hintable for GKRProofInput { + type HintVariable = GKRProofVariable; + + fn read(builder: &mut Builder) -> Self::HintVariable { + let num_var_with_rotation = usize::read(builder); + let layer_proofs = Vec::::read(builder); + Self::HintVariable { + num_var_with_rotation, + layer_proofs, + } + } + fn write(&self) -> Vec::N>> { + let mut stream = Vec::new(); + stream.extend(>::write(&self.num_var_with_rotation)); + stream.extend(self.layer_proofs.write()); + stream + } +} \ No newline at end of file diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 6d330bf..35f8b58 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -12,6 +12,7 @@ use crate::basefold_verifier::utils::pow_2; use crate::basefold_verifier::verifier::batch_verify; use crate::tower_verifier::program::verify_tower_proof; use crate::transcript::transcript_observe_label; +use crate::zkvm_verifier::binding::GKRProofVariable; use crate::{ arithmetics::{ build_eq_x_r_vec_sequential, ceil_log2, concat, dot_product as ext_dot_product, @@ -25,6 +26,8 @@ use ceno_zkvm::e2e::B; use ceno_zkvm::structs::VerifyingKey; use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier}; use ff_ext::BabyBearExt4; +use gkr_iop::gkr::GKRCircuit; +use itertools::interleave; use itertools::max; use itertools::{interleave, Itertools}; use mpcs::{Basefold, BasefoldRSParams}; @@ -839,3 +842,15 @@ pub fn verify_table_proof( rt_tower.fs } */ + +pub fn verify_precompile( + builder: &mut Builder, + gkr_circuit: GKRCircuit, + gkr_proof: GKRProofVariable, +) { + // _debug: placeholders for now + let challenges: Array> = builder.dyn_array(2); + + + +} From 1caa42c29e2b2813cde8451cbf4c0c260a9c055f Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 23 Jul 2025 21:54:09 -0400 Subject: [PATCH 03/24] Add gkr verification logic --- src/zkvm_verifier/verifier.rs | 193 +++++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 5 deletions(-) diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 35f8b58..043251c 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -19,16 +19,23 @@ use crate::{ eq_eval_less_or_equal_than, eval_wellform_address_vec, gen_alpha_pows, max_usize_arr, max_usize_vec, nested_product, next_pow2_instance_padding, product, sum as ext_sum, }, - tower_verifier::{binding::PointVariable, program::iop_verifier_state_verify}, + tower_verifier::{binding::{PointVariable, PointAndEvalVariable}, program::iop_verifier_state_verify}, }; use ceno_mle::expression::{Instance, StructuralWitIn}; use ceno_zkvm::e2e::B; use ceno_zkvm::structs::VerifyingKey; +use ceno_mle::mle::{Point, PointAndEval}; +use ceno_mle::virtual_poly::build_eq_x_r_sequential; use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier}; use ff_ext::BabyBearExt4; -use gkr_iop::gkr::GKRCircuit; -use itertools::interleave; -use itertools::max; +use gkr_iop::{ + gkr::{ + layer::Layer, + GKRCircuit + }, + evaluation::EvalExpression, +}; +use itertools::{interleave, max, Itertools, izip}; use itertools::{interleave, Itertools}; use mpcs::{Basefold, BasefoldRSParams}; use openvm_native_compiler::prelude::*; @@ -843,14 +850,190 @@ pub fn verify_table_proof( } */ +pub fn generate_layer_challenges( + builder: &mut Builder, + challenger: &mut DuplexChallengerVariable, + challenges: &Array>, + n_challenges: usize, +) -> Array> { + let r = builder.dyn_array(n_challenges + 2); + + let alpha = builder.get(challenges, 0); + let beta = builder.get(challenges, 1); + + builder.set(&r, 0, alpha); + builder.set(&r, 1, beta); + + transcript_observe_label(builder, challenger, b"layer challenge"); + let c = gen_alpha_pows(builder, challenger, Usize::from(n_challenges)); + + for i in 0..n_challenges { + let idx = i + 2; + let e = builder.get(&c, i); + builder.set(&r, idx, e); + } + + r +} + +#[derive(DslVariable, Clone)] +pub struct ClaimAndPoint { + evals: Array>, + has_point: Usize, + point: PointVariable, +} + +pub fn evaluate_gkr_expression( + builder: &mut Builder, + expr: &EvalExpression, + claims: &Array>, + challenges: &Array>, +) -> PointAndEvalVariable { + match expr { + EvalExpression::Zero => { + let point = builder.get(claims, 0).point.clone(); + let eval: Ext = builder.constant(C::EF::ZERO); + PointAndEvalVariable { point, eval } + } + EvalExpression::Single(i) => { + builder.get(claims, *i).clone() + }, + EvalExpression::Linear(i, c0, c1) => { + let point = builder.get(claims, *i); + + let eval = point.eval.clone(); + let point = point.point.clone(); + + let empty_arr: Array> = builder.dyn_array(0); + let c0_eval = eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c0); + let c1_eval = eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c1); + + builder.assign(&eval, eval * c0_eval + c1_eval); + + PointAndEvalVariable { point, eval } + }, + EvalExpression::Partition(parts, indices) => { + assert!(izip!(indices.iter(), indices.iter().skip(1)).all(|(a, b)| a.0 < b.0)); + let empty_arr: Array> = builder.dyn_array(0); + let vars = indices + .iter() + .map(|(_, c)| eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c)) + .collect_vec(); + let vars_arr: Array> = builder.dyn_array(vars.len()); + for (i, e) in vars.iter().enumerate() { + builder.set(&vars_arr, i, *e); + } + let parts = parts + .iter() + .map(|part| evaluate_gkr_expression(builder, part, claims, challenges)) + .collect_vec(); + + assert_eq!(parts.len(), 1 << indices.len()); + + // _debug + // assert!(parts.iter().all(|part| part.point == parts[0].point)); + + let mut new_point: Vec> = vec![]; + builder.range(0, parts[0].point.fs.len()).for_each(|idx_vec, builder| { + let e = builder.get(&parts[0].point.fs, idx_vec[0]); + new_point.push(e); + }); + for (index_in_point, c) in indices { + let eval = eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c); + new_point.insert(*index_in_point, eval); + } + + let new_point_arr: Array> = builder.dyn_array(new_point.len()); + for (i, e) in new_point.iter().enumerate() { + builder.set(&new_point_arr, i, *e); + } + let eq = build_eq_x_r_vec_sequential(builder, &vars_arr); + + let parts_arr: Array> = builder.dyn_array(parts.len()); + for (i, pt) in parts.iter().enumerate() { + builder.set(&parts_arr, i, pt.clone()); + } + + let acc: Ext = builder.constant(C::EF::ZERO); + iter_zip!(builder, parts_arr, eq).for_each(|ptr_vec, builder| { + let prt = builder.iter_ptr_get(&parts_arr, ptr_vec[0]); + let eq_v = builder.iter_ptr_get(&eq, ptr_vec[1]); + builder.assign(&acc, acc + prt.eval * eq_v); + }); + + PointAndEvalVariable { + point: PointVariable { fs: new_point_arr }, + eval: acc, + } + } + } +} + +pub fn extract_claim_and_point( + builder: &mut Builder, + layer: &Layer, + claims: &Array>, + challenges: &Array>, +) -> Array> { + let r = builder.dyn_array(layer.out_eq_and_eval_exprs.len()); + + let claims_and_points = layer.out_eq_and_eval_exprs.iter().enumerate().map(|(i, (_, out_evals))| { + let evals = out_evals + .iter() + .map(|out_eval| { + let r = evaluate_gkr_expression(builder, out_eval, claims, challenges); + r.eval + }) + .collect_vec(); + let evals_arr: Array> = builder.dyn_array(evals.len()); + for (i, e) in evals.iter().enumerate() { + builder.set(&evals_arr, i, *e); + } + let point = out_evals.first().map(|out_eval| { + let r = evaluate_gkr_expression(builder, out_eval, claims, challenges); + r.point + }); + + if point.is_some() { + ClaimAndPoint { + evals: evals_arr, + has_point: Usize::from(1), + point: point.unwrap(), + } + } else { + ClaimAndPoint { + evals: evals_arr, + has_point: Usize::from(0), + point: PointVariable { fs: builder.dyn_array(0) }, + } + } + }) + .collect_vec(); + + for (i, ptc) in claims_and_points.into_iter().enumerate() { + builder.set(&r, i, ptc); + } + + r +} + pub fn verify_precompile( builder: &mut Builder, gkr_circuit: GKRCircuit, gkr_proof: GKRProofVariable, ) { - // _debug: placeholders for now + let mut challenger = DuplexChallengerVariable::new(builder); + + // _debug: placeholders let challenges: Array> = builder.dyn_array(2); + let n_evaluations = gkr_circuit.n_evaluations; + let claims: Array> = builder.dyn_array(n_evaluations); + for (i, layer) in gkr_circuit.layers.iter().enumerate() { + let layer_proof = builder.get(&gkr_proof.layer_proofs, i); + let layer_challenges: Array> = generate_layer_challenges(builder, &mut challenger, &challenges, layer.n_challenges); + let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges); + } } From a17589eec35b05b840003274ae96417b262960e7 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Sun, 27 Jul 2025 21:18:09 -0400 Subject: [PATCH 04/24] Consolidate GKR Verification --- src/e2e/mod.rs | 4 +- src/tower_verifier/program.rs | 3 +- src/zkvm_verifier/binding.rs | 14 +- src/zkvm_verifier/verifier.rs | 523 +++++++++++++++++++++++++++++++++- 4 files changed, 529 insertions(+), 15 deletions(-) diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 07d4a6d..db58a28 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -5,7 +5,7 @@ use crate::zkvm_verifier::binding::{ ZKVMProofInput, TowerProofInput, ZKVMOpcodeProofInput, ZKVMTableProofInput, E, F, GKRProofInput, LayerProofInput, SumcheckLayerProofInput, }; -use crate::zkvm_verifier::verifier::{verify_zkvm_proof, verify_precompile}; +use crate::zkvm_verifier::verifier::{verify_zkvm_proof, verify_gkr_circuit}; use ceno_mle::util::ceil_log2; use ff_ext::BabyBearExt4; use gkr_iop::gkr::layer::sumcheck_layer::{SumcheckLayer, SumcheckLayerProof}; @@ -398,7 +398,7 @@ pub fn precompile_test_thread() { // Obtain witness inputs let gkr_proof_input = GKRProofInput::read(&mut builder); - verify_precompile(&mut builder, circuit, gkr_proof_input); + verify_gkr_circuit(&mut builder, circuit, gkr_proof_input); builder.halt(); // Pass in witness stream diff --git a/src/tower_verifier/program.rs b/src/tower_verifier/program.rs index c97e795..a6ef7e8 100644 --- a/src/tower_verifier/program.rs +++ b/src/tower_verifier/program.rs @@ -178,7 +178,8 @@ pub fn iop_verifier_state_verify( let e1 = builder.get(&prover_msg.evaluations, 0); let e2 = builder.get(&prover_msg.evaluations, 1); let target: Ext<::F, ::EF> = builder.eval(e1 + e2); - builder.assert_ext_eq(expected, target); + // _debug + // builder.assert_ext_eq(expected, target); let p_r = unipoly_extrapolator.extrapolate_uni_poly( builder, diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index f8bfb1d..8c80aab 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -411,9 +411,10 @@ pub(crate) struct SumcheckLayerProofInput { pub evals: Vec, } #[derive(DslVariable, Clone)] -pub(crate) struct SumcheckLayerProofVariable { +pub struct SumcheckLayerProofVariable { pub proof: Array>, pub evals: Array>, + pub evals_len_div_3: Var, } impl VecAutoHintable for SumcheckLayerProofInput {} impl Hintable for SumcheckLayerProofInput { @@ -422,15 +423,20 @@ impl Hintable for SumcheckLayerProofInput { fn read(builder: &mut Builder) -> Self::HintVariable { let proof = Vec::::read(builder); let evals = Vec::::read(builder); + let evals_len_div_3 = usize::read(builder); + Self::HintVariable { proof, - evals + evals, + evals_len_div_3, } } fn write(&self) -> Vec::N>> { let mut stream = Vec::new(); stream.extend(self.proof.write()); stream.extend(self.evals.write()); + let evals_len_div_3 = self.evals.len() / 3; + stream.extend(>::write(&evals_len_div_3)); stream } } @@ -441,7 +447,7 @@ pub(crate) struct LayerProofInput { pub main: SumcheckLayerProofInput, } #[derive(DslVariable, Clone)] -pub(crate) struct LayerProofVariable { +pub struct LayerProofVariable { pub has_rotation: Var, pub rotation: SumcheckLayerProofVariable, pub main: SumcheckLayerProofVariable, @@ -475,7 +481,7 @@ pub(crate) struct GKRProofInput { pub layer_proofs: Vec, } #[derive(DslVariable, Clone)] -pub(crate) struct GKRProofVariable { +pub struct GKRProofVariable { pub num_var_with_rotation: Var, pub layer_proofs: Array>, } diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 043251c..327cc49 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -1,6 +1,8 @@ +use std::io::empty; + use super::binding::{ZKVMChipProofInputVariable, ZKVMProofInputVariable}; use crate::arithmetics::{ - challenger_multi_observe, eval_ceno_expr_with_instance, print_ext_arr, print_felt_arr, + challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, print_ext_arr, print_felt_arr, PolyEvaluator, UniPolyExtrapolator, }; use crate::basefold_verifier::basefold::{ @@ -12,7 +14,7 @@ use crate::basefold_verifier::utils::pow_2; use crate::basefold_verifier::verifier::batch_verify; use crate::tower_verifier::program::verify_tower_proof; use crate::transcript::transcript_observe_label; -use crate::zkvm_verifier::binding::GKRProofVariable; +use crate::zkvm_verifier::binding::{GKRProofVariable, LayerProofInput, LayerProofVariable, SumcheckLayerProofInput, SumcheckLayerProofVariable}; use crate::{ arithmetics::{ build_eq_x_r_vec_sequential, ceil_log2, concat, dot_product as ext_dot_product, @@ -24,14 +26,19 @@ use crate::{ use ceno_mle::expression::{Instance, StructuralWitIn}; use ceno_zkvm::e2e::B; use ceno_zkvm::structs::VerifyingKey; -use ceno_mle::mle::{Point, PointAndEval}; -use ceno_mle::virtual_poly::build_eq_x_r_sequential; +use ceno_mle::{ + expression::{Expression, StructuralWitIn, Instance, WitnessId}, + mle::{Point, PointAndEval}, + virtual_poly::build_eq_x_r_sequential +}; use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier}; use ff_ext::BabyBearExt4; +use gkr_iop::gkr::layer::ROTATION_OPENING_COUNT; use gkr_iop::{ gkr::{ layer::Layer, - GKRCircuit + GKRCircuit, + booleanhypercube::BooleanHypercube, }, evaluation::EvalExpression, }; @@ -45,6 +52,7 @@ use openvm_native_recursion::challenger::{ }; use p3_baby_bear::BabyBear; use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; +use p3_field::dot_product; type F = BabyBear; type E = BabyBearExt4; @@ -883,6 +891,23 @@ pub struct ClaimAndPoint { point: PointVariable, } +#[derive(DslVariable, Clone)] +pub struct RotationClaim { + left_evals: Array>, + right_evals: Array>, + target_evals: Array>, + left_point: Array>, + right_point: Array>, + origin_point: Array>, +} + +#[derive(DslVariable, Clone)] +pub struct GKRClaimEvaluation { + pub value: Ext, + pub point: PointVariable, + pub poly: Usize, +} + pub fn evaluate_gkr_expression( builder: &mut Builder, expr: &EvalExpression, @@ -974,8 +999,12 @@ pub fn extract_claim_and_point( layer: &Layer, claims: &Array>, challenges: &Array>, + has_rotation: Var, ) -> Array> { - let r = builder.dyn_array(layer.out_eq_and_eval_exprs.len()); + let r_len: Usize = Usize::Var(has_rotation.clone()); + builder.assign(&r_len, r_len.clone() * Usize::from(3) + Usize::from(layer.out_eq_and_eval_exprs.len())); + + let r = builder.dyn_array(r_len); let claims_and_points = layer.out_eq_and_eval_exprs.iter().enumerate().map(|(i, (_, out_evals))| { let evals = out_evals @@ -1017,12 +1046,13 @@ pub fn extract_claim_and_point( r } -pub fn verify_precompile( +pub fn verify_gkr_circuit( builder: &mut Builder, gkr_circuit: GKRCircuit, gkr_proof: GKRProofVariable, ) { let mut challenger = DuplexChallengerVariable::new(builder); + let mut unipoly_extrapolator = UniPolyExtrapolator::new(builder); // _debug: placeholders let challenges: Array> = builder.dyn_array(2); @@ -1032,8 +1062,485 @@ pub fn verify_precompile( for (i, layer) in gkr_circuit.layers.iter().enumerate() { let layer_proof = builder.get(&gkr_proof.layer_proofs, i); let layer_challenges: Array> = generate_layer_challenges(builder, &mut challenger, &challenges, layer.n_challenges); - let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges); + let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges, layer_proof.has_rotation); + + // ZeroCheckLayer verification (might include other layer types in the future) + let LayerProofVariable { + main: SumcheckLayerProofVariable { + proof, + evals: main_evals, + evals_len_div_3: main_evals_len_div_3, + }, + rotation: rotation_proof, + has_rotation, + } = layer_proof; + + // Verify rotation proof + + builder.if_eq(has_rotation, Usize::from(1)).then(|builder| { + + let first = builder.get(&eval_and_dedup_points, 0); + builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point + let rt = first.point.fs.clone(); + + + let RotationClaim { + left_evals, + right_evals, + target_evals, + left_point, + right_point, + origin_point + } = verify_rotation( + builder, + gkr_proof.num_var_with_rotation, + &rotation_proof, + layer.rotation_cyclic_subgroup_size, + layer.rotation_cyclic_group_log2, + rt, + &mut challenger, + &mut unipoly_extrapolator, + ); + + let last_idx: Usize = builder.eval(eval_and_dedup_points.len() - Usize::from(1)); + builder.set( + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint{ + evals: left_evals, + has_point: Usize::from(1), + point: PointVariable { fs: left_point } + } + ); + + builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); + builder.set( + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint{ + evals: right_evals, + has_point: Usize::from(1), + point: PointVariable { fs: right_point } + } + ); + + builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); + builder.set( + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint{ + evals: target_evals, + has_point: Usize::from(1), + point: PointVariable { fs: origin_point } + } + ); + }); + + let rotation_exprs_len = layer.rotation_exprs.1.len(); + let alpha_pows = gen_alpha_pows(builder, &mut challenger, Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT)); + + let sigma: Ext = builder.constant(C::EF::ZERO); + let alpha_idx: Var = Var::uninit(builder); + builder.assign(&alpha_idx, C::N::from_canonical_usize(0)); + builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { + let ClaimAndPoint { + evals, + has_point: _, + point: _, + } = builder.get(&eval_and_dedup_points, idx_vec[0]); + let end_idx: Var = builder.eval(alpha_idx.clone() + evals.len()); + let alpha_slice = alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); + let sub_sum = ext_dot_product(builder, &evals, &alpha_slice); + builder.assign(&sigma, sigma.clone() + sub_sum); + builder.assign(&alpha_idx, end_idx); + }); + + let max_degree = builder.constant(C::F::from_canonical_usize(layer.max_expr_degree + 1)); + let max_num_variables = builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation); + let (in_point, expected_evaluation) = iop_verifier_state_verify( + builder, + &mut challenger, + &sigma, + &proof, + max_num_variables, + max_degree, + &mut unipoly_extrapolator + ); + + let eval_and_dedup_points_eq: Array> = builder.dyn_array(eval_and_dedup_points.len()); + let zero = builder.constant(C::EF::ZERO); + let one = builder.constant(C::EF::ONE); + builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { + let ClaimAndPoint { + evals: _, + has_point, + point: out_point, + } = builder.get(&eval_and_dedup_points, idx_vec[0]); + + builder.if_eq(has_point, Usize::from(1)).then(|builder| { + let eq = eq_eval(builder, &out_point.fs, &in_point, one, zero); + builder.set(&eval_and_dedup_points_eq, idx_vec[0], eq); + }); + }); + + layer.out_eq_and_eval_exprs.iter().enumerate().for_each(|(idx, (eq_expr, _))| { + match eq_expr { + Some(Expression::WitIn(id)) | Some(Expression::StructuralWitIn(id, _, _, _)) => { + let eval = builder.get(&eval_and_dedup_points_eq, idx); + builder.set(&main_evals, id.clone() as usize, eval); + }, + _ => unreachable!(), + } + }); + + // Check zero expressions + let offset_eq_id = layer.n_witin as WitnessId; + let empty_arr: Array> = builder.dyn_array(0); + let alpha_idx: Var = Var::uninit(builder); + builder.assign(&alpha_idx, C::N::ZERO); + + let mut expr_iter = layer.exprs.iter(); + let got_claim: Ext = builder.constant(C::EF::ZERO); + let mut zero_check_exprs: Vec> = Vec::with_capacity(layer.out_eq_and_eval_exprs.len()); + for (eq_expr, out_evals) in layer.out_eq_and_eval_exprs.iter() { + let group_length = out_evals.len(); + let zero_check_expr_sum: Ext = builder.constant(C::EF::ZERO); + expr_iter.by_ref().take(group_length).for_each(|expr| { + let e = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + expr, + ); + let alpha = builder.get(&alpha_pows, alpha_idx); + builder.assign(&alpha_idx, alpha_idx + C::N::ONE); + builder.assign(&zero_check_expr_sum, zero_check_expr_sum.clone() + e * alpha); + }); + + let eq_expr: Expression = match eq_expr { + Some(Expression::StructuralWitIn(id, ..)) => Expression::WitIn(offset_eq_id + *id), + invalid => panic!("invalid eq format {:?}", invalid), + }; + let eq_expr_val = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + &eq_expr, + ); + builder.assign(&zero_check_expr_sum, zero_check_expr_sum.clone() * eq_expr_val); + builder.assign(&got_claim, got_claim + zero_check_expr_sum); + } + + // Rotation expressions + let (rotation_eq, rotation_exprs) = &layer.rotation_exprs; + if rotation_eq.is_some() { + let rotation_exprs_vals = rotation_exprs.iter().map(|(rotation_expr, expr)| { + ( + eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + rotation_expr, + ), + eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + expr, + ) + ) + }) + .collect::, Ext)>>(); + + let rotation_exprs_len = C::N::from_canonical_usize(rotation_exprs.len()); + + let left_rotation_expr_val: Ext = builder.constant(C::EF::ZERO); + let right_rotation_expr_val: Ext = builder.constant(C::EF::ZERO); + let rotation_expr_val: Ext = builder.constant(C::EF::ZERO); + + let end_idx: Var = builder.eval(alpha_idx + rotation_exprs_len); + let left_alpha_slice = alpha_pows.slice(builder, alpha_idx, end_idx); + + builder.assign(&alpha_idx, end_idx); + let end_idx: Var = builder.eval(alpha_idx + rotation_exprs_len); + let right_alpha_slice = alpha_pows.slice(builder, alpha_idx, end_idx); + + builder.assign(&alpha_idx, end_idx); + let end_idx: Var = builder.eval(alpha_idx + rotation_exprs_len); + let rotation_alpha_slice = alpha_pows.slice(builder, alpha_idx, end_idx); + + rotation_exprs_vals.iter().enumerate().for_each(|(idx, (r_v, e_v))| { + let left_alpha = builder.get(&left_alpha_slice, idx); + let right_alpha = builder.get(&right_alpha_slice, idx); + let rotation_alpha = builder.get(&rotation_alpha_slice, idx); + + builder.assign(&left_rotation_expr_val, left_rotation_expr_val.clone() + r_v.clone() * left_alpha); + builder.assign(&right_rotation_expr_val, right_rotation_expr_val.clone() + r_v.clone() * right_alpha); + builder.assign(&rotation_expr_val, rotation_expr_val.clone() + e_v.clone() * rotation_alpha); + }); + + if let Some( + [ + rotation_left_eq_expr, + rotation_right_eq_expr, + rotation_eq_expr, + ], + ) = rotation_eq.as_ref() + { + let (rotation_left_eq_expr, rotation_right_eq_expr, rotation_eq_expr) = match ( + rotation_left_eq_expr, + rotation_right_eq_expr, + rotation_eq_expr, + ) { + ( + Expression::StructuralWitIn(left_eq_id, ..), + Expression::StructuralWitIn(right_eq_id, ..), + Expression::StructuralWitIn(eq_id, ..), + ) => ( + Expression::WitIn(offset_eq_id + *left_eq_id), + Expression::WitIn(offset_eq_id + *right_eq_id), + Expression::WitIn(offset_eq_id + *eq_id), + ), + invalid => panic!("invalid eq format {:?}", invalid), + }; + + let rotation_left_eq_expr_val = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + &rotation_left_eq_expr, + ); + + let rotation_right_eq_expr_val = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + &rotation_right_eq_expr, + ); + + let rotation_eq_expr_val = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &empty_arr, + &challenges, + &rotation_eq_expr, + ); + + builder.assign(&got_claim, got_claim + rotation_left_eq_expr_val * left_rotation_expr_val); + builder.assign(&got_claim, got_claim + rotation_right_eq_expr_val * right_rotation_expr_val); + builder.assign(&got_claim, got_claim + rotation_eq_expr_val * rotation_expr_val); + } + } + + // _debug + // builder.assert_ext_eq(got_claim, expected_evaluation); + + // Update claim + layer.in_eval_expr.iter().enumerate().for_each(|(idx, pos)| { + let val = builder.get(&main_evals, idx); + builder.set(&claims, *pos, PointAndEvalVariable { + point: PointVariable { + fs: in_point.clone() + }, + eval: val, + }); + }); } + // GKR Claim + let input_layer = gkr_circuit.layers.last().unwrap(); + let gkr_claim = input_layer + .in_eval_expr + .iter() + .enumerate() + .map(|(poly, eval)| { + let PointAndEvalVariable { point, eval } = builder.get(&claims, *eval); + + GKRClaimEvaluation { + value: eval, + point, + poly: Usize::from(poly), + } + }) + .collect_vec(); +} + +pub fn verify_rotation( + builder: &mut Builder, + max_num_variables: Var, + rotation_proof: &SumcheckLayerProofVariable, + rotation_cyclic_subgroup_size: usize, + rotation_cyclic_group_log2: usize, + rt: Array>, + challenger: &mut DuplexChallengerVariable, + unipoly_extrapolator: &mut UniPolyExtrapolator, +) -> RotationClaim { + let SumcheckLayerProofVariable { + proof, + evals, + evals_len_div_3: rotation_expr_len, + } = rotation_proof; + + let rotation_expr_len = Usize::Var(rotation_expr_len.clone()); + + let rotation_alpha_pows = gen_alpha_pows(builder, challenger, rotation_expr_len.clone()); + let sigma: Ext = builder.constant(C::EF::ZERO); + + let max_num_variables = builder.unsafe_cast_var_to_felt(max_num_variables); + let max_degree: Felt = builder.constant(C::F::TWO); + + let (origin_point, expected_evaluation) = iop_verifier_state_verify( + builder, + challenger, + &sigma, + proof, + max_num_variables, + max_degree, + unipoly_extrapolator + ); + + // compute the selector evaluation + let selector_eval = rotation_selector_eval( + builder, + &rt, + &origin_point, + rotation_cyclic_group_log2 + ); + + // check the final evaluations. + let left_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); + let right_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); + let target_evals: Array> = builder.dyn_array(rotation_expr_len); + + let got_claim: Ext = builder.constant(C::EF::ZERO); + let one: Ext = builder.constant(C::EF::ONE); + let last_origin = builder.get(&origin_point, rotation_cyclic_group_log2 - 1); + + builder.range(0, rotation_alpha_pows.len()).for_each(|idx_vec, builder| { + let alpha = builder.get(&rotation_alpha_pows, idx_vec[0]); + + let rvar3 = RVar::from(3); + let left_idx: Var = builder.eval(idx_vec[0] * rvar3); + let right_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(1)); + let target_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(2)); + + let left = builder.get(&evals, left_idx); + let right = builder.get(&evals, right_idx); + let target = builder.get(&evals, target_idx); + + builder.set(&left_evals, idx_vec[0], left); + builder.set(&right_evals, idx_vec[0], right); + builder.set(&target_evals, idx_vec[0], target); + + builder.assign(&got_claim, got_claim + alpha * ((one - last_origin) * left + last_origin * right - target)); + }); + builder.assign(&got_claim, got_claim * selector_eval); + + // _debug + // builder.assert_ext_eq(got_claim, expected_evaluation); + + let (left_point, right_point) = get_rotation_points(builder, rotation_cyclic_group_log2, &origin_point); + + RotationClaim { + left_evals, + right_evals, + target_evals, + left_point, + right_point, + origin_point + } +} + +pub fn get_rotation_points( + builder: &mut Builder, + num_vars: usize, + point: &Array>, + ) -> ( + Array>, + Array>, + ) { + assert_eq!(num_vars, 5); + + let left: Array> = builder.dyn_array(point.len()); + let right: Array> = builder.dyn_array(point.len()); + builder.range(0, 4).for_each(|idx_vec, builder| { + let e = builder.get(point, idx_vec[0]); + let dest_idx: Var = builder.eval(idx_vec[0] + RVar::from(1)); + builder.set(&left, dest_idx, e); + builder.set(&right, dest_idx, e); + }); + + let one: Ext = builder.constant(C::EF::ONE); + builder.set(&right, 0, one); + let r1 = builder.get(&right, 2); + builder.set(&right, 2, one - r1); + + builder.range(5, point.len()).for_each(|idx_vec, builder| { + let e = builder.get(point, idx_vec[0]); + builder.set(&left, idx_vec[0], e); + builder.set(&right, idx_vec[0], e); + }); + + (left, right) + } + +/// sel(rx) +/// = (\sum_{b = 0}^{cyclic_subgroup_size - 1} eq(out_point[..cyclic_group_log2_size], b) * eq(in_point[..cyclic_group_log2_size], b)) +/// * \prod_{k = cyclic_group_log2_size}^{n - 1} eq(out_point[k], in_point[k]) +pub fn rotation_selector_eval( + builder: &mut Builder, + out_point: &Array>, + in_point: &Array>, + cyclic_group_log2_size: usize, +) -> Ext { + let bh = BooleanHypercube::new(cyclic_group_log2_size); + let eval: Ext = builder.constant(C::EF::ZERO); + + let cyclic_group_size: usize = 1 << cyclic_group_log2_size; + let rotation_index = bh.into_iter().take(cyclic_group_size).collect_vec(); + + + let out_subgroup = out_point.slice(builder, 0, cyclic_group_log2_size); + let in_subgroup = in_point.slice(builder, 0, cyclic_group_log2_size); + let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_subgroup); + let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_subgroup); + + for b in rotation_index { + let out_v = builder.get(&out_subgroup_eq, b as usize); + let in_v = builder.get(&in_subgroup_eq, b as usize); + builder.assign(&eval, eval + in_v * out_v); + } + + let out_subgroup = out_point.slice(builder, cyclic_group_log2_size, out_point.len()); + let in_subgroup = in_point.slice(builder, cyclic_group_log2_size, in_point.len()); + + let one: Ext = builder.constant(C::EF::ONE); + let zero: Ext = builder.constant(C::EF::ZERO); + + /* _debug + let eq_eval = eq_eval(builder, &out_subgroup, &in_subgroup, one, zero); + builder.assign(&eval, eval * eq_eval); + */ + eval } From 762d104d8a5fd93a17ae921974fad1224be83433 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Tue, 29 Jul 2025 21:14:47 -0400 Subject: [PATCH 05/24] Complete selector-related verifier update --- Cargo.lock | 65 ++++---- Cargo.toml | 26 ++-- src/arithmetics/mod.rs | 4 +- src/e2e/mod.rs | 1 + src/zkvm_verifier/binding.rs | 11 ++ src/zkvm_verifier/verifier.rs | 269 +++++++++++----------------------- 6 files changed, 150 insertions(+), 226 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 674235b..f5357f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "ceno-examples" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "glob", ] @@ -580,7 +580,7 @@ dependencies = [ [[package]] name = "ceno_emul" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "anyhow", "ceno_rt", @@ -603,7 +603,7 @@ dependencies = [ [[package]] name = "ceno_host" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "anyhow", "ceno_emul", @@ -616,7 +616,7 @@ dependencies = [ [[package]] name = "ceno_rt" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "getrandom 0.2.16", "rkyv", @@ -625,7 +625,7 @@ dependencies = [ [[package]] name = "ceno_zkvm" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "base64", "bincode", @@ -1144,7 +1144,7 @@ dependencies = [ [[package]] name = "ff_ext" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "once_cell", "p3", @@ -1234,7 +1234,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gkr_iop" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "ark-std 0.5.0", "bincode", @@ -1269,9 +1269,9 @@ dependencies = [ [[package]] name = "glam" -version = "0.30.4" +version = "0.30.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50a99dbe56b72736564cfa4b85bf9a33079f16ae8b74983ab06af3b1a3696b11" +checksum = "f2d1aab06663bdce00d6ca5e5ed586ec8d18033a771906c993a1e3755b368d85" [[package]] name = "glob" @@ -1608,9 +1608,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4488594b9328dee448adb906d8b126d9b7deb7cf5c22161ee591610bb1be83c0" +checksum = "360e552c93fa0e8152ab463bc4c4837fce76a225df11dfaeea66c313de5e61f7" dependencies = [ "bitflags", "libc", @@ -1723,7 +1723,7 @@ dependencies = [ [[package]] name = "mpcs" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "aes", "bincode", @@ -1754,7 +1754,7 @@ dependencies = [ [[package]] name = "multilinear_extensions" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "either", "ff_ext", @@ -1768,18 +1768,18 @@ dependencies = [ [[package]] name = "munge" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cce144fab80fbb74ec5b89d1ca9d41ddf6b644ab7e986f7d3ed0aab31625cb1" +checksum = "d7feb0b48aa0a25f9fe0899482c6e1379ee7a11b24a53073eacdecb9adb6dc60" dependencies = [ "munge_macro", ] [[package]] name = "munge_macro" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "574af9cd5b9971cbfdf535d6a8d533778481b241c447826d976101e0149392a1" +checksum = "f2e3795a5d2da581a8b252fec6022eee01aea10161a4d1bf237d4cbe47f7e988" dependencies = [ "proc-macro2", "quote", @@ -2316,7 +2316,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "p3-baby-bear", "p3-challenger", @@ -2774,7 +2774,7 @@ dependencies = [ [[package]] name = "poseidon" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "criterion", "ff_ext", @@ -3105,9 +3105,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] name = "rustc-hash" @@ -3383,7 +3383,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sumcheck" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "crossbeam-channel", "either", @@ -3402,7 +3402,7 @@ dependencies = [ [[package]] name = "sumcheck_macro" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "itertools 0.13.0", "p3", @@ -3676,7 +3676,7 @@ dependencies = [ [[package]] name = "transcript" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "crossbeam-channel", "ff_ext", @@ -3854,7 +3854,7 @@ dependencies = [ [[package]] name = "whir" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "bincode", "blake2", @@ -3914,6 +3914,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.59.0" @@ -3929,7 +3935,7 @@ version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.53.2", + "windows-targets 0.53.3", ] [[package]] @@ -3950,10 +3956,11 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.2" +version = "0.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" dependencies = [ + "windows-link", "windows_aarch64_gnullvm 0.53.0", "windows_aarch64_msvc 0.53.0", "windows_i686_gnu 0.53.0", @@ -4090,7 +4097,7 @@ dependencies = [ [[package]] name = "witness" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" dependencies = [ "ff_ext", "multilinear_extensions", diff --git a/Cargo.toml b/Cargo.toml index 5f98c58..80506d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,15 +40,23 @@ ark-poly = "0.5" ark-serialize = "0.5" # Ceno -ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "multilinear_extensions" } -ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "sumcheck" } -ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "transcript" } -ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "witness" } -ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } +# ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "multilinear_extensions" } +# ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "sumcheck" } +# ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "transcript" } +# ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +# ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +# mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +# ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } + +ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify", package = "multilinear_extensions" } +ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify", package = "sumcheck" } +ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify", package = "transcript" } +ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } +ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } +gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } +mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } +ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } + serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/arithmetics/mod.rs b/src/arithmetics/mod.rs index a8a7bbe..fe85a29 100644 --- a/src/arithmetics/mod.rs +++ b/src/arithmetics/mod.rs @@ -427,9 +427,7 @@ pub fn eq_eval_less_or_equal_than( b: &Array>, ) -> Ext { builder.cycle_tracker_start("Compute eq_eval_less_or_equal_than"); - let eq_bit_decomp: Array> = opcode_proof - .num_instances_minus_one_bit_decomposition - .slice(builder, 0, b.len()); + let eq_bit_decomp: Array> = num_instances_minus_one_bit_decomposition.slice(builder, 0, b.len()); let one_ext: Ext = builder.constant(C::EF::ONE); let rp_len = builder.eval_expr(b.len() + C::N::ONE); diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index db58a28..99f371a 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -318,6 +318,7 @@ pub fn parse_precompile_proof_variables( let mut gkr_proof_input = GKRProofInput { num_var_with_rotation, + num_instances, layer_proofs: vec![], }; diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index 8c80aab..b96f186 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -478,11 +478,13 @@ impl Hintable for LayerProofInput { #[derive(Default)] pub(crate) struct GKRProofInput { pub num_var_with_rotation: usize, + pub num_instances: usize, pub layer_proofs: Vec, } #[derive(DslVariable, Clone)] pub struct GKRProofVariable { pub num_var_with_rotation: Var, + pub num_instances_minus_one_bit_decomposition: Array>, pub layer_proofs: Array>, } impl Hintable for GKRProofInput { @@ -490,15 +492,24 @@ impl Hintable for GKRProofInput { fn read(builder: &mut Builder) -> Self::HintVariable { let num_var_with_rotation = usize::read(builder); + let num_instances_minus_one_bit_decomposition = Vec::::read(builder); let layer_proofs = Vec::::read(builder); Self::HintVariable { num_var_with_rotation, + num_instances_minus_one_bit_decomposition, layer_proofs, } } fn write(&self) -> Vec::N>> { let mut stream = Vec::new(); stream.extend(>::write(&self.num_var_with_rotation)); + + let eq_instance = self.num_instances - 1; + let mut bit_decomp: Vec = vec![]; + for i in 0..32usize { + bit_decomp.push(F::from_canonical_usize((eq_instance >> i) & 1)); + } + stream.extend(bit_decomp.write()); stream.extend(self.layer_proofs.write()); stream } diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 327cc49..2d16f32 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -40,6 +40,7 @@ use gkr_iop::{ GKRCircuit, booleanhypercube::BooleanHypercube, }, + selector::SelectorType, evaluation::EvalExpression, }; use itertools::{interleave, max, Itertools, izip}; @@ -1002,11 +1003,11 @@ pub fn extract_claim_and_point( has_rotation: Var, ) -> Array> { let r_len: Usize = Usize::Var(has_rotation.clone()); - builder.assign(&r_len, r_len.clone() * Usize::from(3) + Usize::from(layer.out_eq_and_eval_exprs.len())); + builder.assign(&r_len, r_len.clone() * Usize::from(3) + Usize::from(layer.out_sel_and_eval_exprs.len())); let r = builder.dyn_array(r_len); - let claims_and_points = layer.out_eq_and_eval_exprs.iter().enumerate().map(|(i, (_, out_evals))| { + let claims_and_points = layer.out_sel_and_eval_exprs.iter().enumerate().map(|(i, (_, out_evals))| { let evals = out_evals .iter() .map(|out_eval| { @@ -1056,6 +1057,7 @@ pub fn verify_gkr_circuit( // _debug: placeholders let challenges: Array> = builder.dyn_array(2); + let pub_io_evals: Array> = builder.dyn_array(2); let n_evaluations = gkr_circuit.n_evaluations; let claims: Array> = builder.dyn_array(n_evaluations); @@ -1076,14 +1078,11 @@ pub fn verify_gkr_circuit( } = layer_proof; // Verify rotation proof - builder.if_eq(has_rotation, Usize::from(1)).then(|builder| { - let first = builder.get(&eval_and_dedup_points, 0); builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point let rt = first.point.fs.clone(); - let RotationClaim { left_evals, right_evals, @@ -1167,190 +1166,30 @@ pub fn verify_gkr_circuit( &mut unipoly_extrapolator ); - let eval_and_dedup_points_eq: Array> = builder.dyn_array(eval_and_dedup_points.len()); - let zero = builder.constant(C::EF::ZERO); - let one = builder.constant(C::EF::ONE); - builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { - let ClaimAndPoint { - evals: _, - has_point, - point: out_point, - } = builder.get(&eval_and_dedup_points, idx_vec[0]); - - builder.if_eq(has_point, Usize::from(1)).then(|builder| { - let eq = eq_eval(builder, &out_point.fs, &in_point, one, zero); - builder.set(&eval_and_dedup_points_eq, idx_vec[0], eq); - }); - }); - - layer.out_eq_and_eval_exprs.iter().enumerate().for_each(|(idx, (eq_expr, _))| { - match eq_expr { - Some(Expression::WitIn(id)) | Some(Expression::StructuralWitIn(id, _, _, _)) => { - let eval = builder.get(&eval_and_dedup_points_eq, idx); - builder.set(&main_evals, id.clone() as usize, eval); - }, - _ => unreachable!(), - } - }); - - // Check zero expressions - let offset_eq_id = layer.n_witin as WitnessId; - let empty_arr: Array> = builder.dyn_array(0); - let alpha_idx: Var = Var::uninit(builder); - builder.assign(&alpha_idx, C::N::ZERO); - - let mut expr_iter = layer.exprs.iter(); - let got_claim: Ext = builder.constant(C::EF::ZERO); - let mut zero_check_exprs: Vec> = Vec::with_capacity(layer.out_eq_and_eval_exprs.len()); - for (eq_expr, out_evals) in layer.out_eq_and_eval_exprs.iter() { - let group_length = out_evals.len(); - let zero_check_expr_sum: Ext = builder.constant(C::EF::ZERO); - expr_iter.by_ref().take(group_length).for_each(|expr| { - let e = eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - expr, - ); - let alpha = builder.get(&alpha_pows, alpha_idx); - builder.assign(&alpha_idx, alpha_idx + C::N::ONE); - builder.assign(&zero_check_expr_sum, zero_check_expr_sum.clone() + e * alpha); - }); + layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(idx, (sel_type, _))| { + let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; - let eq_expr: Expression = match eq_expr { - Some(Expression::StructuralWitIn(id, ..)) => Expression::WitIn(offset_eq_id + *id), - invalid => panic!("invalid eq format {:?}", invalid), - }; - let eq_expr_val = eval_ceno_expr_with_instance( + evaluate_selector( builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - &eq_expr, + sel_type, + &main_evals, + &out_point, + &in_point, + &gkr_proof.num_instances_minus_one_bit_decomposition, + layer.n_witin, ); - builder.assign(&zero_check_expr_sum, zero_check_expr_sum.clone() * eq_expr_val); - builder.assign(&got_claim, got_claim + zero_check_expr_sum); - } - - // Rotation expressions - let (rotation_eq, rotation_exprs) = &layer.rotation_exprs; - if rotation_eq.is_some() { - let rotation_exprs_vals = rotation_exprs.iter().map(|(rotation_expr, expr)| { - ( - eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - rotation_expr, - ), - eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - expr, - ) - ) - }) - .collect::, Ext)>>(); - - let rotation_exprs_len = C::N::from_canonical_usize(rotation_exprs.len()); - - let left_rotation_expr_val: Ext = builder.constant(C::EF::ZERO); - let right_rotation_expr_val: Ext = builder.constant(C::EF::ZERO); - let rotation_expr_val: Ext = builder.constant(C::EF::ZERO); - - let end_idx: Var = builder.eval(alpha_idx + rotation_exprs_len); - let left_alpha_slice = alpha_pows.slice(builder, alpha_idx, end_idx); - - builder.assign(&alpha_idx, end_idx); - let end_idx: Var = builder.eval(alpha_idx + rotation_exprs_len); - let right_alpha_slice = alpha_pows.slice(builder, alpha_idx, end_idx); - - builder.assign(&alpha_idx, end_idx); - let end_idx: Var = builder.eval(alpha_idx + rotation_exprs_len); - let rotation_alpha_slice = alpha_pows.slice(builder, alpha_idx, end_idx); - - rotation_exprs_vals.iter().enumerate().for_each(|(idx, (r_v, e_v))| { - let left_alpha = builder.get(&left_alpha_slice, idx); - let right_alpha = builder.get(&right_alpha_slice, idx); - let rotation_alpha = builder.get(&rotation_alpha_slice, idx); - - builder.assign(&left_rotation_expr_val, left_rotation_expr_val.clone() + r_v.clone() * left_alpha); - builder.assign(&right_rotation_expr_val, right_rotation_expr_val.clone() + r_v.clone() * right_alpha); - builder.assign(&rotation_expr_val, rotation_expr_val.clone() + e_v.clone() * rotation_alpha); - }); - - if let Some( - [ - rotation_left_eq_expr, - rotation_right_eq_expr, - rotation_eq_expr, - ], - ) = rotation_eq.as_ref() - { - let (rotation_left_eq_expr, rotation_right_eq_expr, rotation_eq_expr) = match ( - rotation_left_eq_expr, - rotation_right_eq_expr, - rotation_eq_expr, - ) { - ( - Expression::StructuralWitIn(left_eq_id, ..), - Expression::StructuralWitIn(right_eq_id, ..), - Expression::StructuralWitIn(eq_id, ..), - ) => ( - Expression::WitIn(offset_eq_id + *left_eq_id), - Expression::WitIn(offset_eq_id + *right_eq_id), - Expression::WitIn(offset_eq_id + *eq_id), - ), - invalid => panic!("invalid eq format {:?}", invalid), - }; - - let rotation_left_eq_expr_val = eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - &rotation_left_eq_expr, - ); - - let rotation_right_eq_expr_val = eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - &rotation_right_eq_expr, - ); - - let rotation_eq_expr_val = eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &empty_arr, - &challenges, - &rotation_eq_expr, - ); + }); - builder.assign(&got_claim, got_claim + rotation_left_eq_expr_val * left_rotation_expr_val); - builder.assign(&got_claim, got_claim + rotation_right_eq_expr_val * right_rotation_expr_val); - builder.assign(&got_claim, got_claim + rotation_eq_expr_val * rotation_expr_val); - } - } + let empty_arr: Array> = builder.dyn_array(0); + let got_claim = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &pub_io_evals, + &challenges, + layer.main_sumcheck_expression.as_ref().unwrap(), + ); // _debug // builder.assert_ext_eq(got_claim, expected_evaluation); @@ -1385,6 +1224,66 @@ pub fn verify_gkr_circuit( .collect_vec(); } +pub fn evaluate_selector( + builder: &mut Builder, + sel_type: &SelectorType, + evals: &Array>, + out_point: &Array>, + in_point: &Array>, + num_instances_minus_one_bit_decomposition: &Array>, + offset_eq_id: usize, +) { + let (expr, eval) = match sel_type { + SelectorType::None => return, + SelectorType::Whole(expr) => { + let one = builder.constant(C::EF::ONE); + let zero = builder.constant(C::EF::ZERO); + (expr, eq_eval(builder, out_point, in_point, one, zero)) + } + SelectorType::Prefix(_, expr) => { + ( + expr, + eq_eval_less_or_equal_than( + builder, + num_instances_minus_one_bit_decomposition, + out_point, + in_point + ) + ) + } + SelectorType::OrderedSparse32 { + indices, + expression, + } => { + let out_point_slice = out_point.slice(builder, 0, 5); + let in_point_slice = in_point.slice(builder, 0, 5); + let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_point_slice); + let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_point_slice); + + let eval: Ext = builder.constant(C::EF::ZERO); + for idx in indices { + let out_val = builder.get(&out_subgroup_eq, *idx); + let in_val = builder.get(&in_subgroup_eq, *idx); + builder.assign(&eval, eval + out_val * in_val); + } + + let out_point_slice = out_point.slice(builder, 5, out_point.len()); + let in_point_slice = in_point.slice(builder, 5, in_point.len()); + + let sel = eq_eval_less_or_equal_than(builder, num_instances_minus_one_bit_decomposition, &out_point_slice, &in_point_slice); + builder.assign(&eval, eval * sel); + + (expression, eval) + } + }; + + let Expression::StructuralWitIn(wit_id, _, _, _) = expr else { + panic!("Wrong selector expression format"); + }; + let wit_id = *wit_id as usize + offset_eq_id; + builder.set(evals, wit_id, eval); +} + pub fn verify_rotation( builder: &mut Builder, max_num_variables: Var, From 4b2bc787c0718bf237b8dfe29c7a41f13b0eb5d6 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Thu, 31 Jul 2025 18:04:56 -0400 Subject: [PATCH 06/24] Hold off selector for e2e test context --- src/zkvm_verifier/verifier.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 2d16f32..0ff7b92 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -1134,13 +1134,13 @@ pub fn verify_gkr_circuit( } ); }); - + let rotation_exprs_len = layer.rotation_exprs.1.len(); let alpha_pows = gen_alpha_pows(builder, &mut challenger, Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT)); - let sigma: Ext = builder.constant(C::EF::ZERO); let alpha_idx: Var = Var::uninit(builder); builder.assign(&alpha_idx, C::N::from_canonical_usize(0)); + builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { let ClaimAndPoint { evals, @@ -1166,6 +1166,7 @@ pub fn verify_gkr_circuit( &mut unipoly_extrapolator ); + /* _debug: wait for e2e test context layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(idx, (sel_type, _))| { let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; @@ -1179,6 +1180,7 @@ pub fn verify_gkr_circuit( layer.n_witin, ); }); + */ let empty_arr: Array> = builder.dyn_array(0); let got_claim = eval_ceno_expr_with_instance( From 7a4dafa03b76676ff9415d94b9b693179a6ec3d5 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Thu, 31 Jul 2025 21:09:26 -0400 Subject: [PATCH 07/24] Change build --- Cargo.lock | 32 ++++++++++++++++---------------- Cargo.toml | 24 ++++++++---------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5357f3..84d43ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "ceno-examples" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "glob", ] @@ -580,7 +580,7 @@ dependencies = [ [[package]] name = "ceno_emul" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "anyhow", "ceno_rt", @@ -603,7 +603,7 @@ dependencies = [ [[package]] name = "ceno_host" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "anyhow", "ceno_emul", @@ -616,7 +616,7 @@ dependencies = [ [[package]] name = "ceno_rt" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "getrandom 0.2.16", "rkyv", @@ -625,7 +625,7 @@ dependencies = [ [[package]] name = "ceno_zkvm" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "base64", "bincode", @@ -1144,7 +1144,7 @@ dependencies = [ [[package]] name = "ff_ext" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "once_cell", "p3", @@ -1234,7 +1234,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gkr_iop" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "ark-std 0.5.0", "bincode", @@ -1723,7 +1723,7 @@ dependencies = [ [[package]] name = "mpcs" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "aes", "bincode", @@ -1754,7 +1754,7 @@ dependencies = [ [[package]] name = "multilinear_extensions" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "either", "ff_ext", @@ -2316,7 +2316,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "p3-baby-bear", "p3-challenger", @@ -2774,7 +2774,7 @@ dependencies = [ [[package]] name = "poseidon" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "criterion", "ff_ext", @@ -3383,7 +3383,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sumcheck" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "crossbeam-channel", "either", @@ -3402,7 +3402,7 @@ dependencies = [ [[package]] name = "sumcheck_macro" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "itertools 0.13.0", "p3", @@ -3676,7 +3676,7 @@ dependencies = [ [[package]] name = "transcript" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "crossbeam-channel", "ff_ext", @@ -3854,7 +3854,7 @@ dependencies = [ [[package]] name = "whir" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "bincode", "blake2", @@ -4097,7 +4097,7 @@ dependencies = [ [[package]] name = "witness" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_verify#eda7e55652e04cd310c17d315f7919fa8c4f51bb" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "ff_ext", "multilinear_extensions", diff --git a/Cargo.toml b/Cargo.toml index 80506d8..b22e122 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,22 +40,14 @@ ark-poly = "0.5" ark-serialize = "0.5" # Ceno -# ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "multilinear_extensions" } -# ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "sumcheck" } -# ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "transcript" } -# ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -# ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -# mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -# ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } - -ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify", package = "multilinear_extensions" } -ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify", package = "sumcheck" } -ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify", package = "transcript" } -ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } -ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } -gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } -mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } -ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_verify" } +ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "multilinear_extensions" } +ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "sumcheck" } +ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "transcript" } +ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" From 2d85a966447d667031785253b3a189bed42c61f1 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Sat, 2 Aug 2025 19:46:11 -0400 Subject: [PATCH 08/24] Resolve rebase issues --- Cargo.lock | 32 +++++++------- Cargo.toml | 16 +------ src/arithmetics/mod.rs | 3 +- src/e2e/mod.rs | 9 ++-- src/zkvm_verifier/binding.rs | 79 +++-------------------------------- src/zkvm_verifier/verifier.rs | 4 +- 6 files changed, 31 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84d43ca..4282d30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,11 +516,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.30" -version = "1.2.30" +version = "1.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" dependencies = [ "shlex", ] @@ -713,9 +711,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.41" +version = "4.5.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" +checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882" dependencies = [ "clap_builder", "clap_derive", @@ -723,9 +721,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.41" +version = "4.5.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" +checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966" dependencies = [ "anstream", "anstyle", @@ -1239,13 +1237,11 @@ dependencies = [ "ark-std 0.5.0", "bincode", "ceno_emul", - "ceno_emul", "clap", "either", "ff_ext", "itertools 0.13.0", "mpcs", - "mpcs", "multilinear_extensions", "p3", "p3-field", @@ -1608,9 +1604,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360e552c93fa0e8152ab463bc4c4837fce76a225df11dfaeea66c313de5e61f7" +checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ "bitflags", "libc", @@ -3054,9 +3050,9 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e147371c75553e1e2fcdb483944a8540b8438c31426279553b9a8182a9b7b65" +checksum = "19f5c3e5da784cd8c69d32cdc84673f3204536ca56e1fa01be31a74b92c932ac" dependencies = [ "bytecheck", "bytes", @@ -3073,9 +3069,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246b40ac189af6c675d124b802e8ef6d5246c53e17367ce9501f8f66a81abb7a" +checksum = "4270433626cffc9c4c1d3707dd681f2a2718d3d7b09ad754bec137acecda8d22" dependencies = [ "proc-macro2", "quote", @@ -3242,9 +3238,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.141" +version = "1.0.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" +checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index b22e122..c3e9615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,6 @@ openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.g openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } -openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } -openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } - rand = { version = "0.8.5", default-features = false } itertools = { version = "0.13.0", default-features = false } bincode = "1.3.3" @@ -43,6 +40,7 @@ ark-serialize = "0.5" ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "multilinear_extensions" } ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "sumcheck" } ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "transcript" } +ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "witness" } ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } @@ -53,14 +51,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" [features] -bench-metrics = ["openvm-circuit/bench-metrics"] - -# [patch."https://github.com/scroll-tech/ceno.git"] -# ceno_mle = { path = "../ceno/multilinear_extensions", package = "multilinear_extensions" } -# ceno_sumcheck = { path = "../ceno/sumcheck", package = "sumcheck" } -# ceno_transcript = { path = "../ceno/transcript", package = "transcript" } -# ceno_witness = { path = "../ceno/witness", package = "witness" } -# ceno_zkvm = { path = "../ceno/ceno_zkvm" } -# ceno_emul = { path = "../ceno/ceno_emul" } -# mpcs = { path = "../ceno/mpcs" } -# ff_ext = { path = "../ceno/ff_ext" } +bench-metrics = ["openvm-circuit/bench-metrics"] \ No newline at end of file diff --git a/src/arithmetics/mod.rs b/src/arithmetics/mod.rs index fe85a29..0593b5c 100644 --- a/src/arithmetics/mod.rs +++ b/src/arithmetics/mod.rs @@ -421,13 +421,12 @@ pub fn gen_alpha_pows( /// = \sum_{\mathbf{b}=0}^{max_idx} \prod_{i=0}^{n-1} (x_i y_i b_i + (1 - x_i)(1 - y_i)(1 - b_i)) pub fn eq_eval_less_or_equal_than( builder: &mut Builder, - _challenger: &mut DuplexChallengerVariable, opcode_proof: &ZKVMChipProofInputVariable, a: &Array>, b: &Array>, ) -> Ext { builder.cycle_tracker_start("Compute eq_eval_less_or_equal_than"); - let eq_bit_decomp: Array> = num_instances_minus_one_bit_decomposition.slice(builder, 0, b.len()); + let eq_bit_decomp: Array> = opcode_proof.num_instances_minus_one_bit_decomposition.slice(builder, 0, b.len()); let one_ext: Ext = builder.constant(C::EF::ONE); let rp_len = builder.eval_expr(b.len() + C::N::ONE); diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 99f371a..5da6f36 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -2,13 +2,16 @@ use crate::basefold_verifier::basefold::BasefoldCommitment; use crate::basefold_verifier::query_phase::QueryPhaseVerifierInput; use crate::tower_verifier::binding::IOPProverMessage; use crate::zkvm_verifier::binding::{ - ZKVMProofInput, TowerProofInput, ZKVMOpcodeProofInput, ZKVMTableProofInput, E, F, + ZKVMProofInput, TowerProofInput, E, F, ZKVMChipProofInput, GKRProofInput, LayerProofInput, SumcheckLayerProofInput, }; use crate::zkvm_verifier::verifier::{verify_zkvm_proof, verify_gkr_circuit}; use ceno_mle::util::ceil_log2; use ff_ext::BabyBearExt4; -use gkr_iop::gkr::layer::sumcheck_layer::{SumcheckLayer, SumcheckLayerProof}; +use gkr_iop::gkr::{ + GKRCircuit, + layer::sumcheck_layer::{SumcheckLayer, SumcheckLayerProof} +}; use itertools::Itertools; use mpcs::{Basefold, BasefoldRSParams}; use openvm_circuit::arch::{instructions::program::Program, SystemConfig, VmExecutor}; @@ -439,7 +442,7 @@ pub fn precompile_test_thread() { pub fn test_precompile_verification_from_bincode_exports() { let stack_size = 64 * 1024 * 1024; // 64 MB - let handler = thread::Builder::new() + let handler = std::thread::Builder::new() .stack_size(stack_size) .spawn(precompile_test_thread) .expect("Failed to spawn thread"); diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index b96f186..7366b62 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -148,79 +148,12 @@ impl Hintable for ZKVMProofInput { stream.extend(self.raw_pi.write()); stream.extend(raw_pi_num_variables.write()); stream.extend(self.pi_evals.write()); - stream.extend(self.opcode_proofs.write()); - stream.extend(self.table_proofs.write()); - - // Write in witin_commit - let mut cmt_vec: Vec = vec![]; - self.witin_commit.commit().iter().for_each(|x| { - let f: F = serde_json::from_value(serde_json::to_value(&x).unwrap()).unwrap(); - cmt_vec.push(f); - }); - let mut witin_commit_trivial_commits: Vec> = vec![]; - /* _debug - for trivial_commit in &self.witin_commit.trivial_commits { - let mut t_cmt_vec: Vec = vec![]; - trivial_commit.iter().for_each(|x| { - let f: F = - serde_json::from_value(serde_json::to_value(x.clone()).unwrap()).unwrap(); - t_cmt_vec.push(f); - }); - witin_commit_trivial_commits.push(t_cmt_vec); - } - */ - let witin_commit_log2_max_codeword_size = - F::from_canonical_u32(self.witin_commit.log2_max_codeword_size as u32); - stream.extend(cmt_vec.write()); - stream.extend(witin_commit_trivial_commits.write()); - stream.extend(witin_commit_log2_max_codeword_size.write()); - - // Write in fixed_commit - let has_fixed_commit: usize = if self.fixed_commit.is_some() { 1 } else { 0 }; - let mut fixed_commit_vec: Vec = vec![]; - let mut fixed_commit_trivial_commits: Vec> = vec![]; - let mut fixed_commit_log2_max_codeword_size: F = F::ZERO.clone(); - if has_fixed_commit > 0 { - self.fixed_commit - .as_ref() - .unwrap() - .commit() - .iter() - .for_each(|x| { - let f: F = - serde_json::from_value(serde_json::to_value(x.clone()).unwrap()).unwrap(); - fixed_commit_vec.push(f); - }); - - /* _debug - for trivial_commit in &self.fixed_commit.as_ref().unwrap().trivial_commits { - let mut t_cmt_vec: Vec = vec![]; - trivial_commit.iter().for_each(|x| { - let f: F = - serde_json::from_value(serde_json::to_value(x.clone()).unwrap()).unwrap(); - t_cmt_vec.push(f); - }); - fixed_commit_trivial_commits.push(t_cmt_vec); - } - */ - fixed_commit_log2_max_codeword_size = F::from_canonical_u32( - self.fixed_commit.as_ref().unwrap().log2_max_codeword_size as u32, - ); - } - stream.extend(>::write(&has_fixed_commit)); - stream.extend(fixed_commit_vec.write()); - stream.extend(fixed_commit_trivial_commits.write()); - stream.extend(fixed_commit_log2_max_codeword_size.write()); - - // Write num_instances - let mut num_instances_vec: Vec> = vec![]; - for (circuit_size, num_var) in &self.num_instances { - num_instances_vec.push(vec![ - F::from_canonical_usize(*circuit_size), - F::from_canonical_usize(*num_var), - ]); - } - stream.extend(num_instances_vec.write()); + stream.extend(self.chip_proofs.write()); + stream.extend(>::write(&max_num_var)); + stream.extend(self.witin_commit.write()); + stream.extend(witin_perm.write()); + stream.extend(fixed_perm.write()); + stream.extend(self.pcs_proof.write()); stream } diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 0ff7b92..94e433b 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -23,7 +23,6 @@ use crate::{ }, tower_verifier::{binding::{PointVariable, PointAndEvalVariable}, program::iop_verifier_state_verify}, }; -use ceno_mle::expression::{Instance, StructuralWitIn}; use ceno_zkvm::e2e::B; use ceno_zkvm::structs::VerifyingKey; use ceno_mle::{ @@ -44,7 +43,6 @@ use gkr_iop::{ evaluation::EvalExpression, }; use itertools::{interleave, max, Itertools, izip}; -use itertools::{interleave, Itertools}; use mpcs::{Basefold, BasefoldRSParams}; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; @@ -1226,6 +1224,7 @@ pub fn verify_gkr_circuit( .collect_vec(); } +/* _debug pub fn evaluate_selector( builder: &mut Builder, sel_type: &SelectorType, @@ -1285,6 +1284,7 @@ pub fn evaluate_selector( let wit_id = *wit_id as usize + offset_eq_id; builder.set(evals, wit_id, eval); } +*/ pub fn verify_rotation( builder: &mut Builder, From 0245706fcdb207610d29801c9bbfa14886d6e218 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Sun, 3 Aug 2025 21:05:36 -0400 Subject: [PATCH 09/24] Debug program --- src/e2e/mod.rs | 81 +- src/zkvm_verifier/binding.rs | 52 +- src/zkvm_verifier/verifier.rs | 1578 ++++++++++++++++----------------- 3 files changed, 914 insertions(+), 797 deletions(-) diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 5da6f36..9131ff9 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -189,6 +189,76 @@ pub fn parse_zkvm_proof_import( fixed_in_evals.push(v_e); } + let circuit_name = &verifier.vk.circuit_index_to_name[chip_id]; + let circuit_vk = &verifier.vk.circuit_vks[circuit_name]; + + let composed_cs = circuit_vk.get_cs(); + let num_instances = chip_proof.num_instances; + let next_pow2_instance = num_instances.next_power_of_two().max(2); + let log2_num_instances = ceil_log2(next_pow2_instance); + let num_var_with_rotation = log2_num_instances + composed_cs.rotation_vars().unwrap_or(0); + + let has_gkr_proof = chip_proof.gkr_iop_proof.is_some(); + let mut gkr_iop_proof = GKRProofInput { + num_var_with_rotation, + num_instances, + layer_proofs: vec![], + }; + + if has_gkr_proof { + let gkr_proof = chip_proof.gkr_iop_proof.clone().unwrap(); + + for layer_proof in gkr_proof.0 { + // rotation + let (has_rotation, rotation): (usize, SumcheckLayerProofInput) = if let Some(p) = layer_proof.rotation { + let mut iop_messages: Vec = vec![]; + for m in p.proof.proofs { + let mut evaluations: Vec = vec![]; + for e in m.evaluations { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evaluations.push(v_e); + } + iop_messages.push(IOPProverMessage { evaluations }); + } + let mut evals: Vec = vec![]; + for e in p.evals { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evals.push(v_e); + } + (1, SumcheckLayerProofInput { proof: iop_messages, evals }) + } else { + (0, SumcheckLayerProofInput::default()) + }; + + // main sumcheck + let mut iop_messages: Vec = vec![]; + let mut evals: Vec = vec![]; + for m in layer_proof.main.proof.proofs { + let mut evaluations: Vec = vec![]; + for e in m.evaluations { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evaluations.push(v_e); + } + iop_messages.push(IOPProverMessage { evaluations }); + } + for e in layer_proof.main.evals { + let v_e: E = + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + evals.push(v_e); + } + + let main = SumcheckLayerProofInput { + proof: iop_messages, + evals, + }; + + gkr_iop_proof.layer_proofs.push(LayerProofInput { has_rotation, rotation, main }); + } + } + chip_proofs.push(ZKVMChipProofInput { idx: chip_id.clone(), num_instances: chip_proof.num_instances, @@ -202,6 +272,8 @@ pub fn parse_zkvm_proof_import( main_sumcheck_proofs, wits_in_evals, fixed_in_evals, + has_gkr_proof, + gkr_iop_proof, }); } @@ -236,7 +308,7 @@ pub fn inner_test_thread() { let verifier = ZKVMVerifier::new(vk); let zkvm_proof_input = parse_zkvm_proof_import(zkvm_proof, &verifier); - + // OpenVM DSL let mut builder = AsmBuilder::::default(); @@ -297,6 +369,7 @@ pub fn test_zkvm_proof_verifier_from_bincode_exports() { handler.join().expect("Thread panicked"); } +/* _debug pub fn parse_precompile_proof_variables( zkvm_proof: ZKVMProof>, verifier: &ZKVMVerifier>, @@ -378,8 +451,11 @@ pub fn parse_precompile_proof_variables( (gkr_circuit, gkr_proof_input) } +*/ +// _debug pub fn precompile_test_thread() { + /* _debug setup_tracing_with_log_level(tracing::Level::WARN); let proof_path = "./src/e2e/encoded/proof.bin"; @@ -402,7 +478,7 @@ pub fn precompile_test_thread() { // Obtain witness inputs let gkr_proof_input = GKRProofInput::read(&mut builder); - verify_gkr_circuit(&mut builder, circuit, gkr_proof_input); + verify_gkr_circuit(&mut builder, circuit, &gkr_proof_input); builder.halt(); // Pass in witness stream @@ -436,6 +512,7 @@ pub fn precompile_test_thread() { for (i, seg) in res.iter().enumerate() { println!("=> segment {:?} metrics: {:?}", i, seg.metrics); } + */ } #[test] diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index 7366b62..b02f69f 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -7,7 +7,7 @@ use crate::basefold_verifier::query_phase::{ }; use crate::{ arithmetics::ceil_log2, - tower_verifier::binding::{IOPProverMessage, IOPProverMessageVariable}, + tower_verifier::binding::{PointVariable, IOPProverMessage, IOPProverMessageVariable}, }; use ark_std::iterable::Iterable; use ff_ext::BabyBearExt4; @@ -71,6 +71,9 @@ pub struct ZKVMChipProofInputVariable { pub main_sel_sumcheck_proofs: Array>, pub wits_in_evals: Array>, pub fixed_in_evals: Array>, + + pub has_gkr_proof: Usize, + pub gkr_iop_proof: GKRProofVariable, } pub(crate) struct ZKVMProofInput { @@ -249,6 +252,10 @@ pub struct ZKVMChipProofInput { pub main_sumcheck_proofs: Vec, pub wits_in_evals: Vec, pub fixed_in_evals: Vec, + + // gkr proof + pub has_gkr_proof: bool, + pub gkr_iop_proof: GKRProofInput, } impl VecAutoHintable for ZKVMChipProofInput {} @@ -276,6 +283,9 @@ impl Hintable for ZKVMChipProofInput { let wits_in_evals = Vec::::read(builder); let fixed_in_evals = Vec::::read(builder); + let has_gkr_proof = Usize::Var(usize::read(builder)); + let gkr_iop_proof = GKRProofInput::read(builder); + ZKVMChipProofInputVariable { idx, idx_felt, @@ -292,6 +302,8 @@ impl Hintable for ZKVMChipProofInput { main_sel_sumcheck_proofs, wits_in_evals, fixed_in_evals, + has_gkr_proof, + gkr_iop_proof, } } @@ -333,6 +345,12 @@ impl Hintable for ZKVMChipProofInput { stream.extend(self.main_sumcheck_proofs.write()); stream.extend(self.wits_in_evals.write()); stream.extend(self.fixed_in_evals.write()); + if self.has_gkr_proof { + stream.extend(>::write(&1)); + } else { + stream.extend(>::write(&0)); + } + stream.extend(self.gkr_iop_proof.write()); stream } @@ -381,7 +399,7 @@ pub(crate) struct LayerProofInput { } #[derive(DslVariable, Clone)] pub struct LayerProofVariable { - pub has_rotation: Var, + pub has_rotation: Usize, pub rotation: SumcheckLayerProofVariable, pub main: SumcheckLayerProofVariable, } @@ -390,7 +408,7 @@ impl Hintable for LayerProofInput { type HintVariable = LayerProofVariable; fn read(builder: &mut Builder) -> Self::HintVariable { - let has_rotation = usize::read(builder); + let has_rotation = Usize::Var(usize::read(builder)); let rotation = SumcheckLayerProofInput::read(builder); let main = SumcheckLayerProofInput::read(builder); @@ -416,7 +434,7 @@ pub(crate) struct GKRProofInput { } #[derive(DslVariable, Clone)] pub struct GKRProofVariable { - pub num_var_with_rotation: Var, + pub num_var_with_rotation: Usize, pub num_instances_minus_one_bit_decomposition: Array>, pub layer_proofs: Array>, } @@ -424,7 +442,7 @@ impl Hintable for GKRProofInput { type HintVariable = GKRProofVariable; fn read(builder: &mut Builder) -> Self::HintVariable { - let num_var_with_rotation = usize::read(builder); + let num_var_with_rotation = Usize::Var(usize::read(builder)); let num_instances_minus_one_bit_decomposition = Vec::::read(builder); let layer_proofs = Vec::::read(builder); Self::HintVariable { @@ -446,4 +464,28 @@ impl Hintable for GKRProofInput { stream.extend(self.layer_proofs.write()); stream } +} + +#[derive(DslVariable, Clone)] +pub struct ClaimAndPoint { + pub evals: Array>, + pub has_point: Usize, + pub point: PointVariable, +} + +#[derive(DslVariable, Clone)] +pub struct RotationClaim { + pub left_evals: Array>, + pub right_evals: Array>, + pub target_evals: Array>, + pub left_point: Array>, + pub right_point: Array>, + pub origin_point: Array>, +} + +#[derive(DslVariable, Clone)] +pub struct GKRClaimEvaluation { + pub value: Ext, + pub point: PointVariable, + pub poly: Usize, } \ No newline at end of file diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 94e433b..da57553 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -1,9 +1,8 @@ use std::io::empty; -use super::binding::{ZKVMChipProofInputVariable, ZKVMProofInputVariable}; +use super::binding::{ZKVMChipProofInputVariable, ZKVMProofInputVariable, ClaimAndPoint, RotationClaim,GKRClaimEvaluation}; use crate::arithmetics::{ - challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, print_ext_arr, print_felt_arr, - PolyEvaluator, UniPolyExtrapolator, + challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, join, print_ext_arr, print_felt_arr, print_usize_arr, PolyEvaluator, UniPolyExtrapolator }; use crate::basefold_verifier::basefold::{ BasefoldCommitmentVariable, RoundOpeningVariable, RoundVariable, @@ -23,14 +22,13 @@ use crate::{ }, tower_verifier::{binding::{PointVariable, PointAndEvalVariable}, program::iop_verifier_state_verify}, }; -use ceno_zkvm::e2e::B; use ceno_zkvm::structs::VerifyingKey; use ceno_mle::{ expression::{Expression, StructuralWitIn, Instance, WitnessId}, mle::{Point, PointAndEval}, virtual_poly::build_eq_x_r_sequential }; -use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier}; +use ceno_zkvm::{e2e::B, circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier, structs::ComposedConstrainSystem}; use ff_ext::BabyBearExt4; use gkr_iop::gkr::layer::ROTATION_OPENING_COUNT; use gkr_iop::{ @@ -99,7 +97,17 @@ pub fn verify_zkvm_proof>( zkvm_proof_input: ZKVMProofInputVariable, vk: &ZKVMVerifier, ) { - /* _debug + // _debug + // builder.range(0, zkvm_proof_input.chip_proofs.len()).for_each(|idx_vec, builder| { + // builder.print_debug(77); + // let c = builder.get(&zkvm_proof_input.chip_proofs, idx_vec[0]); + // builder.range(0, c.gkr_iop_proof.layer_proofs.len()).for_each(|inner_idx_vec, builder| { + // builder.print_debug(55); + // let l = builder.get(&c.gkr_iop_proof.layer_proofs, inner_idx_vec[0]); + // builder.print_v(l.has_rotation.get_var()); + // }); + // }); + let mut challenger = DuplexChallengerVariable::new(builder); transcript_observe_label(builder, &mut challenger, b"riscv"); @@ -203,10 +211,12 @@ pub fn verify_zkvm_proof>( .values() .filter(|c| c.get_cs().num_fixed() > 0) .count(); + let witin_openings: Array> = builder.dyn_array(zkvm_proof_input.chip_proofs.len()); let fixed_openings: Array> = builder.dyn_array(Usize::from(num_fixed_opening)); + let num_chips_verified: Usize = builder.eval(C::N::ZERO); let num_chips_have_fixed: Usize = builder.eval(C::N::ZERO); @@ -219,16 +229,65 @@ pub fn verify_zkvm_proof>( builder.set(&chip_indices, i, chip_proof.idx); }); + + // iterate over all chips - for (i, chip_vk) in vk.vk.circuit_vks.values().enumerate() { + // _debug + // for (i, chip_vk) in vk.vk.circuit_vks.values().enumerate() { + + + // _debug example + // for (index, (key, value)) in map.iter().enumerate() { + + // _debug + // for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate() { + for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate().take(19) { + println!("=> circuit_name: {:?}", circuit_name); let chip_id: Var = builder.get(&chip_indices, num_chips_verified.get_var()); + builder.if_eq(chip_id, RVar::from(i)).then(|builder| { let chip_proof = builder.get(&zkvm_proof_input.chip_proofs, num_chips_verified.get_var()); + let circuit_vk = &vk.vk.circuit_vks[circuit_name]; + + builder.assert_usize_eq(chip_proof.wits_in_evals.len(), Usize::from(circuit_vk.get_cs().num_witin())); + builder.assert_usize_eq(chip_proof.fixed_in_evals.len(), Usize::from(circuit_vk.get_cs().num_fixed())); + builder.assert_usize_eq(chip_proof.record_r_out_evals.len(), Usize::from(circuit_vk.get_cs().num_reads())); + builder.assert_usize_eq(chip_proof.record_w_out_evals.len(), Usize::from(circuit_vk.get_cs().num_writes())); + builder.assert_usize_eq(chip_proof.record_lk_out_evals.len(), Usize::from(circuit_vk.get_cs().num_lks())); + + let chip_logup_sum: Ext = builder.constant(C::EF::ZERO); + iter_zip!(builder, chip_proof.record_lk_out_evals).for_each(|ptr_vec, builder| { + let evals = builder.iter_ptr_get(&chip_proof.record_lk_out_evals, ptr_vec[0]); + let p1 = builder.get(&evals, 0); + let p2 = builder.get(&evals, 1); + let q1 = builder.get(&evals, 2); + let q2 = builder.get(&evals, 3); + + builder.assign(&chip_logup_sum, chip_logup_sum + p1 * q1.inverse()); + builder.assign(&chip_logup_sum, chip_logup_sum + p2 * q2.inverse()); + }); + // _debug + // builder.print_e(chip_logup_sum); challenger.observe(builder, chip_proof.idx_felt); builder.cycle_tracker_start("Verify chip proof"); let input_opening_point = if chip_vk.get_cs().is_opcode_circuit() { + // getting the number of dummy padding item that we used in this opcode circuit + let num_lks = chip_vk.get_cs().num_lks(); + // FIXME: use builder to compute this + let num_instances = pow_2(builder, chip_proof.log2_num_instances.get_var()); + let num_padded_instance: Var = + builder.eval(num_instances - chip_proof.num_instances.clone()); + + let new_multiplicity: Usize = + builder.eval(Usize::from(num_lks) * Usize::from(num_padded_instance)); + builder.assign( + &dummy_table_item_multiplicity, + dummy_table_item_multiplicity + new_multiplicity, + ); + + builder.assign(&logup_sum, logup_sum + chip_logup_sum); verify_opcode_proof( builder, &mut challenger, @@ -239,6 +298,7 @@ pub fn verify_zkvm_proof>( &mut unipoly_extrapolator, ) } else { + builder.assign(&logup_sum, logup_sum - chip_logup_sum); verify_table_proof( builder, &mut challenger, @@ -251,44 +311,9 @@ pub fn verify_zkvm_proof>( }; builder.cycle_tracker_end("Verify chip proof"); - // getting the number of dummy padding item that we used in this opcode circuit - if chip_vk.get_cs().is_opcode_circuit() { - let num_lks = chip_vk.get_cs().num_lks(); - // FIXME: use builder to compute this - let num_instances = pow_2(builder, chip_proof.log2_num_instances.get_var()); - let num_padded_instance: Var = - builder.eval(num_instances - chip_proof.num_instances); - - let new_multiplicity: Usize = - builder.eval(Usize::from(num_lks) * Usize::from(num_padded_instance)); - builder.assign( - &dummy_table_item_multiplicity, - dummy_table_item_multiplicity + new_multiplicity, - ); - } - - let record_r_out_evals_prod = nested_product(builder, &chip_proof.record_r_out_evals); - builder.assign(&prod_r, prod_r * record_r_out_evals_prod); - - let record_w_out_evals_prod = nested_product(builder, &chip_proof.record_w_out_evals); - builder.assign(&prod_w, prod_w * record_w_out_evals_prod); - - let sign: Ext = if chip_vk.get_cs().is_opcode_circuit() { - builder.constant(C::EF::ONE) - } else { - builder.constant(-C::EF::ONE) - }; - - iter_zip!(builder, chip_proof.record_lk_out_evals).for_each(|ptr_vec, builder| { - let evals = builder.iter_ptr_get(&chip_proof.record_lk_out_evals, ptr_vec[0]); - let p1 = builder.get(&evals, 0); - let p2 = builder.get(&evals, 1); - let q1 = builder.get(&evals, 2); - let q2 = builder.get(&evals, 3); - - builder.assign(&logup_sum, logup_sum + sign * p1 * q1.inverse()); - builder.assign(&logup_sum, logup_sum + sign * p2 * q2.inverse()); - }); + // _debug + // builder.print_debug(777); + // print_ext_arr(builder, &input_opening_point); builder.assert_usize_eq( chip_proof.log2_num_instances.clone(), @@ -322,9 +347,24 @@ pub fn verify_zkvm_proof>( builder.inc(&num_chips_have_fixed); } + let record_r_out_evals_prod = nested_product(builder, &chip_proof.record_r_out_evals); + builder.assign(&prod_r, prod_r * record_r_out_evals_prod); + + let record_w_out_evals_prod = nested_product(builder, &chip_proof.record_w_out_evals); + builder.assign(&prod_w, prod_w * record_w_out_evals_prod); + + // _debug + // builder.print_debug(888); + // builder.print_e(prod_r); + // builder.print_e(prod_w); + builder.inc(&num_chips_verified); }); } + + + + /* _debug builder.assert_usize_eq(num_chips_have_fixed, Usize::from(num_fixed_opening)); builder.assert_eq::>(num_chips_verified, chip_indices.len()); @@ -398,7 +438,6 @@ pub fn verify_zkvm_proof>( */ } -/* _debug pub fn verify_opcode_proof( builder: &mut Builder, challenger: &mut DuplexChallengerVariable, @@ -430,13 +469,20 @@ pub fn verify_opcode_proof( let log2_num_instances = opcode_proof.log2_num_instances.clone(); + let num_var_with_rotation: Usize = Usize::Var(Var::uninit(builder)); + builder.if_eq(opcode_proof.has_gkr_proof.clone(), Usize::from(1)).then_or_else(|builder| { + builder.assign(&num_var_with_rotation, opcode_proof.gkr_iop_proof.num_var_with_rotation.clone()); + }, |builder| { + builder.assign(&num_var_with_rotation, log2_num_instances.clone()); + }); + let tower_proof = &opcode_proof.tower_proof; let num_variables: Array> = builder.dyn_array(num_batched); builder .range(0, num_variables.len()) .for_each(|idx_vec, builder| { - builder.set(&num_variables, idx_vec[0], log2_num_instances.clone()); + builder.set(&num_variables, idx_vec[0], num_var_with_rotation.clone()); }); let prod_out_evals: Array>> = concat( @@ -456,7 +502,7 @@ pub fn verify_opcode_proof( &opcode_proof.record_lk_out_evals, num_variables, num_fanin, - log2_num_instances.clone(), + num_var_with_rotation.clone(), tower_proof, unipoly_extrapolator, ); @@ -469,442 +515,529 @@ pub fn verify_opcode_proof( let rt = builder.get(&record_evals, 0); let num_rw_records: Usize = builder.eval(r_counts_per_instance + w_counts_per_instance); builder.assert_usize_eq(record_evals.len(), num_rw_records.clone()); - - let alpha_len = builder.eval( - num_rw_records.clone() - + lk_counts_per_instance - + Usize::from(cs.zkvm_v1_css.assert_zero_sumcheck_expressions.len()), - ); - transcript_observe_label(builder, challenger, b"combine subset evals"); - let alpha_pow = gen_alpha_pows(builder, challenger, alpha_len); - - // alpha_read * (out_r[rt] - 1) + alpha_write * (out_w[rt] - 1) + alpha_lk * (out_lk_q - chip_record_alpha) - // + 0 // 0 come from zero check - let claim_sum: Ext = builder.constant(C::EF::ZERO); - let rw_logup_len: Usize = builder.eval(num_rw_records.clone() + logup_q_evals.len()); - let alpha_rw_slice = alpha_pow.slice(builder, 0, num_rw_records.clone()); - iter_zip!(builder, alpha_rw_slice, record_evals).for_each(|ptr_vec, builder| { - let alpha = builder.iter_ptr_get(&alpha_rw_slice, ptr_vec[0]); - let eval = builder.iter_ptr_get(&record_evals, ptr_vec[1]); - - builder.assign(&claim_sum, claim_sum + alpha * (eval.eval - one)); + builder.assert_usize_eq(logup_p_evals.len(), lk_counts_per_instance.clone()); + builder.assert_usize_eq(logup_q_evals.len(), lk_counts_per_instance.clone()); + + let composed_cs = vk.get_cs(); + let ComposedConstrainSystem { + zkvm_v1_css: _, + gkr_circuit, + } = &composed_cs; + let gkr_circuit = gkr_circuit.clone().unwrap(); + + let out_evals_len: Usize = builder.eval(record_evals.len() + logup_q_evals.len()); + let out_evals: Array> = builder.dyn_array(out_evals_len.clone()); + builder.range(0, record_evals.len()).for_each(|idx_vec, builder| { + let cpt = builder.get(&record_evals, idx_vec[0]); + builder.set(&out_evals, idx_vec[0], cpt); }); - let alpha_logup_slice = alpha_pow.slice(builder, num_rw_records.clone(), rw_logup_len); - iter_zip!(builder, alpha_logup_slice, logup_q_evals).for_each(|ptr_vec, builder| { - let alpha = builder.iter_ptr_get(&alpha_logup_slice, ptr_vec[0]); - let eval = builder.iter_ptr_get(&logup_q_evals, ptr_vec[1]); - builder.assign( - &claim_sum, - claim_sum + alpha * (eval.eval - chip_record_alpha), - ); + let q_slice = out_evals.slice(builder, record_evals.len(), out_evals_len); + builder.range(0, logup_q_evals.len()).for_each(|idx_vec, builder| { + let cpt = builder.get(&logup_q_evals, idx_vec[0]); + builder.set(&q_slice, idx_vec[0], cpt); }); - let log2_num_instances_var: Var = RVar::from(log2_num_instances.clone()).variable(); - let log2_num_instances_f: Felt = builder.unsafe_cast_var_to_felt(log2_num_instances_var); - let max_non_lc_degree: usize = cs.zkvm_v1_css.max_non_lc_degree; - let main_sel_subclaim_max_degree: Felt = builder.constant(C::F::from_canonical_u32( - SEL_DEGREE.max(max_non_lc_degree + 1) as u32, - )); - builder.cycle_tracker_start("main sumcheck"); - let (input_opening_point, expected_evaluation) = iop_verifier_state_verify( - builder, - challenger, - &claim_sum, - &opcode_proof.main_sel_sumcheck_proofs, - log2_num_instances_f, - main_sel_subclaim_max_degree, - unipoly_extrapolator, - ); - builder.cycle_tracker_end("main sumcheck"); - - // sel(rt, t) - let sel = eq_eval_less_or_equal_than( + let opening_evaluations = verify_gkr_circuit( builder, challenger, + gkr_circuit, + &opcode_proof.gkr_iop_proof, + challenges, + pi_evals, + &out_evals, opcode_proof, - &input_opening_point, - &rt.point.fs, + unipoly_extrapolator ); - // derive r_records, w_records, lk_records from witness's evaluations - let alpha_idx: Var = builder.uninit(); - builder.assign(&alpha_idx, Usize::from(0)); - let empty_arr: Array> = builder.dyn_array(0); + // _debug + builder.print_debug(666); - let rw_expressions_sum: Ext = builder.constant(C::EF::ZERO); - cs.zkvm_v1_css - .r_expressions - .iter() - .chain(cs.zkvm_v1_css.w_expressions.iter()) - .for_each(|expr| { - let e = eval_ceno_expr_with_instance( + opening_evaluations[0].point.fs.clone() +} + +pub fn verify_gkr_circuit( + builder: &mut Builder, + challenger: &mut DuplexChallengerVariable, + gkr_circuit: GKRCircuit, + gkr_proof: &GKRProofVariable, + challenges: &Array>, + pub_io_evals: &Array>, + claims: &Array>, + opcode_proof: &ZKVMChipProofInputVariable, + unipoly_extrapolator: &mut UniPolyExtrapolator, +) -> Vec> { + for (i, layer) in gkr_circuit.layers.iter().enumerate() { + let layer_proof = builder.get(&gkr_proof.layer_proofs, i); + + // _debug + builder.print_debug(999); + builder.print_debug(i); + builder.print_v(layer_proof.has_rotation.get_var()); + + + let layer_challenges: Array> = generate_layer_challenges(builder, challenger, &challenges, layer.n_challenges); + let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges, &layer_proof.has_rotation); + + // ZeroCheckLayer verification (might include other layer types in the future) + let LayerProofVariable { + main: SumcheckLayerProofVariable { + proof, + evals: main_evals, + evals_len_div_3: main_evals_len_div_3, + }, + rotation: rotation_proof, + has_rotation, + } = layer_proof; + + builder.if_eq(has_rotation, Usize::from(1)).then(|builder| { + let first = builder.get(&eval_and_dedup_points, 0); + builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point + let rt = first.point.fs.clone(); + + // _debug + // builder.print_debug(333); + // builder.print_debug(layer.rotation_cyclic_subgroup_size); + // builder.print_debug(layer.rotation_cyclic_group_log2); + + let RotationClaim { + left_evals, + right_evals, + target_evals, + left_point, + right_point, + origin_point + } = verify_rotation( builder, - &empty_arr, - &opcode_proof.wits_in_evals, - &empty_arr, - pi_evals, - challenges, - expr, + gkr_proof.num_var_with_rotation.clone(), + &rotation_proof, + layer.rotation_cyclic_subgroup_size, + layer.rotation_cyclic_group_log2, + rt, + challenger, + unipoly_extrapolator, ); - let alpha = builder.get(&alpha_pow, alpha_idx); - builder.assign(&alpha_idx, alpha_idx + Usize::from(1)); - builder.assign(&rw_expressions_sum, rw_expressions_sum + alpha * (e - one)) + + // let last_idx: Usize = builder.eval(eval_and_dedup_points.len() - Usize::from(1)); + // builder.set( + // &eval_and_dedup_points, + // last_idx.clone(), + // ClaimAndPoint{ + // evals: left_evals, + // has_point: Usize::from(1), + // point: PointVariable { fs: left_point } + // } + // ); + + // builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); + // builder.set( + // &eval_and_dedup_points, + // last_idx.clone(), + // ClaimAndPoint{ + // evals: right_evals, + // has_point: Usize::from(1), + // point: PointVariable { fs: right_point } + // } + // ); + + // builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); + // builder.set( + // &eval_and_dedup_points, + // last_idx.clone(), + // ClaimAndPoint{ + // evals: target_evals, + // has_point: Usize::from(1), + // point: PointVariable { fs: origin_point } + // } + // ); + + // _debug + builder.print_debug(444); }); - builder.assign(&rw_expressions_sum, rw_expressions_sum * sel); - let lk_expressions_sum: Ext = builder.constant(C::EF::ZERO); - cs.zkvm_v1_css.lk_expressions.iter().for_each(|expr| { - let e = eval_ceno_expr_with_instance( + let rotation_exprs_len = layer.rotation_exprs.1.len(); + transcript_observe_label(builder, challenger, b"combine subset evals"); + let alpha_pows = gen_alpha_pows(builder, challenger, Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT)); + let sigma: Ext = builder.constant(C::EF::ZERO); + let alpha_idx: Var = Var::uninit(builder); + builder.assign(&alpha_idx, C::N::from_canonical_usize(0)); + + builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { + let ClaimAndPoint { + evals, + has_point: _, + point: _, + } = builder.get(&eval_and_dedup_points, idx_vec[0]); + let end_idx: Var = builder.eval(alpha_idx.clone() + evals.len()); + let alpha_slice = alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); + + let sub_sum = ext_dot_product(builder, &evals, &alpha_slice); + builder.assign(&sigma, sigma.clone() + sub_sum); + builder.assign(&alpha_idx, end_idx); + }); + + // _debug + // builder.print_debug(888); + // builder.print_e(sigma); + + let max_degree = builder.constant(C::F::from_canonical_usize(layer.max_expr_degree + 1)); + let max_num_variables = builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation.get_var()); + let (in_point, expected_evaluation) = iop_verifier_state_verify( builder, - &empty_arr, - &opcode_proof.wits_in_evals, - &empty_arr, - pi_evals, - challenges, - expr, + challenger, + &sigma, + &proof, + max_num_variables, + max_degree, + unipoly_extrapolator ); - let alpha = builder.get(&alpha_pow, alpha_idx); - builder.assign(&alpha_idx, alpha_idx + Usize::from(1)); - builder.assign( - &lk_expressions_sum, - lk_expressions_sum + alpha * (e - chip_record_alpha), - ) - }); - builder.assign(&lk_expressions_sum, lk_expressions_sum * sel); - let zero_expressions_sum: Ext = builder.constant(C::EF::ZERO); - cs.zkvm_v1_css - .assert_zero_sumcheck_expressions - .iter() - .for_each(|expr| { - // evaluate zero expression by all wits_in_evals because they share the unique input_opening_point opening - let e = eval_ceno_expr_with_instance( + // _debug + // print_ext_arr(builder, &in_point); + // builder.print_e(expected_evaluation); + + layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(idx, (sel_type, _))| { + let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; + evaluate_selector( builder, - &empty_arr, - &opcode_proof.wits_in_evals, - &empty_arr, - pi_evals, - challenges, - expr, + sel_type, + &main_evals, + &out_point, + &in_point, + opcode_proof, + layer.n_witin, ); - let alpha = builder.get(&alpha_pow, alpha_idx); - builder.assign(&alpha_idx, alpha_idx + Usize::from(1)); - builder.assign(&zero_expressions_sum, zero_expressions_sum + alpha * e); }); - builder.assign(&zero_expressions_sum, zero_expressions_sum * sel); - let computed_eval: Ext = - builder.eval(rw_expressions_sum + lk_expressions_sum + zero_expressions_sum); - builder.assert_ext_eq(computed_eval, expected_evaluation); + let main_sumcheck_challenges_len: Usize = builder.eval(alpha_pows.len() + Usize::from(2)); + let main_sumcheck_challenges: Array> = builder.dyn_array(main_sumcheck_challenges_len.clone()); + let alpha = builder.get(&challenges, 0); + let beta = builder.get(&challenges, 1); + builder.set(&main_sumcheck_challenges, 0, alpha); + builder.set(&main_sumcheck_challenges, 1, beta); + let challenge_slice = main_sumcheck_challenges.slice(builder, 2, main_sumcheck_challenges_len); + builder.range(0, alpha_pows.len()).for_each(|idx_vec, builder| { + let alpha = builder.get(&alpha_pows, idx_vec[0]); + builder.set(&challenge_slice, idx_vec[0], alpha); + }); - // verify zero expression (degree = 1) statement, thus no sumcheck - cs.zkvm_v1_css - .assert_zero_expressions - .iter() - .for_each(|expr| { - let e = eval_ceno_expr_with_instance( - builder, - &empty_arr, - &opcode_proof.wits_in_evals, - &empty_arr, - pi_evals, - challenges, - expr, - ); - builder.assert_ext_eq(e, zero); + // _debug + // builder.print_debug(101); + // print_ext_arr(builder, &main_evals); + // print_ext_arr(builder, &pub_io_evals); + // print_ext_arr(builder, &main_sumcheck_challenges); + + let empty_arr: Array> = builder.dyn_array(0); + let got_claim = eval_ceno_expr_with_instance( + builder, + &empty_arr, + &main_evals, + &empty_arr, + &pub_io_evals, + &main_sumcheck_challenges, + layer.main_sumcheck_expression.as_ref().unwrap(), + ); + + // _debug + // builder.print_e(got_claim); + + builder.assert_ext_eq(got_claim, expected_evaluation); + + // Update claim + layer.in_eval_expr.iter().enumerate().for_each(|(idx, pos)| { + let val = builder.get(&main_evals, idx); + builder.set(&claims, *pos, PointAndEvalVariable { + point: PointVariable { + fs: in_point.clone() + }, + eval: val, + }); }); + } + + // GKR Claim + let input_layer = gkr_circuit.layers.last().unwrap(); + input_layer + .in_eval_expr + .iter() + .enumerate() + .map(|(poly, eval)| { + let PointAndEvalVariable { point, eval } = builder.get(&claims, *eval); - input_opening_point + GKRClaimEvaluation { + value: eval, + point, + poly: Usize::from(poly), + } + }) + .collect_vec() } -pub fn verify_table_proof( +pub fn verify_rotation( builder: &mut Builder, + max_num_variables: Usize, + rotation_proof: &SumcheckLayerProofVariable, + rotation_cyclic_subgroup_size: usize, + rotation_cyclic_group_log2: usize, + rt: Array>, challenger: &mut DuplexChallengerVariable, - table_proof: &ZKVMChipProofInputVariable, - // raw_pi: &Array>>, - // raw_pi_num_variables: &Array>, - pi_evals: &Array>, - challenges: &Array>, - vk: &VerifyingKey, unipoly_extrapolator: &mut UniPolyExtrapolator, - // poly_evaluator: &mut PolyEvaluator, -) -> Array> { - let cs = vk.get_cs(); - let tower_proof: &super::binding::TowerProofInputVariable = &table_proof.tower_proof; - - let r_expected_rounds: Array> = - builder.dyn_array(cs.zkvm_v1_css.r_table_expressions.len() * 2); - cs - // only iterate r set, as read/write set round should match - .zkvm_v1_css - .r_table_expressions - .iter() - .enumerate() - .for_each(|(idx, expr)| { - let num_vars: Usize = match expr.table_spec.len { - Some(l) => Usize::from(ceil_log2(l)), - None => { - let var_vec = expr - .table_spec - .structural_witins - .iter() - .map(|StructuralWitIn { .. }| table_proof.log2_num_instances.clone()) - .collect::>>(); +) -> RotationClaim { + + let SumcheckLayerProofVariable { + proof, + evals, + evals_len_div_3: rotation_expr_len, + } = rotation_proof; - max_usize_vec(builder, var_vec) - } - }; + let rotation_expr_len = Usize::Var(rotation_expr_len.clone()); + transcript_observe_label(builder, challenger, b"combine subset evals"); + let rotation_alpha_pows = gen_alpha_pows(builder, challenger, rotation_expr_len.clone()); + let sigma: Ext = builder.constant(C::EF::ZERO); - builder.set(&r_expected_rounds, idx * 2, num_vars.clone()); - builder.set(&r_expected_rounds, idx * 2 + 1, num_vars.clone()); - }); + let max_num_variables = builder.unsafe_cast_var_to_felt(max_num_variables.get_var()); + let max_degree: Felt = builder.constant(C::F::TWO); - let lk_expected_rounds: Array> = - builder.dyn_array(cs.zkvm_v1_css.lk_table_expressions.len()); - cs.zkvm_v1_css - .lk_table_expressions - .iter() - .enumerate() - .for_each(|(idx, expr)| { - let num_vars: Usize = match expr.table_spec.len { - Some(l) => Usize::from(ceil_log2(l)), - None => { - let var_vec = expr - .table_spec - .structural_witins - .iter() - .map(|StructuralWitIn { .. }| table_proof.log2_num_instances.clone()) - .collect::>>(); + let (origin_point, expected_evaluation) = iop_verifier_state_verify( + builder, + challenger, + &sigma, + proof, + max_num_variables, + max_degree, + unipoly_extrapolator + ); - max_usize_vec(builder, var_vec) - } - }; + // _debug + // builder.print_debug(111); + // builder.print_f(max_num_variables); + // print_ext_arr(builder, &origin_point); + // builder.print_e(expected_evaluation); - builder.set(&lk_expected_rounds, idx, num_vars); - }); - let expected_rounds = concat(builder, &r_expected_rounds, &lk_expected_rounds); - let max_expected_rounds = max_usize_arr(builder, &expected_rounds); - let num_fanin: Usize = Usize::from(NUM_FANIN); - let max_num_variables: Usize = Usize::from(max_expected_rounds); - let prod_out_evals: Array>> = concat( + // compute the selector evaluation + let selector_eval = rotation_selector_eval( builder, - &table_proof.record_r_out_evals, - &table_proof.record_w_out_evals, + &rt, + &origin_point, + rotation_cyclic_subgroup_size, + rotation_cyclic_group_log2, ); + + /* _debug + + // check the final evaluations. + let left_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); + let right_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); + let target_evals: Array> = builder.dyn_array(rotation_expr_len); - builder.cycle_tracker_start("verify tower proof"); - let (rt_tower, prod_point_and_eval, logup_p_point_and_eval, logup_q_point_and_eval) = - verify_tower_proof( - builder, - challenger, - prod_out_evals, - &table_proof.record_lk_out_evals, - expected_rounds, - num_fanin, - max_num_variables, - tower_proof, - unipoly_extrapolator, - ); - builder.cycle_tracker_end("verify tower proof"); + let got_claim: Ext = builder.constant(C::EF::ZERO); + let one: Ext = builder.constant(C::EF::ONE); + let last_origin = builder.get(&origin_point, rotation_cyclic_group_log2 - 1); - builder.assert_usize_eq( - logup_q_point_and_eval.len(), - Usize::from(cs.zkvm_v1_css.lk_table_expressions.len()), - ); - builder.assert_usize_eq( - logup_p_point_and_eval.len(), - Usize::from(cs.zkvm_v1_css.lk_table_expressions.len()), - ); - builder.assert_usize_eq( - prod_point_and_eval.len(), - Usize::from( - cs.zkvm_v1_css.r_table_expressions.len() + cs.zkvm_v1_css.w_table_expressions.len(), - ), - ); + builder.range(0, rotation_alpha_pows.len()).for_each(|idx_vec, builder| { + let alpha = builder.get(&rotation_alpha_pows, idx_vec[0]); - // in table proof, we always skip same point sumcheck for now - // as tower sumcheck batch product argument/logup in same length - let _is_skip_same_point_sumcheck = true; + let rvar3 = RVar::from(3); + let left_idx: Var = builder.eval(idx_vec[0] * rvar3); + let right_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(1)); + let target_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(2)); - // evaluate structural witness from verifier - let set_table_exprs = cs - .zkvm_v1_css - .r_table_expressions - .iter() - .map(|r| &r.table_spec) - .chain( - cs.zkvm_v1_css - .lk_table_expressions - .iter() - .map(|r| &r.table_spec), - ) - .collect::>(); - let structural_witnesses_vec: Vec> = set_table_exprs - .iter() - .flat_map(|table_spec| { - table_spec - .structural_witins - .iter() - .map( - |StructuralWitIn { - offset, - multi_factor, - descending, - .. - }| { - // TODO: Remove modulo field prime - // OpenVM Config cannot automatically accept u32 exceeding its prime limit - // Use Babybear prime defined as p = 15 * 2^27 + 1 - let babybear_prime: u32 = 2013265921; - let offset = if *offset > babybear_prime { - *offset - babybear_prime - } else { - *offset - }; - let multi_factor = if *multi_factor > babybear_prime as usize { - *multi_factor - babybear_prime as usize - } else { - *multi_factor - }; + let left = builder.get(&evals, left_idx); + let right = builder.get(&evals, right_idx); + let target = builder.get(&evals, target_idx); - eval_wellform_address_vec( - builder, - offset as u32, - multi_factor as u32, - &rt_tower.fs, - *descending, - ) - }, - ) - .collect::>>() - }) - .collect::>>(); - let structural_witnesses: Array> = - builder.dyn_array(structural_witnesses_vec.len()); - structural_witnesses_vec - .into_iter() - .enumerate() - .for_each(|(idx, e)| { - builder.set(&structural_witnesses, idx, e); - }); + builder.set(&left_evals, idx_vec[0], left); + builder.set(&right_evals, idx_vec[0], right); + builder.set(&target_evals, idx_vec[0], target); - let in_evals_len: Usize = builder.eval( - prod_point_and_eval.len() + logup_p_point_and_eval.len() + logup_q_point_and_eval.len(), - ); - let in_evals: Array> = builder.dyn_array(in_evals_len); - builder - .range(0, prod_point_and_eval.len()) - .for_each(|idx_vec, builder| { - let e = builder.get(&prod_point_and_eval, idx_vec[0]).eval; - builder.set(&in_evals, idx_vec[0], e); - }); - builder - .range(0, logup_p_point_and_eval.len()) - .for_each(|idx_vec, builder| { - let p_e = builder.get(&logup_p_point_and_eval, idx_vec[0]).eval; - let q_e = builder.get(&logup_q_point_and_eval, idx_vec[0]).eval; + builder.assign(&got_claim, got_claim + alpha * ((one - last_origin) * left + last_origin * right - target)); + }); + builder.assign(&got_claim, got_claim * selector_eval); - let p_idx: Usize = - builder.eval(prod_point_and_eval.len() + idx_vec[0] * Usize::from(2)); - let q_idx: Usize = builder - .eval(prod_point_and_eval.len() + idx_vec[0] * Usize::from(2) + Usize::from(1)); + // _debug + // builder.assert_ext_eq(got_claim, expected_evaluation); + + let (left_point, right_point) = get_rotation_points(builder, rotation_cyclic_group_log2, &origin_point); + + RotationClaim { + left_evals, + right_evals, + target_evals, + left_point, + right_point, + origin_point + } + */ - builder.set(&in_evals, p_idx, p_e); - builder.set(&in_evals, q_idx, q_e); - }); + // _debug: DELETE DELETE DELTE + RotationClaim { + left_evals: builder.dyn_array(0), + right_evals: builder.dyn_array(0), + target_evals: builder.dyn_array(0), + left_point: builder.dyn_array(0), + right_point: builder.dyn_array(0), + origin_point: builder.dyn_array(0) + } +} - // verify records (degree = 1) statement, thus no sumcheck - interleave( - &cs.zkvm_v1_css.r_table_expressions, // r - &cs.zkvm_v1_css.w_table_expressions, // w - ) - .map(|rw| &rw.expr) - .chain( - cs.zkvm_v1_css - .lk_table_expressions - .iter() - .flat_map(|lk| vec![&lk.multiplicity, &lk.values]), // p, q - ) - .enumerate() - .for_each(|(idx, expr)| { - let e = eval_ceno_expr_with_instance( - builder, - &table_proof.fixed_in_evals, - &table_proof.wits_in_evals, - &structural_witnesses, - pi_evals, - challenges, - expr, - ); +/// sel(rx) +/// = (\sum_{b = 0}^{cyclic_subgroup_size - 1} eq(out_point[..cyclic_group_log2_size], b) * eq(in_point[..cyclic_group_log2_size], b)) +/// * \prod_{k = cyclic_group_log2_size}^{n - 1} eq(out_point[k], in_point[k]) +pub fn rotation_selector_eval( + builder: &mut Builder, + out_point: &Array>, + in_point: &Array>, + rotation_cyclic_subgroup_size: usize, + cyclic_group_log2_size: usize, +) -> Ext { + // _debug: dynamic boolean hypercube + let bh = BooleanHypercube::new(5); + let eval: Ext = builder.constant(C::EF::ZERO); + let cyclic_group_size: usize = 1 << cyclic_group_log2_size; + let rotation_index = bh.into_iter().take(rotation_cyclic_subgroup_size).collect_vec(); + + let out_subgroup = out_point.slice(builder, 0, cyclic_group_log2_size); + let in_subgroup = in_point.slice(builder, 0, cyclic_group_log2_size); - let expected_evals = builder.get(&in_evals, idx); - builder.assert_ext_eq(e, expected_evals); - }); + // _debug + // builder.print_debug(222); + // print_ext_arr(builder, &out_subgroup); + // builder.print_debug(222); + // print_ext_arr(builder, &in_subgroup); - /* TODO: enable this - // assume public io is tiny vector, so we evaluate it directly without PCS - for &Instance(idx) in cs.instance_name_map().keys() { - let poly = builder.get(raw_pi, idx); - let poly_num_vars = builder.get(raw_pi_num_variables, idx); - let eval_point = rt_tower.fs.slice(builder, 0, poly_num_vars); - let expected_eval = poly_evaluator.evaluate_base_poly_at_point(builder, &poly, &eval_point); - let eval = builder.get(&pi_evals, idx); - builder.assert_ext_eq(eval, expected_eval); + let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_subgroup); + let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_subgroup); + + for b in rotation_index { + let out_v = builder.get(&out_subgroup_eq, b as usize); + let in_v = builder.get(&in_subgroup_eq, b as usize); + builder.assign(&eval, eval + in_v * out_v); } + + // _debug + // builder.print_debug(222); + // builder.print_e(eval); + + /* _debug + + + let out_subgroup = out_point.slice(builder, cyclic_group_log2_size, out_point.len()); + let in_subgroup = in_point.slice(builder, cyclic_group_log2_size, in_point.len()); + + let one: Ext = builder.constant(C::EF::ONE); + let zero: Ext = builder.constant(C::EF::ZERO); + + + let eq_eval = eq_eval(builder, &out_subgroup, &in_subgroup, one, zero); + builder.assign(&eval, eval * eq_eval); */ - rt_tower.fs + eval } -*/ -pub fn generate_layer_challenges( +pub fn evaluate_selector( builder: &mut Builder, - challenger: &mut DuplexChallengerVariable, - challenges: &Array>, - n_challenges: usize, -) -> Array> { - let r = builder.dyn_array(n_challenges + 2); + sel_type: &SelectorType, + evals: &Array>, + out_point: &Array>, + in_point: &Array>, + opcode_proof: &ZKVMChipProofInputVariable, + offset_eq_id: usize, +) { + let (expr, eval) = match sel_type { + SelectorType::None => return, + SelectorType::Whole(expr) => { + // _debug + // builder.print_debug(111); - let alpha = builder.get(challenges, 0); - let beta = builder.get(challenges, 1); + let one = builder.constant(C::EF::ONE); + let zero = builder.constant(C::EF::ZERO); + (expr, eq_eval(builder, out_point, in_point, one, zero)) + } + SelectorType::Prefix(_, expr) => { + // _debug + // builder.print_debug(222); - builder.set(&r, 0, alpha); - builder.set(&r, 1, beta); + ( + expr, + eq_eval_less_or_equal_than( + builder, + opcode_proof, + out_point, + in_point + ) + ) + } + SelectorType::OrderedSparse32 { + indices, + expression, + } => { + // _debug + // builder.print_debug(333); - transcript_observe_label(builder, challenger, b"layer challenge"); - let c = gen_alpha_pows(builder, challenger, Usize::from(n_challenges)); + let out_point_slice = out_point.slice(builder, 0, 5); + let in_point_slice = in_point.slice(builder, 0, 5); + let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_point_slice); + let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_point_slice); - for i in 0..n_challenges { - let idx = i + 2; - let e = builder.get(&c, i); - builder.set(&r, idx, e); - } + let eval: Ext = builder.constant(C::EF::ZERO); + for idx in indices { + let out_val = builder.get(&out_subgroup_eq, *idx); + let in_val = builder.get(&in_subgroup_eq, *idx); + builder.assign(&eval, eval + out_val * in_val); + } - r -} + let out_point_slice = out_point.slice(builder, 5, out_point.len()); + let in_point_slice = in_point.slice(builder, 5, in_point.len()); -#[derive(DslVariable, Clone)] -pub struct ClaimAndPoint { - evals: Array>, - has_point: Usize, - point: PointVariable, -} + let sel = eq_eval_less_or_equal_than(builder, opcode_proof, &out_point_slice, &in_point_slice); + builder.assign(&eval, eval * sel); + + (expression, eval) + } + }; -#[derive(DslVariable, Clone)] -pub struct RotationClaim { - left_evals: Array>, - right_evals: Array>, - target_evals: Array>, - left_point: Array>, - right_point: Array>, - origin_point: Array>, + // _debug + // builder.print_debug(444); + // builder.print_e(eval); + + let Expression::StructuralWitIn(wit_id, _, _, _) = expr else { + panic!("Wrong selector expression format"); + }; + let wit_id = *wit_id as usize + offset_eq_id; + builder.set(evals, wit_id, eval); } -#[derive(DslVariable, Clone)] -pub struct GKRClaimEvaluation { - pub value: Ext, - pub point: PointVariable, - pub poly: Usize, +pub fn get_rotation_points( + builder: &mut Builder, + num_vars: usize, + point: &Array>, +) -> ( + Array>, + Array>, +) { + assert_eq!(num_vars, 5); + + let left: Array> = builder.dyn_array(point.len()); + let right: Array> = builder.dyn_array(point.len()); + builder.range(0, 4).for_each(|idx_vec, builder| { + let e = builder.get(point, idx_vec[0]); + let dest_idx: Var = builder.eval(idx_vec[0] + RVar::from(1)); + builder.set(&left, dest_idx, e); + builder.set(&right, dest_idx, e); + }); + + let one: Ext = builder.constant(C::EF::ONE); + builder.set(&right, 0, one); + let r1 = builder.get(&right, 2); + builder.set(&right, 2, one - r1); + + builder.range(5, point.len()).for_each(|idx_vec, builder| { + let e = builder.get(point, idx_vec[0]); + builder.set(&left, idx_vec[0], e); + builder.set(&right, idx_vec[0], e); + }); + + (left, right) } pub fn evaluate_gkr_expression( @@ -998,10 +1131,10 @@ pub fn extract_claim_and_point( layer: &Layer, claims: &Array>, challenges: &Array>, - has_rotation: Var, + has_rotation: &Usize, ) -> Array> { - let r_len: Usize = Usize::Var(has_rotation.clone()); - builder.assign(&r_len, r_len.clone() * Usize::from(3) + Usize::from(layer.out_sel_and_eval_exprs.len())); + let r_len: Usize = Usize::Var(Var::uninit(builder)); + builder.assign(&r_len, has_rotation.clone() * Usize::from(3) + Usize::from(layer.out_sel_and_eval_exprs.len())); let r = builder.dyn_array(r_len); @@ -1045,403 +1178,268 @@ pub fn extract_claim_and_point( r } -pub fn verify_gkr_circuit( +pub fn generate_layer_challenges( builder: &mut Builder, - gkr_circuit: GKRCircuit, - gkr_proof: GKRProofVariable, -) { - let mut challenger = DuplexChallengerVariable::new(builder); - let mut unipoly_extrapolator = UniPolyExtrapolator::new(builder); - - // _debug: placeholders - let challenges: Array> = builder.dyn_array(2); - let pub_io_evals: Array> = builder.dyn_array(2); - let n_evaluations = gkr_circuit.n_evaluations; - let claims: Array> = builder.dyn_array(n_evaluations); - - for (i, layer) in gkr_circuit.layers.iter().enumerate() { - let layer_proof = builder.get(&gkr_proof.layer_proofs, i); - let layer_challenges: Array> = generate_layer_challenges(builder, &mut challenger, &challenges, layer.n_challenges); - let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges, layer_proof.has_rotation); - - // ZeroCheckLayer verification (might include other layer types in the future) - let LayerProofVariable { - main: SumcheckLayerProofVariable { - proof, - evals: main_evals, - evals_len_div_3: main_evals_len_div_3, - }, - rotation: rotation_proof, - has_rotation, - } = layer_proof; - - // Verify rotation proof - builder.if_eq(has_rotation, Usize::from(1)).then(|builder| { - let first = builder.get(&eval_and_dedup_points, 0); - builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point - let rt = first.point.fs.clone(); - - let RotationClaim { - left_evals, - right_evals, - target_evals, - left_point, - right_point, - origin_point - } = verify_rotation( - builder, - gkr_proof.num_var_with_rotation, - &rotation_proof, - layer.rotation_cyclic_subgroup_size, - layer.rotation_cyclic_group_log2, - rt, - &mut challenger, - &mut unipoly_extrapolator, - ); - - let last_idx: Usize = builder.eval(eval_and_dedup_points.len() - Usize::from(1)); - builder.set( - &eval_and_dedup_points, - last_idx.clone(), - ClaimAndPoint{ - evals: left_evals, - has_point: Usize::from(1), - point: PointVariable { fs: left_point } - } - ); - - builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); - builder.set( - &eval_and_dedup_points, - last_idx.clone(), - ClaimAndPoint{ - evals: right_evals, - has_point: Usize::from(1), - point: PointVariable { fs: right_point } - } - ); - - builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); - builder.set( - &eval_and_dedup_points, - last_idx.clone(), - ClaimAndPoint{ - evals: target_evals, - has_point: Usize::from(1), - point: PointVariable { fs: origin_point } - } - ); - }); - - let rotation_exprs_len = layer.rotation_exprs.1.len(); - let alpha_pows = gen_alpha_pows(builder, &mut challenger, Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT)); - let sigma: Ext = builder.constant(C::EF::ZERO); - let alpha_idx: Var = Var::uninit(builder); - builder.assign(&alpha_idx, C::N::from_canonical_usize(0)); - - builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { - let ClaimAndPoint { - evals, - has_point: _, - point: _, - } = builder.get(&eval_and_dedup_points, idx_vec[0]); - let end_idx: Var = builder.eval(alpha_idx.clone() + evals.len()); - let alpha_slice = alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); - let sub_sum = ext_dot_product(builder, &evals, &alpha_slice); - builder.assign(&sigma, sigma.clone() + sub_sum); - builder.assign(&alpha_idx, end_idx); - }); - - let max_degree = builder.constant(C::F::from_canonical_usize(layer.max_expr_degree + 1)); - let max_num_variables = builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation); - let (in_point, expected_evaluation) = iop_verifier_state_verify( - builder, - &mut challenger, - &sigma, - &proof, - max_num_variables, - max_degree, - &mut unipoly_extrapolator - ); - - /* _debug: wait for e2e test context - layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(idx, (sel_type, _))| { - let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; + challenger: &mut DuplexChallengerVariable, + challenges: &Array>, + n_challenges: usize, +) -> Array> { + let r = builder.dyn_array(n_challenges + 2); - evaluate_selector( - builder, - sel_type, - &main_evals, - &out_point, - &in_point, - &gkr_proof.num_instances_minus_one_bit_decomposition, - layer.n_witin, - ); - }); - */ + let alpha = builder.get(challenges, 0); + let beta = builder.get(challenges, 1); - let empty_arr: Array> = builder.dyn_array(0); - let got_claim = eval_ceno_expr_with_instance( - builder, - &empty_arr, - &main_evals, - &empty_arr, - &pub_io_evals, - &challenges, - layer.main_sumcheck_expression.as_ref().unwrap(), - ); + builder.set(&r, 0, alpha); + builder.set(&r, 1, beta); - // _debug - // builder.assert_ext_eq(got_claim, expected_evaluation); + transcript_observe_label(builder, challenger, b"layer challenge"); + let c = gen_alpha_pows(builder, challenger, Usize::from(n_challenges)); - // Update claim - layer.in_eval_expr.iter().enumerate().for_each(|(idx, pos)| { - let val = builder.get(&main_evals, idx); - builder.set(&claims, *pos, PointAndEvalVariable { - point: PointVariable { - fs: in_point.clone() - }, - eval: val, - }); - }); + for i in 0..n_challenges { + let idx = i + 2; + let e = builder.get(&c, i); + builder.set(&r, idx, e); } - // GKR Claim - let input_layer = gkr_circuit.layers.last().unwrap(); - let gkr_claim = input_layer - .in_eval_expr - .iter() - .enumerate() - .map(|(poly, eval)| { - let PointAndEvalVariable { point, eval } = builder.get(&claims, *eval); - - GKRClaimEvaluation { - value: eval, - point, - poly: Usize::from(poly), - } - }) - .collect_vec(); -} - -/* _debug -pub fn evaluate_selector( - builder: &mut Builder, - sel_type: &SelectorType, - evals: &Array>, - out_point: &Array>, - in_point: &Array>, - num_instances_minus_one_bit_decomposition: &Array>, - offset_eq_id: usize, -) { - let (expr, eval) = match sel_type { - SelectorType::None => return, - SelectorType::Whole(expr) => { - let one = builder.constant(C::EF::ONE); - let zero = builder.constant(C::EF::ZERO); - (expr, eq_eval(builder, out_point, in_point, one, zero)) - } - SelectorType::Prefix(_, expr) => { - ( - expr, - eq_eval_less_or_equal_than( - builder, - num_instances_minus_one_bit_decomposition, - out_point, - in_point - ) - ) - } - SelectorType::OrderedSparse32 { - indices, - expression, - } => { - let out_point_slice = out_point.slice(builder, 0, 5); - let in_point_slice = in_point.slice(builder, 0, 5); - let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_point_slice); - let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_point_slice); - - let eval: Ext = builder.constant(C::EF::ZERO); - for idx in indices { - let out_val = builder.get(&out_subgroup_eq, *idx); - let in_val = builder.get(&in_subgroup_eq, *idx); - builder.assign(&eval, eval + out_val * in_val); - } - - let out_point_slice = out_point.slice(builder, 5, out_point.len()); - let in_point_slice = in_point.slice(builder, 5, in_point.len()); - - let sel = eq_eval_less_or_equal_than(builder, num_instances_minus_one_bit_decomposition, &out_point_slice, &in_point_slice); - builder.assign(&eval, eval * sel); - - (expression, eval) - } - }; - - let Expression::StructuralWitIn(wit_id, _, _, _) = expr else { - panic!("Wrong selector expression format"); - }; - let wit_id = *wit_id as usize + offset_eq_id; - builder.set(evals, wit_id, eval); + r } -*/ -pub fn verify_rotation( +pub fn verify_table_proof( builder: &mut Builder, - max_num_variables: Var, - rotation_proof: &SumcheckLayerProofVariable, - rotation_cyclic_subgroup_size: usize, - rotation_cyclic_group_log2: usize, - rt: Array>, challenger: &mut DuplexChallengerVariable, + table_proof: &ZKVMChipProofInputVariable, + // raw_pi: &Array>>, + // raw_pi_num_variables: &Array>, + pi_evals: &Array>, + challenges: &Array>, + vk: &VerifyingKey, unipoly_extrapolator: &mut UniPolyExtrapolator, -) -> RotationClaim { - let SumcheckLayerProofVariable { - proof, - evals, - evals_len_div_3: rotation_expr_len, - } = rotation_proof; + // poly_evaluator: &mut PolyEvaluator, +) -> Array> { + let cs = vk.get_cs(); + let tower_proof: &super::binding::TowerProofInputVariable = &table_proof.tower_proof; - let rotation_expr_len = Usize::Var(rotation_expr_len.clone()); + let r_expected_rounds: Array> = + builder.dyn_array(cs.zkvm_v1_css.r_table_expressions.len() * 2); + cs + // only iterate r set, as read/write set round should match + .zkvm_v1_css + .r_table_expressions + .iter() + .enumerate() + .for_each(|(idx, expr)| { + let num_vars: Usize = match expr.table_spec.len { + Some(l) => Usize::from(ceil_log2(l)), + None => { + let var_vec = expr + .table_spec + .structural_witins + .iter() + .map(|StructuralWitIn { .. }| table_proof.log2_num_instances.clone()) + .collect::>>(); - let rotation_alpha_pows = gen_alpha_pows(builder, challenger, rotation_expr_len.clone()); - let sigma: Ext = builder.constant(C::EF::ZERO); + max_usize_vec(builder, var_vec) + } + }; - let max_num_variables = builder.unsafe_cast_var_to_felt(max_num_variables); - let max_degree: Felt = builder.constant(C::F::TWO); + builder.set(&r_expected_rounds, idx * 2, num_vars.clone()); + builder.set(&r_expected_rounds, idx * 2 + 1, num_vars.clone()); + }); + + let lk_expected_rounds: Array> = + builder.dyn_array(cs.zkvm_v1_css.lk_table_expressions.len()); + cs.zkvm_v1_css + .lk_table_expressions + .iter() + .enumerate() + .for_each(|(idx, expr)| { + let num_vars: Usize = match expr.table_spec.len { + Some(l) => Usize::from(ceil_log2(l)), + None => { + let var_vec = expr + .table_spec + .structural_witins + .iter() + .map(|StructuralWitIn { .. }| table_proof.log2_num_instances.clone()) + .collect::>>(); - let (origin_point, expected_evaluation) = iop_verifier_state_verify( - builder, - challenger, - &sigma, - proof, - max_num_variables, - max_degree, - unipoly_extrapolator - ); + max_usize_vec(builder, var_vec) + } + }; - // compute the selector evaluation - let selector_eval = rotation_selector_eval( + builder.set(&lk_expected_rounds, idx, num_vars); + }); + let expected_rounds = concat(builder, &r_expected_rounds, &lk_expected_rounds); + let max_expected_rounds = max_usize_arr(builder, &expected_rounds); + let num_fanin: Usize = Usize::from(NUM_FANIN); + let max_num_variables: Usize = Usize::from(max_expected_rounds); + let prod_out_evals: Array>> = concat( builder, - &rt, - &origin_point, - rotation_cyclic_group_log2 + &table_proof.record_r_out_evals, + &table_proof.record_w_out_evals, ); - - // check the final evaluations. - let left_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); - let right_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); - let target_evals: Array> = builder.dyn_array(rotation_expr_len); - - let got_claim: Ext = builder.constant(C::EF::ZERO); - let one: Ext = builder.constant(C::EF::ONE); - let last_origin = builder.get(&origin_point, rotation_cyclic_group_log2 - 1); - - builder.range(0, rotation_alpha_pows.len()).for_each(|idx_vec, builder| { - let alpha = builder.get(&rotation_alpha_pows, idx_vec[0]); - let rvar3 = RVar::from(3); - let left_idx: Var = builder.eval(idx_vec[0] * rvar3); - let right_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(1)); - let target_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(2)); + builder.cycle_tracker_start("verify tower proof"); + let (rt_tower, prod_point_and_eval, logup_p_point_and_eval, logup_q_point_and_eval) = + verify_tower_proof( + builder, + challenger, + prod_out_evals, + &table_proof.record_lk_out_evals, + expected_rounds, + num_fanin, + max_num_variables, + tower_proof, + unipoly_extrapolator, + ); + builder.cycle_tracker_end("verify tower proof"); - let left = builder.get(&evals, left_idx); - let right = builder.get(&evals, right_idx); - let target = builder.get(&evals, target_idx); + builder.assert_usize_eq( + logup_q_point_and_eval.len(), + Usize::from(cs.zkvm_v1_css.lk_table_expressions.len()), + ); + builder.assert_usize_eq( + logup_p_point_and_eval.len(), + Usize::from(cs.zkvm_v1_css.lk_table_expressions.len()), + ); + builder.assert_usize_eq( + prod_point_and_eval.len(), + Usize::from( + cs.zkvm_v1_css.r_table_expressions.len() + cs.zkvm_v1_css.w_table_expressions.len(), + ), + ); - builder.set(&left_evals, idx_vec[0], left); - builder.set(&right_evals, idx_vec[0], right); - builder.set(&target_evals, idx_vec[0], target); + // in table proof, we always skip same point sumcheck for now + // as tower sumcheck batch product argument/logup in same length + let _is_skip_same_point_sumcheck = true; - builder.assign(&got_claim, got_claim + alpha * ((one - last_origin) * left + last_origin * right - target)); - }); - builder.assign(&got_claim, got_claim * selector_eval); + // evaluate structural witness from verifier + let set_table_exprs = cs + .zkvm_v1_css + .r_table_expressions + .iter() + .map(|r| &r.table_spec) + .chain( + cs.zkvm_v1_css + .lk_table_expressions + .iter() + .map(|r| &r.table_spec), + ) + .collect::>(); + let structural_witnesses_vec: Vec> = set_table_exprs + .iter() + .flat_map(|table_spec| { + table_spec + .structural_witins + .iter() + .map( + |StructuralWitIn { + offset, + multi_factor, + descending, + .. + }| { + // TODO: Remove modulo field prime + // OpenVM Config cannot automatically accept u32 exceeding its prime limit + // Use Babybear prime defined as p = 15 * 2^27 + 1 + let babybear_prime: u32 = 2013265921; + let offset = if *offset > babybear_prime { + *offset - babybear_prime + } else { + *offset + }; + let multi_factor = if *multi_factor > babybear_prime as usize { + *multi_factor - babybear_prime as usize + } else { + *multi_factor + }; - // _debug - // builder.assert_ext_eq(got_claim, expected_evaluation); - - let (left_point, right_point) = get_rotation_points(builder, rotation_cyclic_group_log2, &origin_point); - - RotationClaim { - left_evals, - right_evals, - target_evals, - left_point, - right_point, - origin_point - } -} + eval_wellform_address_vec( + builder, + offset as u32, + multi_factor as u32, + &rt_tower.fs, + *descending, + ) + }, + ) + .collect::>>() + }) + .collect::>>(); + let structural_witnesses: Array> = + builder.dyn_array(structural_witnesses_vec.len()); + structural_witnesses_vec + .into_iter() + .enumerate() + .for_each(|(idx, e)| { + builder.set(&structural_witnesses, idx, e); + }); -pub fn get_rotation_points( - builder: &mut Builder, - num_vars: usize, - point: &Array>, - ) -> ( - Array>, - Array>, - ) { - assert_eq!(num_vars, 5); - - let left: Array> = builder.dyn_array(point.len()); - let right: Array> = builder.dyn_array(point.len()); - builder.range(0, 4).for_each(|idx_vec, builder| { - let e = builder.get(point, idx_vec[0]); - let dest_idx: Var = builder.eval(idx_vec[0] + RVar::from(1)); - builder.set(&left, dest_idx, e); - builder.set(&right, dest_idx, e); + let in_evals_len: Usize = builder.eval( + prod_point_and_eval.len() + logup_p_point_and_eval.len() + logup_q_point_and_eval.len(), + ); + let in_evals: Array> = builder.dyn_array(in_evals_len); + builder + .range(0, prod_point_and_eval.len()) + .for_each(|idx_vec, builder| { + let e = builder.get(&prod_point_and_eval, idx_vec[0]).eval; + builder.set(&in_evals, idx_vec[0], e); }); + builder + .range(0, logup_p_point_and_eval.len()) + .for_each(|idx_vec, builder| { + let p_e = builder.get(&logup_p_point_and_eval, idx_vec[0]).eval; + let q_e = builder.get(&logup_q_point_and_eval, idx_vec[0]).eval; - let one: Ext = builder.constant(C::EF::ONE); - builder.set(&right, 0, one); - let r1 = builder.get(&right, 2); - builder.set(&right, 2, one - r1); + let p_idx: Usize = + builder.eval(prod_point_and_eval.len() + idx_vec[0] * Usize::from(2)); + let q_idx: Usize = builder + .eval(prod_point_and_eval.len() + idx_vec[0] * Usize::from(2) + Usize::from(1)); - builder.range(5, point.len()).for_each(|idx_vec, builder| { - let e = builder.get(point, idx_vec[0]); - builder.set(&left, idx_vec[0], e); - builder.set(&right, idx_vec[0], e); + builder.set(&in_evals, p_idx, p_e); + builder.set(&in_evals, q_idx, q_e); }); - (left, right) - } + // verify records (degree = 1) statement, thus no sumcheck + interleave( + &cs.zkvm_v1_css.r_table_expressions, // r + &cs.zkvm_v1_css.w_table_expressions, // w + ) + .map(|rw| &rw.expr) + .chain( + cs.zkvm_v1_css + .lk_table_expressions + .iter() + .flat_map(|lk| vec![&lk.multiplicity, &lk.values]), // p, q + ) + .enumerate() + .for_each(|(idx, expr)| { + let e = eval_ceno_expr_with_instance( + builder, + &table_proof.fixed_in_evals, + &table_proof.wits_in_evals, + &structural_witnesses, + pi_evals, + challenges, + expr, + ); -/// sel(rx) -/// = (\sum_{b = 0}^{cyclic_subgroup_size - 1} eq(out_point[..cyclic_group_log2_size], b) * eq(in_point[..cyclic_group_log2_size], b)) -/// * \prod_{k = cyclic_group_log2_size}^{n - 1} eq(out_point[k], in_point[k]) -pub fn rotation_selector_eval( - builder: &mut Builder, - out_point: &Array>, - in_point: &Array>, - cyclic_group_log2_size: usize, -) -> Ext { - let bh = BooleanHypercube::new(cyclic_group_log2_size); - let eval: Ext = builder.constant(C::EF::ZERO); - - let cyclic_group_size: usize = 1 << cyclic_group_log2_size; - let rotation_index = bh.into_iter().take(cyclic_group_size).collect_vec(); - - - let out_subgroup = out_point.slice(builder, 0, cyclic_group_log2_size); - let in_subgroup = in_point.slice(builder, 0, cyclic_group_log2_size); - let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_subgroup); - let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_subgroup); + let expected_evals = builder.get(&in_evals, idx); + builder.assert_ext_eq(e, expected_evals); + }); - for b in rotation_index { - let out_v = builder.get(&out_subgroup_eq, b as usize); - let in_v = builder.get(&in_subgroup_eq, b as usize); - builder.assign(&eval, eval + in_v * out_v); + /* TODO: enable this + // assume public io is tiny vector, so we evaluate it directly without PCS + for &Instance(idx) in cs.instance_name_map().keys() { + let poly = builder.get(raw_pi, idx); + let poly_num_vars = builder.get(raw_pi_num_variables, idx); + let eval_point = rt_tower.fs.slice(builder, 0, poly_num_vars); + let expected_eval = poly_evaluator.evaluate_base_poly_at_point(builder, &poly, &eval_point); + let eval = builder.get(&pi_evals, idx); + builder.assert_ext_eq(eval, expected_eval); } - - let out_subgroup = out_point.slice(builder, cyclic_group_log2_size, out_point.len()); - let in_subgroup = in_point.slice(builder, cyclic_group_log2_size, in_point.len()); - - let one: Ext = builder.constant(C::EF::ONE); - let zero: Ext = builder.constant(C::EF::ZERO); - - /* _debug - let eq_eval = eq_eval(builder, &out_subgroup, &in_subgroup, one, zero); - builder.assign(&eval, eval * eq_eval); */ - eval + rt_tower.fs } + From d0fca604987b3a93ef2d19a12b2555e62031fbca Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Sun, 3 Aug 2025 21:55:31 -0400 Subject: [PATCH 10/24] Debug program --- src/zkvm_verifier/verifier.rs | 204 +++++++--------------------------- 1 file changed, 43 insertions(+), 161 deletions(-) diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index da57553..74d293d 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -97,17 +97,6 @@ pub fn verify_zkvm_proof>( zkvm_proof_input: ZKVMProofInputVariable, vk: &ZKVMVerifier, ) { - // _debug - // builder.range(0, zkvm_proof_input.chip_proofs.len()).for_each(|idx_vec, builder| { - // builder.print_debug(77); - // let c = builder.get(&zkvm_proof_input.chip_proofs, idx_vec[0]); - // builder.range(0, c.gkr_iop_proof.layer_proofs.len()).for_each(|inner_idx_vec, builder| { - // builder.print_debug(55); - // let l = builder.get(&c.gkr_iop_proof.layer_proofs, inner_idx_vec[0]); - // builder.print_v(l.has_rotation.get_var()); - // }); - // }); - let mut challenger = DuplexChallengerVariable::new(builder); transcript_observe_label(builder, &mut challenger, b"riscv"); @@ -229,20 +218,12 @@ pub fn verify_zkvm_proof>( builder.set(&chip_indices, i, chip_proof.idx); }); - - - // iterate over all chips // _debug - // for (i, chip_vk) in vk.vk.circuit_vks.values().enumerate() { - - - // _debug example - // for (index, (key, value)) in map.iter().enumerate() { - - // _debug - // for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate() { - for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate().take(19) { + for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate().take(35) { + // for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate().take(27) { + // _debug println!("=> circuit_name: {:?}", circuit_name); + let chip_id: Var = builder.get(&chip_indices, num_chips_verified.get_var()); builder.if_eq(chip_id, RVar::from(i)).then(|builder| { @@ -267,8 +248,6 @@ pub fn verify_zkvm_proof>( builder.assign(&chip_logup_sum, chip_logup_sum + p1 * q1.inverse()); builder.assign(&chip_logup_sum, chip_logup_sum + p2 * q2.inverse()); }); - // _debug - // builder.print_e(chip_logup_sum); challenger.observe(builder, chip_proof.idx_felt); builder.cycle_tracker_start("Verify chip proof"); @@ -311,15 +290,6 @@ pub fn verify_zkvm_proof>( }; builder.cycle_tracker_end("Verify chip proof"); - // _debug - // builder.print_debug(777); - // print_ext_arr(builder, &input_opening_point); - - builder.assert_usize_eq( - chip_proof.log2_num_instances.clone(), - input_opening_point.len(), - ); - let witin_round: RoundOpeningVariable = builder.eval(RoundOpeningVariable { num_var: chip_proof.log2_num_instances.get_var(), point_and_evals: PointAndEvalsVariable { @@ -353,11 +323,6 @@ pub fn verify_zkvm_proof>( let record_w_out_evals_prod = nested_product(builder, &chip_proof.record_w_out_evals); builder.assign(&prod_w, prod_w * record_w_out_evals_prod); - // _debug - // builder.print_debug(888); - // builder.print_e(prod_r); - // builder.print_e(prod_w); - builder.inc(&num_chips_verified); }); } @@ -549,9 +514,6 @@ pub fn verify_opcode_proof( unipoly_extrapolator ); - // _debug - builder.print_debug(666); - opening_evaluations[0].point.fs.clone() } @@ -568,13 +530,6 @@ pub fn verify_gkr_circuit( ) -> Vec> { for (i, layer) in gkr_circuit.layers.iter().enumerate() { let layer_proof = builder.get(&gkr_proof.layer_proofs, i); - - // _debug - builder.print_debug(999); - builder.print_debug(i); - builder.print_v(layer_proof.has_rotation.get_var()); - - let layer_challenges: Array> = generate_layer_challenges(builder, challenger, &challenges, layer.n_challenges); let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges, &layer_proof.has_rotation); @@ -594,11 +549,6 @@ pub fn verify_gkr_circuit( builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point let rt = first.point.fs.clone(); - // _debug - // builder.print_debug(333); - // builder.print_debug(layer.rotation_cyclic_subgroup_size); - // builder.print_debug(layer.rotation_cyclic_group_log2); - let RotationClaim { left_evals, right_evals, @@ -617,41 +567,38 @@ pub fn verify_gkr_circuit( unipoly_extrapolator, ); - // let last_idx: Usize = builder.eval(eval_and_dedup_points.len() - Usize::from(1)); - // builder.set( - // &eval_and_dedup_points, - // last_idx.clone(), - // ClaimAndPoint{ - // evals: left_evals, - // has_point: Usize::from(1), - // point: PointVariable { fs: left_point } - // } - // ); - - // builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); - // builder.set( - // &eval_and_dedup_points, - // last_idx.clone(), - // ClaimAndPoint{ - // evals: right_evals, - // has_point: Usize::from(1), - // point: PointVariable { fs: right_point } - // } - // ); - - // builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); - // builder.set( - // &eval_and_dedup_points, - // last_idx.clone(), - // ClaimAndPoint{ - // evals: target_evals, - // has_point: Usize::from(1), - // point: PointVariable { fs: origin_point } - // } - // ); + let last_idx: Usize = builder.eval(eval_and_dedup_points.len() - Usize::from(1)); + builder.set( + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint{ + evals: left_evals, + has_point: Usize::from(1), + point: PointVariable { fs: left_point } + } + ); + + builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); + builder.set( + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint{ + evals: right_evals, + has_point: Usize::from(1), + point: PointVariable { fs: right_point } + } + ); - // _debug - builder.print_debug(444); + builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); + builder.set( + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint{ + evals: target_evals, + has_point: Usize::from(1), + point: PointVariable { fs: origin_point } + } + ); }); let rotation_exprs_len = layer.rotation_exprs.1.len(); @@ -675,10 +622,6 @@ pub fn verify_gkr_circuit( builder.assign(&alpha_idx, end_idx); }); - // _debug - // builder.print_debug(888); - // builder.print_e(sigma); - let max_degree = builder.constant(C::F::from_canonical_usize(layer.max_expr_degree + 1)); let max_num_variables = builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation.get_var()); let (in_point, expected_evaluation) = iop_verifier_state_verify( @@ -691,10 +634,6 @@ pub fn verify_gkr_circuit( unipoly_extrapolator ); - // _debug - // print_ext_arr(builder, &in_point); - // builder.print_e(expected_evaluation); - layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(idx, (sel_type, _))| { let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; evaluate_selector( @@ -720,12 +659,6 @@ pub fn verify_gkr_circuit( builder.set(&challenge_slice, idx_vec[0], alpha); }); - // _debug - // builder.print_debug(101); - // print_ext_arr(builder, &main_evals); - // print_ext_arr(builder, &pub_io_evals); - // print_ext_arr(builder, &main_sumcheck_challenges); - let empty_arr: Array> = builder.dyn_array(0); let got_claim = eval_ceno_expr_with_instance( builder, @@ -737,9 +670,6 @@ pub fn verify_gkr_circuit( layer.main_sumcheck_expression.as_ref().unwrap(), ); - // _debug - // builder.print_e(got_claim); - builder.assert_ext_eq(got_claim, expected_evaluation); // Update claim @@ -807,12 +737,6 @@ pub fn verify_rotation( unipoly_extrapolator ); - // _debug - // builder.print_debug(111); - // builder.print_f(max_num_variables); - // print_ext_arr(builder, &origin_point); - // builder.print_e(expected_evaluation); - // compute the selector evaluation let selector_eval = rotation_selector_eval( builder, @@ -822,8 +746,6 @@ pub fn verify_rotation( rotation_cyclic_group_log2, ); - /* _debug - // check the final evaluations. let left_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); let right_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); @@ -831,7 +753,11 @@ pub fn verify_rotation( let got_claim: Ext = builder.constant(C::EF::ZERO); let one: Ext = builder.constant(C::EF::ONE); - let last_origin = builder.get(&origin_point, rotation_cyclic_group_log2 - 1); + let last_origin = if rotation_cyclic_group_log2 > 0 { + builder.get(&origin_point, rotation_cyclic_group_log2 - 1) + } else { + one.clone() + }; builder.range(0, rotation_alpha_pows.len()).for_each(|idx_vec, builder| { let alpha = builder.get(&rotation_alpha_pows, idx_vec[0]); @@ -852,9 +778,7 @@ pub fn verify_rotation( builder.assign(&got_claim, got_claim + alpha * ((one - last_origin) * left + last_origin * right - target)); }); builder.assign(&got_claim, got_claim * selector_eval); - - // _debug - // builder.assert_ext_eq(got_claim, expected_evaluation); + builder.assert_ext_eq(got_claim, expected_evaluation); let (left_point, right_point) = get_rotation_points(builder, rotation_cyclic_group_log2, &origin_point); @@ -866,17 +790,6 @@ pub fn verify_rotation( right_point, origin_point } - */ - - // _debug: DELETE DELETE DELTE - RotationClaim { - left_evals: builder.dyn_array(0), - right_evals: builder.dyn_array(0), - target_evals: builder.dyn_array(0), - left_point: builder.dyn_array(0), - right_point: builder.dyn_array(0), - origin_point: builder.dyn_array(0) - } } /// sel(rx) @@ -897,13 +810,6 @@ pub fn rotation_selector_eval( let out_subgroup = out_point.slice(builder, 0, cyclic_group_log2_size); let in_subgroup = in_point.slice(builder, 0, cyclic_group_log2_size); - - // _debug - // builder.print_debug(222); - // print_ext_arr(builder, &out_subgroup); - // builder.print_debug(222); - // print_ext_arr(builder, &in_subgroup); - let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_subgroup); let in_subgroup_eq = build_eq_x_r_vec_sequential(builder, &in_subgroup); @@ -913,23 +819,14 @@ pub fn rotation_selector_eval( builder.assign(&eval, eval + in_v * out_v); } - // _debug - // builder.print_debug(222); - // builder.print_e(eval); - - /* _debug - - let out_subgroup = out_point.slice(builder, cyclic_group_log2_size, out_point.len()); let in_subgroup = in_point.slice(builder, cyclic_group_log2_size, in_point.len()); let one: Ext = builder.constant(C::EF::ONE); let zero: Ext = builder.constant(C::EF::ZERO); - - let eq_eval = eq_eval(builder, &out_subgroup, &in_subgroup, one, zero); - builder.assign(&eval, eval * eq_eval); - */ + let eq_eval = eq_eval(builder, &out_subgroup, &in_subgroup, one, zero); + builder.assign(&eval, eval * eq_eval); eval } @@ -946,17 +843,11 @@ pub fn evaluate_selector( let (expr, eval) = match sel_type { SelectorType::None => return, SelectorType::Whole(expr) => { - // _debug - // builder.print_debug(111); - let one = builder.constant(C::EF::ONE); let zero = builder.constant(C::EF::ZERO); (expr, eq_eval(builder, out_point, in_point, one, zero)) } SelectorType::Prefix(_, expr) => { - // _debug - // builder.print_debug(222); - ( expr, eq_eval_less_or_equal_than( @@ -971,9 +862,6 @@ pub fn evaluate_selector( indices, expression, } => { - // _debug - // builder.print_debug(333); - let out_point_slice = out_point.slice(builder, 0, 5); let in_point_slice = in_point.slice(builder, 0, 5); let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_point_slice); @@ -996,10 +884,6 @@ pub fn evaluate_selector( } }; - // _debug - // builder.print_debug(444); - // builder.print_e(eval); - let Expression::StructuralWitIn(wit_id, _, _, _) = expr else { panic!("Wrong selector expression format"); }; @@ -1015,8 +899,6 @@ pub fn get_rotation_points( Array>, Array>, ) { - assert_eq!(num_vars, 5); - let left: Array> = builder.dyn_array(point.len()); let right: Array> = builder.dyn_array(point.len()); builder.range(0, 4).for_each(|idx_vec, builder| { From 4a49814a852e2eaaf1740a735d555c90e376c190 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Mon, 4 Aug 2025 19:13:18 -0400 Subject: [PATCH 11/24] Debug program --- src/basefold_verifier/verifier.rs | 1 - src/e2e/mod.rs | 158 ------------------------------ src/tower_verifier/program.rs | 10 +- src/zkvm_verifier/verifier.rs | 79 +++++++-------- 4 files changed, 46 insertions(+), 202 deletions(-) diff --git a/src/basefold_verifier/verifier.rs b/src/basefold_verifier/verifier.rs index 1ea6c12..e52fdf7 100644 --- a/src/basefold_verifier/verifier.rs +++ b/src/basefold_verifier/verifier.rs @@ -340,7 +340,6 @@ pub mod tests { let executor = VmExecutor::::new(config); executor.execute(program.clone(), witness.clone()).unwrap(); - // _debug let results = executor.execute_segments(program, witness).unwrap(); for seg in results { println!("=> cycle count: {:?}", seg.metrics.cycle_count); diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 9131ff9..b4d15ee 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -368,161 +368,3 @@ pub fn test_zkvm_proof_verifier_from_bincode_exports() { handler.join().expect("Thread panicked"); } - -/* _debug -pub fn parse_precompile_proof_variables( - zkvm_proof: ZKVMProof>, - verifier: &ZKVMVerifier>, -) -> (GKRCircuit, GKRProofInput) { - let index: usize = 18; - let proof = &zkvm_proof.chip_proofs[&index]; - - let circuit_name = &verifier.vk.circuit_index_to_name[&index]; - let circuit_vk = &verifier.vk.circuit_vks[circuit_name]; - - let composed_cs = circuit_vk.get_cs(); - let ComposedConstrainSystem { - zkvm_v1_css: _, - gkr_circuit, - } = &composed_cs; - let gkr_circuit = gkr_circuit.clone().unwrap(); - let num_instances = proof.num_instances; - let next_pow2_instance = num_instances.next_power_of_two().max(2); - let log2_num_instances = ceil_log2(next_pow2_instance); - let num_var_with_rotation = log2_num_instances + composed_cs.rotation_vars().unwrap_or(0); - let gkr_proof = proof.gkr_iop_proof.clone().unwrap(); - - let mut gkr_proof_input = GKRProofInput { - num_var_with_rotation, - num_instances, - layer_proofs: vec![], - }; - - for layer_proof in gkr_proof.0 { - // rotation - let (has_rotation, rotation): (usize, SumcheckLayerProofInput) = if let Some(p) = layer_proof.rotation { - let mut iop_messages: Vec = vec![]; - for m in p.proof.proofs { - let mut evaluations: Vec = vec![]; - for e in m.evaluations { - let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); - evaluations.push(v_e); - } - iop_messages.push(IOPProverMessage { evaluations }); - } - let mut evals: Vec = vec![]; - for e in p.evals { - let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); - evals.push(v_e); - } - - (1, SumcheckLayerProofInput { proof: iop_messages, evals }) - } else { - (0, SumcheckLayerProofInput::default()) - }; - - // main sumcheck - let mut iop_messages: Vec = vec![]; - let mut evals: Vec = vec![]; - for m in layer_proof.main.proof.proofs { - let mut evaluations: Vec = vec![]; - for e in m.evaluations { - let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); - evaluations.push(v_e); - } - iop_messages.push(IOPProverMessage { evaluations }); - } - for e in layer_proof.main.evals { - let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); - evals.push(v_e); - } - - let main = SumcheckLayerProofInput { - proof: iop_messages, - evals, - }; - - gkr_proof_input.layer_proofs.push(LayerProofInput { has_rotation, rotation, main }); - } - - (gkr_circuit, gkr_proof_input) -} -*/ - -// _debug -pub fn precompile_test_thread() { - /* _debug - setup_tracing_with_log_level(tracing::Level::WARN); - - let proof_path = "./src/e2e/encoded/proof.bin"; - let vk_path = "./src/e2e/encoded/vk.bin"; - - let zkvm_proof: ZKVMProof> = - bincode::deserialize_from(File::open(proof_path).expect("Failed to open proof file")) - .expect("Failed to deserialize proof file"); - - let vk: ZKVMVerifyingKey> = - bincode::deserialize_from(File::open(vk_path).expect("Failed to open vk file")) - .expect("Failed to deserialize vk file"); - - let verifier = ZKVMVerifier::new(vk); - - let (circuit, gkr_proof) = parse_precompile_proof_variables(zkvm_proof, &verifier); - - // OpenVM DSL - let mut builder = AsmBuilder::::default(); - - // Obtain witness inputs - let gkr_proof_input = GKRProofInput::read(&mut builder); - verify_gkr_circuit(&mut builder, circuit, &gkr_proof_input); - builder.halt(); - - // Pass in witness stream - let mut witness_stream: Vec< - Vec>, - > = Vec::new(); - - witness_stream.extend(gkr_proof.write()); - - // Compile program - let options = CompilerOptions::default().with_cycle_tracker(); - let mut compiler = AsmCompiler::new(options.word_size); - compiler.build(builder.operations); - let asm_code = compiler.code(); - - let program: Program< - p3_monty_31::MontyField31, - > = convert_program(asm_code, options); - let mut system_config = SystemConfig::default() - .with_public_values(4) - .with_max_segment_len((1 << 25) - 100); - system_config.profiling = true; - let config = NativeConfig::new(system_config, Native); - - let executor = VmExecutor::::new(config); - - let res = executor - .execute_and_then(program, witness_stream, |_, seg| Ok(seg), |err| err) - .unwrap(); - - for (i, seg) in res.iter().enumerate() { - println!("=> segment {:?} metrics: {:?}", i, seg.metrics); - } - */ -} - -#[test] -pub fn test_precompile_verification_from_bincode_exports() { - let stack_size = 64 * 1024 * 1024; // 64 MB - - let handler = std::thread::Builder::new() - .stack_size(stack_size) - .spawn(precompile_test_thread) - .expect("Failed to spawn thread"); - - handler.join().expect("Thread panicked"); -} diff --git a/src/tower_verifier/program.rs b/src/tower_verifier/program.rs index a6ef7e8..af6afc5 100644 --- a/src/tower_verifier/program.rs +++ b/src/tower_verifier/program.rs @@ -7,6 +7,7 @@ use crate::arithmetics::{ use crate::transcript::transcript_observe_label; use crate::zkvm_verifier::binding::TowerProofInputVariable; use ceno_zkvm::scheme::constants::NUM_FANIN; +use openvm::platform::print; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; use openvm_native_recursion::challenger::ChallengerVariable; @@ -164,6 +165,7 @@ pub fn iop_verifier_state_verify( .range(0, max_num_variables_usize.clone()) .for_each(|i_vec, builder| { let i = i_vec[0]; + // TODO: this takes 7 cycles, can we optimize it? let prover_msg = builder.get(&prover_messages, i); @@ -178,8 +180,8 @@ pub fn iop_verifier_state_verify( let e1 = builder.get(&prover_msg.evaluations, 0); let e2 = builder.get(&prover_msg.evaluations, 1); let target: Ext<::F, ::EF> = builder.eval(e1 + e2); - // _debug - // builder.assert_ext_eq(expected, target); + + builder.assert_ext_eq(expected, target); let p_r = unipoly_extrapolator.extrapolate_uni_poly( builder, @@ -374,9 +376,9 @@ pub fn verify_tower_proof( let mut next_rt = PointAndEvalVariable { point: PointVariable { - fs: builder.dyn_array(1), + fs: initial_rt, }, - eval: builder.constant(C::EF::ZERO), + eval: initial_claim, }; builder diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 74d293d..c264583 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -218,12 +218,7 @@ pub fn verify_zkvm_proof>( builder.set(&chip_indices, i, chip_proof.idx); }); - // _debug - for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate().take(35) { - // for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate().take(27) { - // _debug - println!("=> circuit_name: {:?}", circuit_name); - + for (i, (circuit_name, chip_vk)) in vk.vk.circuit_vks.iter().enumerate() { let chip_id: Var = builder.get(&chip_indices, num_chips_verified.get_var()); builder.if_eq(chip_id, RVar::from(i)).then(|builder| { @@ -569,12 +564,12 @@ pub fn verify_gkr_circuit( let last_idx: Usize = builder.eval(eval_and_dedup_points.len() - Usize::from(1)); builder.set( - &eval_and_dedup_points, - last_idx.clone(), + &eval_and_dedup_points, + last_idx.clone(), ClaimAndPoint{ - evals: left_evals, + evals: target_evals, has_point: Usize::from(1), - point: PointVariable { fs: left_point } + point: PointVariable { fs: origin_point } } ); @@ -591,12 +586,12 @@ pub fn verify_gkr_circuit( builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); builder.set( - &eval_and_dedup_points, - last_idx.clone(), + &eval_and_dedup_points, + last_idx.clone(), ClaimAndPoint{ - evals: target_evals, + evals: left_evals, has_point: Usize::from(1), - point: PointVariable { fs: origin_point } + point: PointVariable { fs: left_point } } ); }); @@ -604,8 +599,9 @@ pub fn verify_gkr_circuit( let rotation_exprs_len = layer.rotation_exprs.1.len(); transcript_observe_label(builder, challenger, b"combine subset evals"); let alpha_pows = gen_alpha_pows(builder, challenger, Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT)); + let sigma: Ext = builder.constant(C::EF::ZERO); - let alpha_idx: Var = Var::uninit(builder); + let alpha_idx: Usize = Usize::Var(Var::uninit(builder)); builder.assign(&alpha_idx, C::N::from_canonical_usize(0)); builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { @@ -614,16 +610,16 @@ pub fn verify_gkr_circuit( has_point: _, point: _, } = builder.get(&eval_and_dedup_points, idx_vec[0]); - let end_idx: Var = builder.eval(alpha_idx.clone() + evals.len()); - let alpha_slice = alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); + let end_idx: Usize = builder.eval(alpha_idx.clone() + evals.len()); + let alpha_slice: Array::F, ::EF>> = alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); let sub_sum = ext_dot_product(builder, &evals, &alpha_slice); builder.assign(&sigma, sigma.clone() + sub_sum); builder.assign(&alpha_idx, end_idx); }); - let max_degree = builder.constant(C::F::from_canonical_usize(layer.max_expr_degree + 1)); let max_num_variables = builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation.get_var()); + let (in_point, expected_evaluation) = iop_verifier_state_verify( builder, challenger, @@ -712,7 +708,6 @@ pub fn verify_rotation( challenger: &mut DuplexChallengerVariable, unipoly_extrapolator: &mut UniPolyExtrapolator, ) -> RotationClaim { - let SumcheckLayerProofVariable { proof, evals, @@ -802,7 +797,6 @@ pub fn rotation_selector_eval( rotation_cyclic_subgroup_size: usize, cyclic_group_log2_size: usize, ) -> Ext { - // _debug: dynamic boolean hypercube let bh = BooleanHypercube::new(5); let eval: Ext = builder.constant(C::EF::ZERO); let cyclic_group_size: usize = 1 << cyclic_group_log2_size; @@ -1020,7 +1014,7 @@ pub fn extract_claim_and_point( let r = builder.dyn_array(r_len); - let claims_and_points = layer.out_sel_and_eval_exprs.iter().enumerate().map(|(i, (_, out_evals))| { + layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(i, (_, out_evals))| { let evals = out_evals .iter() .map(|out_eval| { @@ -1029,8 +1023,8 @@ pub fn extract_claim_and_point( }) .collect_vec(); let evals_arr: Array> = builder.dyn_array(evals.len()); - for (i, e) in evals.iter().enumerate() { - builder.set(&evals_arr, i, *e); + for (j, e) in evals.iter().enumerate() { + builder.set(&evals_arr, j, *e); } let point = out_evals.first().map(|out_eval| { let r = evaluate_gkr_expression(builder, out_eval, claims, challenges); @@ -1038,24 +1032,22 @@ pub fn extract_claim_and_point( }); if point.is_some() { + builder.set(&r, i, ClaimAndPoint { evals: evals_arr, has_point: Usize::from(1), point: point.unwrap(), - } + }); } else { + let pt = PointVariable { fs: builder.dyn_array(0) }; + builder.set(&r, i, ClaimAndPoint { evals: evals_arr, has_point: Usize::from(0), - point: PointVariable { fs: builder.dyn_array(0) }, - } + point: pt, + }); } - }) - .collect_vec(); - - for (i, ptc) in claims_and_points.into_iter().enumerate() { - builder.set(&r, i, ptc); - } + }); r } @@ -1153,6 +1145,7 @@ pub fn verify_table_proof( }); let expected_rounds = concat(builder, &r_expected_rounds, &lk_expected_rounds); let max_expected_rounds = max_usize_arr(builder, &expected_rounds); + let num_fanin: Usize = Usize::from(NUM_FANIN); let max_num_variables: Usize = Usize::from(max_expected_rounds); let prod_out_evals: Array>> = concat( @@ -1283,7 +1276,7 @@ pub fn verify_table_proof( }); // verify records (degree = 1) statement, thus no sumcheck - interleave( + let expected_evals_vec: Vec> = interleave( &cs.zkvm_v1_css.r_table_expressions, // r &cs.zkvm_v1_css.w_table_expressions, // w ) @@ -1295,8 +1288,8 @@ pub fn verify_table_proof( .flat_map(|lk| vec![&lk.multiplicity, &lk.values]), // p, q ) .enumerate() - .for_each(|(idx, expr)| { - let e = eval_ceno_expr_with_instance( + .map(|(_, expr)| { + eval_ceno_expr_with_instance( builder, &table_proof.fixed_in_evals, &table_proof.wits_in_evals, @@ -1304,10 +1297,18 @@ pub fn verify_table_proof( pi_evals, challenges, expr, - ); + ) + }).collect_vec(); - let expected_evals = builder.get(&in_evals, idx); - builder.assert_ext_eq(e, expected_evals); + let expected_evals: Array> = builder.dyn_array(expected_evals_vec.len()); + expected_evals_vec.into_iter().enumerate().for_each(|(idx, e)| { + builder.set(&expected_evals, idx, e); + }); + + iter_zip!(builder, in_evals, expected_evals).for_each(|ptr_vec, builder| { + let eval = builder.iter_ptr_get(&in_evals, ptr_vec[0]); + let expected = builder.iter_ptr_get(&expected_evals, ptr_vec[1]); + builder.assert_ext_eq(eval, expected); }); /* TODO: enable this @@ -1321,7 +1322,7 @@ pub fn verify_table_proof( builder.assert_ext_eq(eval, expected_eval); } */ - + rt_tower.fs } From 68ab151c5209277f7528ee65b758cbce8edcec3c Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Mon, 4 Aug 2025 19:24:30 -0400 Subject: [PATCH 12/24] Debug program --- src/zkvm_verifier/verifier.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index c264583..973a22d 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -322,9 +322,6 @@ pub fn verify_zkvm_proof>( }); } - - - /* _debug builder.assert_usize_eq(num_chips_have_fixed, Usize::from(num_fixed_opening)); builder.assert_eq::>(num_chips_verified, chip_indices.len()); @@ -335,7 +332,7 @@ pub fn verify_zkvm_proof>( logup_sum - dummy_table_item_multiplicity * dummy_table_item.inverse(), ); - let rounds = if num_fixed_opening > 0 { + let rounds: Array> = if num_fixed_opening > 0 { builder.dyn_array(2) } else { builder.dyn_array(1) @@ -349,6 +346,7 @@ pub fn verify_zkvm_proof>( perm: zkvm_proof_input.witin_perm.clone(), }, ); + if num_fixed_opening > 0 { builder.set( &rounds, @@ -360,6 +358,8 @@ pub fn verify_zkvm_proof>( }, ); } + + /* _debug batch_verify( builder, zkvm_proof_input.max_num_var, @@ -367,6 +367,7 @@ pub fn verify_zkvm_proof>( zkvm_proof_input.pcs_proof, &mut challenger, ); + */ let empty_arr: Array> = builder.dyn_array(0); let initial_global_state = eval_ceno_expr_with_instance( @@ -394,8 +395,6 @@ pub fn verify_zkvm_proof>( /* TODO: Temporarily disable product check for missing subcircuits builder.assert_ext_eq(prod_r, prod_w); */ - - */ } pub fn verify_opcode_proof( From 8acfff9778dd8b646452968a01429276b09c2dc3 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Mon, 4 Aug 2025 20:10:36 -0400 Subject: [PATCH 13/24] Complete e2e debugging (leave Basefold) --- src/zkvm_verifier/verifier.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 973a22d..c51d9c3 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -277,10 +277,13 @@ pub fn verify_zkvm_proof>( builder, &mut challenger, &chip_proof, + &zkvm_proof_input.raw_pi, + &zkvm_proof_input.raw_pi_num_variables, &zkvm_proof_input.pi_evals, &challenges, &chip_vk, &mut unipoly_extrapolator, + &mut poly_evaluator, ) }; builder.cycle_tracker_end("Verify chip proof"); @@ -1081,13 +1084,13 @@ pub fn verify_table_proof( builder: &mut Builder, challenger: &mut DuplexChallengerVariable, table_proof: &ZKVMChipProofInputVariable, - // raw_pi: &Array>>, - // raw_pi_num_variables: &Array>, + raw_pi: &Array>>, + raw_pi_num_variables: &Array>, pi_evals: &Array>, challenges: &Array>, vk: &VerifyingKey, unipoly_extrapolator: &mut UniPolyExtrapolator, - // poly_evaluator: &mut PolyEvaluator, + poly_evaluator: &mut PolyEvaluator, ) -> Array> { let cs = vk.get_cs(); let tower_proof: &super::binding::TowerProofInputVariable = &table_proof.tower_proof; @@ -1310,7 +1313,6 @@ pub fn verify_table_proof( builder.assert_ext_eq(eval, expected); }); - /* TODO: enable this // assume public io is tiny vector, so we evaluate it directly without PCS for &Instance(idx) in cs.instance_name_map().keys() { let poly = builder.get(raw_pi, idx); @@ -1318,10 +1320,10 @@ pub fn verify_table_proof( let eval_point = rt_tower.fs.slice(builder, 0, poly_num_vars); let expected_eval = poly_evaluator.evaluate_base_poly_at_point(builder, &poly, &eval_point); let eval = builder.get(&pi_evals, idx); + builder.assert_ext_eq(eval, expected_eval); } - */ - + rt_tower.fs } From b149b6b3220a5cae81074309de85f1d0bd946947 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 13 Aug 2025 20:10:28 -0400 Subject: [PATCH 14/24] Upgrade multi_observe --- Cargo.lock | 234 ++++++++++++++++++++++++++--------------------------- Cargo.toml | 16 ++-- 2 files changed, 125 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4282d30..e7142f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,9 +83,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -113,29 +113,29 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anyhow" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" [[package]] name = "ark-ff" @@ -194,7 +194,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" dependencies = [ "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -220,7 +220,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -235,7 +235,7 @@ dependencies = [ "ark-std 0.5.0", "educe", "fnv", - "hashbrown 0.15.4", + "hashbrown 0.15.5", ] [[package]] @@ -270,7 +270,7 @@ checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -350,9 +350,9 @@ dependencies = [ [[package]] name = "bitcode" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf300f4aa6e66f3bdff11f1236a88c622fe47ea814524792240b4d554d9858ee" +checksum = "648bd963d2e5d465377acecfb4b827f9f553b6bc97a8f61715779e9ed9e52b74" dependencies = [ "arrayvec", "bitcode_derive", @@ -363,13 +363,13 @@ dependencies = [ [[package]] name = "bitcode_derive" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42b6b4cb608b8282dc3b53d0f4c9ab404655d562674c682db7e6c0458cc83c23" +checksum = "ffebfc2d28a12b262c303cb3860ee77b91bd83b1f20f0bd2a9693008e2f55a9e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -487,14 +487,14 @@ checksum = "efb7846e0cb180355c2dec69e721edafa36919850f1a9f52ffba4ebc0393cb71" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "bytemuck" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" +checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" [[package]] name = "byteorder" @@ -516,9 +516,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.31" +version = "1.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" +checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" dependencies = [ "shlex", ] @@ -711,9 +711,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.42" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -721,9 +721,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.42" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -733,14 +733,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -911,7 +911,7 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -922,7 +922,7 @@ checksum = "2cdc8d50f426189eef89dac62fabfa0abb27d5cc008f25bf4156a0203325becc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -935,7 +935,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -955,7 +955,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", "unicode-xid", ] @@ -1006,7 +1006,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -1053,7 +1053,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -1065,7 +1065,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -1220,7 +1220,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -1271,9 +1271,9 @@ checksum = "f2d1aab06663bdce00d6ca5e5ed586ec8d18033a771906c993a1e3755b368d85" [[package]] name = "glob" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "goldilocks" @@ -1418,9 +1418,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "allocator-api2", ] @@ -1457,9 +1457,9 @@ dependencies = [ [[package]] name = "indenter" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5" [[package]] name = "indexmap" @@ -1468,7 +1468,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", - "hashbrown 0.15.4", + "hashbrown 0.15.5", ] [[package]] @@ -1592,9 +1592,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libm" @@ -1779,7 +1779,7 @@ checksum = "f2e3795a5d2da581a8b252fec6022eee01aea10161a4d1bf237d4cbe47f7e988" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -1855,7 +1855,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -1948,8 +1948,8 @@ checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "openvm" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "bytemuck", "num-bigint 0.4.6", @@ -1961,8 +1961,8 @@ dependencies = [ [[package]] name = "openvm-circuit" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "backtrace", "cfg-if", @@ -1992,18 +1992,18 @@ dependencies = [ [[package]] name = "openvm-circuit-derive" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "itertools 0.14.0", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "openvm-circuit-primitives" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "derive-new 0.6.0", "itertools 0.14.0", @@ -2017,28 +2017,28 @@ dependencies = [ [[package]] name = "openvm-circuit-primitives-derive" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "itertools 0.14.0", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "openvm-custom-insn" version = "0.1.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "openvm-instructions" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "backtrace", "derive-new 0.6.0", @@ -2054,17 +2054,17 @@ dependencies = [ [[package]] name = "openvm-instructions-derive" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "openvm-native-circuit" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "derive-new 0.6.0", "derive_more 1.0.0", @@ -2090,8 +2090,8 @@ dependencies = [ [[package]] name = "openvm-native-compiler" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "backtrace", "itertools 0.14.0", @@ -2112,17 +2112,17 @@ dependencies = [ [[package]] name = "openvm-native-compiler-derive" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "openvm-native-recursion" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "cfg-if", "itertools 0.14.0", @@ -2145,8 +2145,8 @@ dependencies = [ [[package]] name = "openvm-platform" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "libm", "openvm-custom-insn", @@ -2155,8 +2155,8 @@ dependencies = [ [[package]] name = "openvm-poseidon2-air" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "derivative", "lazy_static", @@ -2172,8 +2172,8 @@ dependencies = [ [[package]] name = "openvm-rv32im-circuit" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "derive-new 0.6.0", "derive_more 1.0.0", @@ -2195,8 +2195,8 @@ dependencies = [ [[package]] name = "openvm-rv32im-guest" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "openvm-custom-insn", "p3-field", @@ -2205,8 +2205,8 @@ dependencies = [ [[package]] name = "openvm-rv32im-transpiler" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "openvm-instructions", "openvm-instructions-derive", @@ -2222,7 +2222,7 @@ dependencies = [ [[package]] name = "openvm-stark-backend" version = "1.1.1" -source = "git+https://github.com/openvm-org/stark-backend.git?rev=f48090c9febd021f8ee0349bc929a775fb1fa3ad#f48090c9febd021f8ee0349bc929a775fb1fa3ad" +source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.1.1#0879de162658b797b8dd6b6ee4429cbb8dd78ba1" dependencies = [ "bitcode", "cfg-if", @@ -2247,7 +2247,7 @@ dependencies = [ [[package]] name = "openvm-stark-sdk" version = "1.1.1" -source = "git+https://github.com/openvm-org/stark-backend.git?rev=f48090c9febd021f8ee0349bc929a775fb1fa3ad#f48090c9febd021f8ee0349bc929a775fb1fa3ad" +source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.1.1#0879de162658b797b8dd6b6ee4429cbb8dd78ba1" dependencies = [ "derivative", "derive_more 0.99.20", @@ -2282,8 +2282,8 @@ dependencies = [ [[package]] name = "openvm-transpiler" -version = "1.2.1-rc.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=feat%2Fnative_multi_observe#831470c9d5fbc4cd15c60dc87b2f7b75b2c28a2e" +version = "1.3.0" +source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" dependencies = [ "elf", "eyre", @@ -2831,14 +2831,14 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" dependencies = [ "unicode-ident", ] @@ -2860,7 +2860,7 @@ checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -2966,9 +2966,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" dependencies = [ "either", "rayon-core", @@ -2976,9 +2976,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -3056,7 +3056,7 @@ checksum = "19f5c3e5da784cd8c69d32cdc84673f3204536ca56e1fa01be31a74b92c932ac" dependencies = [ "bytecheck", "bytes", - "hashbrown 0.15.4", + "hashbrown 0.15.5", "indexmap", "munge", "ptr_meta", @@ -3075,7 +3075,7 @@ checksum = "4270433626cffc9c4c1d3707dd681f2a2718d3d7b09ad754bec137acecda8d22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -3141,9 +3141,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" @@ -3233,7 +3233,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -3354,7 +3354,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -3405,7 +3405,7 @@ dependencies = [ "proc-macro2", "quote", "rand", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -3421,9 +3421,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619" dependencies = [ "proc-macro2", "quote", @@ -3477,7 +3477,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -3614,7 +3614,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -3734,9 +3734,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" dependencies = [ "js-sys", "wasm-bindgen", @@ -3801,7 +3801,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", "wasm-bindgen-shared", ] @@ -3823,7 +3823,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4130,7 +4130,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] @@ -4150,7 +4150,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.105", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c3e9615..c604bac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,14 @@ version = "0.1.0" edition = "2021" [dependencies] -openvm = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } -openvm-circuit = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false, features = ["bench-metrics"] } -openvm-native-circuit = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } -openvm-native-compiler = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } -openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } -openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", branch = "feat/native_multi_observe", default-features = false } -openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } -openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", rev = "f48090c9febd021f8ee0349bc929a775fb1fa3ad", default-features = false } +openvm = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-circuit = { git = "https://github.com/scroll-tech/openvm.git", default-features = false, features = ["bench-metrics"] } +openvm-native-circuit = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-native-compiler = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1", default-features = false } +openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1", default-features = false } rand = { version = "0.8.5", default-features = false } itertools = { version = "0.13.0", default-features = false } bincode = "1.3.3" From 04c22366cd88513b001ab5c4bb36e5a0b463421e Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 13 Aug 2025 20:35:42 -0400 Subject: [PATCH 15/24] Add STARK proof generation and verification to e2e --- src/e2e/mod.rs | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index b4d15ee..1402ebc 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -14,7 +14,7 @@ use gkr_iop::gkr::{ }; use itertools::Itertools; use mpcs::{Basefold, BasefoldRSParams}; -use openvm_circuit::arch::{instructions::program::Program, SystemConfig, VmExecutor}; +use openvm_circuit::arch::{instructions::program::Program, SystemConfig, VmExecutor, verify_single, VirtualMachine}; use openvm_native_circuit::{Native, NativeConfig}; use openvm_native_compiler::{ asm::AsmBuilder, @@ -23,9 +23,14 @@ use openvm_native_compiler::{ }; use openvm_native_recursion::hints::Hintable; use openvm_stark_backend::config::StarkGenericConfig; -use openvm_stark_sdk::config::setup_tracing_with_log_level; use openvm_stark_sdk::{ - config::baby_bear_poseidon2::BabyBearPoseidon2Config, p3_baby_bear::BabyBear, + engine::StarkFriEngine, + p3_baby_bear::BabyBear, + config::{ + baby_bear_poseidon2::{BabyBearPoseidon2Engine, BabyBearPoseidon2Config}, + fri_params::standard_fri_params_with_100_bits_conjectured_security, + setup_tracing_with_log_level, FriParameters, + } }; use std::fs::File; @@ -349,12 +354,39 @@ pub fn inner_test_thread() { let executor = VmExecutor::::new(config); let res = executor - .execute_and_then(program, witness_stream, |_, seg| Ok(seg), |err| err) + .execute_and_then(program.clone(), witness_stream.clone(), |_, seg| Ok(seg), |err| err) .unwrap(); for (i, seg) in res.iter().enumerate() { println!("=> segment {:?} metrics: {:?}", i, seg.metrics); } + + let poseidon2_max_constraint_degree = 3; + let log_blowup = 1; + + let fri_params = if matches!(std::env::var("OPENVM_FAST_TEST"), Ok(x) if &x == "1") { + FriParameters { + log_blowup, + log_final_poly_len: 0, + num_queries: 10, + proof_of_work_bits: 0, + } + } else { + standard_fri_params_with_100_bits_conjectured_security(log_blowup) + }; + + let engine = BabyBearPoseidon2Engine::new(fri_params); + let mut config = NativeConfig::aggregation(0, poseidon2_max_constraint_degree); + config.system.memory_config.max_access_adapter_n = 16; + + let vm = VirtualMachine::new(engine, config); + + let pk = vm.keygen(); + let result = vm.execute_and_generate(program, witness_stream).unwrap(); + let proofs = vm.prove(&pk, result); + for proof in proofs { + verify_single(&vm.engine, &pk.get_vk(), &proof).expect("Verification failed"); + } } #[test] From 9963a07ae5a25b3f545dc74e97b664e1605956e9 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 13 Aug 2025 21:02:55 -0400 Subject: [PATCH 16/24] Adjust test --- scripts/e2e_test.sh | 4 ++-- src/e2e/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/e2e_test.sh b/scripts/e2e_test.sh index 6d9c077..934bbde 100755 --- a/scripts/e2e_test.sh +++ b/scripts/e2e_test.sh @@ -9,11 +9,11 @@ if [ ! -d "$REPO_ROOT/build/ceno" ] || [ -z "$(ls -A "$REPO_ROOT/build/ceno" 2>/ fi # Enter the ceno directory -cd $REPO_ROOT/build/ceno && git checkout build/smaller_field_support_plonky3_539bbc +cd $REPO_ROOT/build/ceno && git checkout feat/smaller_field_support # Execute the ceno_zkvm e2e test RUST_LOG=info cargo run --release --package ceno_zkvm --bin e2e -- --platform=ceno \ - --hints=10 --public-io=4191 examples/target/riscv32im-ceno-zkvm-elf/release/examples/fibonacci \ + examples/target/riscv32im-ceno-zkvm-elf/release/examples/keccak_syscall \ --field=baby-bear mkdir -p $REPO_ROOT/src/e2e/encoded diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 1402ebc..6e21478 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -390,7 +390,7 @@ pub fn inner_test_thread() { } #[test] -pub fn test_zkvm_proof_verifier_from_bincode_exports() { +pub fn test_zkvm_verifier() { let stack_size = 64 * 1024 * 1024; // 64 MB let handler = std::thread::Builder::new() From 4636d9cd0c5b0c866e1d5bfaefcf2cc593c324eb Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 13 Aug 2025 21:40:50 -0400 Subject: [PATCH 17/24] fmt --- src/arithmetics/mod.rs | 12 +++++------ src/e2e/mod.rs | 2 ++ src/extensions/mod.rs | 23 +++------------------ src/tower_verifier/binding.rs | 22 ++------------------ src/tower_verifier/program.rs | 6 ++---- src/zkvm_verifier/binding.rs | 8 +------ src/zkvm_verifier/verifier.rs | 39 +++++++++++------------------------ 7 files changed, 27 insertions(+), 85 deletions(-) diff --git a/src/arithmetics/mod.rs b/src/arithmetics/mod.rs index 0593b5c..00a35ee 100644 --- a/src/arithmetics/mod.rs +++ b/src/arithmetics/mod.rs @@ -7,30 +7,28 @@ use ff_ext::{BabyBearExt4, SmallField}; use itertools::Either; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; -use openvm_native_recursion::challenger::ChallengerVariable; use openvm_native_recursion::challenger::{ - duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, + duplex::DuplexChallengerVariable, FeltChallenger, }; -use openvm_stark_backend::p3_field::{FieldAlgebra, FieldExtensionAlgebra, extension::BinomialExtensionField}; +use openvm_stark_backend::p3_field::{FieldAlgebra, FieldExtensionAlgebra}; type E = BabyBearExt4; -const HASH_RATE: usize = 8; const MAX_NUM_VARS: usize = 25; -pub fn print_ext_arr(builder: &mut Builder, arr: &Array>) { +pub fn _print_ext_arr(builder: &mut Builder, arr: &Array>) { iter_zip!(builder, arr).for_each(|ptr_vec, builder| { let e = builder.iter_ptr_get(arr, ptr_vec[0]); builder.print_e(e); }); } -pub fn print_felt_arr(builder: &mut Builder, arr: &Array>) { +pub fn _print_felt_arr(builder: &mut Builder, arr: &Array>) { iter_zip!(builder, arr).for_each(|ptr_vec, builder| { let f = builder.iter_ptr_get(arr, ptr_vec[0]); builder.print_f(f); }); } -pub fn print_usize_arr(builder: &mut Builder, arr: &Array>) { +pub fn _print_usize_arr(builder: &mut Builder, arr: &Array>) { iter_zip!(builder, arr).for_each(|ptr_vec, builder| { let n = builder.iter_ptr_get(arr, ptr_vec[0]); builder.print_v(n.get_var()); diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 6e21478..beb15aa 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -361,6 +361,7 @@ pub fn inner_test_thread() { println!("=> segment {:?} metrics: {:?}", i, seg.metrics); } + /* _debug let poseidon2_max_constraint_degree = 3; let log_blowup = 1; @@ -387,6 +388,7 @@ pub fn inner_test_thread() { for proof in proofs { verify_single(&vm.engine, &pk.get_vk(), &proof).expect("Verification failed"); } + */ } #[test] diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 6042866..5e4e1cf 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -1,17 +1,7 @@ #[cfg(test)] mod tests { - use crate::arithmetics::{challenger_multi_observe, exts_to_felts}; - - use crate::zkvm_verifier::binding::{E, F}; - use ceno_mle::expression::StructuralWitIn; - use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier}; - use ff_ext::BabyBearExt4; - use itertools::interleave; - use itertools::max; - use itertools::Itertools; - use mpcs::BasefoldCommitment; - use mpcs::{Basefold, BasefoldRSParams}; + use crate::zkvm_verifier::binding::F; use openvm_circuit::arch::SystemConfig; use openvm_circuit::arch::VmExecutor; use openvm_native_circuit::Native; @@ -19,23 +9,16 @@ mod tests { use openvm_native_compiler::conversion::convert_program; use openvm_native_compiler::prelude::*; use openvm_native_compiler::{asm::AsmBuilder, conversion::CompilerOptions}; - use openvm_native_compiler_derive::iter_zip; - use openvm_native_recursion::challenger::{self, CanSampleVariable}; + use openvm_native_recursion::challenger::CanSampleVariable; use openvm_native_recursion::challenger::{ - duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, + duplex::DuplexChallengerVariable, CanObserveVariable, }; - use openvm_native_recursion::hints::Hintable; use openvm_stark_backend::config::StarkGenericConfig; use openvm_stark_sdk::{ config::baby_bear_poseidon2::BabyBearPoseidon2Config, p3_baby_bear::BabyBear, }; use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; - type Pcs = Basefold; - const NUM_FANIN: usize = 2; - const MAINCONSTRAIN_SUMCHECK_BATCH_SIZE: usize = 3; // read/write/lookup - const SEL_DEGREE: usize = 2; - type SC = BabyBearPoseidon2Config; type EF = ::Challenge; diff --git a/src/tower_verifier/binding.rs b/src/tower_verifier/binding.rs index 1e750f9..d87d64a 100644 --- a/src/tower_verifier/binding.rs +++ b/src/tower_verifier/binding.rs @@ -3,7 +3,6 @@ use openvm_native_compiler::{ ir::{Array, Builder, Config}, prelude::*, }; -use openvm_native_compiler_derive::iter_zip; use openvm_native_recursion::hints::{Hintable, VecAutoHintable}; pub type F = BabyBear; pub type E = BinomialExtensionField; @@ -11,7 +10,7 @@ pub type InnerConfig = AsmConfig; use openvm_stark_sdk::p3_baby_bear::BabyBear; use openvm_stark_backend::p3_field::extension::BinomialExtensionField; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; #[derive(DslVariable, Clone)] pub struct PointVariable { @@ -101,21 +100,4 @@ impl Hintable for IOPProverMessage { stream } } -impl VecAutoHintable for IOPProverMessage {} - -pub struct TowerVerifierInput { - pub prod_out_evals: Vec>, - pub logup_out_evals: Vec>, - pub num_variables: Vec, - pub num_fanin: usize, - - // TowerProof - pub num_proofs: usize, - pub num_prod_specs: usize, - pub num_logup_specs: usize, - pub _max_num_variables: usize, - - pub proofs: Vec>, - pub prod_specs_eval: Vec>>, - pub logup_specs_eval: Vec>>, -} +impl VecAutoHintable for IOPProverMessage {} \ No newline at end of file diff --git a/src/tower_verifier/program.rs b/src/tower_verifier/program.rs index af6afc5..5a0d549 100644 --- a/src/tower_verifier/program.rs +++ b/src/tower_verifier/program.rs @@ -1,16 +1,14 @@ use super::binding::{IOPProverMessageVariable, PointAndEvalVariable, PointVariable}; use crate::arithmetics::{ - challenger_multi_observe, dot_product, eq_eval, evaluate_at_point_degree_1, extend, - exts_to_felts, fixed_dot_product, gen_alpha_pows, is_smaller_than, print_ext_arr, reverse, + challenger_multi_observe, eq_eval, evaluate_at_point_degree_1, extend, + exts_to_felts, fixed_dot_product, reverse, UniPolyExtrapolator, }; use crate::transcript::transcript_observe_label; use crate::zkvm_verifier::binding::TowerProofInputVariable; use ceno_zkvm::scheme::constants::NUM_FANIN; -use openvm::platform::print; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; -use openvm_native_recursion::challenger::ChallengerVariable; use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index 0d0bf69..73f2ec6 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -2,17 +2,11 @@ use crate::arithmetics::next_pow2_instance_padding; use crate::basefold_verifier::basefold::{ BasefoldCommitment, BasefoldCommitmentVariable, BasefoldProof, BasefoldProofVariable, }; -use crate::basefold_verifier::query_phase::{ - QueryPhaseVerifierInput, QueryPhaseVerifierInputVariable, -}; use crate::{ arithmetics::ceil_log2, tower_verifier::binding::{PointVariable, IOPProverMessage, IOPProverMessageVariable}, }; -use ark_std::iterable::Iterable; -use ff_ext::BabyBearExt4; use itertools::Itertools; -use openvm_circuit::derive; use openvm_native_compiler::{ asm::AsmConfig, ir::{Array, Builder, Config, Felt}, @@ -448,7 +442,7 @@ impl Hintable for LayerProofInput { } } #[derive(Default)] -pub(crate) struct GKRProofInput { +pub struct GKRProofInput { pub num_var_with_rotation: usize, pub num_instances: usize, pub layer_proofs: Vec, diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index c51d9c3..1156ff1 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -1,8 +1,6 @@ -use std::io::empty; - use super::binding::{ZKVMChipProofInputVariable, ZKVMProofInputVariable, ClaimAndPoint, RotationClaim,GKRClaimEvaluation}; use crate::arithmetics::{ - challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, join, print_ext_arr, print_felt_arr, print_usize_arr, PolyEvaluator, UniPolyExtrapolator + challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, PolyEvaluator, UniPolyExtrapolator }; use crate::basefold_verifier::basefold::{ BasefoldCommitmentVariable, RoundOpeningVariable, RoundVariable, @@ -10,25 +8,23 @@ use crate::basefold_verifier::basefold::{ use crate::basefold_verifier::mmcs::MmcsCommitmentVariable; use crate::basefold_verifier::query_phase::PointAndEvalsVariable; use crate::basefold_verifier::utils::pow_2; -use crate::basefold_verifier::verifier::batch_verify; +// use crate::basefold_verifier::verifier::batch_verify; use crate::tower_verifier::program::verify_tower_proof; use crate::transcript::transcript_observe_label; -use crate::zkvm_verifier::binding::{GKRProofVariable, LayerProofInput, LayerProofVariable, SumcheckLayerProofInput, SumcheckLayerProofVariable}; +use crate::zkvm_verifier::binding::{GKRProofVariable, LayerProofVariable, SumcheckLayerProofVariable}; use crate::{ arithmetics::{ build_eq_x_r_vec_sequential, ceil_log2, concat, dot_product as ext_dot_product, eq_eval_less_or_equal_than, eval_wellform_address_vec, gen_alpha_pows, max_usize_arr, - max_usize_vec, nested_product, next_pow2_instance_padding, product, sum as ext_sum, + max_usize_vec, nested_product, }, tower_verifier::{binding::{PointVariable, PointAndEvalVariable}, program::iop_verifier_state_verify}, }; use ceno_zkvm::structs::VerifyingKey; use ceno_mle::{ - expression::{Expression, StructuralWitIn, Instance, WitnessId}, - mle::{Point, PointAndEval}, - virtual_poly::build_eq_x_r_sequential + expression::{Expression, StructuralWitIn, Instance}, }; -use ceno_zkvm::{e2e::B, circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier, structs::ComposedConstrainSystem}; +use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier, structs::ComposedConstrainSystem}; use ff_ext::BabyBearExt4; use gkr_iop::gkr::layer::ROTATION_OPENING_COUNT; use gkr_iop::{ @@ -40,7 +36,7 @@ use gkr_iop::{ selector::SelectorType, evaluation::EvalExpression, }; -use itertools::{interleave, max, Itertools, izip}; +use itertools::{interleave, Itertools, izip}; use mpcs::{Basefold, BasefoldRSParams}; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; @@ -48,16 +44,13 @@ use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; use p3_baby_bear::BabyBear; -use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; -use p3_field::dot_product; +use openvm_stark_backend::p3_field::FieldAlgebra; type F = BabyBear; type E = BabyBearExt4; type Pcs = Basefold; const NUM_FANIN: usize = 2; -const MAINCONSTRAIN_SUMCHECK_BATCH_SIZE: usize = 3; // read/write/lookup -const SEL_DEGREE: usize = 2; pub fn transcript_group_observe_label( builder: &mut Builder, @@ -411,24 +404,18 @@ pub fn verify_opcode_proof( ) -> Array> { let cs = vk.get_cs(); let one: Ext = builder.constant(C::EF::ONE); - let zero: Ext = builder.constant(C::EF::ZERO); let r_len = cs.zkvm_v1_css.r_expressions.len(); let w_len = cs.zkvm_v1_css.w_expressions.len(); let lk_len = cs.zkvm_v1_css.lk_expressions.len(); let num_batched = r_len + w_len + lk_len; - let chip_record_alpha: Ext = builder.get(challenges, 0); let r_counts_per_instance: Usize = Usize::from(r_len); let w_counts_per_instance: Usize = Usize::from(w_len); let lk_counts_per_instance: Usize = Usize::from(lk_len); let num_batched: Usize = Usize::from(num_batched); - let log2_r_count: Usize = Usize::from(ceil_log2(r_len)); - let log2_w_count: Usize = Usize::from(ceil_log2(w_len)); - let log2_lk_count: Usize = Usize::from(ceil_log2(lk_len)); - let log2_num_instances = opcode_proof.log2_num_instances.clone(); let num_var_with_rotation: Usize = Usize::Var(Var::uninit(builder)); @@ -454,10 +441,9 @@ pub fn verify_opcode_proof( ); let num_fanin: Usize = Usize::from(NUM_FANIN); - let max_expr_len = *max([r_len, w_len, lk_len].iter()).unwrap(); builder.cycle_tracker_start("verify tower proof for opcode"); - let (rt_tower, record_evals, logup_p_evals, logup_q_evals) = verify_tower_proof( + let (_, record_evals, logup_p_evals, logup_q_evals) = verify_tower_proof( builder, challenger, prod_out_evals, @@ -474,7 +460,7 @@ pub fn verify_opcode_proof( builder.assert_ext_eq(logup_p_eval, one); // verify zero statement (degree > 1) + sel sumcheck - let rt = builder.get(&record_evals, 0); + let _rt = builder.get(&record_evals, 0); let num_rw_records: Usize = builder.eval(r_counts_per_instance + w_counts_per_instance); builder.assert_usize_eq(record_evals.len(), num_rw_records.clone()); builder.assert_usize_eq(logup_p_evals.len(), lk_counts_per_instance.clone()); @@ -535,7 +521,7 @@ pub fn verify_gkr_circuit( main: SumcheckLayerProofVariable { proof, evals: main_evals, - evals_len_div_3: main_evals_len_div_3, + evals_len_div_3: _main_evals_len_div_3, }, rotation: rotation_proof, has_rotation, @@ -801,7 +787,6 @@ pub fn rotation_selector_eval( ) -> Ext { let bh = BooleanHypercube::new(5); let eval: Ext = builder.constant(C::EF::ZERO); - let cyclic_group_size: usize = 1 << cyclic_group_log2_size; let rotation_index = bh.into_iter().take(rotation_cyclic_subgroup_size).collect_vec(); let out_subgroup = out_point.slice(builder, 0, cyclic_group_log2_size); @@ -889,7 +874,7 @@ pub fn evaluate_selector( pub fn get_rotation_points( builder: &mut Builder, - num_vars: usize, + _num_vars: usize, point: &Array>, ) -> ( Array>, From 35d54ad65d9377728bbb5a557f65fd9d85d49afe Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Wed, 13 Aug 2025 21:46:49 -0400 Subject: [PATCH 18/24] fmt --- src/arithmetics/mod.rs | 102 ---------------------------------- src/tower_verifier/program.rs | 49 +--------------- src/transcript/mod.rs | 8 +-- src/zkvm_verifier/binding.rs | 5 +- 4 files changed, 7 insertions(+), 157 deletions(-) diff --git a/src/arithmetics/mod.rs b/src/arithmetics/mod.rs index 00a35ee..b9d6793 100644 --- a/src/arithmetics/mod.rs +++ b/src/arithmetics/mod.rs @@ -202,24 +202,6 @@ pub fn dot_product( acc } -pub fn dot_product_pt_n_eval( - builder: &mut Builder, - pt_and_eval: &Array>, - b: &Array>, -) -> Ext<::F, ::EF> { - let acc: Ext = builder.eval(C::F::ZERO); - - iter_zip!(builder, pt_and_eval, b).for_each(|idx_vec, builder| { - let ptr_a = idx_vec[0]; - let ptr_b = idx_vec[1]; - let v_a = builder.iter_ptr_get(&pt_and_eval, ptr_a); - let v_b = builder.iter_ptr_get(&b, ptr_b); - builder.assign(&acc, acc + v_a.eval * v_b); - }); - - acc -} - pub fn reverse>( builder: &mut Builder, arr: &Array, @@ -319,20 +301,6 @@ pub fn eq_eval_with_index( acc } -// Multiply all elements in the Array -pub fn product( - builder: &mut Builder, - arr: &Array>, -) -> Ext { - let acc = builder.constant(C::EF::ONE); - iter_zip!(builder, arr).for_each(|idx_vec, builder| { - let el = builder.iter_ptr_get(arr, idx_vec[0]); - builder.assign(&acc, acc * el); - }); - - acc -} - // Multiply all elements in a nested Array pub fn nested_product( builder: &mut Builder, @@ -351,47 +319,6 @@ pub fn nested_product( acc } -// Add all elements in the Array -pub fn sum( - builder: &mut Builder, - arr: &Array>, -) -> Ext { - let acc = builder.constant(C::EF::ZERO); - iter_zip!(builder, arr).for_each(|idx_vec, builder| { - let el = builder.iter_ptr_get(arr, idx_vec[0]); - builder.assign(&acc, acc + el); - }); - - acc -} - -// Join two arrays -pub fn join( - builder: &mut Builder, - a: &Array>, - b: &Array>, -) -> Array> { - let a_len = a.len(); - let b_len = b.len(); - let out_len = builder.eval_expr(a_len.clone() + b_len.clone()); - let out = builder.dyn_array(out_len); - - builder.range(0, a_len.clone()).for_each(|i_vec, builder| { - let i = i_vec[0]; - let a_val = builder.get(a, i); - builder.set(&out, i, a_val); - }); - - builder.range(0, b_len).for_each(|i_vec, builder| { - let b_i = i_vec[0]; - let i = builder.eval_expr(b_i + a_len.clone()); - let b_val = builder.get(b, b_i); - builder.set(&out, i, b_val); - }); - - out -} - // Generate alpha power challenges pub fn gen_alpha_pows( builder: &mut Builder, @@ -514,35 +441,6 @@ pub fn build_eq_x_r_vec_sequential( evals } -pub fn build_eq_x_r_vec_sequential_with_offset( - builder: &mut Builder, - r: &Array>, - offset: Usize, -) -> Array> { - // we build eq(x,r) from its evaluations - // we want to evaluate eq(x,r) over x \in {0, 1}^num_vars - // for example, with num_vars = 4, x is a binary vector of 4, then - // 0 0 0 0 -> (1-r0) * (1-r1) * (1-r2) * (1-r3) - // 1 0 0 0 -> r0 * (1-r1) * (1-r2) * (1-r3) - // 0 1 0 0 -> (1-r0) * r1 * (1-r2) * (1-r3) - // 1 1 0 0 -> r0 * r1 * (1-r2) * (1-r3) - // .... - // 1 1 1 1 -> r0 * r1 * r2 * r3 - // we will need 2^num_var evaluations - - let r_len: Var = builder.eval(r.len() - offset); - let evals_len: Felt = builder.constant(C::F::ONE); - let evals_len = builder.exp_power_of_2_v::>(evals_len, r_len); - let evals_len = builder.cast_felt_to_var(evals_len); - - let evals: Array> = builder.dyn_array(evals_len); - // _debug - // build_eq_x_r_helper_sequential_offset(r, &mut evals, E::ONE); - // unsafe { std::mem::transmute(evals) } - // FIXME: this function is not implemented yet - evals -} - pub fn ceil_log2(x: usize) -> usize { assert!(x > 0, "ceil_log2: x must be positive"); // Calculate the number of bits in usize diff --git a/src/tower_verifier/program.rs b/src/tower_verifier/program.rs index 5a0d549..429335e 100644 --- a/src/tower_verifier/program.rs +++ b/src/tower_verifier/program.rs @@ -85,51 +85,6 @@ pub(crate) fn interpolate_uni_poly( res } -// Interpolate a uni-variate degree-`p_i.len()-1` polynomial and evaluate this -// polynomial at `eval_at`: -// -// \sum_{i=0}^len p_i * (\prod_{j!=i} (eval_at - j)/(i-j) ) -// -pub(crate) fn interpolate_uni_poly_with_weights( - builder: &mut Builder, - p_i: &Array>, - eval_at: Ext, - interpolation_weights: &Array>>, -) -> Ext { - // \prod_i (eval_at - i) - let weights_idx: Usize = builder.eval(p_i.len() - Usize::from(2)); - let weights = builder.get(interpolation_weights, weights_idx); - let num_points = p_i.len().get_var(); - - let one: Ext = builder.constant(C::EF::ONE); - let zero: Ext = builder.constant(C::EF::ZERO); - let mut iter_i: Ext = builder.eval(zero + zero); // 0 + 0 to take advantage of AddE - let prod: Ext = builder.eval(one + zero); // 1 + 0 to take advantage of AddE - builder.range(0, num_points).for_each(|_, builder| { - builder.assign(&prod, prod * (eval_at - iter_i)); - builder.assign(&iter_i, iter_i + one); - }); - - iter_i = builder.eval(zero + zero); // reset to 0 - let result = zero; // take ownership - iter_zip!(builder, p_i, weights).for_each(|ptr_vec, builder| { - let pi_ptr = ptr_vec[0]; - let w_ptr = ptr_vec[1]; - - let p_i_val = builder.iter_ptr_get(p_i, pi_ptr); - let weight = builder.iter_ptr_get(&weights, w_ptr); - - // weight_i = \prod_{j!=i} 1/(i-j) - // \sum_{i=0}^len p_i * weight_i * prod / (eval_at-i) - let e: Ext = builder.eval(eval_at - iter_i); - let term = p_i_val * weight * prod / e; // TODO: how to handle e = 0 - builder.assign(&iter_i, iter_i + one); - builder.assign(&result, result + term); - }); - - result -} - pub fn iop_verifier_state_verify( builder: &mut Builder, challenger: &mut DuplexChallengerVariable, @@ -350,7 +305,7 @@ pub fn verify_tower_proof( builder.set(&interleaved_point_n_eval, q_i, q); }); - let mut initial_claim: Ext = builder.eval(zero + zero); + let initial_claim: Ext = builder.eval(zero + zero); iter_zip!(builder, prod_spec_point_n_eval).for_each(|ptr_vec, builder| { let ptr = ptr_vec[0]; @@ -372,7 +327,7 @@ pub fn verify_tower_proof( let op_range: RVar = builder.eval_expr(max_num_variables - Usize::from(1)); let round: Felt = builder.constant(C::F::ZERO); - let mut next_rt = PointAndEvalVariable { + let next_rt = PointAndEvalVariable { point: PointVariable { fs: initial_rt, }, diff --git a/src/transcript/mod.rs b/src/transcript/mod.rs index 7007aa8..fe8256f 100644 --- a/src/transcript/mod.rs +++ b/src/transcript/mod.rs @@ -1,10 +1,8 @@ use ff_ext::{BabyBearExt4, ExtensionField as CenoExtensionField, SmallField}; use openvm_native_compiler::prelude::*; -use openvm_native_recursion::challenger::{ - duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, -}; -use openvm_native_recursion::challenger::{CanSampleBitsVariable, ChallengerVariable}; -use openvm_stark_backend::p3_field::{FieldAlgebra, FieldExtensionAlgebra}; +use openvm_native_recursion::challenger::{duplex::DuplexChallengerVariable, CanObserveVariable}; +use openvm_native_recursion::challenger::CanSampleBitsVariable; +use openvm_stark_backend::p3_field::FieldAlgebra; pub fn transcript_observe_label( builder: &mut Builder, diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index 73f2ec6..8f80162 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -372,7 +372,7 @@ impl Hintable for ZKVMChipProofInput { } #[derive(Default)] -pub(crate) struct SumcheckLayerProofInput { +pub struct SumcheckLayerProofInput { pub proof: Vec, pub evals: Vec, } @@ -406,8 +406,7 @@ impl Hintable for SumcheckLayerProofInput { stream } } - -pub(crate) struct LayerProofInput { +pub struct LayerProofInput { pub has_rotation: usize, pub rotation: SumcheckLayerProofInput, pub main: SumcheckLayerProofInput, From a98cc601a1afcea0476d6889f9022d2833a65989 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Thu, 14 Aug 2025 19:34:56 -0400 Subject: [PATCH 19/24] Test debug branch --- Cargo.lock | 69 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 43 ++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7142f1..becb995 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -526,7 +526,7 @@ dependencies = [ [[package]] name = "ceno-examples" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "glob", ] @@ -543,7 +543,6 @@ dependencies = [ "ceno_emul", "ceno_zkvm", "ff_ext", - "gkr_iop", "itertools 0.13.0", "mpcs", "multilinear_extensions", @@ -578,7 +577,7 @@ dependencies = [ [[package]] name = "ceno_emul" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "anyhow", "ceno_rt", @@ -601,7 +600,7 @@ dependencies = [ [[package]] name = "ceno_host" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "anyhow", "ceno_emul", @@ -614,7 +613,7 @@ dependencies = [ [[package]] name = "ceno_rt" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "getrandom 0.2.16", "rkyv", @@ -623,7 +622,7 @@ dependencies = [ [[package]] name = "ceno_zkvm" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "base64", "bincode", @@ -1142,7 +1141,7 @@ dependencies = [ [[package]] name = "ff_ext" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "once_cell", "p3", @@ -1232,7 +1231,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gkr_iop" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "ark-std 0.5.0", "bincode", @@ -1719,7 +1718,7 @@ dependencies = [ [[package]] name = "mpcs" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "aes", "bincode", @@ -1750,7 +1749,7 @@ dependencies = [ [[package]] name = "multilinear_extensions" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "either", "ff_ext", @@ -1949,7 +1948,7 @@ checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "openvm" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "bytemuck", "num-bigint 0.4.6", @@ -1962,7 +1961,7 @@ dependencies = [ [[package]] name = "openvm-circuit" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "backtrace", "cfg-if", @@ -1993,7 +1992,7 @@ dependencies = [ [[package]] name = "openvm-circuit-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "itertools 0.14.0", "quote", @@ -2003,7 +2002,7 @@ dependencies = [ [[package]] name = "openvm-circuit-primitives" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "derive-new 0.6.0", "itertools 0.14.0", @@ -2018,7 +2017,7 @@ dependencies = [ [[package]] name = "openvm-circuit-primitives-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "itertools 0.14.0", "quote", @@ -2028,7 +2027,7 @@ dependencies = [ [[package]] name = "openvm-custom-insn" version = "0.1.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "proc-macro2", "quote", @@ -2038,7 +2037,7 @@ dependencies = [ [[package]] name = "openvm-instructions" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "backtrace", "derive-new 0.6.0", @@ -2055,7 +2054,7 @@ dependencies = [ [[package]] name = "openvm-instructions-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "quote", "syn 2.0.105", @@ -2064,7 +2063,7 @@ dependencies = [ [[package]] name = "openvm-native-circuit" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "derive-new 0.6.0", "derive_more 1.0.0", @@ -2091,7 +2090,7 @@ dependencies = [ [[package]] name = "openvm-native-compiler" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "backtrace", "itertools 0.14.0", @@ -2113,7 +2112,7 @@ dependencies = [ [[package]] name = "openvm-native-compiler-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "quote", "syn 2.0.105", @@ -2122,7 +2121,7 @@ dependencies = [ [[package]] name = "openvm-native-recursion" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "cfg-if", "itertools 0.14.0", @@ -2146,7 +2145,7 @@ dependencies = [ [[package]] name = "openvm-platform" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "libm", "openvm-custom-insn", @@ -2156,7 +2155,7 @@ dependencies = [ [[package]] name = "openvm-poseidon2-air" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "derivative", "lazy_static", @@ -2173,7 +2172,7 @@ dependencies = [ [[package]] name = "openvm-rv32im-circuit" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "derive-new 0.6.0", "derive_more 1.0.0", @@ -2196,7 +2195,7 @@ dependencies = [ [[package]] name = "openvm-rv32im-guest" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "openvm-custom-insn", "p3-field", @@ -2206,7 +2205,7 @@ dependencies = [ [[package]] name = "openvm-rv32im-transpiler" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "openvm-instructions", "openvm-instructions-derive", @@ -2283,7 +2282,7 @@ dependencies = [ [[package]] name = "openvm-transpiler" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git#e4e261b33fdd7523301c9bf7402b40e764a464b6" +source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" dependencies = [ "elf", "eyre", @@ -2312,7 +2311,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "p3-baby-bear", "p3-challenger", @@ -2770,7 +2769,7 @@ dependencies = [ [[package]] name = "poseidon" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "criterion", "ff_ext", @@ -3379,7 +3378,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sumcheck" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "crossbeam-channel", "either", @@ -3398,7 +3397,7 @@ dependencies = [ [[package]] name = "sumcheck_macro" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "itertools 0.13.0", "p3", @@ -3672,7 +3671,7 @@ dependencies = [ [[package]] name = "transcript" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "crossbeam-channel", "ff_ext", @@ -3850,7 +3849,7 @@ dependencies = [ [[package]] name = "whir" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "bincode", "blake2", @@ -4093,7 +4092,7 @@ dependencies = [ [[package]] name = "witness" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" +source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" dependencies = [ "ff_ext", "multilinear_extensions", diff --git a/Cargo.toml b/Cargo.toml index c604bac..3142179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,15 @@ version = "0.1.0" edition = "2021" [dependencies] -openvm = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } -openvm-circuit = { git = "https://github.com/scroll-tech/openvm.git", default-features = false, features = ["bench-metrics"] } -openvm-native-circuit = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } -openvm-native-compiler = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } -openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } -openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } +openvm-circuit = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false, features = ["bench-metrics"] } +openvm-native-circuit = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } +openvm-native-compiler = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } +openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } +openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1", default-features = false } openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1", default-features = false } + rand = { version = "0.8.5", default-features = false } itertools = { version = "0.13.0", default-features = false } bincode = "1.3.3" @@ -37,18 +38,26 @@ ark-poly = "0.5" ark-serialize = "0.5" # Ceno -ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "multilinear_extensions" } -ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "sumcheck" } -ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "transcript" } -ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "witness" } -ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } -ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } - +ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "multilinear_extensions" } +ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "sumcheck" } +ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "transcript" } +ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "witness" } +ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } +ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } +mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } +ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" [features] -bench-metrics = ["openvm-circuit/bench-metrics"] \ No newline at end of file +bench-metrics = ["openvm-circuit/bench-metrics"] + +# [patch."https://github.com/scroll-tech/ceno.git"] +# ceno_mle = { path = "../ceno/multilinear_extensions", package = "multilinear_extensions" } +# ceno_sumcheck = { path = "../ceno/sumcheck", package = "sumcheck" } +# ceno_transcript = { path = "../ceno/transcript", package = "transcript" } +# ceno_witness = { path = "../ceno/witness", package = "witness" } +# ceno_zkvm = { path = "../ceno/ceno_zkvm" } +# ceno_emul = { path = "../ceno/ceno_emul" } +# mpcs = { path = "../ceno/mpcs" } +# ff_ext = { path = "../ceno/ff_ext" } From a89bd22ddabcbd474c36f5205d464f69d1835cd9 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Thu, 14 Aug 2025 19:53:14 -0400 Subject: [PATCH 20/24] Fix dependency --- Cargo.lock | 33 +++++++++++++++++---------------- Cargo.toml | 17 +++++++++-------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index becb995..b4dc749 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -526,7 +526,7 @@ dependencies = [ [[package]] name = "ceno-examples" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "glob", ] @@ -543,6 +543,7 @@ dependencies = [ "ceno_emul", "ceno_zkvm", "ff_ext", + "gkr_iop", "itertools 0.13.0", "mpcs", "multilinear_extensions", @@ -577,7 +578,7 @@ dependencies = [ [[package]] name = "ceno_emul" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "anyhow", "ceno_rt", @@ -600,7 +601,7 @@ dependencies = [ [[package]] name = "ceno_host" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "anyhow", "ceno_emul", @@ -613,7 +614,7 @@ dependencies = [ [[package]] name = "ceno_rt" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "getrandom 0.2.16", "rkyv", @@ -622,7 +623,7 @@ dependencies = [ [[package]] name = "ceno_zkvm" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "base64", "bincode", @@ -1141,7 +1142,7 @@ dependencies = [ [[package]] name = "ff_ext" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "once_cell", "p3", @@ -1231,7 +1232,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gkr_iop" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "ark-std 0.5.0", "bincode", @@ -1718,7 +1719,7 @@ dependencies = [ [[package]] name = "mpcs" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "aes", "bincode", @@ -1749,7 +1750,7 @@ dependencies = [ [[package]] name = "multilinear_extensions" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "either", "ff_ext", @@ -2311,7 +2312,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "p3-baby-bear", "p3-challenger", @@ -2769,7 +2770,7 @@ dependencies = [ [[package]] name = "poseidon" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "criterion", "ff_ext", @@ -3378,7 +3379,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sumcheck" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "crossbeam-channel", "either", @@ -3397,7 +3398,7 @@ dependencies = [ [[package]] name = "sumcheck_macro" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "itertools 0.13.0", "p3", @@ -3671,7 +3672,7 @@ dependencies = [ [[package]] name = "transcript" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "crossbeam-channel", "ff_ext", @@ -3849,7 +3850,7 @@ dependencies = [ [[package]] name = "whir" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "bincode", "blake2", @@ -4092,7 +4093,7 @@ dependencies = [ [[package]] name = "witness" version = "0.1.0" -source = "git+https://github.com/scroll-tech/ceno.git?branch=build%2Fsmaller_field_support_plonky3_539bbc#1acd5edfd68727e431aad0daead3a1ef80c918f2" +source = "git+https://github.com/scroll-tech/ceno.git?branch=feat%2Fsmaller_field_support#6b24e309c2050b2adbe62ed5702147e36bc965a0" dependencies = [ "ff_ext", "multilinear_extensions", diff --git a/Cargo.toml b/Cargo.toml index 3142179..78d4c37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,14 +38,15 @@ ark-poly = "0.5" ark-serialize = "0.5" # Ceno -ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "multilinear_extensions" } -ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "sumcheck" } -ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "transcript" } -ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc", package = "witness" } -ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } -ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "build/smaller_field_support_plonky3_539bbc" } +ceno_mle = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "multilinear_extensions" } +ceno_sumcheck = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "sumcheck" } +ceno_transcript = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "transcript" } +ceno_witness = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support", package = "witness" } +ceno_zkvm = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +ceno_emul = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +gkr_iop = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +mpcs = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } +ff_ext = { git = "https://github.com/scroll-tech/ceno.git", branch = "feat/smaller_field_support" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" From cf67f33e1e25656d026136612493e6d9099f88cb Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Thu, 14 Aug 2025 20:05:05 -0400 Subject: [PATCH 21/24] Enable STARK proof generation and verification in e2e --- src/e2e/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index beb15aa..6e21478 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -361,7 +361,6 @@ pub fn inner_test_thread() { println!("=> segment {:?} metrics: {:?}", i, seg.metrics); } - /* _debug let poseidon2_max_constraint_degree = 3; let log_blowup = 1; @@ -388,7 +387,6 @@ pub fn inner_test_thread() { for proof in proofs { verify_single(&vm.engine, &pk.get_vk(), &proof).expect("Verification failed"); } - */ } #[test] From 374a60fcb187dec6255e9fcd6d096fe078def57f Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Thu, 14 Aug 2025 20:06:20 -0400 Subject: [PATCH 22/24] fmt --- src/arithmetics/mod.rs | 8 +- src/e2e/mod.rs | 56 ++-- src/extensions/mod.rs | 2 +- src/tower_verifier/binding.rs | 4 +- src/tower_verifier/program.rs | 9 +- src/transcript/mod.rs | 2 +- src/zkvm_verifier/binding.rs | 12 +- src/zkvm_verifier/verifier.rs | 483 ++++++++++++++++++++-------------- 8 files changed, 347 insertions(+), 229 deletions(-) diff --git a/src/arithmetics/mod.rs b/src/arithmetics/mod.rs index b9d6793..9457e95 100644 --- a/src/arithmetics/mod.rs +++ b/src/arithmetics/mod.rs @@ -7,9 +7,7 @@ use ff_ext::{BabyBearExt4, SmallField}; use itertools::Either; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; -use openvm_native_recursion::challenger::{ - duplex::DuplexChallengerVariable, FeltChallenger, -}; +use openvm_native_recursion::challenger::{duplex::DuplexChallengerVariable, FeltChallenger}; use openvm_stark_backend::p3_field::{FieldAlgebra, FieldExtensionAlgebra}; type E = BabyBearExt4; const MAX_NUM_VARS: usize = 25; @@ -351,7 +349,9 @@ pub fn eq_eval_less_or_equal_than( b: &Array>, ) -> Ext { builder.cycle_tracker_start("Compute eq_eval_less_or_equal_than"); - let eq_bit_decomp: Array> = opcode_proof.num_instances_minus_one_bit_decomposition.slice(builder, 0, b.len()); + let eq_bit_decomp: Array> = opcode_proof + .num_instances_minus_one_bit_decomposition + .slice(builder, 0, b.len()); let one_ext: Ext = builder.constant(C::EF::ONE); let rp_len = builder.eval_expr(b.len() + C::N::ONE); diff --git a/src/e2e/mod.rs b/src/e2e/mod.rs index 6e21478..203f293 100644 --- a/src/e2e/mod.rs +++ b/src/e2e/mod.rs @@ -2,19 +2,21 @@ use crate::basefold_verifier::basefold::BasefoldCommitment; use crate::basefold_verifier::query_phase::QueryPhaseVerifierInput; use crate::tower_verifier::binding::IOPProverMessage; use crate::zkvm_verifier::binding::{ - ZKVMProofInput, TowerProofInput, E, F, ZKVMChipProofInput, - GKRProofInput, LayerProofInput, SumcheckLayerProofInput, + GKRProofInput, LayerProofInput, SumcheckLayerProofInput, TowerProofInput, ZKVMChipProofInput, + ZKVMProofInput, E, F, }; -use crate::zkvm_verifier::verifier::{verify_zkvm_proof, verify_gkr_circuit}; +use crate::zkvm_verifier::verifier::{verify_gkr_circuit, verify_zkvm_proof}; use ceno_mle::util::ceil_log2; use ff_ext::BabyBearExt4; use gkr_iop::gkr::{ + layer::sumcheck_layer::{SumcheckLayer, SumcheckLayerProof}, GKRCircuit, - layer::sumcheck_layer::{SumcheckLayer, SumcheckLayerProof} }; use itertools::Itertools; use mpcs::{Basefold, BasefoldRSParams}; -use openvm_circuit::arch::{instructions::program::Program, SystemConfig, VmExecutor, verify_single, VirtualMachine}; +use openvm_circuit::arch::{ + instructions::program::Program, verify_single, SystemConfig, VirtualMachine, VmExecutor, +}; use openvm_native_circuit::{Native, NativeConfig}; use openvm_native_compiler::{ asm::AsmBuilder, @@ -24,13 +26,13 @@ use openvm_native_compiler::{ use openvm_native_recursion::hints::Hintable; use openvm_stark_backend::config::StarkGenericConfig; use openvm_stark_sdk::{ - engine::StarkFriEngine, - p3_baby_bear::BabyBear, config::{ - baby_bear_poseidon2::{BabyBearPoseidon2Engine, BabyBearPoseidon2Config}, + baby_bear_poseidon2::{BabyBearPoseidon2Config, BabyBearPoseidon2Engine}, fri_params::standard_fri_params_with_100_bits_conjectured_security, setup_tracing_with_log_level, FriParameters, - } + }, + engine::StarkFriEngine, + p3_baby_bear::BabyBear, }; use std::fs::File; @@ -215,13 +217,16 @@ pub fn parse_zkvm_proof_import( for layer_proof in gkr_proof.0 { // rotation - let (has_rotation, rotation): (usize, SumcheckLayerProofInput) = if let Some(p) = layer_proof.rotation { + let (has_rotation, rotation): (usize, SumcheckLayerProofInput) = if let Some(p) = + layer_proof.rotation + { let mut iop_messages: Vec = vec![]; for m in p.proof.proofs { let mut evaluations: Vec = vec![]; for e in m.evaluations { let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()) + .unwrap(); evaluations.push(v_e); } iop_messages.push(IOPProverMessage { evaluations }); @@ -229,10 +234,17 @@ pub fn parse_zkvm_proof_import( let mut evals: Vec = vec![]; for e in p.evals { let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()) + .unwrap(); evals.push(v_e); } - (1, SumcheckLayerProofInput { proof: iop_messages, evals }) + ( + 1, + SumcheckLayerProofInput { + proof: iop_messages, + evals, + }, + ) } else { (0, SumcheckLayerProofInput::default()) }; @@ -244,7 +256,8 @@ pub fn parse_zkvm_proof_import( let mut evaluations: Vec = vec![]; for e in m.evaluations { let v_e: E = - serde_json::from_value(serde_json::to_value(e.clone()).unwrap()).unwrap(); + serde_json::from_value(serde_json::to_value(e.clone()).unwrap()) + .unwrap(); evaluations.push(v_e); } iop_messages.push(IOPProverMessage { evaluations }); @@ -260,7 +273,11 @@ pub fn parse_zkvm_proof_import( evals, }; - gkr_iop_proof.layer_proofs.push(LayerProofInput { has_rotation, rotation, main }); + gkr_iop_proof.layer_proofs.push(LayerProofInput { + has_rotation, + rotation, + main, + }); } } @@ -313,7 +330,7 @@ pub fn inner_test_thread() { let verifier = ZKVMVerifier::new(vk); let zkvm_proof_input = parse_zkvm_proof_import(zkvm_proof, &verifier); - + // OpenVM DSL let mut builder = AsmBuilder::::default(); @@ -354,7 +371,12 @@ pub fn inner_test_thread() { let executor = VmExecutor::::new(config); let res = executor - .execute_and_then(program.clone(), witness_stream.clone(), |_, seg| Ok(seg), |err| err) + .execute_and_then( + program.clone(), + witness_stream.clone(), + |_, seg| Ok(seg), + |err| err, + ) .unwrap(); for (i, seg) in res.iter().enumerate() { diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 5e4e1cf..60ec658 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -14,10 +14,10 @@ mod tests { duplex::DuplexChallengerVariable, CanObserveVariable, }; use openvm_stark_backend::config::StarkGenericConfig; + use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; use openvm_stark_sdk::{ config::baby_bear_poseidon2::BabyBearPoseidon2Config, p3_baby_bear::BabyBear, }; - use openvm_stark_backend::p3_field::{Field, FieldAlgebra}; type SC = BabyBearPoseidon2Config; type EF = ::Challenge; diff --git a/src/tower_verifier/binding.rs b/src/tower_verifier/binding.rs index d87d64a..2e4749f 100644 --- a/src/tower_verifier/binding.rs +++ b/src/tower_verifier/binding.rs @@ -8,8 +8,8 @@ pub type F = BabyBear; pub type E = BinomialExtensionField; pub type InnerConfig = AsmConfig; -use openvm_stark_sdk::p3_baby_bear::BabyBear; use openvm_stark_backend::p3_field::extension::BinomialExtensionField; +use openvm_stark_sdk::p3_baby_bear::BabyBear; use serde::Deserialize; #[derive(DslVariable, Clone)] @@ -100,4 +100,4 @@ impl Hintable for IOPProverMessage { stream } } -impl VecAutoHintable for IOPProverMessage {} \ No newline at end of file +impl VecAutoHintable for IOPProverMessage {} diff --git a/src/tower_verifier/program.rs b/src/tower_verifier/program.rs index 429335e..c5f08a8 100644 --- a/src/tower_verifier/program.rs +++ b/src/tower_verifier/program.rs @@ -1,8 +1,7 @@ use super::binding::{IOPProverMessageVariable, PointAndEvalVariable, PointVariable}; use crate::arithmetics::{ - challenger_multi_observe, eq_eval, evaluate_at_point_degree_1, extend, - exts_to_felts, fixed_dot_product, reverse, - UniPolyExtrapolator, + challenger_multi_observe, eq_eval, evaluate_at_point_degree_1, extend, exts_to_felts, + fixed_dot_product, reverse, UniPolyExtrapolator, }; use crate::transcript::transcript_observe_label; use crate::zkvm_verifier::binding::TowerProofInputVariable; @@ -328,9 +327,7 @@ pub fn verify_tower_proof( let round: Felt = builder.constant(C::F::ZERO); let next_rt = PointAndEvalVariable { - point: PointVariable { - fs: initial_rt, - }, + point: PointVariable { fs: initial_rt }, eval: initial_claim, }; diff --git a/src/transcript/mod.rs b/src/transcript/mod.rs index fe8256f..0d8792c 100644 --- a/src/transcript/mod.rs +++ b/src/transcript/mod.rs @@ -1,7 +1,7 @@ use ff_ext::{BabyBearExt4, ExtensionField as CenoExtensionField, SmallField}; use openvm_native_compiler::prelude::*; -use openvm_native_recursion::challenger::{duplex::DuplexChallengerVariable, CanObserveVariable}; use openvm_native_recursion::challenger::CanSampleBitsVariable; +use openvm_native_recursion::challenger::{duplex::DuplexChallengerVariable, CanObserveVariable}; use openvm_stark_backend::p3_field::FieldAlgebra; pub fn transcript_observe_label( diff --git a/src/zkvm_verifier/binding.rs b/src/zkvm_verifier/binding.rs index 8f80162..fdf7b72 100644 --- a/src/zkvm_verifier/binding.rs +++ b/src/zkvm_verifier/binding.rs @@ -4,7 +4,7 @@ use crate::basefold_verifier::basefold::{ }; use crate::{ arithmetics::ceil_log2, - tower_verifier::binding::{PointVariable, IOPProverMessage, IOPProverMessageVariable}, + tower_verifier::binding::{IOPProverMessage, IOPProverMessageVariable, PointVariable}, }; use itertools::Itertools; use openvm_native_compiler::{ @@ -14,8 +14,8 @@ use openvm_native_compiler::{ }; use openvm_native_compiler_derive::iter_zip; use openvm_native_recursion::hints::{Hintable, VecAutoHintable}; +use openvm_stark_backend::p3_field::{extension::BinomialExtensionField, FieldAlgebra}; use openvm_stark_sdk::p3_baby_bear::BabyBear; -use openvm_stark_backend::p3_field::{FieldAlgebra, extension::BinomialExtensionField}; pub type F = BabyBear; pub type E = BinomialExtensionField; @@ -390,7 +390,7 @@ impl Hintable for SumcheckLayerProofInput { let proof = Vec::::read(builder); let evals = Vec::::read(builder); let evals_len_div_3 = usize::read(builder); - + Self::HintVariable { proof, evals, @@ -467,7 +467,9 @@ impl Hintable for GKRProofInput { } fn write(&self) -> Vec::N>> { let mut stream = Vec::new(); - stream.extend(>::write(&self.num_var_with_rotation)); + stream.extend(>::write( + &self.num_var_with_rotation, + )); let eq_instance = self.num_instances - 1; let mut bit_decomp: Vec = vec![]; @@ -502,4 +504,4 @@ pub struct GKRClaimEvaluation { pub value: Ext, pub point: PointVariable, pub poly: Usize, -} \ No newline at end of file +} diff --git a/src/zkvm_verifier/verifier.rs b/src/zkvm_verifier/verifier.rs index 1156ff1..2a9286b 100644 --- a/src/zkvm_verifier/verifier.rs +++ b/src/zkvm_verifier/verifier.rs @@ -1,6 +1,10 @@ -use super::binding::{ZKVMChipProofInputVariable, ZKVMProofInputVariable, ClaimAndPoint, RotationClaim,GKRClaimEvaluation}; +use super::binding::{ + ClaimAndPoint, GKRClaimEvaluation, RotationClaim, ZKVMChipProofInputVariable, + ZKVMProofInputVariable, +}; use crate::arithmetics::{ - challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, PolyEvaluator, UniPolyExtrapolator + challenger_multi_observe, eq_eval, eval_ceno_expr_with_instance, PolyEvaluator, + UniPolyExtrapolator, }; use crate::basefold_verifier::basefold::{ BasefoldCommitmentVariable, RoundOpeningVariable, RoundVariable, @@ -11,40 +15,41 @@ use crate::basefold_verifier::utils::pow_2; // use crate::basefold_verifier::verifier::batch_verify; use crate::tower_verifier::program::verify_tower_proof; use crate::transcript::transcript_observe_label; -use crate::zkvm_verifier::binding::{GKRProofVariable, LayerProofVariable, SumcheckLayerProofVariable}; +use crate::zkvm_verifier::binding::{ + GKRProofVariable, LayerProofVariable, SumcheckLayerProofVariable, +}; use crate::{ arithmetics::{ build_eq_x_r_vec_sequential, ceil_log2, concat, dot_product as ext_dot_product, eq_eval_less_or_equal_than, eval_wellform_address_vec, gen_alpha_pows, max_usize_arr, max_usize_vec, nested_product, }, - tower_verifier::{binding::{PointVariable, PointAndEvalVariable}, program::iop_verifier_state_verify}, + tower_verifier::{ + binding::{PointAndEvalVariable, PointVariable}, + program::iop_verifier_state_verify, + }, }; +use ceno_mle::expression::{Expression, Instance, StructuralWitIn}; use ceno_zkvm::structs::VerifyingKey; -use ceno_mle::{ - expression::{Expression, StructuralWitIn, Instance}, +use ceno_zkvm::{ + circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier, structs::ComposedConstrainSystem, }; -use ceno_zkvm::{circuit_builder::SetTableSpec, scheme::verifier::ZKVMVerifier, structs::ComposedConstrainSystem}; use ff_ext::BabyBearExt4; use gkr_iop::gkr::layer::ROTATION_OPENING_COUNT; use gkr_iop::{ - gkr::{ - layer::Layer, - GKRCircuit, - booleanhypercube::BooleanHypercube, - }, - selector::SelectorType, evaluation::EvalExpression, + gkr::{booleanhypercube::BooleanHypercube, layer::Layer, GKRCircuit}, + selector::SelectorType, }; -use itertools::{interleave, Itertools, izip}; +use itertools::{interleave, izip, Itertools}; use mpcs::{Basefold, BasefoldRSParams}; use openvm_native_compiler::prelude::*; use openvm_native_compiler_derive::iter_zip; use openvm_native_recursion::challenger::{ duplex::DuplexChallengerVariable, CanObserveVariable, FeltChallenger, }; -use p3_baby_bear::BabyBear; use openvm_stark_backend::p3_field::FieldAlgebra; +use p3_baby_bear::BabyBear; type F = BabyBear; type E = BabyBearExt4; @@ -219,11 +224,26 @@ pub fn verify_zkvm_proof>( builder.get(&zkvm_proof_input.chip_proofs, num_chips_verified.get_var()); let circuit_vk = &vk.vk.circuit_vks[circuit_name]; - builder.assert_usize_eq(chip_proof.wits_in_evals.len(), Usize::from(circuit_vk.get_cs().num_witin())); - builder.assert_usize_eq(chip_proof.fixed_in_evals.len(), Usize::from(circuit_vk.get_cs().num_fixed())); - builder.assert_usize_eq(chip_proof.record_r_out_evals.len(), Usize::from(circuit_vk.get_cs().num_reads())); - builder.assert_usize_eq(chip_proof.record_w_out_evals.len(), Usize::from(circuit_vk.get_cs().num_writes())); - builder.assert_usize_eq(chip_proof.record_lk_out_evals.len(), Usize::from(circuit_vk.get_cs().num_lks())); + builder.assert_usize_eq( + chip_proof.wits_in_evals.len(), + Usize::from(circuit_vk.get_cs().num_witin()), + ); + builder.assert_usize_eq( + chip_proof.fixed_in_evals.len(), + Usize::from(circuit_vk.get_cs().num_fixed()), + ); + builder.assert_usize_eq( + chip_proof.record_r_out_evals.len(), + Usize::from(circuit_vk.get_cs().num_reads()), + ); + builder.assert_usize_eq( + chip_proof.record_w_out_evals.len(), + Usize::from(circuit_vk.get_cs().num_writes()), + ); + builder.assert_usize_eq( + chip_proof.record_lk_out_evals.len(), + Usize::from(circuit_vk.get_cs().num_lks()), + ); let chip_logup_sum: Ext = builder.constant(C::EF::ZERO); iter_zip!(builder, chip_proof.record_lk_out_evals).for_each(|ptr_vec, builder| { @@ -419,11 +439,19 @@ pub fn verify_opcode_proof( let log2_num_instances = opcode_proof.log2_num_instances.clone(); let num_var_with_rotation: Usize = Usize::Var(Var::uninit(builder)); - builder.if_eq(opcode_proof.has_gkr_proof.clone(), Usize::from(1)).then_or_else(|builder| { - builder.assign(&num_var_with_rotation, opcode_proof.gkr_iop_proof.num_var_with_rotation.clone()); - }, |builder| { - builder.assign(&num_var_with_rotation, log2_num_instances.clone()); - }); + builder + .if_eq(opcode_proof.has_gkr_proof.clone(), Usize::from(1)) + .then_or_else( + |builder| { + builder.assign( + &num_var_with_rotation, + opcode_proof.gkr_iop_proof.num_var_with_rotation.clone(), + ); + }, + |builder| { + builder.assign(&num_var_with_rotation, log2_num_instances.clone()); + }, + ); let tower_proof = &opcode_proof.tower_proof; @@ -475,15 +503,19 @@ pub fn verify_opcode_proof( let out_evals_len: Usize = builder.eval(record_evals.len() + logup_q_evals.len()); let out_evals: Array> = builder.dyn_array(out_evals_len.clone()); - builder.range(0, record_evals.len()).for_each(|idx_vec, builder| { - let cpt = builder.get(&record_evals, idx_vec[0]); - builder.set(&out_evals, idx_vec[0], cpt); - }); + builder + .range(0, record_evals.len()) + .for_each(|idx_vec, builder| { + let cpt = builder.get(&record_evals, idx_vec[0]); + builder.set(&out_evals, idx_vec[0], cpt); + }); let q_slice = out_evals.slice(builder, record_evals.len(), out_evals_len); - builder.range(0, logup_q_evals.len()).for_each(|idx_vec, builder| { - let cpt = builder.get(&logup_q_evals, idx_vec[0]); - builder.set(&q_slice, idx_vec[0], cpt); - }); + builder + .range(0, logup_q_evals.len()) + .for_each(|idx_vec, builder| { + let cpt = builder.get(&logup_q_evals, idx_vec[0]); + builder.set(&q_slice, idx_vec[0], cpt); + }); let opening_evaluations = verify_gkr_circuit( builder, @@ -494,7 +526,7 @@ pub fn verify_opcode_proof( pi_evals, &out_evals, opcode_proof, - unipoly_extrapolator + unipoly_extrapolator, ); opening_evaluations[0].point.fs.clone() @@ -513,23 +545,31 @@ pub fn verify_gkr_circuit( ) -> Vec> { for (i, layer) in gkr_circuit.layers.iter().enumerate() { let layer_proof = builder.get(&gkr_proof.layer_proofs, i); - let layer_challenges: Array> = generate_layer_challenges(builder, challenger, &challenges, layer.n_challenges); - let eval_and_dedup_points: Array> = extract_claim_and_point(builder, layer, &claims, &layer_challenges, &layer_proof.has_rotation); + let layer_challenges: Array> = + generate_layer_challenges(builder, challenger, &challenges, layer.n_challenges); + let eval_and_dedup_points: Array> = extract_claim_and_point( + builder, + layer, + &claims, + &layer_challenges, + &layer_proof.has_rotation, + ); // ZeroCheckLayer verification (might include other layer types in the future) let LayerProofVariable { - main: SumcheckLayerProofVariable { - proof, - evals: main_evals, - evals_len_div_3: _main_evals_len_div_3, - }, + main: + SumcheckLayerProofVariable { + proof, + evals: main_evals, + evals_len_div_3: _main_evals_len_div_3, + }, rotation: rotation_proof, has_rotation, } = layer_proof; builder.if_eq(has_rotation, Usize::from(1)).then(|builder| { let first = builder.get(&eval_and_dedup_points, 0); - builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point + builder.assert_usize_eq(first.has_point, Usize::from(1)); // Rotation proof should have at least one point let rt = first.point.fs.clone(); let RotationClaim { @@ -538,7 +578,7 @@ pub fn verify_gkr_circuit( target_evals, left_point, right_point, - origin_point + origin_point, } = verify_rotation( builder, gkr_proof.num_var_with_rotation.clone(), @@ -554,59 +594,67 @@ pub fn verify_gkr_circuit( builder.set( &eval_and_dedup_points, last_idx.clone(), - ClaimAndPoint{ + ClaimAndPoint { evals: target_evals, has_point: Usize::from(1), - point: PointVariable { fs: origin_point } - } + point: PointVariable { fs: origin_point }, + }, ); builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); builder.set( &eval_and_dedup_points, last_idx.clone(), - ClaimAndPoint{ + ClaimAndPoint { evals: right_evals, has_point: Usize::from(1), - point: PointVariable { fs: right_point } - } + point: PointVariable { fs: right_point }, + }, ); builder.assign(&last_idx, last_idx.clone() - Usize::from(1)); builder.set( - &eval_and_dedup_points, - last_idx.clone(), - ClaimAndPoint{ + &eval_and_dedup_points, + last_idx.clone(), + ClaimAndPoint { evals: left_evals, has_point: Usize::from(1), - point: PointVariable { fs: left_point } - } + point: PointVariable { fs: left_point }, + }, ); }); let rotation_exprs_len = layer.rotation_exprs.1.len(); transcript_observe_label(builder, challenger, b"combine subset evals"); - let alpha_pows = gen_alpha_pows(builder, challenger, Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT)); + let alpha_pows = gen_alpha_pows( + builder, + challenger, + Usize::from(layer.exprs.len() + rotation_exprs_len * ROTATION_OPENING_COUNT), + ); let sigma: Ext = builder.constant(C::EF::ZERO); let alpha_idx: Usize = Usize::Var(Var::uninit(builder)); builder.assign(&alpha_idx, C::N::from_canonical_usize(0)); - - builder.range(0, eval_and_dedup_points.len()).for_each(|idx_vec, builder| { - let ClaimAndPoint { - evals, - has_point: _, - point: _, - } = builder.get(&eval_and_dedup_points, idx_vec[0]); - let end_idx: Usize = builder.eval(alpha_idx.clone() + evals.len()); - let alpha_slice: Array::F, ::EF>> = alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); - - let sub_sum = ext_dot_product(builder, &evals, &alpha_slice); - builder.assign(&sigma, sigma.clone() + sub_sum); - builder.assign(&alpha_idx, end_idx); - }); + + builder + .range(0, eval_and_dedup_points.len()) + .for_each(|idx_vec, builder| { + let ClaimAndPoint { + evals, + has_point: _, + point: _, + } = builder.get(&eval_and_dedup_points, idx_vec[0]); + let end_idx: Usize = builder.eval(alpha_idx.clone() + evals.len()); + let alpha_slice: Array::F, ::EF>> = + alpha_pows.slice(builder, alpha_idx.clone(), end_idx.clone()); + + let sub_sum = ext_dot_product(builder, &evals, &alpha_slice); + builder.assign(&sigma, sigma.clone() + sub_sum); + builder.assign(&alpha_idx, end_idx); + }); let max_degree = builder.constant(C::F::from_canonical_usize(layer.max_expr_degree + 1)); - let max_num_variables = builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation.get_var()); + let max_num_variables = + builder.unsafe_cast_var_to_felt(gkr_proof.num_var_with_rotation.get_var()); let (in_point, expected_evaluation) = iop_verifier_state_verify( builder, @@ -615,33 +663,42 @@ pub fn verify_gkr_circuit( &proof, max_num_variables, max_degree, - unipoly_extrapolator + unipoly_extrapolator, ); - layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(idx, (sel_type, _))| { - let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; - evaluate_selector( - builder, - sel_type, - &main_evals, - &out_point, - &in_point, - opcode_proof, - layer.n_witin, - ); - }); + layer + .out_sel_and_eval_exprs + .iter() + .enumerate() + .for_each(|(idx, (sel_type, _))| { + let out_point = builder.get(&eval_and_dedup_points, idx).point.fs; + evaluate_selector( + builder, + sel_type, + &main_evals, + &out_point, + &in_point, + opcode_proof, + layer.n_witin, + ); + }); - let main_sumcheck_challenges_len: Usize = builder.eval(alpha_pows.len() + Usize::from(2)); - let main_sumcheck_challenges: Array> = builder.dyn_array(main_sumcheck_challenges_len.clone()); + let main_sumcheck_challenges_len: Usize = + builder.eval(alpha_pows.len() + Usize::from(2)); + let main_sumcheck_challenges: Array> = + builder.dyn_array(main_sumcheck_challenges_len.clone()); let alpha = builder.get(&challenges, 0); let beta = builder.get(&challenges, 1); builder.set(&main_sumcheck_challenges, 0, alpha); builder.set(&main_sumcheck_challenges, 1, beta); - let challenge_slice = main_sumcheck_challenges.slice(builder, 2, main_sumcheck_challenges_len); - builder.range(0, alpha_pows.len()).for_each(|idx_vec, builder| { - let alpha = builder.get(&alpha_pows, idx_vec[0]); - builder.set(&challenge_slice, idx_vec[0], alpha); - }); + let challenge_slice = + main_sumcheck_challenges.slice(builder, 2, main_sumcheck_challenges_len); + builder + .range(0, alpha_pows.len()) + .for_each(|idx_vec, builder| { + let alpha = builder.get(&alpha_pows, idx_vec[0]); + builder.set(&challenge_slice, idx_vec[0], alpha); + }); let empty_arr: Array> = builder.dyn_array(0); let got_claim = eval_ceno_expr_with_instance( @@ -657,15 +714,23 @@ pub fn verify_gkr_circuit( builder.assert_ext_eq(got_claim, expected_evaluation); // Update claim - layer.in_eval_expr.iter().enumerate().for_each(|(idx, pos)| { - let val = builder.get(&main_evals, idx); - builder.set(&claims, *pos, PointAndEvalVariable { - point: PointVariable { - fs: in_point.clone() - }, - eval: val, + layer + .in_eval_expr + .iter() + .enumerate() + .for_each(|(idx, pos)| { + let val = builder.get(&main_evals, idx); + builder.set( + &claims, + *pos, + PointAndEvalVariable { + point: PointVariable { + fs: in_point.clone(), + }, + eval: val, + }, + ); }); - }); } // GKR Claim @@ -696,10 +761,10 @@ pub fn verify_rotation( challenger: &mut DuplexChallengerVariable, unipoly_extrapolator: &mut UniPolyExtrapolator, ) -> RotationClaim { - let SumcheckLayerProofVariable { - proof, - evals, - evals_len_div_3: rotation_expr_len, + let SumcheckLayerProofVariable { + proof, + evals, + evals_len_div_3: rotation_expr_len, } = rotation_proof; let rotation_expr_len = Usize::Var(rotation_expr_len.clone()); @@ -717,7 +782,7 @@ pub fn verify_rotation( proof, max_num_variables, max_degree, - unipoly_extrapolator + unipoly_extrapolator, ); // compute the selector evaluation @@ -728,7 +793,7 @@ pub fn verify_rotation( rotation_cyclic_subgroup_size, rotation_cyclic_group_log2, ); - + // check the final evaluations. let left_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); let right_evals: Array> = builder.dyn_array(rotation_expr_len.clone()); @@ -742,36 +807,42 @@ pub fn verify_rotation( one.clone() }; - builder.range(0, rotation_alpha_pows.len()).for_each(|idx_vec, builder| { - let alpha = builder.get(&rotation_alpha_pows, idx_vec[0]); + builder + .range(0, rotation_alpha_pows.len()) + .for_each(|idx_vec, builder| { + let alpha = builder.get(&rotation_alpha_pows, idx_vec[0]); - let rvar3 = RVar::from(3); - let left_idx: Var = builder.eval(idx_vec[0] * rvar3); - let right_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(1)); - let target_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(2)); + let rvar3 = RVar::from(3); + let left_idx: Var = builder.eval(idx_vec[0] * rvar3); + let right_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(1)); + let target_idx: Var = builder.eval(idx_vec[0] * rvar3 + RVar::from(2)); - let left = builder.get(&evals, left_idx); - let right = builder.get(&evals, right_idx); - let target = builder.get(&evals, target_idx); + let left = builder.get(&evals, left_idx); + let right = builder.get(&evals, right_idx); + let target = builder.get(&evals, target_idx); - builder.set(&left_evals, idx_vec[0], left); - builder.set(&right_evals, idx_vec[0], right); - builder.set(&target_evals, idx_vec[0], target); + builder.set(&left_evals, idx_vec[0], left); + builder.set(&right_evals, idx_vec[0], right); + builder.set(&target_evals, idx_vec[0], target); - builder.assign(&got_claim, got_claim + alpha * ((one - last_origin) * left + last_origin * right - target)); - }); + builder.assign( + &got_claim, + got_claim + alpha * ((one - last_origin) * left + last_origin * right - target), + ); + }); builder.assign(&got_claim, got_claim * selector_eval); builder.assert_ext_eq(got_claim, expected_evaluation); - - let (left_point, right_point) = get_rotation_points(builder, rotation_cyclic_group_log2, &origin_point); - - RotationClaim { + + let (left_point, right_point) = + get_rotation_points(builder, rotation_cyclic_group_log2, &origin_point); + + RotationClaim { left_evals, right_evals, target_evals, left_point, right_point, - origin_point + origin_point, } } @@ -787,8 +858,11 @@ pub fn rotation_selector_eval( ) -> Ext { let bh = BooleanHypercube::new(5); let eval: Ext = builder.constant(C::EF::ZERO); - let rotation_index = bh.into_iter().take(rotation_cyclic_subgroup_size).collect_vec(); - + let rotation_index = bh + .into_iter() + .take(rotation_cyclic_subgroup_size) + .collect_vec(); + let out_subgroup = out_point.slice(builder, 0, cyclic_group_log2_size); let in_subgroup = in_point.slice(builder, 0, cyclic_group_log2_size); let out_subgroup_eq = build_eq_x_r_vec_sequential(builder, &out_subgroup); @@ -828,17 +902,10 @@ pub fn evaluate_selector( let zero = builder.constant(C::EF::ZERO); (expr, eq_eval(builder, out_point, in_point, one, zero)) } - SelectorType::Prefix(_, expr) => { - ( - expr, - eq_eval_less_or_equal_than( - builder, - opcode_proof, - out_point, - in_point - ) - ) - } + SelectorType::Prefix(_, expr) => ( + expr, + eq_eval_less_or_equal_than(builder, opcode_proof, out_point, in_point), + ), SelectorType::OrderedSparse32 { indices, expression, @@ -858,7 +925,12 @@ pub fn evaluate_selector( let out_point_slice = out_point.slice(builder, 5, out_point.len()); let in_point_slice = in_point.slice(builder, 5, in_point.len()); - let sel = eq_eval_less_or_equal_than(builder, opcode_proof, &out_point_slice, &in_point_slice); + let sel = eq_eval_less_or_equal_than( + builder, + opcode_proof, + &out_point_slice, + &in_point_slice, + ); builder.assign(&eval, eval * sel); (expression, eval) @@ -876,10 +948,7 @@ pub fn get_rotation_points( builder: &mut Builder, _num_vars: usize, point: &Array>, -) -> ( - Array>, - Array>, -) { +) -> (Array>, Array>) { let left: Array> = builder.dyn_array(point.len()); let right: Array> = builder.dyn_array(point.len()); builder.range(0, 4).for_each(|idx_vec, builder| { @@ -915,9 +984,7 @@ pub fn evaluate_gkr_expression( let eval: Ext = builder.constant(C::EF::ZERO); PointAndEvalVariable { point, eval } } - EvalExpression::Single(i) => { - builder.get(claims, *i).clone() - }, + EvalExpression::Single(i) => builder.get(claims, *i).clone(), EvalExpression::Linear(i, c0, c1) => { let point = builder.get(claims, *i); @@ -925,19 +992,27 @@ pub fn evaluate_gkr_expression( let point = point.point.clone(); let empty_arr: Array> = builder.dyn_array(0); - let c0_eval = eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c0); - let c1_eval = eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c1); + let c0_eval = eval_ceno_expr_with_instance( + builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c0, + ); + let c1_eval = eval_ceno_expr_with_instance( + builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c1, + ); builder.assign(&eval, eval * c0_eval + c1_eval); PointAndEvalVariable { point, eval } - }, + } EvalExpression::Partition(parts, indices) => { assert!(izip!(indices.iter(), indices.iter().skip(1)).all(|(a, b)| a.0 < b.0)); let empty_arr: Array> = builder.dyn_array(0); let vars = indices .iter() - .map(|(_, c)| eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c)) + .map(|(_, c)| { + eval_ceno_expr_with_instance( + builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c, + ) + }) .collect_vec(); let vars_arr: Array> = builder.dyn_array(vars.len()); for (i, e) in vars.iter().enumerate() { @@ -954,12 +1029,16 @@ pub fn evaluate_gkr_expression( // assert!(parts.iter().all(|part| part.point == parts[0].point)); let mut new_point: Vec> = vec![]; - builder.range(0, parts[0].point.fs.len()).for_each(|idx_vec, builder| { - let e = builder.get(&parts[0].point.fs, idx_vec[0]); - new_point.push(e); - }); + builder + .range(0, parts[0].point.fs.len()) + .for_each(|idx_vec, builder| { + let e = builder.get(&parts[0].point.fs, idx_vec[0]); + new_point.push(e); + }); for (index_in_point, c) in indices { - let eval = eval_ceno_expr_with_instance(builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c); + let eval = eval_ceno_expr_with_instance( + builder, &empty_arr, &empty_arr, &empty_arr, &empty_arr, challenges, c, + ); new_point.insert(*index_in_point, eval); } @@ -981,8 +1060,8 @@ pub fn evaluate_gkr_expression( builder.assign(&acc, acc + prt.eval * eq_v); }); - PointAndEvalVariable { - point: PointVariable { fs: new_point_arr }, + PointAndEvalVariable { + point: PointVariable { fs: new_point_arr }, eval: acc, } } @@ -997,44 +1076,59 @@ pub fn extract_claim_and_point( has_rotation: &Usize, ) -> Array> { let r_len: Usize = Usize::Var(Var::uninit(builder)); - builder.assign(&r_len, has_rotation.clone() * Usize::from(3) + Usize::from(layer.out_sel_and_eval_exprs.len())); + builder.assign( + &r_len, + has_rotation.clone() * Usize::from(3) + Usize::from(layer.out_sel_and_eval_exprs.len()), + ); let r = builder.dyn_array(r_len); - layer.out_sel_and_eval_exprs.iter().enumerate().for_each(|(i, (_, out_evals))| { - let evals = out_evals - .iter() - .map(|out_eval| { + layer + .out_sel_and_eval_exprs + .iter() + .enumerate() + .for_each(|(i, (_, out_evals))| { + let evals = out_evals + .iter() + .map(|out_eval| { + let r = evaluate_gkr_expression(builder, out_eval, claims, challenges); + r.eval + }) + .collect_vec(); + let evals_arr: Array> = builder.dyn_array(evals.len()); + for (j, e) in evals.iter().enumerate() { + builder.set(&evals_arr, j, *e); + } + let point = out_evals.first().map(|out_eval| { let r = evaluate_gkr_expression(builder, out_eval, claims, challenges); - r.eval - }) - .collect_vec(); - let evals_arr: Array> = builder.dyn_array(evals.len()); - for (j, e) in evals.iter().enumerate() { - builder.set(&evals_arr, j, *e); - } - let point = out_evals.first().map(|out_eval| { - let r = evaluate_gkr_expression(builder, out_eval, claims, challenges); - r.point - }); - - if point.is_some() { - builder.set(&r, i, - ClaimAndPoint { - evals: evals_arr, - has_point: Usize::from(1), - point: point.unwrap(), - }); - } else { - let pt = PointVariable { fs: builder.dyn_array(0) }; - builder.set(&r, i, - ClaimAndPoint { - evals: evals_arr, - has_point: Usize::from(0), - point: pt, + r.point }); - } - }); + + if point.is_some() { + builder.set( + &r, + i, + ClaimAndPoint { + evals: evals_arr, + has_point: Usize::from(1), + point: point.unwrap(), + }, + ); + } else { + let pt = PointVariable { + fs: builder.dyn_array(0), + }; + builder.set( + &r, + i, + ClaimAndPoint { + evals: evals_arr, + has_point: Usize::from(0), + point: pt, + }, + ); + } + }); r } @@ -1285,12 +1379,16 @@ pub fn verify_table_proof( challenges, expr, ) - }).collect_vec(); + }) + .collect_vec(); let expected_evals: Array> = builder.dyn_array(expected_evals_vec.len()); - expected_evals_vec.into_iter().enumerate().for_each(|(idx, e)| { - builder.set(&expected_evals, idx, e); - }); + expected_evals_vec + .into_iter() + .enumerate() + .for_each(|(idx, e)| { + builder.set(&expected_evals, idx, e); + }); iter_zip!(builder, in_evals, expected_evals).for_each(|ptr_vec, builder| { let eval = builder.iter_ptr_get(&in_evals, ptr_vec[0]); @@ -1311,4 +1409,3 @@ pub fn verify_table_proof( rt_tower.fs } - From 5e0bc367be4eeef34529748e0bc16e81d53ef2ed Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Sun, 17 Aug 2025 18:58:35 -0400 Subject: [PATCH 23/24] Switch to main --- Cargo.lock | 36 ++++++++++++++++++------------------ Cargo.toml | 12 ++++++------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4dc749..cb1fd23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1949,7 +1949,7 @@ checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "openvm" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "bytemuck", "num-bigint 0.4.6", @@ -1962,7 +1962,7 @@ dependencies = [ [[package]] name = "openvm-circuit" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "backtrace", "cfg-if", @@ -1993,7 +1993,7 @@ dependencies = [ [[package]] name = "openvm-circuit-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "itertools 0.14.0", "quote", @@ -2003,7 +2003,7 @@ dependencies = [ [[package]] name = "openvm-circuit-primitives" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "derive-new 0.6.0", "itertools 0.14.0", @@ -2018,7 +2018,7 @@ dependencies = [ [[package]] name = "openvm-circuit-primitives-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "itertools 0.14.0", "quote", @@ -2028,7 +2028,7 @@ dependencies = [ [[package]] name = "openvm-custom-insn" version = "0.1.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "proc-macro2", "quote", @@ -2038,7 +2038,7 @@ dependencies = [ [[package]] name = "openvm-instructions" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "backtrace", "derive-new 0.6.0", @@ -2055,7 +2055,7 @@ dependencies = [ [[package]] name = "openvm-instructions-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "quote", "syn 2.0.105", @@ -2064,7 +2064,7 @@ dependencies = [ [[package]] name = "openvm-native-circuit" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "derive-new 0.6.0", "derive_more 1.0.0", @@ -2091,7 +2091,7 @@ dependencies = [ [[package]] name = "openvm-native-compiler" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "backtrace", "itertools 0.14.0", @@ -2113,7 +2113,7 @@ dependencies = [ [[package]] name = "openvm-native-compiler-derive" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "quote", "syn 2.0.105", @@ -2122,7 +2122,7 @@ dependencies = [ [[package]] name = "openvm-native-recursion" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "cfg-if", "itertools 0.14.0", @@ -2146,7 +2146,7 @@ dependencies = [ [[package]] name = "openvm-platform" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "libm", "openvm-custom-insn", @@ -2156,7 +2156,7 @@ dependencies = [ [[package]] name = "openvm-poseidon2-air" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "derivative", "lazy_static", @@ -2173,7 +2173,7 @@ dependencies = [ [[package]] name = "openvm-rv32im-circuit" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "derive-new 0.6.0", "derive_more 1.0.0", @@ -2196,7 +2196,7 @@ dependencies = [ [[package]] name = "openvm-rv32im-guest" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "openvm-custom-insn", "p3-field", @@ -2206,7 +2206,7 @@ dependencies = [ [[package]] name = "openvm-rv32im-transpiler" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "openvm-instructions", "openvm-instructions-derive", @@ -2283,7 +2283,7 @@ dependencies = [ [[package]] name = "openvm-transpiler" version = "1.3.0" -source = "git+https://github.com/scroll-tech/openvm.git?branch=debug%2Fmulti_observe#ad05d58d8b79a9cba79504e4ba4ac527ffaea62f" +source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "elf", "eyre", diff --git a/Cargo.toml b/Cargo.toml index 78d4c37..647c29d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,12 @@ version = "0.1.0" edition = "2021" [dependencies] -openvm = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } -openvm-circuit = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false, features = ["bench-metrics"] } -openvm-native-circuit = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } -openvm-native-compiler = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } -openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } -openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", branch = "debug/multi_observe", default-features = false } +openvm = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-circuit = { git = "https://github.com/scroll-tech/openvm.git", default-features = false, features = ["bench-metrics"] } +openvm-native-circuit = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-native-compiler = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-native-compiler-derive = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } +openvm-native-recursion = { git = "https://github.com/scroll-tech/openvm.git", default-features = false } openvm-stark-backend = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1", default-features = false } openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1", default-features = false } From 4122de70225e21e5354504dc2d76589cd89f4b8d Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Sun, 17 Aug 2025 18:58:56 -0400 Subject: [PATCH 24/24] Update git lock --- Cargo.lock | 82 +++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb1fd23..a09d24d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" dependencies = [ "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -220,7 +220,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -270,7 +270,7 @@ checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -369,7 +369,7 @@ checksum = "ffebfc2d28a12b262c303cb3860ee77b91bd83b1f20f0bd2a9693008e2f55a9e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -390,9 +390,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" [[package]] name = "bitvec" @@ -487,7 +487,7 @@ checksum = "efb7846e0cb180355c2dec69e721edafa36919850f1a9f52ffba4ebc0393cb71" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -516,9 +516,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.32" +version = "1.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" +checksum = "3ee0f8803222ba5a7e2777dd72ca451868909b1ac410621b676adf07280e9b5f" dependencies = [ "shlex", ] @@ -740,7 +740,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -911,7 +911,7 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -922,7 +922,7 @@ checksum = "2cdc8d50f426189eef89dac62fabfa0abb27d5cc008f25bf4156a0203325becc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -935,7 +935,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -955,7 +955,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", "unicode-xid", ] @@ -1006,7 +1006,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -1053,7 +1053,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -1065,7 +1065,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -1220,7 +1220,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -1779,7 +1779,7 @@ checksum = "f2e3795a5d2da581a8b252fec6022eee01aea10161a4d1bf237d4cbe47f7e988" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -1855,7 +1855,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -1997,7 +1997,7 @@ source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe95024 dependencies = [ "itertools 0.14.0", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2022,7 +2022,7 @@ source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe95024 dependencies = [ "itertools 0.14.0", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2032,7 +2032,7 @@ source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe95024 dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2058,7 +2058,7 @@ version = "1.3.0" source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2116,7 +2116,7 @@ version = "1.3.0" source = "git+https://github.com/scroll-tech/openvm.git#9b7591dce3c0afc1dbe9502499cd670e864e47a6" dependencies = [ "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2831,14 +2831,14 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] name = "proc-macro2" -version = "1.0.97" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] @@ -2860,7 +2860,7 @@ checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3075,7 +3075,7 @@ checksum = "4270433626cffc9c4c1d3707dd681f2a2718d3d7b09ad754bec137acecda8d22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3233,7 +3233,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3354,7 +3354,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3405,7 +3405,7 @@ dependencies = [ "proc-macro2", "quote", "rand", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3421,9 +3421,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.105" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -3477,7 +3477,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3614,7 +3614,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -3801,7 +3801,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", "wasm-bindgen-shared", ] @@ -3823,7 +3823,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4130,7 +4130,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -4150,7 +4150,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]]