Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bf17327
wip
shekhirin Oct 23, 2022
3e3c9b5
fix comparisons with zero
shekhirin Oct 23, 2022
4f4ee35
new failing test in run()
shekhirin Oct 23, 2022
5a999b6
remove failing test testing
shekhirin Oct 23, 2022
5876d22
fix default BlockEnv values
shekhirin Oct 23, 2022
a86388b
splice -> copy_from_slice
shekhirin Oct 23, 2022
1611897
use more ruint algorithms
shekhirin Oct 24, 2022
e0fb329
revertme: use primitive_types for ADD/MUL/SUB which is better than ruint
shekhirin Oct 24, 2022
07956b2
Revert "revertme: use primitive_types for ADD/MUL/SUB which is better…
shekhirin Oct 24, 2022
3a2c2f1
4 * 8 -> 32 :kekw:
shekhirin Oct 24, 2022
c2fc13a
bump ruint
shekhirin Oct 24, 2022
86e7bdf
fix revm-js
shekhirin Oct 24, 2022
6df65f8
Use ruint 1.5.1.
recmo Oct 25, 2022
a107572
Better inlining
recmo Oct 25, 2022
5a72f4f
fix clippy
shekhirin Oct 25, 2022
391669e
fixes after remco's review
shekhirin Oct 26, 2022
037d94e
bump ruint, fix wasm example
shekhirin Oct 27, 2022
35c02bd
wip
shekhirin Oct 28, 2022
fd32ec2
replace exp implementation with pow from ruint
shekhirin Oct 28, 2022
46b92f2
revert B160 changes
shekhirin Oct 28, 2022
cc9756b
bump ruint
shekhirin Oct 29, 2022
a97ca40
Merge branch 'ruint' into ruint-bits
shekhirin Oct 29, 2022
b415c61
Merge remote-tracking branch 'upstream/main' into ruint-bits
shekhirin Oct 29, 2022
bc699ac
wip bits
shekhirin Oct 30, 2022
f304db3
Merge remote-tracking branch 'upstream/main' into ruint-bits
shekhirin Oct 30, 2022
724cd83
more fixes
shekhirin Nov 1, 2022
8b7440d
return primitive_types to revme
shekhirin Nov 1, 2022
2a37e07
more fixes
shekhirin Nov 1, 2022
346c3c0
use more ruint features
shekhirin Nov 1, 2022
3d8faf3
done?
shekhirin Nov 1, 2022
b57aeef
cleanup Cargo.toml
shekhirin Nov 1, 2022
a77db51
bits! -> uint! macro
shekhirin Nov 3, 2022
8dfc4c2
bump ruint
shekhirin Nov 3, 2022
fa4792b
bump ruint
shekhirin Nov 4, 2022
0e72595
import uint! macro
shekhirin Nov 4, 2022
137201b
fix clippy
shekhirin Nov 4, 2022
6f00eee
to_be_bytes_vec -> to_be_bytes
shekhirin Nov 4, 2022
dd82fa1
revm bits
rakita Nov 16, 2022
b9884a4
Progress on switching to revm bits
rakita Nov 20, 2022
e4ecab9
Flushing out bits
rakita Nov 26, 2022
febe333
Merge remote-tracking branch 'origin/main' into baseline
rakita Nov 26, 2022
9c87565
bits and nits. bugs squashed
rakita Nov 26, 2022
3628658
Merge remote-tracking branch 'origin/main' into baseline
rakita Nov 26, 2022
e32aafd
rm primitive_types from revm
rakita Nov 26, 2022
4da6f20
nits
rakita Dec 2, 2022
5a60bd6
Merge3855
rakita Dec 2, 2022
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
201 changes: 67 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ codegen-units = 1
[profile.ethtests]
inherits = "test"
opt-level = 3

[patch.crates-io]
ruint = { git = "https://github.com/recmo/uint" }
1 change: 0 additions & 1 deletion bins/revm-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
[dependencies]
bytes = "1.1"
hex = "0.4"
primitive-types = { version = "0.12", features = ["rlp"] }
revm = { path = "../../crates/revm", version = "2.3.1" }

[[bin]]
Expand Down
14 changes: 9 additions & 5 deletions bins/revm-test/src/bin/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{str::FromStr, time::Instant};
use std::time::Instant;

use bytes::Bytes;
use primitive_types::H160;
use revm::{db::BenchmarkDB, Bytecode, TransactTo};

