Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ceno_cli/example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
[package]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
name = "ceno_example"
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion ceno_emul/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 8 additions & 7 deletions ceno_emul/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))?;
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -270,10 +270,11 @@ 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 {
symbols.insert(symbol.st_value, name.to_string());
}
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());
}
}
}
Expand All @@ -286,5 +287,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)
}
2 changes: 1 addition & 1 deletion ceno_emul/src/syscalls/keccak_permute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]"),
Expand Down
2 changes: 1 addition & 1 deletion ceno_emul/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ceno_rt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ceno_rt/riscv32im-ceno-zkvm-elf.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
21 changes: 12 additions & 9 deletions ceno_rt/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ceno_rt/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
27 changes: 15 additions & 12 deletions ceno_rt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(clippy::cargo)]
#![feature(strict_overflow_ops)]
#![feature(linkage)]
use getrandom::{Error, register_custom_getrandom};

Expand All @@ -25,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()
Expand All @@ -49,25 +48,29 @@ 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 {
static mut X: u32 = 0xae569764;
// 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];
}
}
}

Expand Down Expand Up @@ -131,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;
}
8 changes: 4 additions & 4 deletions ceno_rt/src/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions ceno_rt/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ fn debug_memory_ranges<'a, I: Iterator<Item = &'a MemFinalRecord>>(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();
Expand Down
2 changes: 2 additions & 0 deletions ceno_zkvm/src/instructions/riscv/slt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(not(feature = "u16limb_circuit"))]
mod slt_circuit;
#[cfg(feature = "u16limb_circuit")]
mod slt_circuit_v2;

use ceno_emul::InsnKind;
Expand Down
2 changes: 0 additions & 2 deletions ceno_zkvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 3 additions & 7 deletions ceno_zkvm/src/precompiles/lookup_keccakf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ where
push_instance::<E, _>(
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;
Expand Down Expand Up @@ -1214,7 +1214,7 @@ pub fn run_faster_keccakf<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>
// }
}

let out_evals = gkr_output
gkr_output
.0
.par_iter()
.map(|wit| {
Expand All @@ -1224,11 +1224,7 @@ pub fn run_faster_keccakf<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>
eval: wit.evaluate(&point),
}
})
.collect::<Vec<_>>();

// assert_eq!(out_evals.len(), KECCAK_OUT_EVAL_SIZE);

out_evals
.collect::<Vec<_>>()
};
exit_span!(span);

Expand Down
Loading