SHA-256
The SHA-256 extension guest provides a function that is meant to be linked to other external libraries. The external libraries can use this function as a hook for the SHA-256 intrinsic. This is enabled only when the target is zkvm.
zkvm_sha256_impl(input: *const u8, len: usize, output: *mut u8): This function hasCABI. It takes in a pointer to the input, the length of the input, and a pointer to the output buffer.
In the external library, you can do the following:
#![allow(unused)] fn main() { extern "C" { fn zkvm_sha256_impl(input: *const u8, len: usize, output: *mut u8); } fn sha256(input: &[u8]) -> [u8; 32] { #[cfg(target_os = "zkvm")] { let mut output = [0u8; 32]; unsafe { zkvm_sha256_impl(input.as_ptr(), input.len(), output.as_mut_ptr() as *mut u8); } output } #[cfg(not(target_os = "zkvm"))] { // Regular SHA-256 implementation } } }
Config parameters
For the guest program to build successfully add the following to your .toml file:
[app_vm_config.sha256]