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
6 changes: 1 addition & 5 deletions crates/ee-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,8 @@ where

// Compare the output objects directly
if *output != expected {
// If they don't match, generate a nicer error by pretty-printing both as JSON
// This helps with debugging by showing the exact differences
let expected_pretty = serde_json::to_string_pretty(&expected).unwrap();

panic!(
"Value does not match testdata.\nExpected:\n{expected_pretty}\n\nActual:\n{output_json}"
"Value does not match testdata.\nExpected:\n{expected_json}\n\nActual:\n{output_json}"
);
}
}
Expand Down
44 changes: 0 additions & 44 deletions crates/handler/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,47 +727,3 @@ pub fn return_create<JOURNAL: JournalTr>(

interpreter_result.result = InstructionResult::Return;
}

/*
pub fn return_eofcreate<JOURNAL: JournalTr>(
journal: &mut JOURNAL,
checkpoint: JournalCheckpoint,
interpreter_result: &mut InterpreterResult,
address: Address,
max_code_size: usize,
) {
// Note we still execute RETURN opcode and return the bytes.
// In EOF those opcodes should abort execution.
//
// In RETURN gas is still protecting us from ddos and in oog,
// behaviour will be same as if it failed on return.
//
// Bytes of RETURN will drained in `insert_eofcreate_outcome`.
if interpreter_result.result != InstructionResult::ReturnContract {
journal.checkpoint_revert(checkpoint);
return;
}

if interpreter_result.output.len() > max_code_size {
journal.checkpoint_revert(checkpoint);
interpreter_result.result = InstructionResult::CreateContractSizeLimit;
return;
}

// Deduct gas for code deployment.
let gas_for_code = interpreter_result.output.len() as u64 * gas::CODEDEPOSIT;
if !interpreter_result.gas.record_cost(gas_for_code) {
journal.checkpoint_revert(checkpoint);
interpreter_result.result = InstructionResult::OutOfGas;
return;
}

journal.checkpoint_commit();

// Decode bytecode has a performance hit, but it has reasonable restrains.
let bytecode = Eof::decode(interpreter_result.output.clone()).expect("Eof is already verified");

// Eof bytecode is going to be hashed.
journal.set_code(address, Bytecode::Eof(Arc::new(bytecode)));
}
*/
4 changes: 2 additions & 2 deletions crates/handler/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub trait InstructionProvider {

/// Ethereum instruction contains list of mainnet instructions that is used for Interpreter execution.
#[derive(Debug)]
pub struct EthInstructions<WIRE: InterpreterTypes, HOST> {
pub struct EthInstructions<WIRE: InterpreterTypes, HOST: ?Sized> {
/// Table containing instruction implementations indexed by opcode.
pub instruction_table: Box<InstructionTable<WIRE, HOST>>,
}

impl<WIRE, HOST> Clone for EthInstructions<WIRE, HOST>
impl<WIRE, HOST: Host + ?Sized> Clone for EthInstructions<WIRE, HOST>
where
WIRE: InterpreterTypes,
{
Expand Down
22 changes: 9 additions & 13 deletions crates/interpreter/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,15 @@ impl Gas {
false
}

/// Record memory expansion
#[inline]
#[must_use = "internally uses record_cost that flags out of gas error"]
pub fn record_memory_expansion(&mut self, new_len: usize) -> MemoryExtensionResult {
let Some(additional_cost) = self.memory.record_new_len(new_len) else {
return MemoryExtensionResult::Same;
};

if !self.record_cost(additional_cost) {
return MemoryExtensionResult::OutOfGas;
}

MemoryExtensionResult::Extended
/// Records an explicit cost. In case of underflow the gas will wrap around cost.
///
/// Returns `true` if the gas limit is exceeded.
#[inline(always)]
#[must_use = "In case of not enough gas, the interpreter should halt with an out-of-gas error"]
pub fn record_cost_unsafe(&mut self, cost: u64) -> bool {
let oog = self.remaining < cost;
self.remaining = self.remaining.wrapping_sub(cost);
oog
}
}

Expand Down
23 changes: 1 addition & 22 deletions crates/interpreter/src/instruction_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{interpreter_types::Jumps, Interpreter, InterpreterTypes};

use super::Instruction;
use crate::{Interpreter, InterpreterTypes};

/// Context passed to instruction implementations containing the host and interpreter.
/// This struct provides access to both the host interface for external state operations
Expand All @@ -20,22 +18,3 @@ impl<H: ?Sized, ITy: InterpreterTypes> std::fmt::Debug for InstructionContext<'_
.finish()
}
}

impl<H: ?Sized, ITy: InterpreterTypes> InstructionContext<'_, H, ITy> {
/// Executes the instruction at the current instruction pointer.
///
/// Internally it will increment instruction pointer by one.
#[inline]
pub(crate) fn step(self, instruction_table: &[Instruction<ITy, H>; 256]) {
// Get current opcode.
let opcode = self.interpreter.bytecode.opcode();

// SAFETY: In analysis we are doing padding of bytecode so that we are sure that last
// byte instruction is STOP so we are safe to just increment program_counter bcs on last instruction
// it will do noop and just stop execution of this contract
self.interpreter.bytecode.relative_jump(1);

// Execute instruction.
instruction_table[opcode as usize](self)
}
}
Loading
Loading