extern crate alloc;
Expand All @@ -13,9 +12,14 @@ fn main() {
let mut evm = revm::new();

// execution globals block hash/gas_limit/coinbase/timestamp..
evm.env.tx.caller = H160::from_str("0x1000000000000000000000000000000000000000").unwrap();
evm.env.tx.transact_to =
TransactTo::Call(H160::from_str("0x0000000000000000000000000000000000000000").unwrap());
evm.env.tx.caller = "0x1000000000000000000000000000000000000000"
.parse()
.unwrap();
evm.env.tx.transact_to = TransactTo::Call(
"0x0000000000000000000000000000000000000000"
.parse()
.unwrap(),
);
//evm.env.tx.data = Bytes::from(hex::decode("30627b7c").unwrap());
evm.env.tx.data = Bytes::from(hex::decode("8035F0CE").unwrap());
evm.env.cfg.perf_all_precompiles_have_balance = true;
Expand Down
14 changes: 9 additions & 5 deletions bins/revm-test/src/bin/snailtracer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{str::FromStr, time::Instant};
use std::time::Instant;

use bytes::Bytes;
use primitive_types::H160;
use revm::{db::BenchmarkDB, Bytecode, TransactTo};

extern crate alloc;
Expand All @@ -14,9 +13,14 @@ pub fn simple_example() {
evm.database(BenchmarkDB::new_bytecode(Bytecode::new_raw(contract_data)));

// execution globals block hash/gas_limit/coinbase/timestamp..
evm.env.tx.caller = H160::from_str("0x1000000000000000000000000000000000000000").unwrap();
evm.env.tx.transact_to =
TransactTo::Call(H160::from_str("0x0000000000000000000000000000000000000000").unwrap());
evm.env.tx.caller = "0x1000000000000000000000000000000000000000"
.parse()
.unwrap();
evm.env.tx.transact_to = TransactTo::Call(
"0x0000000000000000000000000000000000000000"
.parse()
.unwrap(),
);
evm.env.tx.data = Bytes::from(hex::decode("30627b7c").unwrap());

let mut elapsed = std::time::Duration::ZERO;
Expand Down
13 changes: 9 additions & 4 deletions bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ hex = "0.4"
indicatif = "0.17"
plain_hasher = "0.2"
primitive-types = { version = "0.12", features = ["rlp", "serde"] }
revm = { path = "../../crates/revm", version = "2.3.1", default-features = false, features = ["web3db","std","secp256k1"] }
revm = { path = "../../crates/revm", version = "2.3.1", default-features = false, features = [
"web3db",
"std",
"secp256k1",
"with-serde",
] }
rlp = { version = "0.5", default-features = false }
ruint = { version = "1.6.0", features = ["rlp", "serde"] }
serde = "1.0"
serde_derive = "1.0"
ruint = { version = "1.7.0", features = ["rlp", "serde"] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
sha3 = { version = "0.10", default-features = false }
structopt = "0.3"
thiserror = "1.0"
triehash = "0.8"
walkdir = "2.3"
hex-literal = "0.3"
22 changes: 10 additions & 12 deletions bins/revme/src/cli_env.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::str::FromStr;

use bytes::Bytes;
use primitive_types::H160;
use revm::{Env, TransactTo};
use ruint::aliases::U256;
use revm::{Env, TransactTo, B160, U256};
use structopt::StructOpt;

#[derive(StructOpt, Clone, Debug)]
Expand Down Expand Up @@ -65,8 +63,8 @@ pub struct CliEnvBlock {
pub number: Option<u64>,
/// Coinbase or miner or address that created and signed the block.
/// Address where we are going to send gas spend
#[structopt(long = "env.block.coinbase", parse(try_from_str = parse_h160))]
pub coinbase: Option<H160>,
#[structopt(long = "env.block.coinbase", parse(try_from_str = parse_b160))]
pub coinbase: Option<B160>,
#[structopt(long = "env.block.timestamp")]
pub timestamp: Option<u64>,
#[structopt(long = "env.block.difficulty")]
Expand All @@ -79,16 +77,16 @@ pub struct CliEnvBlock {
#[derive(StructOpt, Clone, Debug)]
pub struct CliEnvTx {
/// Caller or Author or tx signer
#[structopt(long = "env.tx.caller", parse(try_from_str = parse_h160))]
pub caller: Option<H160>,
#[structopt(long = "env.tx.caller", parse(try_from_str = parse_b160))]
pub caller: Option<B160>,
#[structopt(long = "env.tx.gas_limit")]
pub tx_gas_limit: Option<u64>,
#[structopt(long = "env.tx.gas_price")]
pub gas_price: Option<u64>,
#[structopt(long = "env.tx.gas_priority_fee")]
pub gas_priority_fee: Option<u64>,
#[structopt(long = "env.tx.to", parse(try_from_str = parse_h160))]
pub transact_to: Option<H160>,
#[structopt(long = "env.tx.to", parse(try_from_str = parse_b160))]
pub transact_to: Option<B160>,
#[structopt(long = "env.tx.value")]
pub value: Option<u64>,
#[structopt(long = "env.tx.data", parse(try_from_str = parse_hex))]
Expand All @@ -98,13 +96,13 @@ pub struct CliEnvTx {
#[structopt(long = "env.tx.nonce")]
pub nonce: Option<u64>,
//#[structopt(long = "env.")]
//TODO pub access_list: Vec<(H160, Vec<U256>)>,
//TODO pub access_list: Vec<(B160, Vec<U256>)>,
}

fn parse_hex(src: &str) -> Result<Bytes, hex::FromHexError> {
Ok(Bytes::from(hex::decode(src)?))
}

pub fn parse_h160(input: &str) -> Result<H160, <H160 as FromStr>::Err> {
H160::from_str(input)
pub fn parse_b160(input: &str) -> Result<B160, <B160 as FromStr>::Err> {
B160::from_str(input)
}
4 changes: 3 additions & 1 deletion bins/revme/src/statetest/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use structopt::StructOpt;
pub struct Cmd {
#[structopt(required = true)]
path: Vec<PathBuf>,
#[structopt(short = "s", long)]
single_thread: bool,
}

impl Cmd {
pub fn run(&self) -> Result<(), TestError> {
for path in &self.path {
println!("Start running tests on: {path:?}");
let test_files = find_all_json_tests(path);
run(test_files)?
run(test_files, self.single_thread)?
}
Ok(())
}
Expand Down
29 changes: 16 additions & 13 deletions bins/revme/src/statetest/merkle_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ use bytes::Bytes;
use hash_db::Hasher;
use plain_hasher::PlainHasher;
use primitive_types::{H160, H256};
use revm::{db::DbAccount, Log};
use revm::{common::keccak256, db::DbAccount, Log, B160, B256, U256};
use rlp::RlpStream;
use ruint::aliases::U256;
use sha3::{Digest, Keccak256};
use triehash::sec_trie_root;

pub fn log_rlp_hash(logs: Vec<Log>) -> H256 {
pub fn log_rlp_hash(logs: Vec<Log>) -> B256 {
//https://github.com/ethereum/go-ethereum/blob/356bbe343a30789e77bb38f25983c8f2f2bfbb47/cmd/evm/internal/t8ntool/execution.go#L255
let mut stream = RlpStream::new();
stream.begin_unbounded_list();
for log in logs {
stream.begin_list(3);
stream.append(&log.address);
stream.append_list(&log.topics);
stream.append(&log.address.0.as_ref());
stream.begin_unbounded_list();
for topic in log.topics {
stream.append(&topic.0.as_ref());
}
stream.finalize_unbounded_list();
stream.append(&log.data);
}
stream.finalize_unbounded_list();
let out = stream.out().freeze();

let out = Keccak256::digest(out);
H256::from_slice(out.as_slice())
keccak256(&out)
}

pub fn state_merkle_trie_root(accounts: impl Iterator<Item = (H160, DbAccount)>) -> H256 {
pub fn state_merkle_trie_root(accounts: impl Iterator<Item = (B160, DbAccount)>) -> B256 {
let vec = accounts
.map(|(address, info)| {
let acc_root = trie_account_rlp(&info);
(address, acc_root)
(H160::from(address.0), acc_root)
})
.collect();

Expand All @@ -46,19 +48,20 @@ pub fn trie_account_rlp(acc: &DbAccount) -> Bytes {
acc.storage
.iter()
.filter(|(_k, &v)| v != U256::ZERO)
.map(|(k, v)| (H256::from(k.to_be_bytes()), rlp::encode(v))),
.map(|(&k, v)| (H256::from(k.to_be_bytes()), rlp::encode(v))),
)
});
stream.append(&acc.info.code_hash.as_bytes());
stream.append(&acc.info.code_hash.0.as_ref());
stream.out().freeze()
}

pub fn trie_root(acc_data: Vec<(H160, Bytes)>) -> H256 {
sec_trie_root::<KeccakHasher, _, _, _>(acc_data.into_iter())
pub fn trie_root(acc_data: Vec<(H160, Bytes)>) -> B256 {
B256(sec_trie_root::<KeccakHasher, _, _, _>(acc_data.into_iter()).0)
}

#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct KeccakHasher;

impl Hasher for KeccakHasher {
type Out = H256;
type StdHasher = PlainHasher;
Expand Down
7 changes: 3 additions & 4 deletions bins/revme/src/statetest/models/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::str::FromStr;

use bytes::Bytes;
use primitive_types::H160;
use ruint::aliases::U256;
use revm::{B160, U256};
use serde::{
de::{self, Error},
Deserialize,
Expand Down Expand Up @@ -50,15 +49,15 @@ where
Ok(out)
}

pub fn deserialize_maybe_empty<'de, D>(deserializer: D) -> Result<Option<H160>, D::Error>
pub fn deserialize_maybe_empty<'de, D>(deserializer: D) -> Result<Option<B160>, D::Error>
where
D: de::Deserializer<'de>,
{
let string: String = String::deserialize(deserializer)?;
if string.is_empty() {
return Ok(None);
}
Ok(Some(H160::from_str(&string).map_err(D::Error::custom)?))
Ok(Some(B160::from_str(&string).map_err(D::Error::custom)?))
}

pub fn deserialize_str_as_bytes<'de, D>(deserializer: D) -> Result<Bytes, D::Error>
Expand Down
38 changes: 26 additions & 12 deletions bins/revme/src/statetest/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use bytes::Bytes;
use primitive_types::{H160, H256};
use ruint::aliases::U256;
use revm::{B160, B256, U256};
use std::collections::{BTreeMap, HashMap};
mod deserializer;
mod spec;

use deserializer::*;

use serde_derive::*;
use serde::Deserialize;

pub use self::spec::SpecName;

Expand All @@ -17,7 +16,7 @@ pub struct TestSuit(pub BTreeMap<String, TestUnit>);
#[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct TestUnit {
pub env: Env,
pub pre: HashMap<H160, AccountInfo>,
pub pre: HashMap<B160, AccountInfo>,
pub post: BTreeMap<SpecName, Vec<Test>>,
pub transaction: TransactionParts,
}
Expand All @@ -26,11 +25,11 @@ pub struct TestUnit {
#[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct Test {
/// Post state hash
pub hash: H256,
pub hash: B256,
/// Indexes
pub indexes: TxPartIndices,
// logs
pub logs: H256,
pub logs: B256,
#[serde(default)]
#[serde(deserialize_with = "deserialize_opt_str_as_bytes")]
pub txbytes: Option<Bytes>,
Expand Down Expand Up @@ -58,7 +57,7 @@ pub struct AccountInfo {
#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Env {
pub current_coinbase: H160,
pub current_coinbase: B160,
#[serde(default, deserialize_with = "deserialize_str_as_u256")]
pub current_difficulty: U256,
#[serde(deserialize_with = "deserialize_str_as_u256")]
Expand All @@ -68,7 +67,7 @@ pub struct Env {
#[serde(deserialize_with = "deserialize_str_as_u256")]
pub current_timestamp: U256,
pub current_base_fee: Option<U256>,
pub previous_hash: H256,
pub previous_hash: B256,
}

#[derive(Debug, PartialEq, Eq, Deserialize)]
Expand All @@ -80,9 +79,9 @@ pub struct TransactionParts {
pub gas_limit: Vec<U256>,
pub gas_price: Option<U256>,
pub nonce: U256,
pub secret_key: Option<H256>,
pub secret_key: Option<B256>,
#[serde(deserialize_with = "deserialize_maybe_empty")]
pub to: Option<H160>,
pub to: Option<B160>,
pub value: Vec<U256>,
pub max_fee_per_gas: Option<U256>,
pub max_priority_fee_per_gas: Option<U256>,
Expand All @@ -91,8 +90,8 @@ pub struct TransactionParts {
#[derive(Debug, PartialEq, Eq, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AccessListItem {
pub address: H160,
pub storage_keys: Vec<H256>,
pub address: B160,
pub storage_keys: Vec<B256>,
}

pub type AccessList = Vec<AccessListItem>;
Expand All @@ -101,6 +100,7 @@ pub type AccessList = Vec<AccessListItem>;
mod tests {

use super::*;
use revm::B160;
use serde_json::Error;

#[test]
Expand All @@ -116,4 +116,18 @@ mod tests {
println!("out:{out:?}");
Ok(())
}

#[test]
pub fn serialize_b160() -> Result<(), Error> {
let json = r#"{"_item":"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"}"#;

#[derive(Deserialize, Debug)]
pub struct Test {
_item: B160,
}

let out: Test = serde_json::from_str(json)?;
println!("out:{out:?}");
Ok(())
}
}
Loading