mirror of
https://github.com/eth-act/ere.git
synced 2026-02-19 11:54:42 -05:00
ere-risc0: allocator alignments test (#120)
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
tests/risc0/allocs_alignment/Cargo.toml
Normal file
13
tests/risc0/allocs_alignment/Cargo.toml
Normal 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" }
|
||||
11
tests/risc0/allocs_alignment/src/main.rs
Normal file
11
tests/risc0/allocs_alignment/src/main.rs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user