Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions crates/interpreter/src/instructions/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub fn caller<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {

pub fn codesize<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
gas!(interpreter, gas::BASE);
// Inform the optimizer that the bytecode cannot be EOF to remove a bounds check.
assume!(!interpreter.contract.bytecode.is_eof());
push!(interpreter, U256::from(interpreter.contract.bytecode.len()));
}

Expand All @@ -45,6 +47,8 @@ pub fn codecopy<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H)
let code_offset = as_usize_saturated!(code_offset);
resize_memory!(interpreter, memory_offset, len);

// Inform the optimizer that the bytecode cannot be EOF to remove a bounds check.
assume!(!interpreter.contract.bytecode.is_eof());
// Note: this can't panic because we resized memory to fit.
interpreter.shared_memory.set_data(
memory_offset,
Expand Down
6 changes: 4 additions & 2 deletions crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ impl Bytecode {
}

/// Return reference to the EOF if bytecode is EOF.
pub fn eof(&self) -> Option<&Eof> {
#[inline]
pub const fn eof(&self) -> Option<&Eof> {
match self {
Self::Eof(eof) => Some(eof),
_ => None,
}
}

/// Return true if bytecode is EOF.
pub fn is_eof(&self) -> bool {
#[inline]
pub const fn is_eof(&self) -> bool {
matches!(self, Self::Eof(_))
}

Expand Down