From 3e2a71060e9a53e96b851b0f36834187a91a4629 Mon Sep 17 00:00:00 2001 From: lightsing Date: Mon, 22 Sep 2025 16:48:04 +0800 Subject: [PATCH 1/6] upgrade toolchain to nightly-2025-08-18 --- Cargo.toml | 2 +- ceno_emul/src/addr.rs | 2 +- ceno_emul/src/elf.rs | 12 ++++++------ ceno_emul/src/syscalls/keccak_permute.rs | 2 +- ceno_emul/src/utils.rs | 2 +- ceno_rt/riscv32im-ceno-zkvm-elf.json | 2 +- ceno_rt/src/io.rs | 2 +- ceno_rt/src/lib.rs | 1 - ceno_zkvm/src/e2e.rs | 2 +- ceno_zkvm/src/lib.rs | 2 -- ceno_zkvm/src/precompiles/lookup_keccakf.rs | 10 +++------- ceno_zkvm/src/precompiles/utils.rs | 2 +- ceno_zkvm/src/scheme/cpu/mod.rs | 2 +- ceno_zkvm/src/scheme/hal.rs | 2 +- ceno_zkvm/src/scheme/mock_prover.rs | 4 ++-- ceno_zkvm/src/scheme/prover.rs | 2 +- ceno_zkvm/src/uint.rs | 6 +++--- ceno_zkvm/src/uint/arithmetic.rs | 16 ++++++++-------- gkr_iop/src/cpu/mod.rs | 12 ++++++------ gkr_iop/src/lib.rs | 1 - rust-toolchain.toml | 2 +- 21 files changed, 40 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2712903a7..cca6efcd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ resolver = "2" [workspace.package] categories = ["cryptography", "zk", "blockchain", "ceno"] -edition = "2021" +edition = "2024" keywords = ["cryptography", "zk", "blockchain", "ceno"] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/ceno_emul/src/addr.rs b/ceno_emul/src/addr.rs index d9069e1a0..892cebbe9 100644 --- a/ceno_emul/src/addr.rs +++ b/ceno_emul/src/addr.rs @@ -89,7 +89,7 @@ impl ByteAddr { } pub const fn is_aligned(&self) -> bool { - self.0 % WORD_SIZE as u32 == 0 + self.0.is_multiple_of(WORD_SIZE as u32) } pub const fn is_null(&self) -> bool { diff --git a/ceno_emul/src/elf.rs b/ceno_emul/src/elf.rs index 2dbd9f8fd..9218ecff6 100644 --- a/ceno_emul/src/elf.rs +++ b/ceno_emul/src/elf.rs @@ -97,7 +97,7 @@ impl Program { .e_entry .try_into() .map_err(|err| anyhow!("e_entry was larger than 32 bits. {err}"))?; - if entry >= max_mem || entry % WORD_SIZE as u32 != 0 { + if entry >= max_mem || !entry.is_multiple_of(WORD_SIZE as u32) { bail!("Invalid entrypoint"); } let segments = elf.segments().ok_or(anyhow!("Missing segment table"))?; @@ -136,7 +136,7 @@ impl Program { return Err(anyhow!("only support one executable segment")); } } - if vaddr % WORD_SIZE as u32 != 0 { + if !vaddr.is_multiple_of(WORD_SIZE as u32) { bail!("vaddr {vaddr:08x} is unaligned"); } tracing::debug!( @@ -270,10 +270,10 @@ fn collect_addr_symbols_mapping<'data>( if let Some((symtab, strtab)) = elf.symbol_table()? { for symbol in symtab.iter() { - if let Ok(name) = strtab.get(symbol.st_name as usize) { - if !name.is_empty() && symbol.st_value != 0 { + if let Ok(name) = strtab.get(symbol.st_name as usize) + && !name.is_empty() && symbol.st_value != 0 { symbols.insert(symbol.st_value, name.to_string()); - } + } } } @@ -286,5 +286,5 @@ fn find_max_symbol_in_range( start: u64, end: u64, ) -> Option<(&u64, &String)> { - symbols.range(start..end).max_by_key(|(&addr, _)| addr) + symbols.range(start..end).max_by_key(|&(addr, _)| addr) } diff --git a/ceno_emul/src/syscalls/keccak_permute.rs b/ceno_emul/src/syscalls/keccak_permute.rs index 5436b2c43..31757ea38 100644 --- a/ceno_emul/src/syscalls/keccak_permute.rs +++ b/ceno_emul/src/syscalls/keccak_permute.rs @@ -28,7 +28,7 @@ impl From<[Word; KECCAK_WORDS]> for KeccakState { KeccakState( words .chunks_exact(2) - .map(|chunk| (chunk[0] as u64 | ((chunk[1] as u64) << 32))) + .map(|chunk| chunk[0] as u64 | ((chunk[1] as u64) << 32)) .collect_vec() .try_into() .expect("failed to parse words into [u64; 25]"), diff --git a/ceno_emul/src/utils.rs b/ceno_emul/src/utils.rs index 0ca214176..52346ae0b 100644 --- a/ceno_emul/src/utils.rs +++ b/ceno_emul/src/utils.rs @@ -13,7 +13,7 @@ impl<'a, const LENGTH: usize> MemoryView<'a, LENGTH> { /// Creates a new memory segment view /// Asserts that `start` is a multiple of `WORD_SIZE` pub fn new(vm: &'a VMState, start: u32) -> Self { - assert!(start % WORD_SIZE as u32 == 0); + assert!(start.is_multiple_of(WORD_SIZE as u32)); // TODO: do we need stricter alignment requirements for keccak (u64 array) MemoryView { vm, diff --git a/ceno_rt/riscv32im-ceno-zkvm-elf.json b/ceno_rt/riscv32im-ceno-zkvm-elf.json index 79f865260..e822289f5 100644 --- a/ceno_rt/riscv32im-ceno-zkvm-elf.json +++ b/ceno_rt/riscv32im-ceno-zkvm-elf.json @@ -26,7 +26,7 @@ "panic-strategy": "abort", "relocation-model": "static", "singlethread": true, - "target-c-int-width": "32", + "target-c-int-width": 32, "target-endian": "little", "target-pointer-width": "32" } diff --git a/ceno_rt/src/io.rs b/ceno_rt/src/io.rs index 241b9bd09..ea27cc3f0 100644 --- a/ceno_rt/src/io.rs +++ b/ceno_rt/src/io.rs @@ -12,7 +12,7 @@ unsafe impl Sync for IOWriter {} impl IOWriter { #[cfg(debug_assertions)] const fn new(addr: u32) -> Self { - assert!(addr % WORD_SIZE as u32 == 0); + assert!(addr.is_multiple_of(WORD_SIZE as u32)); IOWriter { cursor: Cell::new(addr as *mut u32), } diff --git a/ceno_rt/src/lib.rs b/ceno_rt/src/lib.rs index 306904e4a..43d7967c6 100644 --- a/ceno_rt/src/lib.rs +++ b/ceno_rt/src/lib.rs @@ -1,5 +1,4 @@ #![deny(clippy::cargo)] -#![feature(strict_overflow_ops)] #![feature(linkage)] use getrandom::{Error, register_custom_getrandom}; diff --git a/ceno_zkvm/src/e2e.rs b/ceno_zkvm/src/e2e.rs index bb9ea2200..226231c2b 100644 --- a/ceno_zkvm/src/e2e.rs +++ b/ceno_zkvm/src/e2e.rs @@ -845,7 +845,7 @@ fn debug_memory_ranges<'a, I: Iterator>(vm: &VMState, .tracer() .final_accesses() .iter() - .filter(|(_, &cycle)| (cycle != 0)) + .filter(|&(_, cycle)| *cycle != 0) .map(|(&addr, _)| addr.baddr()) .filter(|addr| vm.platform().can_read(addr.0)) .collect_vec(); diff --git a/ceno_zkvm/src/lib.rs b/ceno_zkvm/src/lib.rs index 59e4ee5f8..16e7ee821 100644 --- a/ceno_zkvm/src/lib.rs +++ b/ceno_zkvm/src/lib.rs @@ -1,8 +1,6 @@ #![deny(clippy::cargo)] #![feature(box_patterns)] #![feature(stmt_expr_attributes)] -#![feature(strict_overflow_ops)] -#![feature(let_chains)] pub mod error; pub mod instructions; diff --git a/ceno_zkvm/src/precompiles/lookup_keccakf.rs b/ceno_zkvm/src/precompiles/lookup_keccakf.rs index ec27a16a2..13bdab62a 100644 --- a/ceno_zkvm/src/precompiles/lookup_keccakf.rs +++ b/ceno_zkvm/src/precompiles/lookup_keccakf.rs @@ -960,7 +960,7 @@ where push_instance::( wits, rc_witin[0].id.into(), - (0..8).map(|i| ((RC[round] >> (i << 3)) & 0xFF)), + (0..8).map(|i| (RC[round] >> (i << 3)) & 0xFF), ); state64 = iota_output64; @@ -1214,7 +1214,7 @@ pub fn run_faster_keccakf // } } - let out_evals = gkr_output + gkr_output .0 .par_iter() .map(|wit| { @@ -1224,11 +1224,7 @@ pub fn run_faster_keccakf eval: wit.evaluate(&point), } }) - .collect::>(); - - // assert_eq!(out_evals.len(), KECCAK_OUT_EVAL_SIZE); - - out_evals + .collect::>() }; exit_span!(span); diff --git a/ceno_zkvm/src/precompiles/utils.rs b/ceno_zkvm/src/precompiles/utils.rs index b15c91b1f..61312d996 100644 --- a/ceno_zkvm/src/precompiles/utils.rs +++ b/ceno_zkvm/src/precompiles/utils.rs @@ -85,7 +85,7 @@ impl MaskRepresentation { pub fn to_bits(&self) -> Vec { self.rep .iter() - .flat_map(|mask| (0..mask.size).map(move |i| ((mask.value >> i) & 1))) + .flat_map(|mask| (0..mask.size).map(move |i| (mask.value >> i) & 1)) .collect() } diff --git a/ceno_zkvm/src/scheme/cpu/mod.rs b/ceno_zkvm/src/scheme/cpu/mod.rs index 04ba68306..414cf1068 100644 --- a/ceno_zkvm/src/scheme/cpu/mod.rs +++ b/ceno_zkvm/src/scheme/cpu/mod.rs @@ -761,7 +761,7 @@ impl> DeviceTransporter as ProverBackend>::Pcs, >, >, - ) -> DeviceProvingKey> { + ) -> DeviceProvingKey<'_, CpuBackend> { let pcs_data = pk.fixed_commit_wd.clone().unwrap(); let fixed_mles = PCS::get_arc_mle_witness_from_commitment(pk.fixed_commit_wd.as_ref().unwrap()); diff --git a/ceno_zkvm/src/scheme/hal.rs b/ceno_zkvm/src/scheme/hal.rs index 892133748..85cb5ce45 100644 --- a/ceno_zkvm/src/scheme/hal.rs +++ b/ceno_zkvm/src/scheme/hal.rs @@ -163,7 +163,7 @@ pub trait DeviceTransporter { fn transport_proving_key( &self, proving_key: Arc>, - ) -> DeviceProvingKey; + ) -> DeviceProvingKey<'_, PB>; fn transport_mles<'a>( &self, diff --git a/ceno_zkvm/src/scheme/mock_prover.rs b/ceno_zkvm/src/scheme/mock_prover.rs index 226126c4a..028f844a6 100644 --- a/ceno_zkvm/src/scheme/mock_prover.rs +++ b/ceno_zkvm/src/scheme/mock_prover.rs @@ -372,7 +372,7 @@ fn load_tables( challenge: [E; 2], ) { for (i, bits) in std::iter::once(0) - .chain((0..=MAX_BITS).flat_map(|i| (0..(1 << i)))) + .chain((0..=MAX_BITS).flat_map(|i| 0..(1 << i))) .zip( std::iter::once(0) .chain((0..=MAX_BITS).flat_map(|i| std::iter::repeat_n(i, 1 << i))), @@ -395,7 +395,7 @@ fn load_tables( ) { for (a, b) in (0..(1 << 8)) .flat_map(|i| std::iter::repeat_n(i, 1 << 8)) - .zip(std::iter::repeat_n(0, 1 << 8).flat_map(|_| (0..(1 << 8)))) + .zip(std::iter::repeat_n(0, 1 << 8).flat_map(|_| 0..(1 << 8))) { let rlc_record = cs.rlc_chip_record(vec![ (LookupTable::DoubleU8 as usize).into(), diff --git a/ceno_zkvm/src/scheme/prover.rs b/ceno_zkvm/src/scheme/prover.rs index 35919c27d..1a1c4f17e 100644 --- a/ceno_zkvm/src/scheme/prover.rs +++ b/ceno_zkvm/src/scheme/prover.rs @@ -79,7 +79,7 @@ impl< &mut self, witnesses: ZKVMWitnesses, pi: PublicValues, - mut transcript: (impl Transcript + 'static), + mut transcript: impl Transcript + 'static, ) -> Result, ZKVMError> { let raw_pi = pi.to_vec::(); let mut pi_evals = ZKVMProof::::pi_evals(&raw_pi); diff --git a/ceno_zkvm/src/uint.rs b/ceno_zkvm/src/uint.rs index 306b6916d..1ca7156d5 100644 --- a/ceno_zkvm/src/uint.rs +++ b/ceno_zkvm/src/uint.rs @@ -328,7 +328,7 @@ impl UIntLimbs { pub fn from_u8_limbs( x: &UIntLimbs, ) -> Result, CircuitBuilderError> { - assert!(C % 8 == 0, "we only support multiple of 8 limb sizes"); + assert!(C.is_multiple_of(8), "we only support multiple of 8 limb sizes"); assert!(x.carries.is_none()); let k = C / 8; let shift_pows = { @@ -358,7 +358,7 @@ impl UIntLimbs { circuit_builder: &mut CircuitBuilder, x: UIntLimbs, ) -> UIntLimbs { - assert!(C % 8 == 0, "we only support multiple of 8 limb sizes"); + assert!(C.is_multiple_of(8), "we only support multiple of 8 limb sizes"); assert!(x.carries.is_none()); let k = C / 8; let shift_pows = { @@ -626,7 +626,7 @@ pub struct ValueMul { } impl ValueMul { - pub fn as_hi_value + From + Copy + Default>(&self) -> Value { + pub fn as_hi_value + From + Copy + Default>(&self) -> Value<'_, T> { Value::::from_limb_slice_unchecked(self.as_hi_limb_slice()) } diff --git a/ceno_zkvm/src/uint/arithmetic.rs b/ceno_zkvm/src/uint/arithmetic.rs index 9dfb231ee..c35c0e70a 100644 --- a/ceno_zkvm/src/uint/arithmetic.rs +++ b/ceno_zkvm/src/uint/arithmetic.rs @@ -51,11 +51,11 @@ impl UIntLimbs { let next_carry = carries.get(i); let mut limb_expr = a.clone() + b.clone(); - if carry.is_some() { - limb_expr = limb_expr.clone() + carry.unwrap().expr(); + if let Some(carry) = carry { + limb_expr = limb_expr.clone() + carry.expr(); } - if next_carry.is_some() { - limb_expr = limb_expr.clone() - next_carry.unwrap().expr() * Self::POW_OF_C; + if let Some(next_carry) = next_carry { + limb_expr = limb_expr.clone() - next_carry.expr() * Self::POW_OF_C; } circuit_builder @@ -197,11 +197,11 @@ impl UIntLimbs { let carry = if i > 0 { c_carries.get(i - 1) } else { None }; let next_carry = c_carries.get(i); result_c[i] = result_c[i].clone() - c_limb.expr(); - if carry.is_some() { - result_c[i] = result_c[i].clone() + carry.unwrap().expr(); + if let Some(carry) = carry { + result_c[i] = result_c[i].clone() + carry.expr(); } - if next_carry.is_some() { - result_c[i] = result_c[i].clone() - next_carry.unwrap().expr() * Self::POW_OF_C; + if let Some(next_carry) = next_carry { + result_c[i] = result_c[i].clone() - next_carry.expr() * Self::POW_OF_C; } circuit_builder.require_zero(|| format!("mul_zero_{i}"), result_c[i].clone())?; Ok::<(), CircuitBuilderError>(()) diff --git a/gkr_iop/src/cpu/mod.rs b/gkr_iop/src/cpu/mod.rs index a819706b4..1d96b263a 100644 --- a/gkr_iop/src/cpu/mod.rs +++ b/gkr_iop/src/cpu/mod.rs @@ -118,8 +118,8 @@ impl> .zip_eq(layer.expr_names.par_iter()) .zip_eq(out_evals.par_iter()) .map(|((expr, expr_name), (_, out_eval))| { - if cfg!(debug_assertions) { - if let EvalExpression::Zero = out_eval { + if cfg!(debug_assertions) + && let EvalExpression::Zero = out_eval { assert!( wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) .evaluations() @@ -128,7 +128,7 @@ impl> layer.name ); } - }; + ; match out_eval { EvalExpression::Linear(_, _, _) | EvalExpression::Single(_) => { wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) @@ -161,8 +161,8 @@ where .zip_eq(layer.expr_names.par_iter()) .zip_eq(out_evals.par_iter()) .map(|((expr, expr_name), (_, out_eval))| { - if cfg!(debug_assertions) { - if let EvalExpression::Zero = out_eval { + if cfg!(debug_assertions) + && let EvalExpression::Zero = out_eval { assert!( wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) .evaluations() @@ -171,7 +171,7 @@ where layer.name ); } - }; + ; match out_eval { EvalExpression::Linear(_, _, _) | EvalExpression::Single(_) => { wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) diff --git a/gkr_iop/src/lib.rs b/gkr_iop/src/lib.rs index 4ba9cb615..26416aac6 100644 --- a/gkr_iop/src/lib.rs +++ b/gkr_iop/src/lib.rs @@ -1,5 +1,4 @@ #![feature(variant_count)] -#![feature(strict_overflow_ops)] use crate::{ chip::Chip, circuit_builder::CircuitBuilder, error::CircuitBuilderError, utils::lk_multiplicity::LkMultiplicity, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f22a9d0bc..7d676f1ad 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2025-03-25" +channel = "nightly-2025-08-18" targets = ["riscv32im-unknown-none-elf"] # We need the sources for build-std. components = ["rust-src"] From 629f24c289fb94cb82d8cef82200e78716c9a1bf Mon Sep 17 00:00:00 2001 From: lightsing Date: Mon, 22 Sep 2025 16:52:26 +0800 Subject: [PATCH 2/6] fmt --- ceno_emul/src/elf.rs | 7 ++++--- ceno_zkvm/src/uint.rs | 10 ++++++++-- gkr_iop/src/cpu/mod.rs | 40 ++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/ceno_emul/src/elf.rs b/ceno_emul/src/elf.rs index 9218ecff6..72faea5ad 100644 --- a/ceno_emul/src/elf.rs +++ b/ceno_emul/src/elf.rs @@ -271,9 +271,10 @@ fn collect_addr_symbols_mapping<'data>( if let Some((symtab, strtab)) = elf.symbol_table()? { for symbol in symtab.iter() { if let Ok(name) = strtab.get(symbol.st_name as usize) - && !name.is_empty() && symbol.st_value != 0 { - symbols.insert(symbol.st_value, name.to_string()); - + && !name.is_empty() + && symbol.st_value != 0 + { + symbols.insert(symbol.st_value, name.to_string()); } } } diff --git a/ceno_zkvm/src/uint.rs b/ceno_zkvm/src/uint.rs index 1ca7156d5..b1ee7c07f 100644 --- a/ceno_zkvm/src/uint.rs +++ b/ceno_zkvm/src/uint.rs @@ -328,7 +328,10 @@ impl UIntLimbs { pub fn from_u8_limbs( x: &UIntLimbs, ) -> Result, CircuitBuilderError> { - assert!(C.is_multiple_of(8), "we only support multiple of 8 limb sizes"); + assert!( + C.is_multiple_of(8), + "we only support multiple of 8 limb sizes" + ); assert!(x.carries.is_none()); let k = C / 8; let shift_pows = { @@ -358,7 +361,10 @@ impl UIntLimbs { circuit_builder: &mut CircuitBuilder, x: UIntLimbs, ) -> UIntLimbs { - assert!(C.is_multiple_of(8), "we only support multiple of 8 limb sizes"); + assert!( + C.is_multiple_of(8), + "we only support multiple of 8 limb sizes" + ); assert!(x.carries.is_none()); let k = C / 8; let shift_pows = { diff --git a/gkr_iop/src/cpu/mod.rs b/gkr_iop/src/cpu/mod.rs index 1d96b263a..32ccb77a0 100644 --- a/gkr_iop/src/cpu/mod.rs +++ b/gkr_iop/src/cpu/mod.rs @@ -119,16 +119,16 @@ impl> .zip_eq(out_evals.par_iter()) .map(|((expr, expr_name), (_, out_eval))| { if cfg!(debug_assertions) - && let EvalExpression::Zero = out_eval { - assert!( - wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) - .evaluations() - .is_zero(), - "layer name: {}, expr name: \"{expr_name}\" got non_zero mle", - layer.name - ); - } - ; + && let EvalExpression::Zero = out_eval + { + assert!( + wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) + .evaluations() + .is_zero(), + "layer name: {}, expr name: \"{expr_name}\" got non_zero mle", + layer.name + ); + }; match out_eval { EvalExpression::Linear(_, _, _) | EvalExpression::Single(_) => { wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) @@ -162,16 +162,16 @@ where .zip_eq(out_evals.par_iter()) .map(|((expr, expr_name), (_, out_eval))| { if cfg!(debug_assertions) - && let EvalExpression::Zero = out_eval { - assert!( - wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) - .evaluations() - .is_zero(), - "layer name: {}, expr name: \"{expr_name}\" got non_zero mle", - layer.name - ); - } - ; + && let EvalExpression::Zero = out_eval + { + assert!( + wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) + .evaluations() + .is_zero(), + "layer name: {}, expr name: \"{expr_name}\" got non_zero mle", + layer.name + ); + }; match out_eval { EvalExpression::Linear(_, _, _) | EvalExpression::Single(_) => { wit_infer_by_monomial_expr(expr, layer_wits, pub_io_evals, challenges) From 09d361d0b286493ec5fc65b29fd6e45ff09d522a Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 26 Sep 2025 10:50:40 +0800 Subject: [PATCH 3/6] update ci --- .github/workflows/lints.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 1c91eeb7a..c848ad2d2 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -25,7 +25,7 @@ jobs: components: rustfmt, clippy targets: riscv32im-unknown-none-elf # TODO: figure out way to keep this in sync with rust-toolchain.toml automatically - toolchain: nightly-2025-03-25 + toolchain: nightly-2025-08-18 - name: Cargo cache uses: actions/cache@v4 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ddf01b269..4e84e46ca 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: with: targets: riscv32im-unknown-none-elf # TODO: figure out way to keep this in sync with rust-toolchain.toml automatically - toolchain: nightly-2025-03-25 + toolchain: nightly-2025-08-18 - name: Cargo cache uses: actions/cache@v4 with: From 046aa3b2b0854399220d4366936245451432f5b4 Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 26 Sep 2025 10:56:50 +0800 Subject: [PATCH 4/6] fix lint --- ceno_zkvm/src/instructions/riscv/slt.rs | 2 ++ guest_libs/keccak/src/lib.rs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ceno_zkvm/src/instructions/riscv/slt.rs b/ceno_zkvm/src/instructions/riscv/slt.rs index 0ff3e230d..7b27617ad 100644 --- a/ceno_zkvm/src/instructions/riscv/slt.rs +++ b/ceno_zkvm/src/instructions/riscv/slt.rs @@ -1,4 +1,6 @@ +#[cfg(not(feature = "u16limb_circuit"))] mod slt_circuit; +#[cfg(feature = "u16limb_circuit")] mod slt_circuit_v2; use ceno_emul::InsnKind; diff --git a/guest_libs/keccak/src/lib.rs b/guest_libs/keccak/src/lib.rs index 6cbeb8886..6a8025425 100644 --- a/guest_libs/keccak/src/lib.rs +++ b/guest_libs/keccak/src/lib.rs @@ -39,7 +39,6 @@ mod keccakf { /// [`keccak256`]: https://en.wikipedia.org/wiki/SHA-3 /// [`sha3`]: https://docs.rs/sha3/latest/sha3/ /// [`tiny_keccak`]: https://docs.rs/tiny-keccak/latest/tiny_keccak/ -#[inline(always)] #[no_mangle] pub unsafe extern "C" fn native_keccak256(bytes: *const u8, len: usize, output: *mut u8) { use crate::{Hasher, Keccak}; From 742069f12191bcba696dbd728bd173a97c7675ac Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 26 Sep 2025 11:15:29 +0800 Subject: [PATCH 5/6] fix lint --- ceno_cli/example/Cargo.toml | 2 +- ceno_rt/Cargo.toml | 2 +- ceno_rt/src/allocator.rs | 21 ++++++++++++--------- ceno_rt/src/lib.rs | 26 +++++++++++++++----------- ceno_rt/src/mmio.rs | 8 ++++---- ceno_rt/src/syscalls.rs | 12 ++++++------ ceno_zkvm/src/uint/arithmetic.rs | 21 ++++++++++----------- examples/Cargo.toml | 2 +- examples/examples/is_prime.rs | 2 +- guest_libs/keccak/Cargo.toml | 2 +- guest_libs/keccak/src/lib.rs | 2 +- utils/cuda_hal/Cargo.toml | 2 +- 12 files changed, 54 insertions(+), 48 deletions(-) diff --git a/ceno_cli/example/Cargo.toml b/ceno_cli/example/Cargo.toml index 022e6cca3..a3470883c 100644 --- a/ceno_cli/example/Cargo.toml +++ b/ceno_cli/example/Cargo.toml @@ -1,6 +1,6 @@ [workspace] [package] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" name = "ceno_example" version = "0.1.0" diff --git a/ceno_rt/Cargo.toml b/ceno_rt/Cargo.toml index 6587e3162..fd47edc50 100644 --- a/ceno_rt/Cargo.toml +++ b/ceno_rt/Cargo.toml @@ -1,7 +1,7 @@ [package] categories = ["cryptography", "zk", "blockchain", "ceno"] description = "Ceno runtime library" -edition = "2021" +edition = "2024" keywords = ["cryptography", "zk", "blockchain", "ceno"] license = "MIT OR Apache-2.0" name = "ceno_rt" diff --git a/ceno_rt/src/allocator.rs b/ceno_rt/src/allocator.rs index 91c697b7f..58d4cacb8 100644 --- a/ceno_rt/src/allocator.rs +++ b/ceno_rt/src/allocator.rs @@ -10,32 +10,35 @@ struct SimpleAllocator { unsafe impl GlobalAlloc for SimpleAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { // SAFETY: Single threaded, so nothing else can touch this while we're working. - let mut heap_pos = HEAP.next_alloc; + let mut heap_pos = unsafe { HEAP.next_alloc }; let align = layout.align(); // `Layout` contract forbids making a `Layout` with align=0, or align not power of 2. - core::hint::assert_unchecked(align.is_power_of_two()); - core::hint::assert_unchecked(align != 0); - heap_pos = heap_pos.add(heap_pos.align_offset(align)); + unsafe { + core::hint::assert_unchecked(align.is_power_of_two()); + core::hint::assert_unchecked(align != 0); + heap_pos = heap_pos.add(heap_pos.align_offset(align)); + } let ptr = heap_pos; // We don't want to wrap around, and overwrite stack etc. // (We could also return a null pointer, but only malicious programs would ever hit this.) - heap_pos = heap_pos.add(layout.size()); - - HEAP.next_alloc = heap_pos; + unsafe { + heap_pos = heap_pos.add(layout.size()); + HEAP.next_alloc = heap_pos; + } ptr } unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - self.alloc(layout) + unsafe { self.alloc(layout) } } /// Never deallocate. unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } -extern "C" { +unsafe extern "C" { /// The address of this variable is the start of the heap (growing upwards). /// /// It is defined in the linker script. diff --git a/ceno_rt/src/lib.rs b/ceno_rt/src/lib.rs index 43d7967c6..1ced41d48 100644 --- a/ceno_rt/src/lib.rs +++ b/ceno_rt/src/lib.rs @@ -24,19 +24,19 @@ pub use params::*; pub mod syscalls; -#[no_mangle] +#[unsafe(no_mangle)] #[linkage = "weak"] pub extern "C" fn sys_write(_fd: i32, _buf: *const u8, _count: usize) -> isize { 0 } -#[no_mangle] +#[unsafe(no_mangle)] #[linkage = "weak"] pub extern "C" fn sys_alloc_words(nwords: usize) -> *mut u32 { unsafe { alloc_zeroed(Layout::from_size_align(4 * nwords, 4).unwrap()) as *mut u32 } } -#[no_mangle] +#[unsafe(no_mangle)] #[linkage = "weak"] pub extern "C" fn sys_getenv(_name: *const u8) -> *const u8 { null() @@ -48,7 +48,7 @@ pub extern "C" fn sys_getenv(_name: *const u8) -> *const u8 { /// /// Make sure that `buf` has at least `nwords` words. /// This generator is terrible. :) -#[no_mangle] +#[unsafe(no_mangle)] #[linkage = "weak"] pub unsafe extern "C" fn sys_rand(recv_buf: *mut u8, words: usize) { unsafe fn step() -> u32 { @@ -56,17 +56,21 @@ pub unsafe extern "C" fn sys_rand(recv_buf: *mut u8, words: usize) { // We are stealing Borland Delphi's random number generator. // The random numbers here are only good enough to make eg // HashMap work. - X = X.wrapping_mul(134775813) + 1; - X + unsafe { + X = X.wrapping_mul(134775813) + 1; + X + } } // TODO(Matthias): this is a bit inefficient, // we could fill whole u32 words at a time. // But it's just for testing. for i in 0..words { - let element = recv_buf.add(i); - // The lower bits ain't really random, so might as well take - // the higher order ones, if we are only using 8 bits. - *element = step().to_le_bytes()[3]; + unsafe { + let element = recv_buf.add(i); + // The lower bits ain't really random, so might as well take + // the higher order ones, if we are only using 8 bits. + *element = step().to_le_bytes()[3]; + } } } @@ -130,7 +134,7 @@ _start: ", ); -extern "C" { +unsafe extern "C" { // The address of this variable is the start of the stack (growing downwards). static _stack_start: u8; } diff --git a/ceno_rt/src/mmio.rs b/ceno_rt/src/mmio.rs index 69dc71492..da8faa2a8 100644 --- a/ceno_rt/src/mmio.rs +++ b/ceno_rt/src/mmio.rs @@ -14,7 +14,7 @@ use core::slice::from_raw_parts; /// Logically, this is a static constant, but the type system doesn't see it that way. /// (We hope that the optimiser is smart enough to see that it is a constant.) fn hints_region<'a>() -> &'a [u8] { - extern "C" { + unsafe extern "C" { /// The address of this variable is the start of the hints ROM. /// /// It is defined in the linker script. The value of this variable is undefined. @@ -32,7 +32,7 @@ fn hints_region<'a>() -> &'a [u8] { /// Get the length of the next hint fn hint_len() -> usize { - extern "C" { + unsafe extern "C" { /// The address of this variable is the start of the slice that holds the length of the hints. /// /// It is defined in the linker script. The value of this variable is undefined. @@ -59,7 +59,7 @@ where /// The memory region with public io. fn pubio_region<'a>() -> &'a [u8] { - extern "C" { + unsafe extern "C" { /// The address of this variable is the start of the hints ROM. /// /// It is defined in the linker script. The value of this variable is undefined. @@ -77,7 +77,7 @@ fn pubio_region<'a>() -> &'a [u8] { /// Get the length of the next pubio fn pubio_len() -> usize { - extern "C" { + unsafe extern "C" { /// The address of this variable is the start of the slice that holds the length of the hints. /// /// It is defined in the linker script. The value of this variable is undefined. diff --git a/ceno_rt/src/syscalls.rs b/ceno_rt/src/syscalls.rs index 10fbd4c00..d807c46bb 100644 --- a/ceno_rt/src/syscalls.rs +++ b/ceno_rt/src/syscalls.rs @@ -149,7 +149,7 @@ pub fn syscall_sha256_extend(w: *mut [u32; 64]) { /// The caller must ensure that `p` and `q` are valid pointers to data that is aligned along a four /// byte boundary. #[allow(unused_variables)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn syscall_bn254_add(p: *mut [u32; 16], q: *const [u32; 16]) { #[cfg(target_os = "zkvm")] unsafe { @@ -174,7 +174,7 @@ pub extern "C" fn syscall_bn254_add(p: *mut [u32; 16], q: *const [u32; 16]) { /// The caller must ensure that `p` is valid pointer to data that is aligned along a four byte /// boundary. #[allow(unused_variables)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn syscall_bn254_double(p: *mut [u32; 16]) { #[cfg(target_os = "zkvm")] unsafe { @@ -194,7 +194,7 @@ pub extern "C" fn syscall_bn254_double(p: *mut [u32; 16]) { /// /// The result is written over the first input. #[allow(unused_variables)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn syscall_bn254_fp_addmod(x: *mut u32, y: *const u32) { #[cfg(target_os = "zkvm")] unsafe { @@ -214,7 +214,7 @@ pub extern "C" fn syscall_bn254_fp_addmod(x: *mut u32, y: *const u32) { /// /// The result is written over the first input. #[allow(unused_variables)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn syscall_bn254_fp_mulmod(x: *mut u32, y: *const u32) { #[cfg(target_os = "zkvm")] unsafe { @@ -234,7 +234,7 @@ pub extern "C" fn syscall_bn254_fp_mulmod(x: *mut u32, y: *const u32) { /// /// The result is written over the first input. #[allow(unused_variables)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn syscall_bn254_fp2_addmod(x: *mut u32, y: *const u32) { #[cfg(target_os = "zkvm")] unsafe { @@ -254,7 +254,7 @@ pub extern "C" fn syscall_bn254_fp2_addmod(x: *mut u32, y: *const u32) { /// /// The result is written over the first input. #[allow(unused_variables)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn syscall_bn254_fp2_mulmod(x: *mut u32, y: *const u32) { #[cfg(target_os = "zkvm")] unsafe { diff --git a/ceno_zkvm/src/uint/arithmetic.rs b/ceno_zkvm/src/uint/arithmetic.rs index c35c0e70a..ab44bc9b3 100644 --- a/ceno_zkvm/src/uint/arithmetic.rs +++ b/ceno_zkvm/src/uint/arithmetic.rs @@ -447,14 +447,14 @@ mod tests { let mut cb = CircuitBuilder::::new(&mut cs); let challenges = vec![E::ONE; witness_values.len()]; let uint_a = UIntLimbs::::new(|| "uint_a", &mut cb).unwrap(); - let uint_c = if const_b.is_none() { - let uint_b = UIntLimbs::::new(|| "uint_b", &mut cb).unwrap(); - uint_a.add(|| "uint_c", &mut cb, &uint_b, overflow).unwrap() - } else { - let const_b = E::BaseField::from_canonical_u64(const_b.unwrap()).expr(); + let uint_c = if let Some(const_b) = const_b { + let const_b = E::BaseField::from_canonical_u64(const_b).expr(); uint_a .add_const(|| "uint_c", &mut cb, const_b, overflow) .unwrap() + } else { + let uint_b = UIntLimbs::::new(|| "uint_b", &mut cb).unwrap(); + uint_a.add(|| "uint_c", &mut cb, &uint_b, overflow).unwrap() }; let pow_of_c: u64 = 2_usize.pow(UIntLimbs::::MAX_LIMB_BIT_WIDTH as u32) as u64; @@ -462,16 +462,15 @@ mod tests { let a = &witness_values[0..single_wit_size]; let mut const_b_pre_allocated = vec![0u64; single_wit_size]; - let b = if const_b.is_none() { - &witness_values[single_wit_size..2 * single_wit_size] - } else { - let b = const_b.unwrap(); + let b = if let Some(b) = const_b { let limb_bit_mask: u64 = (1 << C) - 1; const_b_pre_allocated .iter_mut() .enumerate() .for_each(|(i, limb)| *limb = (b >> (C * i)) & limb_bit_mask); &const_b_pre_allocated + } else { + &witness_values[single_wit_size..2 * single_wit_size] }; // the num of witness is 3, a, b and c_carries if it's a `add` @@ -495,8 +494,8 @@ mod tests { if i != 0 { result[i] += carries[i - 1]; } - if !overflow && carry.is_some() { - result[i] -= carry.unwrap() * pow_of_c; + if let Some(carry) = carry && !overflow { + result[i] -= carry * pow_of_c; } }); diff --git a/examples/Cargo.toml b/examples/Cargo.toml index e6553d225..d9947337b 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,7 +1,7 @@ [package] categories = ["cryptography", "zk", "blockchain", "ceno"] description = "Ceno RiscV guest examples" -edition = "2021" +edition = "2024" keywords = ["cryptography", "zk", "blockchain", "ceno"] license = "MIT OR Apache-2.0" name = "examples" diff --git a/examples/examples/is_prime.rs b/examples/examples/is_prime.rs index 8e6455010..83bd7e58e 100644 --- a/examples/examples/is_prime.rs +++ b/examples/examples/is_prime.rs @@ -7,7 +7,7 @@ fn is_prime(n: u32) -> bool { } let mut i = 2; while i * i <= n { - if n % i == 0 { + if n.is_multiple_of(i) { return false; } i += 1; diff --git a/guest_libs/keccak/Cargo.toml b/guest_libs/keccak/Cargo.toml index e458ae009..879d748eb 100644 --- a/guest_libs/keccak/Cargo.toml +++ b/guest_libs/keccak/Cargo.toml @@ -1,7 +1,7 @@ [package] categories = ["cryptography", "zk", "blockchain", "ceno"] description = "Ceno zkVM Keccak Guest Library" -edition = "2021" +edition = "2024" keywords = ["cryptography", "zk", "blockchain", "ceno"] license = "MIT OR Apache-2.0" name = "ceno_keccak" diff --git a/guest_libs/keccak/src/lib.rs b/guest_libs/keccak/src/lib.rs index 6a8025425..eb024d542 100644 --- a/guest_libs/keccak/src/lib.rs +++ b/guest_libs/keccak/src/lib.rs @@ -39,7 +39,7 @@ mod keccakf { /// [`keccak256`]: https://en.wikipedia.org/wiki/SHA-3 /// [`sha3`]: https://docs.rs/sha3/latest/sha3/ /// [`tiny_keccak`]: https://docs.rs/tiny-keccak/latest/tiny_keccak/ -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn native_keccak256(bytes: *const u8, len: usize, output: *mut u8) { use crate::{Hasher, Keccak}; diff --git a/utils/cuda_hal/Cargo.toml b/utils/cuda_hal/Cargo.toml index c714995e7..a204b7fad 100644 --- a/utils/cuda_hal/Cargo.toml +++ b/utils/cuda_hal/Cargo.toml @@ -1,5 +1,5 @@ [package] -edition = "2021" +edition = "2024" name = "cuda_hal" publish = false version = "0.1.0" From af471f50a9af2ae70df23815e35197e72fa2fcc2 Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 26 Sep 2025 11:15:36 +0800 Subject: [PATCH 6/6] fmt --- ceno_zkvm/src/uint/arithmetic.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ceno_zkvm/src/uint/arithmetic.rs b/ceno_zkvm/src/uint/arithmetic.rs index ab44bc9b3..a0e2fca8c 100644 --- a/ceno_zkvm/src/uint/arithmetic.rs +++ b/ceno_zkvm/src/uint/arithmetic.rs @@ -494,7 +494,9 @@ mod tests { if i != 0 { result[i] += carries[i - 1]; } - if let Some(carry) = carry && !overflow { + if let Some(carry) = carry + && !overflow + { result[i] -= carry * pow_of_c; } });