Keccak256
The Keccak256 extension guest provides functions that are meant to be linked to other external libraries. The external libraries can use these functions as hooks for the Keccak-256 intrinsics. This is enabled only when the target is zkvm.
We provide the following functions for the low-level Keccak sponge operations:
native_xorin(buffer: *mut u8, input: *const u8, len: usize): XORsleninput bytes into a state buffer in-place.lenis constrained in-circuit to be a non-negative multiple of 4 and at most 136.native_keccakf(buffer: *mut u8): Applies the keccak-f[1600] permutation in-place on a 200-byte state buffer.
The openvm-keccak256 guest library builds on these to provide native_keccak256, a C ABI function that implements the full Keccak-256 hash:
native_keccak256(input: *const u8, len: usize, output: *mut u8): Computes the Keccak-256 hash oflenbytes atinputand writes the 32-byte digest tooutput.
In the external library, you can do the following:
extern "C" {
fn native_keccak256(input: *const u8, len: usize, output: *mut u8);
}
fn keccak256(input: &[u8]) -> [u8; 32] {
#[cfg(target_os = "zkvm")]
{
let mut output = [0u8; 32];
unsafe {
native_keccak256(input.as_ptr(), input.len(), output.as_mut_ptr() as *mut u8);
}
output
}
#[cfg(not(target_os = "zkvm"))] {
// Regular Keccak-256 implementation
}
}Config parameters
For the guest program to build successfully add the following to your .toml file:
[app_vm_config.keccak]