Skip to content

Commit

Permalink
fix(levm): disable opcodes in block.rs for old forks (#1952)
Browse files Browse the repository at this point in the history
**Motivation**

`CHAINID`, `SELFBALANCE` and `BASEFEE` should be disabled for old forks

**Description**

Return `VmError::InvalidOpcode` when the opcodes should be disabled

---------

Co-authored-by: Federico Borello <[email protected]>
  • Loading branch information
LeanSerra and fborello-lambda authored Feb 14, 2025
1 parent 82c51ea commit 092679d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/vm/levm/src/opcode_handlers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ impl VM {
&mut self,
current_call_frame: &mut CallFrame,
) -> Result<OpcodeResult, VMError> {
// https://eips.ethereum.org/EIPS/eip-1344
if self.env.config.fork < Fork::Istanbul {
return Err(VMError::InvalidOpcode);
}
current_call_frame.increase_consumed_gas(gas_cost::CHAINID)?;

current_call_frame.stack.push(self.env.chain_id)?;
Expand All @@ -135,6 +139,10 @@ impl VM {
&mut self,
current_call_frame: &mut CallFrame,
) -> Result<OpcodeResult, VMError> {
// https://eips.ethereum.org/EIPS/eip-1884
if self.env.config.fork < Fork::London {
return Err(VMError::InvalidOpcode);
}
current_call_frame.increase_consumed_gas(gas_cost::SELFBALANCE)?;

let balance = get_account(&mut self.cache, self.db.clone(), current_call_frame.to)
Expand All @@ -150,6 +158,10 @@ impl VM {
&mut self,
current_call_frame: &mut CallFrame,
) -> Result<OpcodeResult, VMError> {
// https://eips.ethereum.org/EIPS/eip-3198
if self.env.config.fork < Fork::London {
return Err(VMError::InvalidOpcode);
}
current_call_frame.increase_consumed_gas(gas_cost::BASEFEE)?;

current_call_frame.stack.push(self.env.base_fee_per_gas)?;
Expand Down

0 comments on commit 092679d

Please sign in to comment.