From 50e1002f0a9c896037a226dc3d4280b4941950c3 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 2 Sep 2024 02:26:57 +0200 Subject: [PATCH] funding.json --- bins/revm-test/Cargo.toml | 2 +- crates/interpreter/src/interpreter.rs | 37 ++++++++++++++++++++++++--- funding.json | 5 ++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 funding.json diff --git a/bins/revm-test/Cargo.toml b/bins/revm-test/Cargo.toml index 1603661040..8f6e456f15 100644 --- a/bins/revm-test/Cargo.toml +++ b/bins/revm-test/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] bytes = "1.7" hex = "0.4" -revm = { path = "../../crates/revm", version = "14.0.1", default-features=false } +revm = { path = "../../crates/revm", version = "14.0.1", default-features=false, features=["std"] } microbench = "0.5" alloy-sol-macro = "0.8.0" alloy-sol-types = "0.8.0" diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index ea1389e7fe..0fe587a924 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -9,12 +9,14 @@ pub use contract::Contract; pub use shared_memory::{num_words, SharedMemory, EMPTY_SHARED_MEMORY}; pub use stack::{Stack, STACK_LIMIT}; +use crate::opcode::make_instruction_table; use crate::{ gas, primitives::Bytes, push, push_b256, return_ok, return_revert, CallOutcome, CreateOutcome, FunctionStack, Gas, Host, InstructionResult, InterpreterAction, }; +use crate::{instructions, Instruction, OPCODE_INFO_JUMPTABLE}; use core::cmp::min; -use revm_primitives::{Bytecode, Eof, U256}; +use revm_primitives::{Bytecode, CancunSpec, Eof, U256}; use std::borrow::ToOwned; use std::sync::Arc; @@ -22,7 +24,7 @@ use std::sync::Arc; #[derive(Debug)] pub struct Interpreter { /// The current instruction pointer. - pub instruction_pointer: *const u8, + pub instruction_pointer: *const usize, /// The gas state. pub gas: Gas, /// Contract information and invoking data @@ -348,6 +350,23 @@ impl Interpreter { /// Internally it will increment instruction pointer by one. #[inline] pub(crate) fn step(&mut self, instruction_table: &[FN; 256], host: &mut H) + where + FN: Fn(&mut Interpreter, &mut H), + { + // Get current opcode. + let opcode = unsafe { *self.instruction_pointer as usize }; + + // 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.instruction_pointer = unsafe { self.instruction_pointer.offset(1) }; + + // execute instruction. + (instruction_table[opcode])(self, host); + } + + #[inline] + pub(crate) fn step_tailed(&mut self, instruction_table: &[FN; 256], host: &mut H) where FN: Fn(&mut Interpreter, &mut H), { @@ -360,7 +379,7 @@ impl Interpreter { self.instruction_pointer = unsafe { self.instruction_pointer.offset(1) }; // execute instruction. - (instruction_table[opcode as usize])(self, host) + (instruction_table[opcode])(self, host); } /// Take memory and replace it with empty memory. @@ -380,11 +399,21 @@ impl Interpreter { { self.next_action = InterpreterAction::None; self.shared_memory = shared_memory; + let time = std::time::Instant::now(); + + let mut bytecode_fn: Vec> = vec![instructions::control::invalid; 10]; + let inst_table = make_instruction_table::(); + + for opcode in self.bytecode.iter() { + let opcode = *opcode as usize; + bytecode_fn[opcode] = inst_table[opcode]; + } + // main loop while self.instruction_result == InstructionResult::Continue { self.step(instruction_table, host); } - + println!("executed in: {:?}", time.elapsed()); // Return next action if it is some. if self.next_action.is_some() { return core::mem::take(&mut self.next_action); diff --git a/funding.json b/funding.json new file mode 100644 index 0000000000..372ec73e9c --- /dev/null +++ b/funding.json @@ -0,0 +1,5 @@ +{ + "opRetro": { + "projectId": "0xb2d109759fe14e11ac5cc100ab6006321ebdd7ffdefbd2efac93a002105f8e92" + } +}