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

feat: additional cost for far calls #13

Merged
merged 1 commit into from
May 3, 2024
Merged
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
20 changes: 19 additions & 1 deletion src/instruction_handlers/far_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::{
Instruction, Predicate, VirtualMachine,
};
use u256::U256;
use zkevm_opcode_defs::system_params::EVM_SIMULATOR_STIPEND;
use zkevm_opcode_defs::{
system_params::{EVM_SIMULATOR_STIPEND, MSG_VALUE_SIMULATOR_ADDITIVE_COST},
ADDRESS_MSG_VALUE,
};

#[repr(u8)]
pub enum CallingMode {
Expand Down Expand Up @@ -52,10 +55,25 @@ fn far_call<const CALLING_MODE: u8, const IS_STATIC: bool>(
abi.is_constructor_call,
);

let mandated_gas = if destination_address == ADDRESS_MSG_VALUE.into() {
MSG_VALUE_SIMULATOR_ADDITIVE_COST
} else {
0
};

// mandated gas is passed even if it means transferring more than the 63/64 rule allows
if let Some(gas_left) = vm.state.current_frame.gas.checked_sub(mandated_gas) {
vm.state.current_frame.gas = gas_left;
} else {
return panic_from_failed_far_call(vm, exception_handler);
};

let maximum_gas = vm.state.current_frame.gas / 64 * 63;
let new_frame_gas = abi.gas_to_pass.min(maximum_gas);
vm.state.current_frame.gas -= new_frame_gas;

let new_frame_gas = new_frame_gas + mandated_gas;

let (Some(calldata), Some((program, is_evm_interpreter))) = (calldata, decommit_result) else {
return panic_from_failed_far_call(vm, exception_handler);
};
Expand Down
Loading