Skip to content

Commit

Permalink
Increase memory stipend for EVM calls
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Nov 21, 2024
1 parent be26e98 commit 977f77c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/zk_evm/src/opcodes/execution/far_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@ impl<const N: usize, E: VmEncodingMode<N>> DecodedOpcode<N, E> {
let memory_stipend = if address_is_kernel(&address_for_next) {
zkevm_opcode_defs::system_params::NEW_KERNEL_FRAME_MEMORY_STIPEND
} else {
zkevm_opcode_defs::system_params::NEW_FRAME_MEMORY_STIPEND
if call_to_evm_simulator {
zkevm_opcode_defs::system_params::NEW_EVM_FRAME_MEMORY_STIPEND
} else {
zkevm_opcode_defs::system_params::NEW_FRAME_MEMORY_STIPEND
}
};

let new_stack = CallStackEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,10 @@ where
cs,
zkevm_opcode_defs::system_params::NEW_FRAME_MEMORY_STIPEND,
);
let memory_size_stipend_for_evm = UInt32::allocated_constant(
cs,
zkevm_opcode_defs::system_params::NEW_EVM_FRAME_MEMORY_STIPEND,
);

let memory_stipend = UInt32::conditionally_select(
cs,
Expand All @@ -1141,6 +1145,13 @@ where
&memory_size_stipend_for_userspace,
);

let memory_stipend = UInt32::conditionally_select(
cs,
versioned_byte_is_evm_bytecode,
&memory_size_stipend_for_evm,
&memory_stipend,
);

new_callstack_entry.heap_upper_bound = memory_stipend;
new_callstack_entry.aux_heap_upper_bound = memory_stipend;

Expand Down
2 changes: 2 additions & 0 deletions crates/zkevm_opcode_defs/src/system_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub const ADDRESS_CODE_ORACLE: u16 = 0x8011;
pub const BOOTLOADER_MAX_MEMORY: u32 = u32::MAX;
// 4 KB for new frames is "free"
pub const NEW_FRAME_MEMORY_STIPEND: u32 = 1u32 << 12;
// 56 KB for new EVM frames is "free"
pub const NEW_EVM_FRAME_MEMORY_STIPEND: u32 = 56 * 1u32 << 10;
// 2 MB for kernel frames, where we can be sure about the behavior.
// Note, that this number should high enough to allow any bytecode for `decommit` opcode.
pub const NEW_KERNEL_FRAME_MEMORY_STIPEND: u32 = 1u32 << 21;
Expand Down

0 comments on commit 977f77c

Please sign in to comment.