Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more fixes
  • Loading branch information
shekhirin committed Nov 1, 2022
commit 724cd835dc641beb6f5aefc1de1d4795a85cd1ad
213 changes: 64 additions & 149 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/shekhirin/uint", branch = "bits-macro" }
2 changes: 1 addition & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plain_hasher = "0.2"
primitive-types = { version = "0.11", features = ["rlp", "serde"] }
revm = { path = "../../crates/revm", version = "2.1", default-features = false, features = ["web3db","std","secp256k1"] }
rlp = { version = "0.5", default-features = false }
ruint = { version = "1.6.0", features = ["rlp", "serde"] }
ruint = { version = "1.7.0", features = ["rlp", "serde"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
20 changes: 10 additions & 10 deletions bins/revme/src/statetest/merkle_trie.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use bytes::Bytes;
use hash_db::Hasher;
use plain_hasher::PlainHasher;
use primitive_types::{H160, H256};
use revm::{db::DbAccount, Log};
use rlp::RlpStream;
use ruint::aliases::U256;
use ruint::aliases::{B160, B256, 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();
Expand All @@ -22,10 +21,10 @@ pub fn log_rlp_hash(logs: Vec<Log>) -> H256 {
let out = stream.out().freeze();

let out = Keccak256::digest(out);
H256::from_slice(out.as_slice())
B256::try_from_be_slice(out.as_slice()).unwrap()
}

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);
Expand All @@ -46,25 +45,26 @@ 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)| (B256::from(k.to_be_bytes()), rlp::encode(v))),
)
});
stream.append(&acc.info.code_hash.as_bytes());
stream.append(&acc.info.code_hash.to_be_bytes_vec());
stream.out().freeze()
}

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

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

impl Hasher for KeccakHasher {
type Out = H256;
type Out = B256;
type StdHasher = PlainHasher;
const LENGTH: usize = 32;
fn hash(x: &[u8]) -> Self::Out {
let out = Keccak256::digest(x);
H256::from_slice(out.as_slice())
B256::try_from_be_slice(out.as_slice()).unwrap()
}
}
9 changes: 3 additions & 6 deletions bins/revme/src/statetest/models/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::str::FromStr;

use bytes::Bytes;
use primitive_types::H160;
use ruint::aliases::U256;
use ruint::aliases::{B160, U256};
use serde::{
de::{self, Error},
Deserialize,
Expand Down Expand Up @@ -50,15 +47,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(string.parse().map_err(D::Error::custom)?))
}

