Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #52

Merged
merged 16 commits into from
Feb 27, 2022
305 changes: 216 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# revm - Revolutionary Machine

Is **Rust Ethereum Virtual Machine** with great name that is focused on **speed** and **simplicity**. It gets ispiration from `SputnikVM` (got opcodes/machine from here), `OpenEthereum` and `Geth` with a help from [wolflo/evm-opcodes](https://github.com/wolflo/evm-opcodes).
Is **Rust Ethereum Virtual Machine** with great name that is focused on **speed** and **simplicity**. It gets ispiration from `SputnikVM` (got opcodes/interp from here), `OpenEthereum` and `Geth` with a help from [wolflo/evm-opcodes](https://github.com/wolflo/evm-opcodes).

It is fast and flexible implementation of EVM with simple interface and embeded Host, there are multiple things done on Host part from const EVM Spec to optimistic changelogs for subroutines to merging `eip2929` in EVM state so that it can be accesses only once that are improving the speed of execution. There are still some improvements on Interepter part that needs to be done so that we can be comparable with evmone, for more info track [this issue](https://github.com/bluealloy/revm/issues/7).

Expand Down
2 changes: 1 addition & 1 deletion bins/revm-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2018"
[dependencies]
bytes = "1.1"
hex = "0.4"
primitive-types = { version = "0.10", features = ["rlp"] }
primitive-types = { version = "0.11", features = ["rlp"] }
revm = { path = "../../crates/revm" }
4 changes: 2 additions & 2 deletions bins/revm-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ pub fn simple_example() {

let mut elapsed = std::time::Duration::ZERO;
let mut times = Vec::new();
for _ in 0..10 {
for _ in 0..30 {
let timer = Instant::now();
let (_, _, _, _, _) = evm.transact();
let i = timer.elapsed();
times.push(i);
elapsed += i;
}
println!("elapsed: {:?}", elapsed / 10);
println!("elapsed: {:?}", elapsed / 30);
for (i, time) in times.iter().enumerate() {
println!("{}: {:?}", i, time);
}
Expand Down
4 changes: 2 additions & 2 deletions bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ hashbrown = "0.12"
hex = "0.4"
indicatif = "0.16"
plain_hasher = "0.2"
primitive-types = { version = "0.10", features = ["rlp", "serde"] }
primitive-types = { version = "0.11", features = ["rlp", "serde"] }

revm = { path = "../../crates/revm", version = "1.1", default-features = false, features = ["web3db","std","k256"] }
rlp = { version = "0.5", default-features = false }
Expand All @@ -25,7 +25,7 @@ serde_derive = "1.0"
serde_json = "1.0"
sha3 = { version = "0.10", default-features = false }
structopt = "0.3"
termwiz = "0.13" # used for debugger ctrl
termwiz = "0.15" # used for debugger ctrl
thiserror = "1.0"
triehash = "0.8"
walkdir = "2.3"
94 changes: 40 additions & 54 deletions bins/revme/src/debugger/ctrl/ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use bytes::Bytes;

use primitive_types::{H160, U256};
use revm::{Database, EVMData, Gas, Inspector, Return, OPCODE_JUMPMAP};
use revm::{CallInputs, CreateInputs, Database, EVMData, Gas, Inspector, Return, OPCODE_JUMPMAP};

use termwiz::lineedit::*;

Expand Down Expand Up @@ -90,15 +90,15 @@ pub enum StateMachine {
}

pub struct Controller {
state_machine: StateMachine,
state_interp: StateMachine,
history_path: Option<PathBuf>,
//call_stack: Vec<>,
}

impl Controller {
pub fn new(history_path: Option<PathBuf>) -> Self {
Self {
state_machine: StateMachine::TriggerStep,
state_interp: StateMachine::TriggerStep,
history_path,
}
}
Expand All @@ -108,73 +108,69 @@ impl Controller {
impl<DB: Database> Inspector<DB> for Controller {
fn step(
&mut self,
machine: &mut revm::Machine,
interp: &mut revm::Interpreter,
data: &mut EVMData<'_, DB>,
_is_static: bool,
) -> Return {
loop {
match Ctrl::next(self.state_machine, &self.history_path) {
match Ctrl::next(self.state_interp, &self.history_path) {
Ctrl::Help => {
println!(
"available controls: \nstep\nexit\nprint all\nstack pop\nstack push 10\n"
)
}
Ctrl::Exit => {
self.state_machine = StateMachine::Exit;
self.state_interp = StateMachine::Exit;
break;
}
Ctrl::Step => {
self.state_machine = StateMachine::TriggerStep;
self.state_interp = StateMachine::TriggerStep;
break;
}
//Ctrl::StepIn => {}
//Ctrl::StepOut => {
// self.state_machine = StateMachine::StepOut;
// self.state_interp = StateMachine::StepOut;
//}
Ctrl::Print(print) => match print {
CtrlPrint::All => {
let opcode = machine
let opcode = interp
.contract
.code
.get(machine.program_counter())
.get(interp.program_counter())
.cloned()
.unwrap();
let gas_spend = machine.gas().spend();
let gas_remaining = machine.gas().remaining();
let gas_spend = interp.gas().spend();
let gas_remaining = interp.gas().remaining();
println!(
"call_depth:{} PC:{} Opcode: {:#x} {:?} gas(spend,remaining):({},{})\n\
Stack:{}",
machine.call_depth,
machine.program_counter(),
interp.call_depth,
interp.program_counter(),
opcode,
OPCODE_JUMPMAP[opcode as usize].unwrap_or("Invalid"),
gas_spend,
gas_remaining,
machine.stack(),
interp.stack(),
);
}
CtrlPrint::Opcode => {
let opcode = *machine
.contract
.code
.get(machine.program_counter())
.unwrap();
let opcode = *interp.contract.code.get(interp.program_counter()).unwrap();
println!(
"PC:{} OpCode: {:#x} {:?}",
machine.program_counter(),
interp.program_counter(),
opcode,
OPCODE_JUMPMAP[opcode as usize]
)
}
CtrlPrint::Stack => {
println!("PC:{} stack:{}", machine.program_counter(), machine.stack())
println!("PC:{} stack:{}", interp.program_counter(), interp.stack())
}
CtrlPrint::Memory => {
println!("memory:{}", hex::encode(&machine.memory.data()))
println!("memory:{}", hex::encode(&interp.memory.data()))
}
},
Ctrl::Continue => {
self.state_machine = StateMachine::TriggerBreakpoint;
self.state_interp = StateMachine::TriggerBreakpoint;
break;
}
Ctrl::Restart => {
Expand All @@ -190,10 +186,10 @@ impl<DB: Database> Inspector<DB> for Controller {
}
Ctrl::AccountPrintOriginal(_address) => (),
Ctrl::StackPop => {
println!("pop:{:?}", machine.stack.pop());
println!("pop:{:?}", interp.stack.pop());
}
Ctrl::StackPush(value) => match machine.stack.push(value) {
Ok(()) => println!("stack:{}", machine.stack()),
Ctrl::StackPush(value) => match interp.stack.push(value) {
Ok(()) => println!("stack:{}", interp.stack()),
Err(e) => println!("push error:{:?}", e),
},
Ctrl::None => break,
Expand All @@ -202,18 +198,20 @@ impl<DB: Database> Inspector<DB> for Controller {
Return::Continue
}

fn step_end(&mut self, _eval: revm::Return, _machine: &mut revm::Machine) -> Return {
fn step_end(
&mut self,
_interp: &mut revm::Interpreter,
_data: &mut EVMData<'_, DB>,
_is_static: bool,
_eval: revm::Return,
) -> Return {
Return::Continue
}

fn call(
&mut self,
_data: &mut revm::EVMData<'_, DB>,
_call: primitive_types::H160,
_context: &revm::CallContext,
_transfer: &revm::Transfer,
_input: &bytes::Bytes,
_gas_limit: u64,
_inputs: &CallInputs,
_is_static: bool,
) -> (Return, Gas, Bytes) {
(Return::Continue, Gas::new(0), Bytes::new())
Expand All @@ -222,48 +220,36 @@ impl<DB: Database> Inspector<DB> for Controller {
fn call_end(
&mut self,
_data: &mut EVMData<'_, DB>,
_call: H160,
_context: &revm::CallContext,
_transfer: &revm::Transfer,
_input: &Bytes,
_gas_limit: u64,
_remaining_gas: u64,
_inputs: &CallInputs,
_remaining_gas: Gas,
_ret: Return,
_out: &Bytes,
_is_static: bool,
) {
if let StateMachine::StepOut = self.state_machine {
self.state_machine = StateMachine::TriggerStep
if let StateMachine::StepOut = self.state_interp {
self.state_interp = StateMachine::TriggerStep
}
}

fn create(
&mut self,
_data: &mut revm::EVMData<'_, DB>,
_caller: primitive_types::H160,
_scheme: &revm::CreateScheme,
_value: primitive_types::U256,
_init_code: &bytes::Bytes,
_gas: u64,
_inputs: &CreateInputs,
) -> (Return, Option<H160>, Gas, Bytes) {
(Return::Continue, None, Gas::new(0), Bytes::new())
}

fn create_end(
&mut self,
_data: &mut EVMData<'_, DB>,
_caller: H160,
_scheme: &revm::CreateScheme,
_value: U256,
_init_code: &Bytes,
_inputs: &CreateInputs,
_ret: Return,
_address: Option<H160>,
_gas_limit: u64,
_remaining_gas: u64,
_remaining_gas: Gas,
_out: &Bytes,
) {
if let StateMachine::StepOut = self.state_machine {
self.state_machine = StateMachine::TriggerStep
if let StateMachine::StepOut = self.state_interp {
self.state_interp = StateMachine::TriggerStep
}
}

Expand Down
Loading