Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixes Stack Overflow and Memory Management Issues #542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions examples/overflow/guest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#![cfg_attr(feature = "guest", no_std)]

extern crate alloc;
use alloc::vec;
use alloc::vec::Vec;

#[jolt::provable(stack_size = 1024)]
#[jolt::provable(stack_size = 2048)] // Increase stack size to prevent overflow
fn overflow_stack() -> u32 {
let arr = [1u32; 1024];
// Use Vec instead of an array to avoid stack overflow
let arr: Vec<u32> = vec![1u32; 1024];
arr.iter().sum()
}

#[jolt::provable(stack_size = 8192)]
fn allocate_stack_with_increased_size() -> u32 {
// Increase stack size to prevent overflow
overflow_stack()
}

#[jolt::provable(memory_size = 4096)]
#[jolt::provable(memory_size = 8192)] // Increase memory size
fn overflow_heap() -> u32 {
let mut vectors = Vec::new();
let mut allocated_memory = 0; // Logic to track allocated memory

loop {
// Limit the amount of allocated memory
while allocated_memory < 1024 * 1024 * 100 { // For example, limit to 100 MB
let v = vec![1u32; 1024];
vectors.extend(v);
vectors.push(v);
allocated_memory += v.len() * std::mem::size_of::<u32>();
}

allocated_memory as u32 // Return the amount of allocated memory
}