powdr-labs / powdr

A modular stack for zkVMs, with a focus on productivity, security and performance.
Apache License 2.0
338 stars 67 forks source link

Keccak Rust Wrappers #1337

Open qwang98 opened 1 month ago

qwang98 commented 1 month ago

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?

pol commit input_state[25];
pol commit output_state[25];
operation keccakf_permutation<0> input_state[0], input_state[1], ..., input_state[24] -> output_state[0], output_state[1], ..., output_state[24]
array::zip(input_state, output_state, |input_state, output_state| (keccakf(input_state) - output_state = 0);
qwang98 commented 1 month ago

Ready for review again.

qwang98 commented 1 month ago

Implement all comments. Ready for a final review.

Changes:

  1. Rust wrapper takes two memory pointers and uses reinterpret casting.
  2. Rust wrapper tested correct using tiny keccak instead of unfinished syscall, which can't be done yet.

Tested using: cargo run -r --bin powdr-rs compile riscv/tests/riscv_data/keccak -o output && RUST_BACKTRACE=full cargo test --release --package powdr-riscv --test riscv -- keccak --exact --show-output --ignored

qwang98 commented 1 month ago

All comments addressed and ready for review again. @pacheco

qwang98 commented 2 weeks ago

Split roadblocked contents to #1408. This PR is ready for a final review. @leonardoalt