Skip to content

Commit

Permalink
EIP-4750: RETF
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Dec 13, 2024
1 parent a9ed0cd commit bd982ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions gasometer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ pub fn dynamic_opcode_cost<H: Handler>(
Opcode::CALLF if config.has_eof => GasCost::Low,
Opcode::CALLF => GasCost::Invalid(opcode),

Opcode::RETF if config.has_eof => GasCost::VeryLow,
Opcode::RETF => GasCost::Invalid(opcode),

_ => GasCost::Invalid(opcode),
};

Expand Down
17 changes: 17 additions & 0 deletions runtime/src/eval/eof/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ pub fn callf<H: Handler>(runtime: &mut Runtime, _handler: &mut H) -> Control<H>

Control::Continue
}

pub fn retf<H: Handler>(runtime: &mut Runtime, _handler: &mut H) -> Control<H> {
let eof = require_eof!(runtime);
let Some(function_return_state) = runtime.context.eof_function_stack.pop() else {
return Control::Exit(ExitFatal::CallErrorAsFatal(ExitError::EOFUnexpectedCall).into());
};

let Some(code_section) = eof.body.code_section.get(function_return_state.index) else {
return Control::Exit(ExitFatal::CallErrorAsFatal(ExitError::EOFUnexpectedCall).into());
};
// Set machine code to target code section
runtime.machine.set_code(code_section);
// Set PC to position 0
runtime.machine.set_pc(function_return_state.pc);

Control::Continue
}
2 changes: 1 addition & 1 deletion runtime/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn eval<H: Handler>(state: &mut Runtime, opcode: Opcode, handler: &mut H) ->
Opcode::RJUMPI => eof::control::rjumpi(state, handler),
Opcode::RJUMPV => eof::control::rjumpv(state, handler),
Opcode::CALLF => eof::call::callf(state, handler),
Opcode::RETF => system::retf(state, handler),
Opcode::RETF => eof::call::retf(state, handler),
Opcode::JUMPF => system::jumpf(state, handler),
Opcode::DUPN => eof::stack::dupn(state),
Opcode::SWAPN => eof::stack::swapn(state),
Expand Down
5 changes: 0 additions & 5 deletions runtime/src/eval/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,6 @@ pub fn call<H: Handler>(runtime: &mut Runtime, scheme: CallScheme, handler: &mut
//===========================
// EOF related functions

#[allow(dead_code)]
pub fn retf<H: Handler>(_runtime: &mut Runtime, _handler: &mut H) -> Control<H> {
todo!()
}

#[allow(dead_code)]
pub fn jumpf<H: Handler>(_runtime: &mut Runtime, _handler: &mut H) -> Control<H> {
todo!()
Expand Down

0 comments on commit bd982ea

Please sign in to comment.