Skip to content
551 changes: 517 additions & 34 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

[workspace]
resolver = "2"
members = [
"bins/*",
"crates/*",
]
members = ["bins/*", "crates/*"]
default-members = ["crates/revm"]

[profile.release]
Expand Down
20 changes: 0 additions & 20 deletions bins/revm-test/Cargo.toml

This file was deleted.

61 changes: 0 additions & 61 deletions bins/revm-test/src/bin/analysis.rs

This file was deleted.

61 changes: 0 additions & 61 deletions bins/revm-test/src/bin/snailtracer.rs

This file was deleted.

39 changes: 0 additions & 39 deletions bins/revm-test/src/bin/transfer.rs

This file was deleted.

2 changes: 1 addition & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ revm = { path = "../../crates/revm", version = "3.3.0", default-features = false
"serde",
] }
rlp = { version = "0.5", default-features = false }
ruint = { version = "1.8.0", features = ["rlp", "serde"] }
ruint = { version = "1.10.1", features = ["rlp", "serde"] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
sha3 = { version = "0.10", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bins/revme/src/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn execute_test_suit(
let json_reader = std::fs::read(path).unwrap();
let suit: TestSuit = serde_json::from_reader(&*json_reader)?;

let map_caller_keys: HashMap<_, _> = vec![
let map_caller_keys: HashMap<_, _> = [
(
B256(hex!(
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
Expand Down
15 changes: 4 additions & 11 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ version = "1.1.2"
readme = "../../README.md"

[dependencies]
revm-primitives = { path = "../primitives", version="1.1.2", default-features = false }

#utility
derive_more = "0.99"
enumn = "0.1"
revm-primitives = { path = "../primitives", version = "1.1.2", default-features = false }

# sha3 keccak hasher
sha3 = { version = "0.10", default-features = false, features = [] }
sha3 = { version = "0.10", default-features = false }

# optional
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
Expand All @@ -27,7 +23,7 @@ proptest-derive = { version = "0.3", optional = true }

[dev-dependencies]
arbitrary = { version = "1.3", features = ["derive"] }
proptest = { version = "1.1" }
proptest = "1.1"
proptest-derive = "0.3"

[features]
Expand All @@ -48,10 +44,7 @@ optional_eip3607 = ["revm-primitives/optional_eip3607"]
optional_gas_refund = ["revm-primitives/optional_gas_refund"]
optional_no_base_fee = ["revm-primitives/optional_no_base_fee"]
std = ["revm-primitives/std"]
serde = [
"dep:serde",
"revm-primitives/serde",
]
serde = ["dep:serde", "revm-primitives/serde"]
arbitrary = [
"std",
"dep:arbitrary",
Expand Down
37 changes: 24 additions & 13 deletions crates/interpreter/src/gas/calc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use super::constants::*;
use crate::alloc::vec::Vec;
use crate::{
inner_models::SelfDestructResult,
primitives::Spec,
primitives::{SpecId::*, U256},
};
use revm_primitives::{Bytes, B160};
use crate::inner_models::SelfDestructResult;
use crate::primitives::{Bytes, Spec, SpecId::*, B160, U256};
use alloc::vec::Vec;

#[allow(clippy::collapsible_else_if)]
pub fn sstore_refund<SPEC: Spec>(original: U256, current: U256, new: U256) -> i64 {
Expand Down Expand Up @@ -57,6 +53,7 @@ pub fn sstore_refund<SPEC: Spec>(original: U256, current: U256, new: U256) -> i6
}
}

#[inline]
pub fn create2_cost(len: usize) -> Option<u64> {
let base = CREATE;
// ceil(len / 32.0)
Expand All @@ -68,6 +65,7 @@ pub fn create2_cost(len: usize) -> Option<u64> {
Some(gas)
}

#[inline]
fn log2floor(value: U256) -> u64 {
assert!(value != U256::ZERO);
let mut l: u64 = 256;
Expand All @@ -87,28 +85,32 @@ fn log2floor(value: U256) -> u64 {
l
}

#[inline]
pub fn exp_cost<SPEC: Spec>(power: U256) -> Option<u64> {
if power == U256::ZERO {
Some(EXP)
} else {
// EIP-160: EXP cost increase
let gas_byte = U256::from(if SPEC::enabled(SPURIOUS_DRAGON) {
50
50u64
} else {
10
}); // EIP-160: EXP cost increase
});
let gas = U256::from(EXP)
.checked_add(gas_byte.checked_mul(U256::from(log2floor(power) / 8 + 1))?)?;

u64::try_from(gas).ok()
}
}

#[inline]
pub fn verylowcopy_cost(len: u64) -> Option<u64> {
let wordd = len / 32;
let wordr = len % 32;
VERYLOW.checked_add(COPY.checked_mul(if wordr == 0 { wordd } else { wordd + 1 })?)
}

#[inline]
pub fn extcodecopy_cost<SPEC: Spec>(len: u64, is_cold: bool) -> Option<u64> {
let wordd = len / 32;
let wordr = len % 32;
Expand Down Expand Up @@ -153,14 +155,18 @@ pub fn keccak256_cost(len: u64) -> Option<u64> {
}

/// EIP-3860: Limit and meter initcode
/// apply extra gas cost of 2 for every 32-byte chunk of initcode
/// Can't overflow as initcode length is assumed to be checked
///
/// Apply extra gas cost of 2 for every 32-byte chunk of initcode.
///
/// This cannot overflow as the initcode length is assumed to be checked.
#[inline]
pub fn initcode_cost(len: u64) -> u64 {
let wordd = len / 32;
let wordr = len % 32;
INITCODE_WORD_COST * if wordr == 0 { wordd } else { wordd + 1 }
}

#[inline]
pub fn sload_cost<SPEC: Spec>(is_cold: bool) -> u64 {
if SPEC::enabled(BERLIN) {
if is_cold {
Expand Down Expand Up @@ -239,14 +245,15 @@ pub fn selfdestruct_cost<SPEC: Spec>(res: SelfDestructResult) -> u64 {
!res.target_exists
};

// EIP-150: Gas cost changes for IO-heavy operations
let selfdestruct_gas_topup = if SPEC::enabled(TANGERINE) && should_charge_topup {
//EIP-150: Gas cost changes for IO-heavy operations
25000
} else {
0
};

let selfdestruct_gas = if SPEC::enabled(TANGERINE) { 5000 } else { 0 }; //EIP-150: Gas cost changes for IO-heavy operations
// EIP-150: Gas cost changes for IO-heavy operations
let selfdestruct_gas = if SPEC::enabled(TANGERINE) { 5000 } else { 0 };

let mut gas = selfdestruct_gas + selfdestruct_gas_topup;
if SPEC::enabled(BERLIN) && res.is_cold {
Expand Down Expand Up @@ -282,6 +289,7 @@ pub fn call_cost<SPEC: Spec>(
+ new_cost::<SPEC>(is_call_or_staticcall, is_new, transfers_value)
}

#[inline]
pub fn hot_cold_cost<SPEC: Spec>(is_cold: bool, regular_value: u64) -> u64 {
if SPEC::enabled(BERLIN) {
if is_cold {
Expand All @@ -294,6 +302,7 @@ pub fn hot_cold_cost<SPEC: Spec>(is_cold: bool, regular_value: u64) -> u64 {
}
}

#[inline]
fn xfer_cost(is_call_or_callcode: bool, transfers_value: bool) -> u64 {
if is_call_or_callcode && transfers_value {
CALLVALUE
Expand All @@ -302,6 +311,7 @@ fn xfer_cost(is_call_or_callcode: bool, transfers_value: bool) -> u64 {
}
}

#[inline]
fn new_cost<SPEC: Spec>(is_call_or_staticcall: bool, is_new: bool, transfers_value: bool) -> u64 {
if is_call_or_staticcall {
// EIP-161: State trie clearing (invariant-preserving alternative)
Expand All @@ -321,6 +331,7 @@ fn new_cost<SPEC: Spec>(is_call_or_staticcall: bool, is_new: bool, transfers_val
}
}

#[inline]
pub fn memory_gas(a: usize) -> u64 {
let a = a as u64;
MEMORY
Expand Down
Loading