Skip to content

Commit

Permalink
chore(examples): fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
4rgon4ut committed Nov 1, 2024
1 parent c2a69aa commit 45b5246
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/overflow/guest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use alloc::vec;
use alloc::vec::Vec;

#[jolt::provable(stack_size = 1024)]
fn allocate_stack() -> u32 {
fn overflow_stack() -> u32 {
let arr = [1u32; 1024];
arr.iter().sum()
}

#[jolt::provable(stack_size = 8192)]
fn allocate_stack_with_increased_size() -> u32 {
allocate_stack()
overflow_stack()
}

#[jolt::provable(memory_size = 4096)]
fn allocate_heap() -> u32 {
fn overflow_heap() -> u32 {
let mut vectors = Vec::new();

loop {
Expand Down
12 changes: 6 additions & 6 deletions examples/overflow/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ use std::any::Any;
use std::panic;

pub fn main() {
let (prove_allocate_stack, _) = guest::build_allocate_stack();
let (prove_overflow_stack, _) = guest::build_overflow_stack();

let res = panic::catch_unwind(|| {
// trying to allocate 1024 elems array and sum it up
// with stack_size=1024, should panic
let (_, _) = prove_allocate_stack();
let (_, _) = prove_overflow_stack();
});
handle_result(res);

// now lets try to overflow the heap, should also panic
let (prove_allocate_heap, _) = guest::build_allocate_heap();
let (prove_overflow_heap, _) = guest::build_overflow_heap();

let res = panic::catch_unwind(|| {
let (_, _) = prove_allocate_heap();
let (_, _) = prove_overflow_heap();
});
handle_result(res);

// valid case for stack allocation, calls allocate_stack() under the hood
// valid case for stack allocation, calls overflow_stack() under the hood
// but with stack_size=8192
let (prove_allocate_stack_with_increased_size, verfiy_allocate_stack_with_increased_size) =
guest::build_allocate_stack_with_increased_size();
Expand All @@ -34,7 +34,7 @@ pub fn main() {
fn handle_result(res: Result<(), Box<dyn Any + Send>>) {
match &res {
Err(e) => match e.downcast_ref::<String>() {
Some(msg) => println!("Panic occurred with message: {}\n", msg),
Some(msg) => println!("> Panic occurred with message: {}\n", msg),
_ => (),
},
_ => (),
Expand Down

0 comments on commit 45b5246

Please sign in to comment.