From b718a546cd527632f44133a63a4c6c75452f2952 Mon Sep 17 00:00:00 2001 From: rakita Date: Sat, 18 Dec 2021 14:18:23 +0100 Subject: [PATCH] Bump versions, Changelogs, fmt, revm readme, clippy. --- CHANGELOG.md | 6 +- Cargo.lock | 67 +++- bins/revm-merkle/Cargo.toml | 2 +- bins/revm-merkle/src/model.rs | 2 - bins/revm-test/src/main.rs | 6 +- bins/revme/CHANGELOG.md | 4 + bins/revme/Cargo.toml | 9 +- bins/revme/LICENSE | 21 ++ bins/revme/README.md | 11 +- bins/revme/src/statetest/runner.rs | 2 +- crates/revm/CHANGELOG.md | 16 + crates/revm/Cargo.toml | 4 +- crates/revm/README.md | 4 +- crates/revm/flamegraph.svg | 414 --------------------- crates/revm/src/db/in_memory_db.rs | 2 +- crates/revm/src/evm_impl.rs | 17 +- crates/revm/src/inspector.rs | 2 + crates/revm/src/instructions/arithmetic.rs | 8 - crates/revm/src/instructions/bitwise.rs | 8 - crates/revm/src/instructions/gas/calc.rs | 3 - crates/revm/src/instructions/i256.rs | 20 +- crates/revm/src/instructions/misc.rs | 23 +- crates/revm/src/instructions/opcode.rs | 6 +- crates/revm/src/instructions/system.rs | 40 -- crates/revm/src/lib.rs | 2 +- crates/revm/src/machine/contract.rs | 9 +- crates/revm/src/machine/machine.rs | 11 +- crates/revm/src/machine/memory.rs | 6 + crates/revm/src/models.rs | 12 +- crates/revm/src/subroutine.rs | 2 +- crates/revm_precompiles/src/lib.rs | 12 +- crates/revmjs/Cargo.toml | 2 +- 32 files changed, 159 insertions(+), 594 deletions(-) create mode 100644 bins/revme/CHANGELOG.md create mode 100644 bins/revme/LICENSE delete mode 100644 crates/revm/flamegraph.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 397b7a7633..007e838aaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ Because this is workspace with multi libraries tags will be simplified, and with this document you can match version of project with git tag. +# v3 tag +revm: v1.0.0 +revme: v0.1.0 + # v2 tag revm: v0.5.0 revm_precomiles: v0.3.0 -# v1 tag +# v1 tag revm: v0.4.0 revm_precompiles: v0.2.0 revmjs: v0.1.0 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5e0b861de5..a2bfb18a3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,6 +134,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" +dependencies = [ + "generic-array", +] + [[package]] name = "block-padding" version = "0.2.1" @@ -313,6 +322,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-common" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" +dependencies = [ + "generic-array", +] + [[package]] name = "derivative" version = "2.2.0" @@ -346,6 +364,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "digest" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" +dependencies = [ + "block-buffer 0.10.0", + "crypto-common", + "generic-array", +] + [[package]] name = "dirs" version = "2.0.2" @@ -399,7 +428,7 @@ dependencies = [ "hex", "serde", "serde_json", - "sha3", + "sha3 0.9.1", "thiserror", "uint", ] @@ -1656,7 +1685,7 @@ dependencies = [ [[package]] name = "revm" -version = "0.5.0" +version = "1.0.0" dependencies = [ "arrayref", "auto_impl", @@ -1669,7 +1698,7 @@ dependencies = [ "primitive-types 0.10.1", "revm_precompiles", "rlp", - "sha3", + "sha3 0.10.0", "tokio", "web3", "zkp-u256", @@ -1688,7 +1717,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha3", + "sha3 0.10.0", "triehash", ] @@ -1714,7 +1743,7 @@ dependencies = [ "ripemd160", "secp256k1", "sha2", - "sha3", + "sha3 0.9.1", "substrate-bn", ] @@ -1734,7 +1763,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha3", + "sha3 0.10.0", "structopt", "termwiz", "thiserror", @@ -1762,8 +1791,8 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eca4ecc81b7f313189bf73ce724400a07da2a6dac19588b03c8bd76a2dcc251" dependencies = [ - "block-buffer", - "digest", + "block-buffer 0.9.0", + "digest 0.9.0", "opaque-debug", ] @@ -1931,10 +1960,10 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] @@ -1944,10 +1973,10 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] @@ -1957,12 +1986,22 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" dependencies = [ - "block-buffer", - "digest", + "block-buffer 0.9.0", + "digest 0.9.0", "keccak", "opaque-debug", ] +[[package]] +name = "sha3" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" +dependencies = [ + "digest 0.10.1", + "keccak", +] + [[package]] name = "signal-hook" version = "0.1.17" diff --git a/bins/revm-merkle/Cargo.toml b/bins/revm-merkle/Cargo.toml index 3a53cc63d9..7204a1f594 100644 --- a/bins/revm-merkle/Cargo.toml +++ b/bins/revm-merkle/Cargo.toml @@ -16,4 +16,4 @@ rlp = { version = "0.5", default-features = false } triehash = "0.8" hash-db = "0.15" plain_hasher = "0.2" -sha3 = { version = "0.9", default-features = false} \ No newline at end of file +sha3 = { version = "0.10", default-features = false} \ No newline at end of file diff --git a/bins/revm-merkle/src/model.rs b/bins/revm-merkle/src/model.rs index c52ecb7b2b..5c2626fb47 100644 --- a/bins/revm-merkle/src/model.rs +++ b/bins/revm-merkle/src/model.rs @@ -9,8 +9,6 @@ use serde::{ use std::collections::HashMap; -use serde_derive::*; - #[derive(Clone, Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] diff --git a/bins/revm-test/src/main.rs b/bins/revm-test/src/main.rs index 343d4c427c..58806e8cd7 100644 --- a/bins/revm-test/src/main.rs +++ b/bins/revm-test/src/main.rs @@ -1,10 +1,10 @@ use std::{str::FromStr, time::Instant}; use bytes::Bytes; -use primitive_types::{H160, U256}; +use primitive_types::H160; use revm::{ - db::{BenchmarkDB, EmptyDB}, - AccountInfo, InMemoryDB, TransactTo, KECCAK_EMPTY, + db::{BenchmarkDB}, + TransactTo, }; extern crate alloc; diff --git a/bins/revme/CHANGELOG.md b/bins/revme/CHANGELOG.md new file mode 100644 index 0000000000..bd54177210 --- /dev/null +++ b/bins/revme/CHANGELOG.md @@ -0,0 +1,4 @@ +# v0.1.0 +date: 18.12.2021 + +Initial release. statetest are done, other things I have just started working on. \ No newline at end of file diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index bd312100a6..366979b189 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -1,7 +1,10 @@ [package] +authors = ["Dragan Rakita "] edition = "2018" name = "revme" - +keywords = ["ethereum", "evm"] +license = "MIT" +repository = "https://github.com/bluealloy/revm" description = "Rust Ethereum Virtual Machine Executable" version = "0.1.0" @@ -15,12 +18,12 @@ indicatif = "0.16" plain_hasher = "0.2" primitive-types = {version = "0.10", features = ["rlp", "serde"]} -revm = {path="../../crates/revm", features = ["web3db"]} +revm = {path="../../crates/revm", version="1.0", features = ["web3db"]} rlp = {version = "0.5", default-features = false} serde = "1.0" serde_derive = "1.0" serde_json = "1.0" -sha3 = {version = "0.9", default-features = false} +sha3 = {version = "0.10", default-features = false} thiserror = "1.0" triehash = "0.8" walkdir = "2.3" diff --git a/bins/revme/LICENSE b/bins/revme/LICENSE new file mode 100644 index 0000000000..fb60ef41ea --- /dev/null +++ b/bins/revme/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 draganrakita + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bins/revme/README.md b/bins/revme/README.md index 9f06502a49..57169186a8 100644 --- a/bins/revme/README.md +++ b/bins/revme/README.md @@ -1,22 +1,23 @@ # Rust EVM executor or short REVME +It is still work in progress and it is published for only reason to take cargo name. This is binary crate that executed evm multiple ways. Currently there are three parts: * statetest: takes path to folder where ethereum statetest json can be found. It recursivly search for all json files and execute them. This is how i run all https://github.com/ethereum/tests to check if revm is compliant. Example `revme statests test/GenericEvmTest/` * debug (WIP): * (WIP) Interactive debugger with ability to change any parametar of EVM in runtime, specify breakpoints and do everything what you expect from debugger. - * Allow inserting accounts,balances,storages. + * (WIP) Allow inserting accounts,balances,storages. * Specify web3 interface to bind database, for example use infura with option `--web infura_link`. * (WIP) revert opcode implemented in EVM we can enable `rewind` of contract call so that you can go to start of contract call and start debugging again. We could even add `rewind opcode` besically rewind call and rerun it until program counter matches. * (TODO) Specify EVM environment from file or from cli. * run (TODO): Intention is to be able to specify contract bytes and input and run it. It is useful for testing and benchmarks -This can be very interesting, it gives you ability to step, modify stack/memory, set breakpoints and do everything what you would expect from standard debugger, with addition of rewinding step and contract calls. You can connect to exteranl web3 supported API and fetch for example live state from mainnet via infura, or you can set data local manupulation, either way this should be useful. +It is still WIP,but debugger can be very interesting, it gives you ability to step, modify stack/memory, set breakpoints and do everything what you would expect from standard debugger, with addition of rewinding step and contract calls. You can connect to exteranl web3 supported API and fetch for example live state from mainnet via infura, or you can set data local manupulation, either way this should be useful. This binary will be console based and interaction will be done via console inputs, this is great showcase this is first step. -commands: +Example of commands WIP: * `help` :) * `step` * `continue` @@ -39,6 +40,4 @@ commands: * `account
nonce ` * `storage ` * `storage set ` -* `...` - -what to do with cold/hot access, do we add clear hot command? \ No newline at end of file +* `...` \ No newline at end of file diff --git a/bins/revme/src/statetest/runner.rs b/bins/revme/src/statetest/runner.rs index 95a0d1138d..31ff0dec4a 100644 --- a/bins/revme/src/statetest/runner.rs +++ b/bins/revme/src/statetest/runner.rs @@ -45,7 +45,7 @@ pub fn find_all_json_tests(path: &PathBuf) -> Vec { } pub fn execute_test_suit(path: &PathBuf, elapsed: &Arc>) -> Result<(), TestError> { - // funky test with bigint value in json :) + // funky test with bigint value in json :) if path.file_name() == Some(OsStr::new("ValueOverflow.json")) { return Ok(()); } diff --git a/crates/revm/CHANGELOG.md b/crates/revm/CHANGELOG.md index 5c33937ab1..b962c079c5 100644 --- a/crates/revm/CHANGELOG.md +++ b/crates/revm/CHANGELOG.md @@ -1,8 +1,24 @@ +# v1.0.0 +date: 18.12.2021 + +It feel's like that the lib is in the state that is okay to promote it to the v1 version. Other that that, a lot of optimizations are done and the inspector trait was rewritten. + +Changes: +* web3 db +* precalculated gas blocks. Optimization +* PC opcode as pointer. Optimization +* U256 div_rem optimization +* Inspector refactored and it is now closer to Host interface. + +Optimization thread: https://github.com/bluealloy/revm/issues/7 + + # v0.5.0 date: 17.11.2021 A lot of optimization on machine(interpreter) part, it is now at least 3x faster. On interface side, Error enum was renamed to Return and it is simplified. Additionally if needed gas measuring can be removed with rust feature. +Changes: * push instruction optimized. * mload/mstore and memory optimized * Gas calculation optimized diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 90f9a2cfff..8cf9f94fa8 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -6,7 +6,7 @@ keywords = ["no_std", "ethereum", "evm"] license = "MIT" name = "revm" repository = "https://github.com/bluealloy/revm" -version = "0.5.0" +version = "1.0.0" [dependencies] auto_impl = {version = "0.5", default-features = false} @@ -16,7 +16,7 @@ num_enum = {version = "0.5", default-features = false}#used for SpecId from u8 c primitive-types = {version = "0.10", default-features = false, features = ["rlp"]} revm_precompiles = {path = "../revm_precompiles", version = "0.3", default-features = false} rlp = {version = "0.5", default-features = false}#used for create2 address calculation -sha3 = {version = "0.9", default-features = false} +sha3 = {version = "0.10", default-features = false} arrayref = "0.3" #crypto-bigint = "0.3" zkp-u256 = "0.2.1" diff --git a/crates/revm/README.md b/crates/revm/README.md index d975de9087..59ba64daea 100644 --- a/crates/revm/README.md +++ b/crates/revm/README.md @@ -72,10 +72,10 @@ I just started this project as a hobby to kill some time. Presenty it has good s The structure of the project is getting crystallized and we can see few parts that are worthy to write about: - `Spec` contains a specification of Ethereum standard. It is made as a trait so that it can be optimized away by the compiler -- `opcodes` have one main function `eval` and takes `Machine`, `EVM Host`, `Spec` and `opcode` and depending on opcode it does calculation or for various opcodes it call `Host` for subroutine handling. This is where execution happens and where we cancluate gas consumption. +- `instructions` have one main function `eval` and takes `Machine`, `EVM Host`, `Spec` and `opcode` and depending on opcode it does calculation or for various opcodes it call `Host` for subroutine handling. This is where execution happens and where we cancluate gas consumption. - `machine` contains memory and execution stack of smart contracts. It calls opcode for execution and contains `step` function. It reads the contract, extracts opcodes and handles memory. - `subroutine` for various calls/creates we need to have separate `machine` and separate accessed locations. This is place where all of this is done, additionaly, it contains all caches of accessed accounts/slots/code. EIP2929 related access is integrated into state memory. Getting inside new call `subroutine` creates checkpoint that contain needed information that can revert state if subcall reverts or needs to be discardet. Changeset is made so it is optimistic that means that we dont do any work if call is finished successfully and only do something when it fials. -- `EVM`- Is main entry to the lib,it implements `Host` and connects `subroutine` and `machine` and does `subroutine checkpoint` switches. +- `EVMImpl`- Is main entry to the lib,it implements `Host` and connects `subroutine` and `machine` and does `subroutine checkpoint` switches. ### Subroutine diff --git a/crates/revm/flamegraph.svg b/crates/revm/flamegraph.svg deleted file mode 100644 index 832ce2de2b..0000000000 --- a/crates/revm/flamegraph.svg +++ /dev/null @@ -1,414 +0,0 @@ -Flame Graph Reset ZoomSearch [revm-8221a43e25ba76c9] (30 samples, 0.37%)revm::instructions::i256::tests::benchmark_div (30 samples, 0.37%)revm::instructions::i256::div_u256::div_mod (30 samples, 0.37%)revm::instructions::i256::div_u256::div_mod_knuth (30 samples, 0.37%)revm::instructions::i256::div_u256::full_shl (30 samples, 0.37%)<primitive_types::U256 as core::ops::bit::ShlAssign<T>>::shl_assign (116 samples, 1.44%)<primitive_types::U256 as core::ops::bit::Shl<T>>::shl (17 samples, 0.21%)<T as core::convert::Into<U>>::into (17 samples, 0.21%)[unknown] (165 samples, 2.04%)[..<primitive_types::U256 as core::ops::bit::Shr<T>>::shr (49 samples, 0.61%)primitive_types::U256::bits (21 samples, 0.26%)core::num::<impl u64>::leading_zeros (12 samples, 0.15%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)[unknown] (2 samples, 0.02%)<core::iter::adapters::rev::Rev<I> as core::iter::traits::iterator::Iterator>::next (414 samples, 5.13%)<core:..core::iter::range::<impl core::iter::traits::double_ended::DoubleEndedIterator for core::ops::range::RangeInclusive<A>>::next_back (414 samples, 5.13%)core::..<core::ops::range::RangeInclusive<T> as core::iter::range::RangeInclusiveIteratorImpl>::spec_next_back (414 samples, 5.13%)<core:..core::cmp::impls::<impl core::cmp::PartialOrd for usize>::lt (262 samples, 3.25%)cor..[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)[unknown] (3 samples, 0.04%)<T as core::convert::Into<U>>::into (55 samples, 0.68%)<primitive_types::U256 as core::convert::From<u32>>::from (55 samples, 0.68%)<primitive_types::U256 as core::convert::From<u64>>::from (24 samples, 0.30%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (1 samples, 0.01%)<usize as core::iter::range::Step>::forward_unchecked (13 samples, 0.16%)core::num::<impl usize>::unchecked_add (13 samples, 0.16%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)core::iter::range::<impl core::iter::traits::iterator::Iterator for core::ops::range::Range<A>>::next (42 samples, 0.52%)<core::ops::range::Range<T> as core::iter::range::RangeIteratorImpl>::spec_next (42 samples, 0.52%)core::cmp::impls::<impl core::cmp::PartialOrd for usize>::lt (29 samples, 0.36%)<primitive_types::U256 as core::ops::bit::ShlAssign<T>>::shl_assign (871 samples, 10.79%)<primitive_types..<primitive_types::U256 as core::ops::bit::Shl<T>>::shl (830 samples, 10.28%)<primitive_type..primitive_types::U256::as_usize (42 samples, 0.52%)primitive_types::U256::fits_word (28 samples, 0.35%)[unknown] (6 samples, 0.07%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)core::array::<impl core::ops::index::IndexMut<I> for [T: N]>::index_mut (9 samples, 0.11%)core::slice::index::<impl core::ops::index::IndexMut<I> for [T]>::index_mut (9 samples, 0.11%)<core::ops::range::RangeFrom<usize> as core::slice::index::SliceIndex<[T]>>::index_mut (9 samples, 0.11%)<core::ops::range::RangeFrom<usize> as core::slice::index::SliceIndex<[T]>>::get_unchecked_mut (1 samples, 0.01%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::get_unchecked_mut (1 samples, 0.01%)core::ptr::mut_ptr::<impl *mut T>::add (1 samples, 0.01%)core::ptr::mut_ptr::<impl *mut T>::offset (1 samples, 0.01%)core::num::<impl u64>::leading_zeros (24 samples, 0.30%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)core::tuple::<impl core::cmp::PartialOrd for (A,B)>::le (156 samples, 1.93%)c..core::cmp::impls::<impl core::cmp::PartialEq for u64>::ne (29 samples, 0.36%)primitive_types::U256::zero (1 samples, 0.01%)[unknown] (9 samples, 0.11%)[unknown] (9 samples, 0.11%)[unknown] (9 samples, 0.11%)[unknown] (9 samples, 0.11%)[unknown] (9 samples, 0.11%)[unknown] (9 samples, 0.11%)[unknown] (9 samples, 0.11%)[unknown] (8 samples, 0.10%)[unknown] (8 samples, 0.10%)[unknown] (8 samples, 0.10%)[unknown] (7 samples, 0.09%)[unknown] (6 samples, 0.07%)core::num::<impl u64>::checked_shr (65 samples, 0.81%)core::num::<impl u64>::overflowing_shr (65 samples, 0.81%)core::num::<impl u64>::wrapping_shr (65 samples, 0.81%)core::num::<impl u64>::wrapping_add (45 samples, 0.56%)core::num::<impl u64>::wrapping_mul (60 samples, 0.74%)core::num::<impl u64>::wrapping_sub (104 samples, 1.29%)revm::instructions::i256::div_u256::div_mod_word (3,205 samples, 39.71%)revm::instructions::i256::div_u256::div_mod_wordcore::option::Option<T>::unwrap_or (10 samples, 0.12%)core::slice::<impl [T]>::copy_from_slice (51 samples, 0.63%)core::intrinsics::copy_nonoverlapping (51 samples, 0.63%)revm::instructions::i256::div_u256::full_mul_u64 (321 samples, 3.98%)revm..revm::instructions::i256::div_u256::overflowing_mul_u64 (240 samples, 2.97%)rev..revm::instructions::i256::div_u256::mul_u64 (240 samples, 2.97%)rev..[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)<T as core::convert::Into<U>>::into (69 samples, 0.85%)<primitive_types::U256 as core::convert::From<u32>>::from (45 samples, 0.56%)<primitive_types::U256 as core::convert::From<u64>>::from (18 samples, 0.22%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)<usize as core::iter::range::Step>::forward_unchecked (1 samples, 0.01%)core::num::<impl usize>::unchecked_add (1 samples, 0.01%)core::iter::range::<impl core::iter::traits::iterator::Iterator for core::ops::range::Range<A>>::next (23 samples, 0.28%)<core::ops::range::Range<T> as core::iter::range::RangeIteratorImpl>::spec_next (23 samples, 0.28%)core::cmp::impls::<impl core::cmp::PartialOrd for usize>::lt (22 samples, 0.27%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)revm::instructions::i256::div_u256::full_shl (616 samples, 7.63%)revm::inst..<primitive_types::U256 as core::ops::bit::Shr<T>>::shr (491 samples, 6.08%)<primiti..primitive_types::U256::as_usize (56 samples, 0.69%)primitive_types::U256::fits_word (54 samples, 0.67%)[unknown] (7 samples, 0.09%)[unknown] (7 samples, 0.09%)[unknown] (7 samples, 0.09%)[unknown] (7 samples, 0.09%)[unknown] (7 samples, 0.09%)[unknown] (7 samples, 0.09%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (6 samples, 0.07%)[unknown] (4 samples, 0.05%)revm::instructions::i256::div_u256::full_shr (513 samples, 6.36%)revm::in..core::iter::range::<impl core::iter::traits::iterator::Iterator for core::ops::range::RangeInclusive<A>>::next (95 samples, 1.18%)<core::ops::range::RangeInclusive<T> as core::iter::range::RangeInclusiveIteratorImpl>::spec_next (95 samples, 1.18%)core::cmp::impls::<impl core::cmp::PartialOrd for usize>::lt (87 samples, 1.08%)<core::iter::adapters::zip::Zip<A,B> as core::iter::traits::iterator::Iterator>::next (143 samples, 1.77%)<..<core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::next (143 samples, 1.77%)<..[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)core::num::<impl u64>::overflowing_add (53 samples, 0.66%)core::iter::traits::iterator::Iterator::for_each (547 samples, 6.78%)core::ite..core::iter::traits::iterator::Iterator::fold (547 samples, 6.78%)core::ite..core::iter::traits::iterator::Iterator::for_each::call::{{closure}} (338 samples, 4.19%)core:..revm::instructions::i256::div_u256::binop_slice::{{closure}} (338 samples, 4.19%)revm:..revm::instructions::i256::div_u256::binop_carry (197 samples, 2.44%)re..core::ops::function::Fn::call (35 samples, 0.43%)core::num::<impl u64>::overflowing_sub (35 samples, 0.43%)core::cmp::min (5 samples, 0.06%)core::cmp::Ord::min (5 samples, 0.06%)core::cmp::min_by (5 samples, 0.06%)revm::instructions::i256::div_u256::div_mod_knuth (7,778 samples, 96.36%)revm::instructions::i256::div_u256::div_mod_knuthrevm::instructions::i256::div_u256::sub_slice (596 samples, 7.38%)revm::inst..revm::instructions::i256::div_u256::binop_slice (596 samples, 7.38%)revm::inst..core::iter::traits::iterator::Iterator::zip (49 samples, 0.61%)core::iter::adapters::zip::Zip<A,B>::new (49 samples, 0.61%)<core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::new (49 samples, 0.61%)core::iter::adapters::zip::TrustedRandomAccessNoCoerce::size (44 samples, 0.55%)<core::slice::iter::IterMut<T> as core::iter::traits::iterator::Iterator>::size_hint (44 samples, 0.55%)std::panic::catch_unwind (7,864 samples, 97.42%)std::panic::catch_unwindstd::panicking::try (7,864 samples, 97.42%)std::panicking::trystd::panicking::try::do_call (7,864 samples, 97.42%)std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (7,864 samples, 97.42%)<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_oncestd::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} (7,864 samples, 97.42%)std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (7,864 samples, 97.42%)std::sys_common::backtrace::__rust_begin_short_backtracetest::run_test::run_test_inner::{{closure}} (7,864 samples, 97.42%)test::run_test::run_test_inner::{{closure}}test::run_test::run_test_inner::{{closure}} (7,864 samples, 97.42%)test::run_test::run_test_inner::{{closure}}test::run_test_in_process (7,864 samples, 97.42%)test::run_test_in_processstd::panic::catch_unwind (7,864 samples, 97.42%)std::panic::catch_unwindstd::panicking::try (7,864 samples, 97.42%)std::panicking::trystd::panicking::try::do_call (7,864 samples, 97.42%)std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (7,864 samples, 97.42%)<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once (7,864 samples, 97.42%)<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_oncetest::__rust_begin_short_backtrace (7,864 samples, 97.42%)test::__rust_begin_short_backtracecore::ops::function::FnOnce::call_once (7,864 samples, 97.42%)core::ops::function::FnOnce::call_oncerevm::instructions::i256::tests::benchmark_div (7,864 samples, 97.42%)revm::instructions::i256::tests::benchmark_divrevm::instructions::i256::div_u256::div_mod (7,852 samples, 97.27%)revm::instructions::i256::div_u256::div_modrevm::instructions::i256::div_u256::words (8 samples, 0.10%)instructions::i (8,060 samples, 99.85%)instructions::i__GI___clone (7,865 samples, 97.44%)__GI___clonestart_thread (7,865 samples, 97.44%)start_threadstd::sys::unix::thread::Thread::new::thread_start (7,865 samples, 97.44%)std::sys::unix::thread::Thread::new::thread_start<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once (7,865 samples, 97.44%)<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once (7,865 samples, 97.44%)<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_oncecore::ops::function::FnOnce::call_once{{vtable-shim}} (7,865 samples, 97.44%)core::ops::function::FnOnce::call_once{{vtable-shim}}std::thread::Builder::spawn_unchecked::{{closure}} (7,865 samples, 97.44%)std::thread::Builder::spawn_unchecked::{{closure}}std::sys::unix::thread::guard::current (1 samples, 0.01%)pthread_getattr_np (1 samples, 0.01%)__GI___libc_malloc (1 samples, 0.01%)tcache_init (1 samples, 0.01%)tcache_init (1 samples, 0.01%)arena_get2 (1 samples, 0.01%)arena_get2 (1 samples, 0.01%)_int_new_arena (1 samples, 0.01%)new_heap (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)perf (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)__GI___clone (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (5 samples, 0.06%)[unknown] (4 samples, 0.05%)[unknown] (4 samples, 0.05%)[unknown] (4 samples, 0.05%)[unknown] (4 samples, 0.05%)[unknown] (4 samples, 0.05%)[unknown] (4 samples, 0.05%)all (8,072 samples, 100%)revm-8221a43e25 (7 samples, 0.09%)_start (1 samples, 0.01%)_dl_start (1 samples, 0.01%)_dl_start_final (1 samples, 0.01%)_dl_sysdep_start (1 samples, 0.01%)dl_main (1 samples, 0.01%)_dl_relocate_object (1 samples, 0.01%)elf_dynamic_do_Rela (1 samples, 0.01%)elf_machine_lazy_rel (1 samples, 0.01%)__cosf_ifunc (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%)[unknown] (1 samples, 0.01%) \ No newline at end of file diff --git a/crates/revm/src/db/in_memory_db.rs b/crates/revm/src/db/in_memory_db.rs index 8c15cbc035..5f5fa62822 100644 --- a/crates/revm/src/db/in_memory_db.rs +++ b/crates/revm/src/db/in_memory_db.rs @@ -121,7 +121,7 @@ impl Database for CacheDB { fn storage(&mut self, address: H160, index: U256) -> U256 { match self.storage.entry(address) { Entry::Occupied(mut entry) => match entry.get_mut().entry(index) { - Entry::Occupied(entry) => entry.get().clone(), + Entry::Occupied(entry) => *entry.get(), Entry::Vacant(entry) => { let slot = self.db.storage(address, index); entry.insert(slot); diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 695443334a..f6029a09dc 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -229,11 +229,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, } fn inner_load_account(&mut self, caller: H160) -> bool { - let is_cold = self.data.subroutine.load_account(caller, self.data.db); - // if INSPECT && is_cold { - // self.inspector.load_account(&caller); - // } - is_cold + self.data.subroutine.load_account(caller, self.data.db) } fn initialization(&mut self) -> u64 { @@ -514,7 +510,7 @@ impl<'a, GSPEC: Spec, DB: Database + 'a, const INSPECT: bool> Host } fn env(&mut self) -> &mut Env { - &mut self.data.env + self.data.env } // fn inspect(&mut self) -> &mut dyn Inspector { @@ -591,14 +587,9 @@ impl<'a, GSPEC: Spec, DB: Database + 'a, const INSPECT: bool> Host if INSPECT { self.inspector.selfdestruct(); } - let res = self - .data + self.data .subroutine - .selfdestruct(address, target, self.data.db); - // if INSPECT && res.is_cold { - // self.inspector.load_account(&target); - // } - res + .selfdestruct(address, target, self.data.db) } fn create( diff --git a/crates/revm/src/inspector.rs b/crates/revm/src/inspector.rs index e9ad6f1088..78244e9064 100644 --- a/crates/revm/src/inspector.rs +++ b/crates/revm/src/inspector.rs @@ -22,8 +22,10 @@ pub trait Inspector { /// Called after `step` when instruction is executed. fn step_end(&mut self, eval: Return, machine: &mut Machine) -> Return; + // TODO introduce some struct /// Called inside call_inner with `Return` you can dictate if you want to continue execution of /// this call `Return::Continue` or you want to override that and return from call. + #[allow(clippy::too_many_arguments)] fn call( &mut self, data: &mut EVMData<'_, DB>, diff --git a/crates/revm/src/instructions/arithmetic.rs b/crates/revm/src/instructions/arithmetic.rs index dea18aa248..c9f64f876a 100644 --- a/crates/revm/src/instructions/arithmetic.rs +++ b/crates/revm/src/instructions/arithmetic.rs @@ -4,7 +4,6 @@ use super::i256::{i256_div, i256_mod}; use core::{convert::TryInto, ops::Rem}; use primitive_types::{U256, U512}; - pub fn div(op1: U256, op2: U256) -> U256 { if op2.is_zero() { U256::zero() @@ -21,12 +20,10 @@ pub fn div(op1: U256, op2: U256) -> U256 { } } - pub fn sdiv(op1: U256, op2: U256) -> U256 { i256_div(op1, op2) } - pub fn rem(op1: U256, op2: U256) -> U256 { if op2.is_zero() { U256::zero() @@ -35,7 +32,6 @@ pub fn rem(op1: U256, op2: U256) -> U256 { } } - pub fn smod(op1: U256, op2: U256) -> U256 { if op2.is_zero() { U256::zero() @@ -44,7 +40,6 @@ pub fn smod(op1: U256, op2: U256) -> U256 { } } - pub fn addmod(op1: U256, op2: U256, op3: U256) -> U256 { if op3.is_zero() { U256::zero() @@ -58,7 +53,6 @@ pub fn addmod(op1: U256, op2: U256, op3: U256) -> U256 { } } - pub fn mulmod(op1: U256, op2: U256, op3: U256) -> U256 { if op3.is_zero() { U256::zero() @@ -72,7 +66,6 @@ pub fn mulmod(op1: U256, op2: U256, op3: U256) -> U256 { } } - pub fn exp(op1: U256, op2: U256) -> U256 { let mut op1 = op1; let mut op2 = op2; @@ -88,7 +81,6 @@ pub fn exp(op1: U256, op2: U256) -> U256 { r } - pub fn eval_exp(machine: &mut Machine) -> Return { pop!(machine, op1, op2); gas_or_fail!(machine, gas::exp_cost::(op2)); diff --git a/crates/revm/src/instructions/bitwise.rs b/crates/revm/src/instructions/bitwise.rs index 56c09a93d4..69896e5f2e 100644 --- a/crates/revm/src/instructions/bitwise.rs +++ b/crates/revm/src/instructions/bitwise.rs @@ -3,7 +3,6 @@ use core::cmp::Ordering; use super::i256::{i256_cmp, i256_sign, two_compl, Sign}; use primitive_types::U256; - pub fn slt(op1: U256, op2: U256) -> U256 { if i256_cmp(op1, op2) == Ordering::Less { U256::one() @@ -12,7 +11,6 @@ pub fn slt(op1: U256, op2: U256) -> U256 { } } - pub fn sgt(op1: U256, op2: U256) -> U256 { if i256_cmp(op1, op2) == Ordering::Greater { U256::one() @@ -21,7 +19,6 @@ pub fn sgt(op1: U256, op2: U256) -> U256 { } } - pub fn iszero(op1: U256) -> U256 { if op1.is_zero() { U256::one() @@ -30,12 +27,10 @@ pub fn iszero(op1: U256) -> U256 { } } - pub fn not(op1: U256) -> U256 { !op1 } - pub fn byte(op1: U256, op2: U256) -> U256 { let mut ret = U256::zero(); @@ -52,7 +47,6 @@ pub fn byte(op1: U256, op2: U256) -> U256 { ret } - pub fn shl(shift: U256, value: U256) -> U256 { if value.is_zero() || shift >= U256::from(256) { U256::zero() @@ -62,7 +56,6 @@ pub fn shl(shift: U256, value: U256) -> U256 { } } - pub fn shr(shift: U256, value: U256) -> U256 { if value.is_zero() || shift >= U256::from(256) { U256::zero() @@ -72,7 +65,6 @@ pub fn shr(shift: U256, value: U256) -> U256 { } } - pub fn sar(shift: U256, mut value: U256) -> U256 { let value_sign = i256_sign::(&mut value); diff --git a/crates/revm/src/instructions/gas/calc.rs b/crates/revm/src/instructions/gas/calc.rs index b81686ab67..746442fb8d 100644 --- a/crates/revm/src/instructions/gas/calc.rs +++ b/crates/revm/src/instructions/gas/calc.rs @@ -87,7 +87,6 @@ pub fn exp_cost(power: U256) -> Option { } } - pub fn verylowcopy_cost(len: U256) -> Option { let wordd = len / U256::from(32); let wordr = len % U256::from(32); @@ -134,7 +133,6 @@ pub fn extcodecopy_cost(len: U256, is_cold: bool) -> Option { Some(gas.as_u64()) } - pub fn account_access_gas(is_cold: bool) -> u64 { if SPEC::enabled(BERLIN) { if is_cold { @@ -298,7 +296,6 @@ pub fn call_cost( + new_cost::(is_call_or_staticcall, is_new, transfers_value) } - pub fn hot_cold_cost(is_cold: bool, regular_value: u64) -> u64 { if SPEC::enabled(BERLIN) { if is_cold { diff --git a/crates/revm/src/instructions/i256.rs b/crates/revm/src/instructions/i256.rs index 3c6310adba..0b00356e3e 100644 --- a/crates/revm/src/instructions/i256.rs +++ b/crates/revm/src/instructions/i256.rs @@ -76,6 +76,7 @@ pub fn i256_cmp(mut first: U256, mut second: U256) -> Ordering { } } +/* pub mod inner_zkp_u256 { use core::convert::TryFrom; use zkp_u256::U256; @@ -284,10 +285,9 @@ pub mod inner_zkp_u256 { #[allow(clippy::cast_possible_truncation)] (ret as u64, 0_u64.wrapping_sub((ret >> 64) as u64)) } -} +} */ pub mod div_u256 { - use super::inner_zkp_u256::divrem_2by1; use super::*; const WORD_BITS: usize = 64; @@ -336,12 +336,12 @@ pub mod div_u256 { #[inline(always)] fn fits_word(me: &U256) -> bool { let U256(ref arr) = me; - for i in 1..4 { - if arr[i] != 0 { + for i in arr.iter().take(4).skip(1) { + if *i != 0 { return false; } } - return true; + true } // See Knuth, TAOCP, Volume 2, section 4.3.1, Algorithm D. @@ -480,13 +480,13 @@ pub mod div_u256 { fn full_shr(u: [u64; 4 + 1], shift: u32) -> U256 { debug_assert!(shift < WORD_BITS as u32); let mut res = U256::zero(); - for i in 0..4 { - res.0[i] = u[i] >> shift; + for (i, item) in u.iter().enumerate().take(4) { + res.0[i] = item >> shift; } // carry if shift > 0 { - for i in 1..=4 { - res.0[i - 1] |= u[i] << (WORD_BITS as u32 - shift); + for (i, item) in u.iter().enumerate().skip(1) { + res.0[i - 1] |= item << (WORD_BITS as u32 - shift); } } res @@ -541,9 +541,7 @@ pub mod div_u256 { #[inline(always)] fn div_mod_word(hi: u64, lo: u64, y: u64) -> (u64, u64) { - //divrem_2by1(lo,hi,y) debug_assert!(hi < y); - //NOTE: this is slow (__udivti3) let x = (u128::from(hi) << 64) + u128::from(lo); let d = u128::from(y); ((x / d) as u64, (x % d) as u64) diff --git a/crates/revm/src/instructions/misc.rs b/crates/revm/src/instructions/misc.rs index 410446f2aa..638cb06f47 100644 --- a/crates/revm/src/instructions/misc.rs +++ b/crates/revm/src/instructions/misc.rs @@ -2,7 +2,6 @@ use super::gas; use crate::{machine::Machine, util, Return, Spec, SpecId::*}; use primitive_types::{H256, U256}; - pub fn codesize(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); let size = U256::from(machine.contract.code_size); @@ -10,7 +9,6 @@ pub fn codesize(machine: &mut Machine) -> Return { Return::Continue } - pub fn codecopy(machine: &mut Machine) -> Return { pop!(machine, memory_offset, code_offset, len); gas_or_fail!(machine, gas::verylowcopy_cost(len)); @@ -29,7 +27,6 @@ pub fn codecopy(machine: &mut Machine) -> Return { Return::Continue } - pub fn calldataload(machine: &mut Machine) -> Return { //gas!(machine, gas::VERYLOW); @@ -52,7 +49,6 @@ pub fn calldataload(machine: &mut Machine) -> Return { Return::Continue } - pub fn calldatasize(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); @@ -61,7 +57,6 @@ pub fn calldatasize(machine: &mut Machine) -> Return { Return::Continue } - pub fn calldatacopy(machine: &mut Machine) -> Return { pop!(machine, memory_offset, data_offset, len); gas_or_fail!(machine, gas::verylowcopy_cost(len)); @@ -79,7 +74,6 @@ pub fn calldatacopy(machine: &mut Machine) -> Return { Return::Continue } - pub fn pop(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); machine.stack.reduce_one() @@ -98,7 +92,6 @@ pub fn mload(machine: &mut Machine) -> Return { Return::Continue } - pub fn mstore(machine: &mut Machine) -> Return { //gas!(machine, gas::VERYLOW); @@ -110,7 +103,6 @@ pub fn mstore(machine: &mut Machine) -> Return { Return::Continue } - pub fn mstore8(machine: &mut Machine) -> Return { //gas!(machine, gas::VERYLOW); @@ -124,7 +116,6 @@ pub fn mstore8(machine: &mut Machine) -> Return { Return::Continue } - pub fn jump(machine: &mut Machine) -> Return { //gas!(machine, gas::MID); @@ -132,14 +123,13 @@ pub fn jump(machine: &mut Machine) -> Return { let dest = as_usize_or_fail!(dest, Return::InvalidJump); if machine.contract.is_valid_jump(dest) { - machine.program_counter = unsafe { machine.contract.code.as_ptr().offset(dest as isize) }; + machine.program_counter = unsafe { machine.contract.code.as_ptr().add(dest) }; Return::Continue } else { Return::InvalidJump } } - pub fn jumpi(machine: &mut Machine) -> Return { //gas!(machine, gas::HIGH); @@ -148,8 +138,7 @@ pub fn jumpi(machine: &mut Machine) -> Return { if !value.is_zero() { let dest = as_usize_or_fail!(dest, Return::InvalidJump); if machine.contract.is_valid_jump(dest) { - machine.program_counter = - unsafe { machine.contract.code.as_ptr().offset(dest as isize) }; + machine.program_counter = unsafe { machine.contract.code.as_ptr().add(dest) }; Return::Continue } else { Return::InvalidJump @@ -160,20 +149,17 @@ pub fn jumpi(machine: &mut Machine) -> Return { } } - pub fn jumpdest(machine: &mut Machine) -> Return { gas!(machine, gas::JUMPDEST); machine.add_next_gas_block(machine.program_counter() - 1) } - pub fn pc(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); push!(machine, U256::from(machine.program_counter() - 1)); Return::Continue } - pub fn msize(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); push!(machine, U256::from(machine.memory.effective_len())); @@ -189,23 +175,20 @@ pub fn push(machine: &mut Machine) -> Return { let ret = machine .stack .push_slice::(unsafe { core::slice::from_raw_parts(start, N) }); - machine.program_counter = unsafe { machine.program_counter.offset(N as isize) }; + machine.program_counter = unsafe { machine.program_counter.add(N) }; ret } - pub fn dup(machine: &mut Machine) -> Return { //gas!(machine, gas::VERYLOW); machine.stack.dup::() } - pub fn swap(machine: &mut Machine) -> Return { //gas!(machine, gas::VERYLOW); machine.stack.swap::() } - pub fn ret(machine: &mut Machine) -> Return { // zero gas cost gas!(machine,gas::ZERO); pop!(machine, start, len); diff --git a/crates/revm/src/instructions/opcode.rs b/crates/revm/src/instructions/opcode.rs index 448fc7e030..04801c43aa 100644 --- a/crates/revm/src/instructions/opcode.rs +++ b/crates/revm/src/instructions/opcode.rs @@ -1,4 +1,4 @@ -use crate::{Spec, SpecId}; +use crate::SpecId; use super::gas; @@ -511,7 +511,7 @@ macro_rules! gas_opcodee { } pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] { - return match spec_id { + match spec_id { SpecId::FRONTIER => { gas_opcodee!(O, SpecId::FRONTIER); O @@ -560,7 +560,7 @@ pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] { gas_opcodee!(O, SpecId::LATEST); O } - }; + } } pub const OPCODE_JUMPMAP: [Option<&'static str>; 256] = [ diff --git a/crates/revm/src/instructions/system.rs b/crates/revm/src/instructions/system.rs index 9a0c3dabab..f5f083ca50 100644 --- a/crates/revm/src/instructions/system.rs +++ b/crates/revm/src/instructions/system.rs @@ -12,7 +12,6 @@ use core::cmp::min; use primitive_types::{H160, H256, U256}; use sha3::{Digest, Keccak256}; - pub fn sha3(machine: &mut Machine) -> Return { pop!(machine, from, len); gas_or_fail!(machine, gas::sha3_cost(len)); @@ -32,7 +31,6 @@ pub fn sha3(machine: &mut Machine) -> Return { Return::Continue } - pub fn chainid(machine: &mut Machine, host: &mut H) -> Return { check!(SPEC::enabled(ISTANBUL)); // EIP-1344: ChainID opcode //gas!(machine, gas::BASE); @@ -42,7 +40,6 @@ pub fn chainid(machine: &mut Machine, host: &mut H) -> Retu Return::Continue } - pub fn address(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); @@ -52,7 +49,6 @@ pub fn address(machine: &mut Machine) -> Return { Return::Continue } - pub fn balance(machine: &mut Machine, host: &mut H) -> Return { pop_address!(machine, address); let (balance, is_cold) = host.balance(address); @@ -72,7 +68,6 @@ pub fn balance(machine: &mut Machine, host: &mut H) -> Retu Return::Continue } - pub fn selfbalance(machine: &mut Machine, host: &mut H) -> Return { check!(SPEC::enabled(ISTANBUL)); // EIP-1884: Repricing for trie-size-dependent opcodes //gas!(machine, gas::LOW); @@ -82,7 +77,6 @@ pub fn selfbalance(machine: &mut Machine, host: &mut H) -> Return::Continue } - pub fn basefee(machine: &mut Machine, host: &mut H) -> Return { check!(SPEC::enabled(LONDON)); // EIP-3198: BASEFEE opcode //gas!(machine, gas::BASE); @@ -91,7 +85,6 @@ pub fn basefee(machine: &mut Machine, host: &mut H) -> Retu Return::Continue } - pub fn origin(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); @@ -101,7 +94,6 @@ pub fn origin(machine: &mut Machine, host: &mut H) -> Return { Return::Continue } - pub fn caller(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); @@ -111,7 +103,6 @@ pub fn caller(machine: &mut Machine) -> Return { Return::Continue } - pub fn callvalue(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); @@ -122,14 +113,12 @@ pub fn callvalue(machine: &mut Machine) -> Return { Return::Continue } - pub fn gasprice(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); push!(machine, host.env().effective_gas_price()); Return::Continue } - pub fn extcodesize(machine: &mut Machine, host: &mut H) -> Return { pop_address!(machine, address); @@ -141,7 +130,6 @@ pub fn extcodesize(machine: &mut Machine, host: &mut H) -> Return::Continue } - pub fn extcodehash(machine: &mut Machine, host: &mut H) -> Return { check!(SPEC::enabled(CONSTANTINOPLE)); // EIP-1052: EXTCODEHASH opcode pop_address!(machine, address); @@ -160,7 +148,6 @@ pub fn extcodehash(machine: &mut Machine, host: &mut H) -> Return::Continue } - pub fn extcodecopy(machine: &mut Machine, host: &mut H) -> Return { pop_address!(machine, address); pop!(machine, memory_offset, code_offset, len_u256); @@ -181,7 +168,6 @@ pub fn extcodecopy(machine: &mut Machine, host: &mut H) -> Return::Continue } - pub fn returndatasize(machine: &mut Machine) -> Return { check!(SPEC::enabled(BYZANTINE)); // EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY //gas!(machine, gas::BASE); @@ -192,7 +178,6 @@ pub fn returndatasize(machine: &mut Machine) -> Return { Return::Continue } - pub fn returndatacopy(machine: &mut Machine) -> Return { check!(SPEC::enabled(BYZANTINE)); // EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY pop!(machine, memory_offset, offset, len); @@ -213,7 +198,6 @@ pub fn returndatacopy(machine: &mut Machine) -> Return { Return::Continue } - pub fn blockhash(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BLOCKHASH); @@ -223,7 +207,6 @@ pub fn blockhash(machine: &mut Machine, host: &mut H) -> Return { Return::Continue } - pub fn coinbase(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); @@ -231,14 +214,12 @@ pub fn coinbase(machine: &mut Machine, host: &mut H) -> Return { Return::Continue } - pub fn timestamp(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); push!(machine, host.env().block.timestamp); Return::Continue } - pub fn number(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); @@ -246,7 +227,6 @@ pub fn number(machine: &mut Machine, host: &mut H) -> Return { Return::Continue } - pub fn difficulty(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); @@ -254,7 +234,6 @@ pub fn difficulty(machine: &mut Machine, host: &mut H) -> Return { Return::Continue } - pub fn gaslimit(machine: &mut Machine, host: &mut H) -> Return { //gas!(machine, gas::BASE); @@ -262,7 +241,6 @@ pub fn gaslimit(machine: &mut Machine, host: &mut H) -> Return { Return::Continue } - pub fn sload(machine: &mut Machine, host: &mut H) -> Return { pop!(machine, index); let (value, is_cold) = host.sload(machine.contract.address, index); @@ -271,22 +249,11 @@ pub fn sload(machine: &mut Machine, host: &mut H) -> Return Return::Continue } - pub fn sstore(machine: &mut Machine, host: &mut H) -> Return { check!(!SPEC::IS_STATIC_CALL); pop!(machine, index, value); let (original, old, new, is_cold) = host.sstore(machine.contract.address, index, value); - // inspect!( - // Host, - // sstore, - // machine.contract.address, - // index, - // new, - // old, - // original, - // is_cold - // ); gas_or_fail!(machine, { let remaining_gas = machine.gas.remaining(); gas::sstore_cost::(original, old, new, remaining_gas, is_cold) @@ -295,7 +262,6 @@ pub fn sstore(machine: &mut Machine, host: &mut H) -> Retur Return::Continue } - pub fn gas(machine: &mut Machine) -> Return { //gas!(machine, gas::BASE); @@ -303,7 +269,6 @@ pub fn gas(machine: &mut Machine) -> Return { machine.add_next_gas_block(machine.program_counter() - 1) } - pub fn log(machine: &mut Machine, n: u8, host: &mut H) -> Return { check!(!SPEC::IS_STATIC_CALL); @@ -334,7 +299,6 @@ pub fn log(machine: &mut Machine, n: u8, host: &mut H) -> R Return::Continue } - pub fn selfdestruct(machine: &mut Machine, host: &mut H) -> Return { check!(!SPEC::IS_STATIC_CALL); pop_address!(machine, target); @@ -350,7 +314,6 @@ pub fn selfdestruct(machine: &mut Machine, host: &mut H) -> Return::SelfDestruct } - fn gas_call_l64_after(machine: &mut Machine) -> Result { if SPEC::enabled(TANGERINE) { //EIP-150: Gas cost changes for IO-heavy operations @@ -361,7 +324,6 @@ fn gas_call_l64_after(machine: &mut Machine) -> Result } } - pub fn create( machine: &mut Machine, is_create2: bool, @@ -406,7 +368,6 @@ pub fn create( } else { H256::default() }; - //inspect!(Host, create_return, created_address); push_h256!(machine, created_address); // reimburse gas that is not spend machine.gas.reimburse_unspend(&reason, gas); @@ -416,7 +377,6 @@ pub fn create( } } - pub fn call( machine: &mut Machine, scheme: CallScheme, diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 5f3cce8027..297a610af3 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -21,7 +21,7 @@ pub use db::{Database, DatabaseCommit, InMemoryDB}; pub use evm::{new, EVM}; pub use inspector::{Inspector, NoOpInspector, OverrideSpec}; pub use instructions::{ - opcode::{self, OpCode, OPCODE_JUMPMAP}, + opcode::{self, spec_opcode_gas, OpCode, OPCODE_JUMPMAP}, Return, }; pub use machine::{Gas, Machine}; diff --git a/crates/revm/src/machine/contract.rs b/crates/revm/src/machine/contract.rs index 64e12e432b..41f23c6fdf 100644 --- a/crates/revm/src/machine/contract.rs +++ b/crates/revm/src/machine/contract.rs @@ -136,12 +136,10 @@ impl Contract { ) } - pub fn is_valid_jump(&self, possition: usize) -> bool { self.jumpdest.is_valid(possition) } - pub fn gas_block(&self, possition: usize) -> u64 { self.jumpdest.gas_block(possition) } @@ -180,20 +178,20 @@ impl ValidJumpAddress { } /// Get the length of the valid mapping. This is the same as the /// code bytes. - + pub fn len(&self) -> usize { self.analazis.len() } /// Returns true if the valids list is empty - + pub fn is_empty(&self) -> bool { self.len() == 0 } /// Returns `true` if the position is a valid jump destination. If /// not, returns `false`. - + pub fn is_valid(&self, position: usize) -> bool { if position >= self.analazis.len() { return false; @@ -202,7 +200,6 @@ impl ValidJumpAddress { self.analazis[position].is_jump_dest() } - pub fn gas_block(&self, position: usize) -> u64 { self.analazis[position].gas_block } diff --git a/crates/revm/src/machine/machine.rs b/crates/revm/src/machine/machine.rs index 52449855b1..36681069c6 100644 --- a/crates/revm/src/machine/machine.rs +++ b/crates/revm/src/machine/machine.rs @@ -93,7 +93,7 @@ impl Gas { } /// Record an explict cost. - + #[inline(always)] pub fn record_cost(&mut self, cost: u64) -> bool { let (all_used_gas, overflow) = self.all_used_gas.overflowing_add(cost); if overflow || self.limit < all_used_gas { @@ -106,7 +106,7 @@ impl Gas { } /// used in memory_resize! macro - + pub fn record_memory(&mut self, gas_memory: u64) -> bool { if gas_memory > self.memory { let (all_used_gas, overflow) = self.used.overflowing_add(gas_memory); @@ -152,7 +152,6 @@ impl Machine { &self.stack } - pub fn add_next_gas_block(&mut self, pc: usize) -> Return { if USE_GAS { let gas_block = self.contract.gas_block(pc); @@ -176,10 +175,8 @@ impl Machine { //let timer = std::time::Instant::now(); let mut ret = Return::Continue; // add first gas_block - if USE_GAS { - if !self.gas.record_cost(self.contract.first_gas_block()) { - return Return::OutOfGas; - } + if USE_GAS && !self.gas.record_cost(self.contract.first_gas_block()) { + return Return::OutOfGas; } while ret == Return::Continue { // step diff --git a/crates/revm/src/machine/memory.rs b/crates/revm/src/machine/memory.rs index 36ee36fce1..c2f6477c7a 100644 --- a/crates/revm/src/machine/memory.rs +++ b/crates/revm/src/machine/memory.rs @@ -12,6 +12,12 @@ pub struct Memory { data: Vec, } +impl Default for Memory { + fn default() -> Self { + Memory::new() + } +} + impl Memory { /// Create a new memory with the given limit. pub fn new() -> Self { diff --git a/crates/revm/src/models.rs b/crates/revm/src/models.rs index c4f51b330b..477e9f25a0 100644 --- a/crates/revm/src/models.rs +++ b/crates/revm/src/models.rs @@ -122,7 +122,7 @@ pub struct CallContext { pub apparent_value: U256, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Env { pub cfg: CfgEnv, pub block: BlockEnv, @@ -221,16 +221,6 @@ impl Env { } } -impl Default for Env { - fn default() -> Env { - Env { - cfg: CfgEnv::default(), - block: BlockEnv::default(), - tx: TxEnv::default(), - } - } -} - /// Transfer from source to target, with given value. #[derive(Clone, Debug)] pub struct Transfer { diff --git a/crates/revm/src/subroutine.rs b/crates/revm/src/subroutine.rs index 1e7f34bb48..740f75c696 100644 --- a/crates/revm/src/subroutine.rs +++ b/crates/revm/src/subroutine.rs @@ -103,7 +103,7 @@ impl SubRoutine { pub fn load_precompiles_default(&mut self, precompiles: &[H160]) { let state: State = precompiles - .into_iter() + .iter() .map(|&k| { let mut acc = Account::from(AccountInfo::default()); acc.filth = Filth::Precompile(false); diff --git a/crates/revm_precompiles/src/lib.rs b/crates/revm_precompiles/src/lib.rs index 377bad7cc1..f8c4383fb7 100644 --- a/crates/revm_precompiles/src/lib.rs +++ b/crates/revm_precompiles/src/lib.rs @@ -38,7 +38,7 @@ pub struct PrecompileOutput { pub logs: Vec, } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Log { pub address: Address, pub topics: Vec, @@ -55,16 +55,6 @@ impl PrecompileOutput { } } -impl Default for PrecompileOutput { - fn default() -> Self { - PrecompileOutput { - cost: 0, - output: Vec::new(), - logs: Vec::new(), - } - } -} - /// A precompile operation result. pub type PrecompileResult = Result; diff --git a/crates/revmjs/Cargo.toml b/crates/revmjs/Cargo.toml index cfdce673cf..c3de4ab1a6 100644 --- a/crates/revmjs/Cargo.toml +++ b/crates/revmjs/Cargo.toml @@ -18,6 +18,6 @@ hex = "0.4" js-sys = "0.3" primitive-types = {version = "0.10", default-features = false, features = ["rlp", "rustc-hex"]} # for windows build remove ecrecover features. see more here: https://github.com/bluealloy/revm/issues/3 -revm = {path = "../revm", version = "0.5", default-features = false}#, features = ["ecrecover"]} +revm = {path = "../revm", version = "1.0", default-features = false}#, features = ["ecrecover"]} wasm-bindgen = "0.2" bn-rs = "0.2" \ No newline at end of file