Skip to content

Conversation

@c410-f3r
Copy link
Contributor

Also swaps FIXME with TODO for consistency

.wrapping_add(s0)
.wrapping_add(w[i - 7])
.wrapping_add(s1);
// TODO: why doesn't sp1 use wrapping_add?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Succint uses manual + operators that wrap in release mode and panic in debug. This is a hashing function so wrapping is the right intent IMO.

Comment on lines -62 to -64
// TODO(Matthias): this is a bit inefficient,
// we could fill whole u32 words at a time.
// But it's just for testing.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fills 4 bytes at once. Shouldn't matter because the function is a mock but regardless 🤷

// The random numbers here are only good enough to make eg
// HashMap work.
fn step() -> u32 {
static X: AtomicU32 = AtomicU32::new(0xae569764);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crate provides the runtime for programs running on the Ceno VM.

IIUC it is OK to use atomics in this scenario. If so, static mut is unnecessary.

Copy link
Collaborator

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and sorry to get back lately
Overall change LGTM, just with a few question

#[unsafe(no_mangle)]
#[linkage = "weak"]
pub unsafe extern "C" fn sys_rand(recv_buf: *mut u8, words: usize) {
unsafe fn step() -> u32 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any insights on:

  • the difference in generated assembly code?
  • whether using AtomicU32 introduces any additional sys-calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://godbolt.org/z/TP3TsE91T shows the usage of the lock instruction, which is a native CPU feature (not a syscall). Optimized builds are much smaller -> https://godbolt.org/z/ojY14joaY

The current code has a similar optimized structure -> https://godbolt.org/z/3TEoa3PbP

AtomicU32 is more about removing one layer of unsafe but I can revert back to static mut if you want.

Copy link
Collaborator

@hero78119 hero78119 Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are working on riscv zkvm so one of the concern is the emulator are limited to support native cpu feature in particular for those which is more bind to hardware, such as lock, as we need to "prove" lock behaviour with a dedicated zk circuit which is hard to implemented. So I would suggest retain static mut behaviours as it doesn't introduce instruction outside of riv32im

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem! Thanks for the review

@c410-f3r
Copy link
Contributor Author

The code should be in good shape now.

I am trying to get more hands-on experience with ZK so can you indicate something feasible/solvable for someone new? Looking at the issues alone didn't provide much context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants