Skip to content

Commit

Permalink
feat: Collatz conjecture test for rv32im (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh-axiom-xyz authored Nov 6, 2024
1 parent d4d2011 commit 58d2f5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions toolchain/tests/programs/examples/collatz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![cfg_attr(target_os = "zkvm", no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

axvm::entry!(main);

pub fn main() {
let mut x: u32 = core::hint::black_box(837799);
let mut count: u32 = 0;

while count < 1000 && x != 1 {
if x % 2 == 0 {
x /= 2;
} else {
x = 3 * x + 1;
}
count += 1;
}

// https://en.wikipedia.org/wiki/Collatz_conjecture#Empirical_data
if count != 524 {
axvm::process::panic();
}
}
8 changes: 8 additions & 0 deletions toolchain/tests/src/basic_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ fn test_rv32i_prove(example_name: &str, min_segments: usize) -> Result<()> {
Ok(())
}

#[test_case("collatz", 1)]
fn test_rv32im_prove(example_name: &str, min_segments: usize) -> Result<()> {
let elf = build_example_program(example_name)?;
let config = VmConfig::rv32im();
air_test_with_min_segments(config, elf, vec![], min_segments);
Ok(())
}

#[test]
fn test_read_vec_runtime() -> Result<()> {
let elf = build_example_program("hint")?;
Expand Down

0 comments on commit 58d2f5a

Please sign in to comment.