Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
db01eb5
Add all forks to revm
rakita Aug 16, 2022
38bfb6d
Add all hardforks
rakita Aug 17, 2022
f2ff107
Merge remote-tracking branch 'origin/main' into main
rakita Aug 17, 2022
84739f1
EXTCODESIZE and EXTCODEHASH old hardfork gas fix
rakita Aug 17, 2022
fc1a81e
EXTCODECOPY fix gas hardfork
rakita Aug 17, 2022
daadfa2
fmt
rakita Aug 17, 2022
25f06a0
cleanups
rakita Aug 17, 2022
d10dfdf
EIP-161 is in SPURIOUS_DRAGON hardfork
rakita Aug 18, 2022
6e97f92
EIP-161 create nonce increment for SPURIOUS_DRAGON
rakita Aug 18, 2022
175aee5
Enable SPURIOUS_DRAGON tests
rakita Aug 18, 2022
c25fc75
Change database traits to return Result<Option<>>
rakita Aug 18, 2022
b1de572
80perc done transition
rakita Aug 20, 2022
0d68e72
db result compiled and new forks passing
rakita Aug 21, 2022
588d99d
not_existing, precompile perf is_cold
rakita Aug 22, 2022
4222270
fix for not_existing
rakita Aug 22, 2022
1d532dc
passing most of legact tests
rakita Aug 22, 2022
94bc2be
Remove spurious precompile hotfix for old forks
rakita Aug 22, 2022
61eebc8
EIP-2 OOG if crate bytecode can't be paid
rakita Aug 23, 2022
4859b12
Merge remote-tracking branch 'origin/main' into forks
rakita Aug 26, 2022
c8171a7
Add legacy tests to github ci, fmt,clippy
rakita Aug 26, 2022
2d1edcf
Merge remote-tracking branch 'origin/main' into forks
rakita Aug 26, 2022
b5c65f9
fmt
rakita Aug 26, 2022
4317474
Propagate FatalExternalError
rakita Aug 26, 2022
431fe68
Add Error associated type to Database.
rakita Aug 27, 2022
44f6ec1
Small cleanup
rakita Aug 29, 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
Merge remote-tracking branch 'origin/main' into forks
  • Loading branch information
