Skip to content

Commit

Permalink
vm interp: compress stack in effects
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Dec 4, 2024
1 parent e85d314 commit c8b12d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/vm_interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ pub unsafe extern "C" fn sol_compat_vm_interp_v1(
1
}

pub fn vec_rtrim_zeros(v: &[u8]) -> Vec<u8> {
if let Some(i) = v.iter().rposition(|x| *x != 0) {
return v[..i + 1].into();
}
return vec![];
}

// We are actually executing the JIT-compiled program here
pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffects> {
let instr_ctx: InstrContext = syscall_context.instr_ctx?.try_into().ok()?;
Expand Down Expand Up @@ -269,7 +276,8 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
cu_avail: vm.context_object_pointer.get_remaining(),
frame_count: vm.call_depth,
heap: heap.as_slice().into(),
stack: stack.as_slice().into(),
/* Compress stack by removing right-most 0s, mainly to save 256kB space when stack is unused */
stack: vec_rtrim_zeros(stack.as_slice()),
rodata: rodata.as_slice().into(),
input_data_regions: mem_regions::extract_input_data_regions(&vm.memory_mapping),
log: vec![],
Expand Down

0 comments on commit c8b12d9

Please sign in to comment.