-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sponge construction for keccak syscall & Intruction::keccakf (#2263)
- Loading branch information
Showing
7 changed files
with
174 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
#![no_main] | ||
#![no_std] | ||
extern crate alloc; | ||
use alloc::vec::Vec; | ||
|
||
use powdr_riscv_runtime::hash::keccak; | ||
use hex_literal::hex; | ||
extern crate powdr_riscv_runtime; | ||
use powdr_riscv_runtime::hash::Keccak; | ||
|
||
#[no_mangle] | ||
pub fn main() { | ||
// Tests using our keccak syscall. | ||
let input: [&[u8]; 4] = [ | ||
// Zokrates test vectors | ||
&[0x7a, 0x6f, 0x6b, 0x72, 0x61, 0x74, 0x65, 0x73], | ||
&[0x2a; 135], | ||
&[0x2a; 136], | ||
// All zero test vector | ||
&[0x00; 256], | ||
]; | ||
let inputs = [b"Solidity", b"Powdrrrr"]; | ||
let mut hasher = Keccak::v256(); | ||
let mut output = [0u8; 32]; | ||
for input in inputs.into_iter().cycle().take(100) { | ||
hasher.update(input); | ||
} | ||
hasher.finalize(&mut output); | ||
|
||
let output: Vec<[u8; 32]> = input.iter().map(|x| keccak(x, 0x01)).collect(); | ||
|
||
let expected = [ | ||
hex!("ca85d1976d40dcb6ca3becc8c6596e83c0774f4185cf016a05834f5856a37f39"), | ||
hex!("723e2ae02ca8d8fb45dca21e5f6369c4f124da72f217dca5e657a4bbc69b917d"), | ||
hex!("e60d5160227cb1b8dc8547deb9c6a2c5e6c3306a1ca155611a73ed2c2324bfc0"), | ||
hex!("d397b3b043d87fcd6fad1291ff0bfd16401c274896d8c63a923727f077b8e0b5") | ||
]; | ||
|
||
// Currently commented out because keccakf syscall is not ready (roadblocked by circuit compiler). | ||
// output.iter().zip(expected.iter()).for_each(|(out, exp)| { | ||
// assert_eq!(out, exp); | ||
// }); | ||
// The expected output was generated using tiny-keccak's Keccak256 implementation | ||
// with the following code: | ||
// use tiny_keccak::{Hasher, Keccak}; | ||
// | ||
// let mut output = [0u8; 32]; | ||
// let mut hasher = Keccak::v256(); | ||
// for input in inputs.into_iter().cycle().take(100) { | ||
// hasher.update(input); | ||
// } | ||
// hasher.finalize(&mut output); | ||
assert_eq!( | ||
output, | ||
[ | ||
0xb2, 0x60, 0x1c, 0x72, 0x12, 0xd8, 0x26, 0x0d, 0xa4, 0x6d, 0xde, 0x19, 0x8d, 0x50, | ||
0xa7, 0xe4, 0x67, 0x1f, 0xc1, 0xbb, 0x8f, 0xf2, 0xd1, 0x72, 0x5a, 0x8d, 0xa1, 0x08, | ||
0x11, 0xb5, 0x81, 0x69 | ||
] | ||
); | ||
} |