-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ecall demo with Keccak-f #717
base: master
Are you sure you want to change the base?
Conversation
// Compute Keccak permutation. | ||
let output = { | ||
let mut state = [0_u64; KECCAK_CELLS]; | ||
izip!(state.iter_mut(), input.chunks_exact(2)).for_each(|(cell, chunk)| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff --git a/ceno_emul/src/syscalls/keccak_permute.rs b/ceno_emul/src/syscalls/keccak_permute.rs
index 05c04c87..c3ba4add 100644
--- a/ceno_emul/src/syscalls/keccak_permute.rs
+++ b/ceno_emul/src/syscalls/keccak_permute.rs
@@ -39,11 +39,9 @@ pub fn keccak_permute(vm: &VMState) -> SyscallEffects {
// Compute Keccak permutation.
let output = {
let mut state = [0_u64; KECCAK_CELLS];
- izip!(state.iter_mut(), input.chunks_exact(2)).for_each(|(cell, chunk)| {
- let lo = chunk[0] as u64;
- let hi = chunk[1] as u64;
- *cell = lo | hi << 32;
- });
+ for (cell, (&lo, &hi)) in izip!(&mut state, input.iter().tuples()) {
+ *cell = lo as u64 | (hi as u64) << 32;
+ }
keccakf(&mut state);
state.into_iter().flat_map(|c| [c as u32, (c >> 32) as u32])
};
This might be slightly easier to read.
} | ||
Err(err) if self.platform.unsafe_ecall_nop => { | ||
tracing::warn!("ecall ignored with unsafe_ecall_nop: {:?}", err); | ||
// TODO: remove this example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a TODO for this PR, or for later?
); | ||
let lo = write_ops[0].value.after as u64; | ||
let hi = write_ops[1].value.after as u64; | ||
lo | (hi << 32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are doing the conversion from two u32
to one one u64
and back quite a few times in our code base. Perhaps we should write to helper functions?
@@ -0,0 +1,24 @@ | |||
// Based on https://github.com/succinctlabs/sp1/blob/013c24ea2fa15a0e7ed94f7d11a7ada4baa39ab9/crates/zkvm/entrypoint/src/syscalls/keccak_permute.rs | |||
|
|||
const KECCAK_PERMUTE: u32 = 0x00_01_01_09; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this magic number come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, please see comments.
|
||
mod keccak_permute; | ||
|
||
pub const KECCAK_PERMUTE: u32 = 0x00_01_01_09; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider setting up a syscall numbers table in a common crate that both guest and host code can import.
(There's a few more such common data and structures that we might want to put in this simple crate.)
StepRecord
to support multiple accesses to registers and memory (beyond standard instructions).fn handle_syscall(…)
syscall_keccak_permute
.