Skip to content

Commit

Permalink
properly encode invalid instruction cost
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed Dec 11, 2023
1 parent 7d43fd4 commit f08de5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/addressing_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct Arguments {

pub(crate) const L1_MESSAGE_COST: u32 = 156250;
pub(crate) const SSTORE_COST: u32 = 3501;
pub(crate) const INVALID_INSTRUCTION_COST: u32 = 4294967295;

impl Arguments {
pub fn new(predicate: Predicate, gas_cost: u32) -> Self {
Expand All @@ -82,7 +83,8 @@ impl Arguments {
match x {
L1_MESSAGE_COST => 1,
SSTORE_COST => 2,
1 | 2 => panic!("Reserved gas cost values overlap with actual gas costs"),
INVALID_INSTRUCTION_COST => 3,
1 | 2 | 3 => panic!("Reserved gas cost values overlap with actual gas costs"),
x => x.try_into().expect("Gas cost doesn't fit into 8 bits"),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/instruction_handlers/ret.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::call::get_far_call_arguments;
use crate::{
addressing_modes::{Arguments, Immediate1, Register1, Source},
addressing_modes::{Arguments, Immediate1, Register1, Source, INVALID_INSTRUCTION_COST},
predication::Flags,
rollback::Rollback,
state::{ExecutionEnd, InstructionResult, Panic},
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Instruction {
pub fn from_invalid() -> Self {
Self {
handler: invalid_instruction,
arguments: Arguments::new(Predicate::Always, 4294967295),
arguments: Arguments::new(Predicate::Always, INVALID_INSTRUCTION_COST),
}
}
}

0 comments on commit f08de5b

Please sign in to comment.