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: stack size VM limits #961

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 15 additions & 16 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,20 +549,19 @@ impl Node {
// TODO: move this into the config
// TODO: also this would be nice to have global default with per application customization
fn get_runtime_limits() -> EyreResult<VMLimits> {
Ok(VMLimits::new(
/*max_stack_size:*/ 200 << 10, // 200 KiB
/*max_memory_pages:*/ 1 << 10, // 1 KiB
/*max_registers:*/ 100,
/*max_register_size:*/ (100 << 20).validate()?, // 100 MiB
/*max_registers_capacity:*/ 1 << 30, // 1 GiB
/*max_logs:*/ 100,
/*max_log_size:*/ 16 << 10, // 16 KiB
/*max_events:*/ 100,
/*max_event_kind_size:*/ 100,
/*max_event_data_size:*/ 16 << 10, // 16 KiB
/*max_storage_key_size:*/ (1 << 20).try_into()?, // 1 MiB
/*max_storage_value_size:*/
(10 << 20).try_into()?, // 10 MiB
// can_write: writes, // todo!
))
Ok(calimero_runtime::logic::VMLimits {
max_memory_pages: 1 << 10, // 1 KiB
max_stack_size: 200 << 10, // 200 KiB
max_registers: 100,
max_register_size: (100 << 20).validate()?, // 100 MiB
max_registers_capacity: 1 << 30, // 1 GiB
max_logs: 100,
max_log_size: 16 << 10, // 16 KiB
max_events: 100,
max_event_kind_size: 100,
max_event_data_size: 16 << 10, // 16 KiB
max_storage_key_size: (1 << 20).try_into()?, // 1 MiB
max_storage_value_size: (10 << 20).try_into()?, // 10 MiB
// can_write: writes, // todo!
})
}
28 changes: 14 additions & 14 deletions crates/runtime/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ fn main() -> EyreResult<()> {

let mut storage = InMemoryStorage::default();

let limits = VMLimits::new(
/*max_stack_size:*/ 200 << 10, // 200 KiB
/*max_memory_pages:*/ 1 << 10, // 1 KiB
/*max_registers:*/ 100,
/*max_register_size:*/ (100 << 20).validate()?, // 100 MiB
/*max_registers_capacity:*/ 1 << 30, // 1 GiB
/*max_logs:*/ 100,
/*max_log_size:*/ 16 << 10, // 16 KiB
/*max_events:*/ 100,
/*max_event_kind_size:*/ 100,
/*max_event_data_size:*/ 16 << 10, // 16 KiB
/*max_storage_key_size:*/ (1 << 20).try_into()?, // 1 MiB
/*max_storage_value_size:*/ (10 << 20).try_into()?, // 10 MiB
);
let limits = VMLimits {
max_memory_pages: 1 << 10, // 1 KiB
max_stack_size: 200 << 10, // 200 KiB
max_registers: 100,
max_register_size: (100 << 20).validate()?, // 100 MiB
max_registers_capacity: 1 << 30, // 1 GiB
max_logs: 100,
max_log_size: 16 << 10, // 16 KiB
max_events: 100,
max_event_kind_size: 100,
max_event_data_size: 16 << 10, // 16 KiB
max_storage_key_size: (1 << 20).try_into()?, // 1 MiB
max_storage_value_size: (10 << 20).try_into()?, // 10 MiB
};

let mut execute = |name: &str, payload: Option<Value>| -> EyreResult<()> {
println!("{}", "--".repeat(20).dimmed());
Expand Down
28 changes: 14 additions & 14 deletions crates/runtime/examples/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ fn main() -> EyreResult<()> {

let mut storage = InMemoryStorage::default();

let limits = VMLimits::new(
/*max_stack_size:*/ 200 << 10, // 200 KiB
/*max_memory_pages:*/ 1 << 10, // 1 KiB
/*max_registers:*/ 100,
/*max_register_size:*/ (100 << 20).validate()?, // 100 MiB
/*max_registers_capacity:*/ 1 << 30, // 1 GiB
/*max_logs:*/ 100,
/*max_log_size:*/ 16 << 10, // 16 KiB
/*max_events:*/ 100,
/*max_event_kind_size:*/ 100,
/*max_event_data_size:*/ 16 << 10, // 16 KiB
/*max_storage_key_size:*/ (1 << 20).try_into()?, // 1 MiB
/*max_storage_value_size:*/ (10 << 20).try_into()?, // 10 MiB
);
let limits = VMLimits {
max_memory_pages: 1 << 10, // 1 KiB
max_stack_size: 200 << 10, // 200 KiB
max_registers: 100,
max_register_size: (100 << 20).validate()?, // 100 MiB
max_registers_capacity: 1 << 30, // 1 GiB
max_logs: 100,
max_log_size: 16 << 10, // 16 KiB
max_events: 100,
max_event_kind_size: 100,
max_event_data_size: 16 << 10, // 16 KiB
max_storage_key_size: (1 << 20).try_into()?, // 1 MiB
max_storage_value_size: (10 << 20).try_into()?, // 10 MiB
};

let cx = VMContext::new(
to_json_vec(&json!({
Expand Down
28 changes: 14 additions & 14 deletions crates/runtime/examples/rps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ fn main() -> EyreResult<()> {

let mut storage = InMemoryStorage::default();

let limits = VMLimits::new(
/*max_stack_size:*/ 200 << 10, // 200 KiB
/*max_memory_pages:*/ 1 << 10, // 1 KiB
/*max_registers:*/ 100,
/*max_register_size:*/ (100 << 20).validate()?, // 100 MiB
/*max_registers_capacity:*/ 1 << 30, // 1 GiB
/*max_logs:*/ 100,
/*max_log_size:*/ 16 << 10, // 16 KiB
/*max_events:*/ 100,
/*max_event_kind_size:*/ 100,
/*max_event_data_size:*/ 16 << 10, // 16 KiB
/*max_storage_key_size:*/ (1 << 20).try_into()?, // 1 MiB
/*max_storage_value_size:*/ (10 << 20).try_into()?, // 10 MiB
);
let limits = VMLimits {
max_memory_pages: 1 << 10, // 1 KiB
max_stack_size: 200 << 10, // 200 KiB
max_registers: 100,
max_register_size: (100 << 20).validate()?, // 100 MiB
max_registers_capacity: 1 << 30, // 1 GiB
max_logs: 100,
max_log_size: 16 << 10, // 16 KiB
max_events: 100,
max_event_kind_size: 100,
max_event_data_size: 16 << 10, // 16 KiB
max_storage_key_size: (1 << 20).try_into()?, // 1 MiB
max_storage_value_size: (10 << 20).try_into()?, // 10 MiB
};

println!("{}", "--".repeat(20).dimmed());
println!("{:>35}", "First, we create a keypair for Joe".bold());
Expand Down
35 changes: 0 additions & 35 deletions crates/runtime/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl VMContext {
}

#[derive(Debug)]
#[non_exhaustive]
pub struct VMLimits {
pub max_memory_pages: u32,
pub max_stack_size: usize,
Expand All @@ -64,40 +63,6 @@ pub struct VMLimits {
// number of functions per contract
}

impl VMLimits {
#[expect(clippy::too_many_arguments, reason = "Acceptable here")]
#[must_use]
pub const fn new(
max_memory_pages: u32,
max_stack_size: usize,
max_registers: u64,
max_register_size: Constrained<u64, MaxU64<{ u64::MAX - 1 }>>,
max_registers_capacity: u64,
max_logs: u64,
max_log_size: u64,
max_events: u64,
max_event_kind_size: u64,
max_event_data_size: u64,
max_storage_key_size: NonZeroU64,
max_storage_value_size: NonZeroU64,
) -> Self {
Self {
max_memory_pages,
max_stack_size,
max_registers,
max_register_size,
max_registers_capacity,
max_logs,
max_log_size,
max_events,
max_event_kind_size,
max_event_data_size,
max_storage_key_size,
max_storage_value_size,
}
}
}

#[derive(Debug)]
pub struct VMLogic<'a> {
storage: &'a mut dyn Storage,
Expand Down
Loading