From 5cc69590230ec0eedc7be64273d2f454d394a7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Tue, 10 Dec 2024 09:19:07 +0800 Subject: [PATCH 1/3] Simplify SLTI tests (#710) Extracted from https://github.com/scroll-tech/ceno/pull/667 to make that PR smaller and easier to review. --- ceno_zkvm/src/instructions/riscv/slti.rs | 79 +++++++++++++----------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/ceno_zkvm/src/instructions/riscv/slti.rs b/ceno_zkvm/src/instructions/riscv/slti.rs index d88f0336c..76894f7a0 100644 --- a/ceno_zkvm/src/instructions/riscv/slti.rs +++ b/ceno_zkvm/src/instructions/riscv/slti.rs @@ -150,29 +150,31 @@ mod test { #[test] fn test_sltiu_true() { - verify::("lt = true, 0 < 1", 0, 1, 1); - verify::("lt = true, 1 < 2", 1, 2, 1); - verify::("lt = true, 10 < 20", 10, 20, 1); - verify::("lt = true, 0 < imm upper boundary", 0, 2047, 1); + let verify = |name, a, imm| verify::(name, a, imm, true); + verify("lt = true, 0 < 1", 0, 1); + verify("lt = true, 1 < 2", 1, 2); + verify("lt = true, 10 < 20", 10, 20); + verify("lt = true, 0 < imm upper boundary", 0, 2047); // negative imm is treated as positive - verify::("lt = true, 0 < u32::MAX-1", 0, -1, 1); - verify::("lt = true, 1 < u32::MAX-1", 1, -1, 1); - verify::("lt = true, 0 < imm lower bondary", 0, -2048, 1); + verify("lt = true, 0 < u32::MAX-1", 0, -1); + verify("lt = true, 1 < u32::MAX-1", 1, -1); + verify("lt = true, 0 < imm lower bondary", 0, -2048); } #[test] fn test_sltiu_false() { - verify::("lt = false, 1 < 0", 1, 0, 0); - verify::("lt = false, 2 < 1", 2, 1, 0); - verify::("lt = false, 100 < 50", 100, 50, 0); - verify::("lt = false, 500 < 100", 500, 100, 0); - verify::("lt = false, 100000 < 2047", 100000, 2047, 0); - verify::("lt = false, 100000 < 0", 100000, 0, 0); - verify::("lt = false, 0 == 0", 0, 0, 0); - verify::("lt = false, 1 == 1", 1, 1, 0); - verify::("lt = false, imm upper bondary", u32::MAX, 2047, 0); + let verify = |name, a, imm| verify::(name, a, imm, false); + verify("lt = false, 1 < 0", 1, 0); + verify("lt = false, 2 < 1", 2, 1); + verify("lt = false, 100 < 50", 100, 50); + verify("lt = false, 500 < 100", 500, 100); + verify("lt = false, 100000 < 2047", 100000, 2047); + verify("lt = false, 100000 < 0", 100000, 0); + verify("lt = false, 0 == 0", 0, 0); + verify("lt = false, 1 == 1", 1, 1); + verify("lt = false, imm upper bondary", u32::MAX, 2047); // negative imm is treated as positive - verify::("lt = false, imm lower bondary", u32::MAX, -2048, 0); + verify("lt = false, imm lower bondary", u32::MAX, -2048); } #[test] @@ -181,34 +183,36 @@ mod test { let a: u32 = rng.gen::(); let b: i32 = rng.gen_range(-2048..2048); println!("random: {} ("random unsigned comparison", a, b, (a < (b as u32)) as u32); + verify::("random unsigned comparison", a, b, a < (b as u32)); } #[test] fn test_slti_true() { - verify::("lt = true, 0 < 1", 0, 1, 1); - verify::("lt = true, 1 < 2", 1, 2, 1); - verify::("lt = true, -1 < 0", -1i32 as u32, 0, 1); - verify::("lt = true, -1 < 1", -1i32 as u32, 1, 1); - verify::("lt = true, -2 < -1", -2i32 as u32, -1, 1); + let verify = |name, a: i32, imm| verify::(name, a as u32, imm, true); + verify("lt = true, 0 < 1", 0, 1); + verify("lt = true, 1 < 2", 1, 2); + verify("lt = true, -1 < 0", -1, 0); + verify("lt = true, -1 < 1", -1, 1); + verify("lt = true, -2 < -1", -2, -1); // -2048 <= imm <= 2047 - verify::("lt = true, imm upper bondary", i32::MIN as u32, 2047, 1); - verify::("lt = true, imm lower bondary", i32::MIN as u32, -2048, 1); + verify("lt = true, imm upper bondary", i32::MIN, 2047); + verify("lt = true, imm lower bondary", i32::MIN, -2048); } #[test] fn test_slti_false() { - verify::("lt = false, 1 < 0", 1, 0, 0); - verify::("lt = false, 2 < 1", 2, 1, 0); - verify::("lt = false, 0 < -1", 0, -1, 0); - verify::("lt = false, 1 < -1", 1, -1, 0); - verify::("lt = false, -1 < -2", -1i32 as u32, -2, 0); - verify::("lt = false, 0 == 0", 0, 0, 0); - verify::("lt = false, 1 == 1", 1, 1, 0); - verify::("lt = false, -1 == -1", -1i32 as u32, -1, 0); + let verify = |name, a: i32, imm| verify::(name, a as u32, imm, false); + verify("lt = false, 1 < 0", 1, 0); + verify("lt = false, 2 < 1", 2, 1); + verify("lt = false, 0 < -1", 0, -1); + verify("lt = false, 1 < -1", 1, -1); + verify("lt = false, -1 < -2", -1, -2); + verify("lt = false, 0 == 0", 0, 0); + verify("lt = false, 1 == 1", 1, 1); + verify("lt = false, -1 == -1", -1, -1); // -2048 <= imm <= 2047 - verify::("lt = false, imm upper bondary", i32::MAX as u32, 2047, 0); - verify::("lt = false, imm lower bondary", i32::MAX as u32, -2048, 0); + verify("lt = false, imm upper bondary", i32::MAX, 2047); + verify("lt = false, imm lower bondary", i32::MAX, -2048); } #[test] @@ -217,10 +221,11 @@ mod test { let a: i32 = rng.gen(); let b: i32 = rng.gen_range(-2048..2048); println!("random: {} ("random 1", a as u32, b, (a < b) as u32); + verify::("random 1", a as u32, b, a < b); } - fn verify(name: &'static str, rs1_read: u32, imm: i32, expected_rd: u32) { + fn verify(name: &'static str, rs1_read: u32, imm: i32, expected_rd: bool) { + let expected_rd = expected_rd as u32; let mut cs = ConstraintSystem::::new(|| "riscv"); let mut cb = CircuitBuilder::new(&mut cs); From 79ce99f79627b430e57cdefc6c91cf0521e3c854 Mon Sep 17 00:00:00 2001 From: Ho Date: Tue, 10 Dec 2024 13:19:35 +0900 Subject: [PATCH 2/3] [FIX] Broken integration test caused by transcript (#715) (#721) This PR has fixed issue #715 by respect the assertion in `from_base` method of the Godilock extension field Notice there is two method `from_base` and `form_limbs` in the `ExtensionField` trait which is not well illustrated and maybe we should update them later. The two running mentioned in #715 have been success under this PR `cargo run --package ceno_zkvm --bin e2e -- --platform=sp1 ceno_zkvm/examples/fibonacci.elf` `cargo run --package ceno_zkvm --example riscv_opcodes -- --start 10 --end 11` --- transcript/src/basic.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/transcript/src/basic.rs b/transcript/src/basic.rs index ec455d236..47c32cdf4 100644 --- a/transcript/src/basic.rs +++ b/transcript/src/basic.rs @@ -32,7 +32,13 @@ impl Transcript for BasicTranscript { } fn read_challenge(&mut self) -> Challenge { - let r = E::from_bases(self.permutation.squeeze()); + // notice `from_bases` and `from_limbs` has the same behavior but + // `from_bases` has a sanity check for length of input slices + // while `from_limbs` use the first two fields silently + // we select `from_base` here to make it being more clear that + // we only use the first 2 fields here to construct the + // extension field (i.e. the challenge) + let r = E::from_bases(&self.permutation.squeeze()[..2]); Challenge { elements: r } } From 33901fd8d097abe866d1279afe0315ebd2c8e68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Tue, 10 Dec 2024 14:00:54 +0800 Subject: [PATCH 3/3] Enable debug assertions in integration tests (#714) To catch some bugs, like the recent breakage. --------- Co-authored-by: noelwei --- .github/workflows/integration.yml | 6 ++++-- Cargo.toml | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 767758a8b..ec0de0b14 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -56,10 +56,12 @@ jobs: - name: Run example env: RAYON_NUM_THREADS: 2 - run: cargo run --release --package ceno_zkvm --example riscv_opcodes --target ${{ matrix.target }} -- --start 10 --end 11 + RUSTFLAGS: "-C opt-level=3" + run: cargo run --package ceno_zkvm --example riscv_opcodes --target ${{ matrix.target }} -- --start 10 --end 11 - name: Run fibonacci env: RAYON_NUM_THREADS: 8 RUST_LOG: debug - run: cargo run --release --package ceno_zkvm --bin e2e --target ${{ matrix.target }} -- --platform=sp1 ceno_zkvm/examples/fibonacci.elf \ No newline at end of file + RUSTFLAGS: "-C opt-level=3" + run: cargo run --package ceno_zkvm --bin e2e --target ${{ matrix.target }} -- --platform=sp1 ceno_zkvm/examples/fibonacci.elf diff --git a/Cargo.toml b/Cargo.toml index 1ee0b66ef..ead19b880 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,5 +52,8 @@ tracing = { version = "0.1", features = [ tracing-forest = { version = "0.1.6" } tracing-subscriber = { version = "0.3", features = ["env-filter"] } +[profile.dev] +lto = "thin" + [profile.release] lto = "thin"