diff --git a/provers/risc0/guest/src/mem.rs b/provers/risc0/guest/src/mem.rs index 7a1d294e..0a32268c 100644 --- a/provers/risc0/guest/src/mem.rs +++ b/provers/risc0/guest/src/mem.rs @@ -3,14 +3,13 @@ use std::{ ffi::c_void, }; -/// This is a basic implementation of custom memory allocation functions that mimic C-style memory management. -/// This implementation is designed to be used in ZkVM where we cross-compile Rust code with C +/// This is a basic implementation of custom memory allocation functions that mimic C-style memory management. +/// This implementation is designed to be used in ZkVM where we cross-compile Rust code with C /// due to the dependency of c-kzg. This modification also requires env var: /// $ CC="gcc" /// $ CC_riscv32im-risc0-zkvm-elf="/opt/riscv/bin/riscv32-unknown-elf-gcc" /// which is set in the build pipeline - #[no_mangle] // TODO ideally this is c_size_t, but not stabilized (not guaranteed to be usize on all archs) pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { @@ -26,8 +25,8 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { #[no_mangle] // TODO shouldn't need to zero allocated bytes since the zkvm memory is zeroed, might want to zero anyway -pub unsafe extern "C" fn calloc(size: usize) -> *mut c_void { - malloc(size) +pub unsafe extern "C" fn calloc(nobj: usize, size: usize) -> *mut c_void { + malloc(nobj * size) } #[no_mangle] diff --git a/provers/sp1/guest/src/mem.rs b/provers/sp1/guest/src/mem.rs index 405799ef..0a32268c 100644 --- a/provers/sp1/guest/src/mem.rs +++ b/provers/sp1/guest/src/mem.rs @@ -25,8 +25,8 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { #[no_mangle] // TODO shouldn't need to zero allocated bytes since the zkvm memory is zeroed, might want to zero anyway -pub unsafe extern "C" fn calloc(size: usize) -> *mut c_void { - malloc(size) +pub unsafe extern "C" fn calloc(nobj: usize, size: usize) -> *mut c_void { + malloc(nobj * size) } #[no_mangle]