sp1_core_machine/syscall/precompiles/keccak256/
mod.rs1mod air;
2pub mod columns;
3mod trace;
4
5use p3_keccak_air::KeccakAir;
6
7pub const STATE_SIZE: usize = 25;
8
9pub const STATE_NUM_WORDS: usize = STATE_SIZE * 2;
11
12pub struct KeccakPermuteChip {
13 p3_keccak: KeccakAir,
14}
15
16impl KeccakPermuteChip {
17 pub const fn new() -> Self {
18 Self { p3_keccak: KeccakAir {} }
19 }
20}
21
22#[cfg(test)]
23pub mod permute_tests {
24 use sp1_core_executor::{syscalls::SyscallCode, Executor, Instruction, Opcode, Program};
25 use sp1_stark::{CpuProver, SP1CoreOpts};
26 use test_artifacts::KECCAK_PERMUTE_ELF;
27
28 use crate::{
29 io::SP1Stdin,
30 utils::{self},
31 };
32
33 pub fn keccak_permute_program() -> Program {
34 let digest_ptr = 100;
35 let mut instructions = vec![Instruction::new(Opcode::ADD, 29, 0, 1, false, true)];
36 for i in 0..(25 * 8) {
37 instructions.extend(vec![
38 Instruction::new(Opcode::ADD, 30, 0, digest_ptr + i * 4, false, true),
39 Instruction::new(Opcode::SW, 29, 30, 0, false, true),
40 ]);
41 }
42 instructions.extend(vec![
43 Instruction::new(Opcode::ADD, 5, 0, SyscallCode::KECCAK_PERMUTE as u32, false, true),
44 Instruction::new(Opcode::ADD, 10, 0, digest_ptr, false, true),
45 Instruction::new(Opcode::ECALL, 5, 10, 11, false, false),
46 ]);
47
48 Program::new(instructions, 0, 0)
49 }
50
51 #[test]
52 pub fn test_keccak_permute_program_execute() {
53 utils::setup_logger();
54 let program = keccak_permute_program();
55 let mut runtime = Executor::new(program, SP1CoreOpts::default());
56 runtime.run().unwrap();
57 }
58
59 #[test]
60 fn test_keccak_permute_prove_babybear() {
61 utils::setup_logger();
62
63 let program = keccak_permute_program();
64 let stdin = SP1Stdin::new();
65 utils::run_test::<CpuProver<_, _>>(program, stdin).unwrap();
66 }
67
68 #[test]
69 fn test_keccak_permute_program_prove() {
70 utils::setup_logger();
71 let program = Program::from(KECCAK_PERMUTE_ELF).unwrap();
72 let stdin = SP1Stdin::new();
73 utils::run_test::<CpuProver<_, _>>(program, stdin).unwrap();
74 }
75}