rakita committed Aug 26, 2022
commit 4859b12e37ebeeb1f97a71403e8c3d027592dbd1
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ run tests with command: `cargo run --release -- statetest tests/GeneralStateTest

There is public telegram group: https://t.me/+Ig4WDWOzikA3MzA0

Or you can contact me directly on email: [email protected]
Or if you want to hire me or contact me directly, here is my email: [email protected] and telegram: https://t.me/draganrakita


11 changes: 7 additions & 4 deletions bins/revme/src/statetest/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ use structopt::StructOpt;
#[derive(StructOpt, Debug)]
pub struct Cmd {
#[structopt(required = true)]
path: PathBuf,
path: Vec<PathBuf>,
}

impl Cmd {
pub fn run(&self) -> Result<(), TestError> {
let test_files = find_all_json_tests(&self.path);
println!("Start running tests on: {:?}", self.path);
run(test_files)
for path in &self.path {
println!("Start running tests on: {:?}", path);
let test_files = find_all_json_tests(path);
run(test_files)?
}
Ok(())
}
}
37 changes: 20 additions & 17 deletions crates/revm/src/db/in_memory_db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use super::{DatabaseCommit, DatabaseRef};
use crate::{interpreter::bytecode::Bytecode, Database, KECCAK_EMPTY};
use crate::{Account, AccountInfo, Log};
use alloc::{
collections::btree_map::{self, BTreeMap},
vec::Vec,
};
use alloc::vec::Vec;
use hashbrown::{hash_map::Entry, HashMap as Map};
use primitive_types::{H160, H256, U256};
use sha3::{Digest, Keccak256};
Expand All @@ -22,7 +19,7 @@ impl InMemoryDB {
pub struct CacheDB<ExtDB: DatabaseRef> {
/// Account info where None means it is not existing. None existing state is needed for Pre TANGERINE forks.
/// `code` is always `None`, and bytecode can be found in `contracts`.
pub accounts: BTreeMap<H160, DbAccount>,
pub accounts: Map<H160, DbAccount>,
pub contracts: Map<H256, Bytecode>,
pub logs: Vec<Log>,
pub block_hashes: Map<U256, H256>,
Expand All @@ -35,7 +32,7 @@ pub struct DbAccount {
/// If account is selfdestructed or newly created, storage will be cleared.
pub account_state: AccountState,
/// storage slots
pub storage: BTreeMap<U256, U256>,
pub storage: Map<U256, U256>,
}

impl DbAccount {
Expand Down Expand Up @@ -99,7 +96,7 @@ impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
contracts.insert(KECCAK_EMPTY, Bytecode::new());
contracts.insert(H256::zero(), Bytecode::new());
Self {
accounts: BTreeMap::new(),
accounts: Map::new(),
contracts,
logs: Vec::default(),
block_hashes: Map::new(),
Expand Down Expand Up @@ -130,8 +127,8 @@ impl<ExtDB: DatabaseRef> CacheDB<ExtDB> {
fn load_account(&mut self, address: H160) -> Result<&mut DbAccount, &'static str> {
let db = &self.db;
match self.accounts.entry(address) {
btree_map::Entry::Occupied(entry) => Ok(entry.into_mut()),
btree_map::Entry::Vacant(entry) => Ok(entry.insert(
Entry::Occupied(entry) => Ok(entry.into_mut()),
Entry::Vacant(entry) => Ok(entry.insert(
db.basic(address)?
.map(|info| DbAccount {
info,
Expand Down Expand Up @@ -212,8 +209,8 @@ impl<ExtDB: DatabaseRef> Database for CacheDB<ExtDB> {

fn basic(&mut self, address: H160) -> Result<Option<AccountInfo>, &'static str> {
let basic = match self.accounts.entry(address) {
btree_map::Entry::Occupied(entry) => entry.into_mut(),
btree_map::Entry::Vacant(entry) => entry.insert(
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => entry.insert(
self.db
.basic(address)?
.map(|info| DbAccount {
Expand All @@ -231,12 +228,15 @@ impl<ExtDB: DatabaseRef> Database for CacheDB<ExtDB> {
/// It is assumed that account is already loaded.
fn storage(&mut self, address: H160, index: U256) -> Result<U256, &'static str> {
match self.accounts.entry(address) {
btree_map::Entry::Occupied(mut acc_entry) => {
Entry::Occupied(mut acc_entry) => {
let acc_entry = acc_entry.get_mut();
match acc_entry.storage.entry(index) {
btree_map::Entry::Occupied(entry) => Ok(*entry.get()),
btree_map::Entry::Vacant(entry) => {
if matches!(acc_entry.account_state, AccountState::StorageCleared | AccountState::NotExisting) {
Entry::Occupied(entry) => Ok(*entry.get()),
Entry::Vacant(entry) => {
if matches!(
acc_entry.account_state,
AccountState::StorageCleared | AccountState::NotExisting
) {
Ok(U256::zero())
} else {
let slot = self.db.storage(address, index)?;
Expand All @@ -246,7 +246,7 @@ impl<ExtDB: DatabaseRef> Database for CacheDB<ExtDB> {
}
}
}
btree_map::Entry::Vacant(acc_entry) => {
Entry::Vacant(acc_entry) => {
// acc needs to be loaded for us to access slots.
let info = self.db.basic(address)?;
let (account, value) = if info.is_some() {
Expand Down Expand Up @@ -287,7 +287,10 @@ impl<ExtDB: DatabaseRef> DatabaseRef for CacheDB<ExtDB> {
Some(acc_entry) => match acc_entry.storage.get(&index) {
Some(entry) => Ok(*entry),
None => {
if matches!(acc_entry.account_state, AccountState::StorageCleared | AccountState::NotExisting) {
if matches!(
acc_entry.account_state,
AccountState::StorageCleared | AccountState::NotExisting
) {
Ok(U256::zero())
} else {
self.db.storage(address, index)
Expand Down
9 changes: 7 additions & 2 deletions crates/revm/src/journaled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub struct JournaledState {
pub type State = Map<H160, Account>;
pub type Storage = Map<U256, StorageSlot>;

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Account {
/// Balance of the account.
pub info: AccountInfo,
Expand All @@ -52,8 +53,12 @@ impl Account {
}
pub fn new_not_existing() -> Self {
Self {
info: AccountInfo::default(),
storage: Map::new(),
storage_cleared: false,
is_destroyed: false,
is_touched: false,
is_not_existing: true,
..Default::default()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/revm_precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ripemd = { version = "0.1", default-features = false }
secp256k1 = { version = "0.24.0", default-features = false, features = ["alloc", "recovery"], optional = true }
sha2 = { version = "0.10.2", default-features = false }
sha3 = { version = "0.10.1", default-features = false }
hashbrown = { version = "0.12" }

[dev-dependencies]
hex = "0.4"
Expand Down
26 changes: 14 additions & 12 deletions crates/revm_precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ pub use error::Return;
/// libraries for no_std flag
#[macro_use]
extern crate alloc;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;

use hashbrown::HashMap;

pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 {
(len as u64 + 32 - 1) / 32 * word + base
}
Expand Down Expand Up @@ -61,7 +62,7 @@ pub type StandardPrecompileFn = fn(&[u8], u64) -> PrecompileResult;
pub type CustomPrecompileFn = fn(&[u8], u64) -> PrecompileResult;

pub struct Precompiles {
fun: BTreeMap<Address, Precompile>,
fun: HashMap<Address, Precompile>,
}

impl Default for Precompiles {
Expand Down Expand Up @@ -91,39 +92,40 @@ impl SpecId {

impl Precompiles {
pub fn new<const SPEC_ID: u8>() -> Self {
let mut fun: BTreeMap<Address, Precompile> = BTreeMap::new();
let mut fun: HashMap<Address, Precompile> = HashMap::new();
let mut insert_fun =
|precompile: (Address, Precompile)| fun.insert(precompile.0, precompile.1);

if SpecId::HOMESTEAD.enabled(SPEC_ID) {
fun.push(secp256k1::ECRECOVER);
fun.push(hash::SHA256);
fun.push(hash::RIPED160);
fun.push(identity::FUN);
insert_fun(secp256k1::ECRECOVER);
insert_fun(hash::SHA256);
insert_fun(hash::RIPEMD160);
insert_fun(identity::FUN);
}

if SpecId::ISTANBUL.enabled(SPEC_ID) {
// EIP-152: Add BLAKE2 compression function `F` precompile
// EIP-152: Add BLAKE2 compression function `F` precompile.
insert_fun(blake2::FUN);
}

if SpecId::ISTANBUL.enabled(SPEC_ID) {
// EIP-1108: Reduce alt_bn128 precompile gas costs
// EIP-1108: Reduce alt_bn128 precompile gas costs.
insert_fun(bn128::add::ISTANBUL);
insert_fun(bn128::mul::ISTANBUL);
insert_fun(bn128::pair::ISTANBUL);
} else if SpecId::BYZANTIUM.enabled(SPEC_ID) {
// EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128
// EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128
// EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128.
// EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128.
insert_fun(bn128::add::BYZANTIUM);
insert_fun(bn128::mul::BYZANTIUM);
insert_fun(bn128::pair::BYZANTIUM);
}

if SpecId::BERLIN.enabled(SPEC_ID) {
// EIP-2565: ModExp Gas Cost.
insert_fun(modexp::BERLIN);
} else if SpecId::BYZANTIUM.enabled(SPEC_ID) {
//EIP-198: Big integer modular exponentiation
// EIP-198: Big integer modular exponentiation.
insert_fun(modexp::BYZANTIUM);
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.