pub fn deserialize_str_as_bytes<'de, D>(deserializer: D) -> Result<Bytes, D::Error>
Expand Down
21 changes: 10 additions & 11 deletions bins/revme/src/statetest/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bytes::Bytes;
use primitive_types::{H160, H256};
use ruint::aliases::U256;
use ruint::aliases::{B160, B256, U256};
use std::collections::{BTreeMap, HashMap};
mod deserializer;
mod spec;
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 Down
40 changes: 20 additions & 20 deletions bins/revme/src/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use std::{
use sha3::{Digest, Keccak256};

use indicatif::ProgressBar;
use primitive_types::{H160, H256};
use revm::{db::AccountState, Bytecode, CreateScheme, Env, ExecutionResult, SpecId, TransactTo};
use ruint::aliases::U256;
use ruint::aliases::{B160, B256, U256};
use std::sync::atomic::Ordering;
use walkdir::{DirEntry, WalkDir};

Expand All @@ -29,15 +28,15 @@ pub enum TestError {
RootMissmatch {
spec_id: SpecId,
id: usize,
got: H256,
expect: H256,
got: B256,
expect: B256,
},
#[error("Serde json error")]
SerdeDeserialize(#[from] serde_json::Error),
#[error("Internal system error")]
SystemError,
#[error("Unknown private key: {private_key:?}")]
UnknownPrivateKey { private_key: H256 },
UnknownPrivateKey { private_key: B256 },
}

pub fn find_all_json_tests(path: &Path) -> Vec<PathBuf> {
Expand Down Expand Up @@ -91,34 +90,34 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc<Mutex<Duration>>) -> Result<

let map_caller_keys: HashMap<_, _> = vec![
(
H256::from_str("0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8")
B256::from_str("0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8")
.unwrap(),
H160::from_str("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(),
B160::from_str("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(),
),
(
H256::from_str("0xc85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4")
B256::from_str("0xc85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4")
.unwrap(),
H160::from_str("0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826").unwrap(),
B160::from_str("0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826").unwrap(),
),
(
H256::from_str("0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d")
B256::from_str("0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d")
.unwrap(),
H160::from_str("0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap(),
B160::from_str("0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap(),
),
(
H256::from_str("0x6a7eeac5f12b409d42028f66b0b2132535ee158cfda439e3bfdd4558e8f4bf6c")
B256::from_str("0x6a7eeac5f12b409d42028f66b0b2132535ee158cfda439e3bfdd4558e8f4bf6c")
.unwrap(),
H160::from_str("0xc9c5a15a403e41498b6f69f6f89dd9f5892d21f7").unwrap(),
B160::from_str("0xc9c5a15a403e41498b6f69f6f89dd9f5892d21f7").unwrap(),
),
(
H256::from_str("0xa95defe70ebea7804f9c3be42d20d24375e2a92b9d9666b832069c5f3cd423dd")
B256::from_str("0xa95defe70ebea7804f9c3be42d20d24375e2a92b9d9666b832069c5f3cd423dd")
.unwrap(),
H160::from_str("0x3fb1cd2cd96c6d5c0b5eb3322d807b34482481d4").unwrap(),
B160::from_str("0x3fb1cd2cd96c6d5c0b5eb3322d807b34482481d4").unwrap(),
),
(
H256::from_str("0xfe13266ff57000135fb9aa854bbfe455d8da85b21f626307bf3263a0c2a8e7fe")
B256::from_str("0xfe13266ff57000135fb9aa854bbfe455d8da85b21f626307bf3263a0c2a8e7fe")
.unwrap(),
H160::from_str("0xdcc5ba93a1ed7e045690d722f2bf460a51c61415").unwrap(),
B160::from_str("0xdcc5ba93a1ed7e045690d722f2bf460a51c61415").unwrap(),
),
]
.into_iter()
Expand All @@ -130,7 +129,8 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc<Mutex<Duration>>) -> Result<
for (address, info) in unit.pre.iter() {
let acc_info = revm::AccountInfo {
balance: info.balance,
code_hash: H256::from_slice(Keccak256::digest(&info.code).as_slice()), //try with dummy hash.
code_hash: B256::try_from_be_slice(Keccak256::digest(&info.code).as_slice())
.unwrap(), //try with dummy hash.
code: Some(Bytecode::new_raw(info.code.clone())),
nonce: info.nonce,
};
Expand Down Expand Up @@ -200,8 +200,8 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc<Mutex<Duration>>) -> Result<
(
item.address,
item.storage_keys
.iter()
.map(|f| U256::from_be_bytes(f.0))
.into_iter()
.map(|key| key.into())
.collect::<Vec<_>>(),
)
})
Expand Down
10 changes: 5 additions & 5 deletions bins/revme/src/statetest/trace.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bytes::Bytes;
use primitive_types::H160;
pub use revm::Inspector;
use revm::{
opcode::{self},
CallInputs, CreateInputs, Database, EVMData, Gas, GasInspector, Return,
};
use ruint::aliases::B160;

#[derive(Clone)]
pub struct CustomPrintTracer {
Expand Down Expand Up @@ -93,10 +93,10 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
data: &mut EVMData<'_, DB>,
inputs: &CreateInputs,
ret: Return,
address: Option<H160>,
address: Option<B160>,
remaining_gas: Gas,
out: Bytes,
) -> (Return, Option<H160>, Gas, Bytes) {
) -> (Return, Option<B160>, Gas, Bytes) {
self.gas_inspector
.create_end(data, inputs, ret, address, remaining_gas, out.clone());
(ret, address, remaining_gas, out)
Expand All @@ -123,7 +123,7 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
&mut self,
_data: &mut EVMData<'_, DB>,
inputs: &mut CreateInputs,
) -> (Return, Option<H160>, Gas, Bytes) {
) -> (Return, Option<B160>, Gas, Bytes) {
println!(
"CREATE CALL: caller:{:?}, scheme:{:?}, value:{:?}, init_code:{:?}, gas:{:?}",
inputs.caller,
Expand All @@ -136,7 +136,7 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
}

fn selfdestruct(&mut self) {
//, address: H160, target: H160) {
//, address: B160, target: B160) {
println!("SELFDESTRUCT on "); //{:?} target: {:?}", address, target);
}
}
4 changes: 2 additions & 2 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ 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.6.0", features = ["rlp"] }
ruint = { version = "1.7.0", features = ["rlp"] }
serde = { version = "1.0", features = ["derive","rc"], optional = true }
tokio = { version = "1.21", features = ["rt-multi-thread", "macros"], optional = true }
web3 = { version = "0.18", optional = true }
web3 = { git = "https://github.com/tomusdrw/rust-web3", version = "0.19", optional = true }

# sha3 keccak hasher
sha3 = { version = "0.10", default-features = false, features = []}
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/db/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl DatabaseRef for EmptyDB {

// History related
fn block_hash(&self, number: U256) -> Result<B256, Self::Error> {
Ok(keccak256(&number.to_be_bytes::<{ U256::BYTES }>()))
Ok(keccak256(&number.to_be_bytes_vec()))
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,11 @@ pub fn create2_address(caller: B160, code_hash: B256, salt: U256) -> B160 {
use sha3::{Digest, Keccak256};
let mut hasher = Keccak256::new();
hasher.update([0xff]);
hasher.update(&caller.to_be_bytes()[..]);
hasher.update(salt.to_be_bytes::<{ U256::BYTES }>());
hasher.update(&code_hash.to_be_bytes()[..]);
// TODO(shekhirin): replace with `B160::try_from_be_slice`
hasher.update(&caller.to_be_bytes_vec()[..]);
hasher.update(salt.to_be_bytes_vec());
hasher.update(&code_hash.to_be_bytes_vec()[..]);

// TODO(shekhirin): replace with `B160::try_from_be_slice`
U160::try_from_be_slice(&hasher.finalize().as_slice()[12..])
.unwrap()
.into()
Expand Down
4 changes: 3 additions & 1 deletion crates/revm/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ pub fn create<H: Host, SPEC: Spec>(
interp,
address
// TODO(shekhirin): replace with `B256::try_from_be_slice`
.map(|a| U256::try_from_be_slice(&a.to_be_bytes()).unwrap().into())
.map(|a| U256::try_from_be_slice(&a.to_be_bytes_vec())
.unwrap()
.into())
.unwrap_or_default()
);
interp.gas.erase_cost(gas.remaining());
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/instructions/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! pop_address {
// Safety: Length is checked above.
// TODO(shekhirin): replace with `B160::try_from_be_slice`
let $x1: B160 = ruint::aliases::U160::try_from_be_slice(
&unsafe { $interp.stack.pop_unsafe() }.to_be_bytes::<{ U256::BYTES }>()[12..],
&unsafe { $interp.stack.pop_unsafe() }.to_be_bytes_vec()[12..],
)
.unwrap()
.into();
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/instructions/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ pub fn sha3(interp: &mut Interpreter) -> Return {
pop!(interp, from, len);
let len = as_usize_or_fail!(len, Return::OutOfGas);
gas_or_fail!(interp, gas::sha3_cost(len as u64));
let B256 = if len == 0 {
let hash = if len == 0 {
KECCAK_EMPTY
} else {
let from = as_usize_or_fail!(from, Return::OutOfGas);
memory_resize!(interp, from, len);
keccak256(interp.memory.get_slice(from, len))
};

push_b256!(interp, B256);
push_b256!(interp, hash);
Return::Continue
}

Expand Down
Loading