ere-risc0: allocator alignments test (#120)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
Ignacio Hagopian
2025-09-03 13:18:09 +02:00
committed by GitHub
parent e4b1ccca54
commit 071deec1c3
3 changed files with 46 additions and 0 deletions

View File

@@ -341,4 +341,26 @@ mod tests {
zkvm.prove(&inputs).unwrap_err();
}
}
#[test]
fn test_aligned_allocs() {
let program = RV32_IM_RISC0_ZKVM_ELF
.compile(&testing_guest_directory("risc0", "allocs_alignment"))
.unwrap();
for i in 1..=16_usize {
let zkvm = EreRisc0::new(program.clone(), ProverResourceType::Cpu).unwrap();
let mut input = Input::new();
input.write(i);
if i.is_power_of_two() {
zkvm.execute(&input)
.expect("Power of two alignment should execute successfully");
} else {
zkvm.execute(&input)
.expect_err("Non-power of two aligment is expected to fail");
}
}
}
}

View File

@@ -0,0 +1,13 @@
[package]
name = "ere-test-risc0-allocs-alignment"
version = "0.1.0"
edition = "2021"
[workspace]
[dependencies]
risc0-zkvm = { version = "3.0.1", default-features = false, features = [
"std",
"unstable",
] }
risc0-zkvm-platform = { version = "=2.0.4" }

View File

@@ -0,0 +1,11 @@
use risc0_zkvm::guest::env;
fn main() {
let alignment = env::read::<usize>();
let layout = std::alloc::Layout::from_size_align(1, alignment).unwrap();
let ptr = unsafe { std::alloc::alloc(layout) };
if ptr.is_null() {
panic!("allocation failed");
}
}