-
Notifications
You must be signed in to change notification settings - Fork 68
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
Keccak Rust Wrappers #1337
base: main
Are you sure you want to change the base?
Keccak Rust Wrappers #1337
Conversation
Ready for review again. |
test_data/asm/keccakf.asm
Outdated
let x; | ||
let y; | ||
operation keccakf x -> y; |
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.
same here
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.
Done.
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.
Very cool! :)
Implement all comments. Ready for a final review. Changes:
Tested using: |
riscv-runtime/Cargo.toml
Outdated
@@ -11,6 +11,7 @@ repository = "https://github.com/powdr-labs/powdr" | |||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive", "rc"] } | |||
serde_cbor = { version = "0.11.2", default-features = false, features = ["alloc"] } | |||
powdr-riscv-syscalls = { path = "../riscv-syscalls" } | |||
tiny-keccak = { version = "2.0.2", features = ["keccak"] } |
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.
not sure we want this here... i think the suggestion for tiny-keccak was mostly so it was possible to check things were proper without having the asm side. @leonardoalt?
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.
Exactly. Still prefer to have it here or we need to remove the test coverage in riscv.rs entirely.
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.
I don't think this should be here. Why do we need this dependency here for tests?
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.
This is because currently the keccak.asm isn't ready and depends on Chris's circuit compiler #1218 to be merged first, so we put a placeholder keccak.asm. To test the Rust wrapper, we instead use the tiny-keccak.
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.
I'm removing this now and leaving the keccakf
Rust wrapper as unimplemented.
riscv-runtime/src/hash.rs
Outdated
// asm!("ecall", in("a0") input, in("a1") output, in("t0") u32::from(Syscall::KeccakF)); | ||
// } | ||
|
||
// TODO: delete the following testing only chunk which uses tiny_keccak once syscall implemented |
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.
and this would be just unimplemented
for now
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.
and this would be just
unimplemented
for now
I think the tiny keccak part is still needed just for the test in riscv.rs to pass.
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.
which test is that? The keccak test already imports tiny keccak itself, we shouldn't ship tiny keccak with the riscv-runtime crate
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.
It's the test using our Rust wrapper (rather than tiny keccak) here https://github.com/powdr-labs/powdr/blob/main/riscv/tests/riscv_data/keccak/src/lib.rs, which I'm now moving to a separate draft PR. I'm also leaving this as unimplemented!
for now, and the contents here are also moved to the same draft PR.
All comments addressed and ready for review again. @pacheco |
riscv-runtime/Cargo.toml
Outdated
@@ -11,6 +11,7 @@ repository = "https://github.com/powdr-labs/powdr" | |||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive", "rc"] } | |||
serde_cbor = { version = "0.11.2", default-features = false, features = ["alloc"] } | |||
powdr-riscv-syscalls = { path = "../riscv-syscalls" } | |||
tiny-keccak = { version = "2.0.2", features = ["keccak"] } |
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.
I don't think this should be here. Why do we need this dependency here for tests?
riscv-runtime/src/hash.rs
Outdated
// asm!("ecall", in("a0") input, in("a1") output, in("t0") u32::from(Syscall::KeccakF)); | ||
// } | ||
|
||
// TODO: delete the following testing only chunk which uses tiny_keccak once syscall implemented |
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.
which test is that? The keccak test already imports tiny keccak itself, we shouldn't ship tiny keccak with the riscv-runtime crate
@@ -1,19 +1,32 @@ | |||
#![no_std] | |||
|
|||
use tiny_keccak::{Hasher, Keccak}; | |||
extern crate alloc; |
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.
I don't think this test should be modified like this, I think we should add a new test instead. It's still good to have a test that uses native tiny keccak.
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.
Alrighty. I'm restoring this file entirely and removed all tests using our Rust wrapper because it still depends on keccak.asm
which is road blocked by Chris' circuit compiler.
I'm moving the tests for Rust wrapper to another draft PR, so that we can merge after all road blocks are cleared.
Split roadblocked contents to #1408. This PR is ready for a final review. @leonardoalt |
@@ -8,5 +8,6 @@ edition = "2021" | |||
[dependencies] | |||
tiny-keccak = { version = "2.0.2", features = ["keccak"] } | |||
powdr-riscv-runtime = { path = "../../../../riscv-runtime" } | |||
hex-literal = "0.3.1" |
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.
I think this can also go?
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.
Sorry for being pedantic, but I think we could still add another riscv test (like a sibling of riscv/tests/riscv_data/keccak) that does call the new syscall but has a dummy assert, just so that's "ready to go"
Input for syscall is one memory pointer to the state array of 25 gl fe. Output is calculated in place.
All functions outside of keccakf are executed in Rust. Might need to delete everything except keccakf from keccakf.asm (including the padding, updating, and byte <-> u64 conversions).
Not tested. Should I wait till all infrastructure needed are merged? Technically can also do the following for the machine and I think I can test it already?