From 2bf4c3269c78fbb919bb6718f9e7c6b45aef924f Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Mon, 24 Oct 2022 21:58:05 -0700 Subject: [PATCH 1/2] Use ruint 1.5.1. --- README.md | 12 ++++++++++-- crates/revm/Cargo.toml | 2 +- crates/revm/src/instructions.rs | 6 +++--- crates/revm/src/instructions/macros.rs | 19 ------------------- crates/revm/src/instructions/memory.rs | 2 +- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 174f1ed2a0..974fdb31a9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,16 @@ run tests with command: `cargo run --release -- statetest tests/GeneralStateTest `GeneralStateTests` contains all tests related to EVM. +## Running benchmarks + +```shell +cargo run --package revm-test --release --bin snailtracer +``` + +```shell +cargo flamegraph --root --freq 4000 --min-width 0.001 --package revm-test --bin snailtracer +``` + # Used by * Foundry project (as their main EVM): https://github.com/foundry-rs/foundry @@ -46,5 +56,3 @@ run tests with command: `cargo run --release -- statetest tests/GeneralStateTest There is public telegram group: https://t.me/+Ig4WDWOzikA3MzA0 Or if you want to hire me or contact me directly, here is my email: dragan0rakita@gmail.com and telegram: https://t.me/draganrakita - - diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 957a5cdfcb..d654f2a29a 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -21,7 +21,7 @@ parking_lot = { version = "0.12", optional = true } primitive-types = { version = "0.11", default-features = false, features = ["rlp"] } revm_precompiles = { path = "../revm_precompiles", version = "1.1.1", default-features = false } rlp = { version = "0.5", default-features = false } # used for create2 address calculation -ruint = { version = "1.5.0", features = ["rlp"] } +ruint = { version = "1.5.1", features = ["rlp"] } serde = { version = "1.0", features = ["derive","rc"], optional = true } sha3 = { version = "0.10", default-features = false } tokio = { version = "1.21", features = ["rt-multi-thread", "macros"], optional = true } diff --git a/crates/revm/src/instructions.rs b/crates/revm/src/instructions.rs index 88e87fdc32..296f46e57f 100644 --- a/crates/revm/src/instructions.rs +++ b/crates/revm/src/instructions.rs @@ -86,9 +86,9 @@ pub fn eval(opcode: u8, interp: &mut Interpreter, host: &mut H 246_u8..=249_u8 => Return::OpcodeNotFound, 251_u8..=252_u8 => Return::OpcodeNotFound,*/ opcode::STOP => Return::Stop, - opcode::ADD => op2_u256_tuple!(interp, overflowing_add), - opcode::MUL => op2_u256_tuple!(interp, overflowing_mul), - opcode::SUB => op2_u256_tuple!(interp, overflowing_sub), + opcode::ADD => op2_u256!(interp, wrapping_add), + opcode::MUL => op2_u256!(interp, wrapping_mul), + opcode::SUB => op2_u256!(interp, wrapping_sub), opcode::DIV => op2_u256_fn!(interp, arithmetic::div), opcode::SDIV => op2_u256_fn!(interp, arithmetic::sdiv), opcode::MOD => op2_u256_fn!(interp, arithmetic::rem), diff --git a/crates/revm/src/instructions/macros.rs b/crates/revm/src/instructions/macros.rs index 5df5b0f898..e70c6b6210 100644 --- a/crates/revm/src/instructions/macros.rs +++ b/crates/revm/src/instructions/macros.rs @@ -210,25 +210,6 @@ macro_rules! op2_u256 { }}; } -macro_rules! op2_u256_tuple { - ( $interp:expr, $op:ident) => {{ - // gas!($interp, $gas); - - pop_top!($interp, op1, op2); - let (ret, ..) = op1.$op(*op2); - *op2 = ret; - - Return::Continue - }}; - ( $interp:expr, $op:ident ) => {{ - pop_top!($interp, op1, op2); - let (ret, ..) = op1.$op(op2); - *op2 = ret; - - Return::Continue - }}; -} - macro_rules! op2_u256_fn { ( $interp:expr, $op:path ) => {{ // gas!($interp, $gas); diff --git a/crates/revm/src/instructions/memory.rs b/crates/revm/src/instructions/memory.rs index 166137959c..6f98adf2cc 100644 --- a/crates/revm/src/instructions/memory.rs +++ b/crates/revm/src/instructions/memory.rs @@ -8,7 +8,7 @@ pub fn mload(interp: &mut Interpreter) -> Return { memory_resize!(interp, index, 32); push!( interp, - U256::try_from_be_slice(interp.memory.get_slice(index, 32)).unwrap() + U256::from_be_bytes::<32>(interp.memory.get_slice(index, 32).try_into().unwrap()) ); Return::Continue } From dfc38d8991938c78f8f15e746be7d2aeca8e0c4f Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Mon, 24 Oct 2022 22:02:49 -0700 Subject: [PATCH 2/2] Better inlining --- Cargo.lock | 6 +++--- Cargo.toml | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43495ec737..ad72161136 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1602,11 +1602,11 @@ dependencies = [ [[package]] name = "ruint" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e92ffeb2358f4d0ada2906530800ee2dce75d2a45aafa621f9033fd762aed6" +checksum = "d8e3fd8b28f406396b65269b36de0fba1c1c8b9cd8b2c2eae3733aed700000f7" dependencies = [ - "primitive-types 0.10.1", + "primitive-types 0.11.1", "rlp", "ruint-macro", "rustc_version", diff --git a/Cargo.toml b/Cargo.toml index 76f34fcfbc..87c6e2298a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ default-members = ["crates/revm"] [profile.release] # debug = true +lto = true +codegen-units = 1 [profile.ethtests] inherits = "test"