Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
782c3dd
chore(eof): simplify magic checks (#1633)
DaniPopes Jul 17, 2024
bac2f4a
perf(eof): avoid some allocations (#1632)
DaniPopes Jul 17, 2024
1a13e2a
chore: fix some typos & remove useless Arc::clone (#1621)
jackwener Jul 17, 2024
c1110d4
refactor: use `is_zero` for `U256` and `B256` (#1638)
tcoratger Jul 18, 2024
1adc908
feat(interpreter): derive traits on FunctionStack (#1640)
DaniPopes Jul 18, 2024
d980839
chore: Renamed some city name (#1645)
ioterw Jul 19, 2024
b995fad
perf: avoid cloning original_bytes (#1646)
DaniPopes Jul 19, 2024
a605d05
fix(eof): deny static context in EOFCREATE (#1644)
DaniPopes Jul 19, 2024
8eaff99
feat: use batch bn256 pair operation (#1643)
Rjected Jul 19, 2024
013de92
feat(EOF): implement std::error::Error trait for EofValidationError a…
peyha Jul 22, 2024
31ddbe9
chore(deps): bump thiserror from 1.0.62 to 1.0.63 (#1651)
dependabot[bot] Jul 22, 2024
afb8083
chore(deps): bump tokio from 1.38.0 to 1.38.1 (#1650)
dependabot[bot] Jul 22, 2024
d71acb5
fix(EOF): Overflow on num_sections (#1656)
rakita Jul 24, 2024
e123600
feat(EOF): EOF Validation add code type and sub container tracker (#1…
rakita Jul 24, 2024
28b7021
fix(statetest): Add back Merge spec (#1658)
rakita Jul 25, 2024
9eabd4b
fix(EOF): Validate code access in stack (#1659)
rakita Jul 25, 2024
1163e29
feat(EOF): Add EOF validation in revme bytecode cmd (#1660)
rakita Jul 25, 2024
83df9c4
chore(clippy): 1.80 rust clippy list paragraph ident (#1661)
rakita Jul 25, 2024
dc2b334
feat(EOF): Add non-returning CALLF/JUMPF checks (#1663)
rakita Jul 26, 2024
42bbc74
fix(EOF): returning to non-returning jumpf, enable valition error (#1…
rakita Jul 26, 2024
371e8c2
fix: add DATACOPY to OpCode::modifies_memory (#1639)
klkvr Jul 26, 2024
7a35122
chore(eof): Add opcodes that expand memory (#1665)
rakita Jul 26, 2024
49d68c8
fix(statetest): make bytecode analyzed (#1666)
rakita Jul 28, 2024
574b310
chore(deps): bump serde_json from 1.0.120 to 1.0.121 (#1667)
dependabot[bot] Jul 29, 2024
cf74f81
chore(deps): bump tokio from 1.38.1 to 1.39.2 (#1668)
dependabot[bot] Jul 29, 2024
b30dff4
chore(deps): bump blst from 0.3.12 to 0.3.13 (#1669)
dependabot[bot] Jul 29, 2024
991ef8c
chore(deps): bump serde_json from 1.0.121 to 1.0.122 (#1678)
dependabot[bot] Aug 5, 2024
721f087
chore(deps): bump alloy-eips from 0.2.0 to 0.2.1 (#1679)
dependabot[bot] Aug 5, 2024
7933742
chore(deps): bump regex from 1.10.5 to 1.10.6 (#1682)
dependabot[bot] Aug 5, 2024
535eb8e
chore(deps): bump rstest from 0.21.0 to 0.22.0 (#1681)
dependabot[bot] Aug 5, 2024
4d0feec
Add EOF Layout Fuzz Loop to `revme bytecode` (#1677)
shemnon Aug 5, 2024
05b34f4
docs: improve `InstructionResult` documentation (#1673)
leovct Aug 6, 2024
ab42581
Add OP-Granite hardfork, limiting bn256Pairing input size (#1685)
BrianBland Aug 6, 2024
40b9e10
feat: check for typos in CI (#1686)
adria0 Aug 8, 2024
32aeae4
feat(EOF): add evmone test suite (#1689)
rakita Aug 8, 2024
8267ad5
feat(EOF): Run EOF tests from eth/tests (#1690)
rakita Aug 8, 2024
70bd050
chore: release (#1683)
github-actions[bot] Aug 8, 2024
f3cab1c
bump: tag v41 revm v13.0.0 (#1692)
rakita Aug 8, 2024
428626e
fix(CI): types check (#1693)
rakita Aug 8, 2024
0a5be93
chore(deps): bump alloy-provider from 0.2.0 to 0.2.1 (#1680)
dependabot[bot] Aug 9, 2024
1ad8604
Revert "chore(deps): bump alloy-provider from 0.2.0 to 0.2.1 (#1680)"…
rakita Aug 9, 2024
7ea71af
chore(deps): bump alloy-transport from 0.2.0 to 0.2.1 (#1698)
dependabot[bot] Aug 26, 2024
7abf5c0
chore(deps): bump enumn from 0.1.13 to 0.1.14 (#1701)
dependabot[bot] Aug 26, 2024
ab07fac
doc: update some docs related to state (#1711)
prestwich Aug 26, 2024
d8d75fd
chore: clean up some journalstate docs (#1712)
onbjerg Aug 26, 2024
0f7e5a6
chore(deps): bump bytes from 1.6.1 to 1.7.1 (#1700)
dependabot[bot] Aug 26, 2024
e155d07
chore: switch gas check order in blake2 precompile (#1718)
pcy190 Aug 26, 2024
792b6b2
chore(deps): bump serde from 1.0.204 to 1.0.209 (#1717)
dependabot[bot] Aug 26, 2024
d29e132
docs: fix spelling issues (#1715)
nnsW3 Aug 26, 2024
a46a88b
feat: c-kzg bump, cleanup on kzgsetting (#1719)
rakita Aug 26, 2024
c75e095
chore: bump `kzg-rs` version (#1726)
0xWOLAND Aug 28, 2024
0ae01d5
chore: cast block number to u64 and not usize (#1727)
rakita Aug 28, 2024
8094c45
feat(eip7702): Impl newest version of EIP (#1695)
rakita Aug 29, 2024
c77f2a5
chore(deps): bump alloy and primitives (#1725)
klkvr Aug 29, 2024
85fc688
chore: release (#1722)
github-actions[bot] Aug 29, 2024
3085f04
bump: main changelog (#1730)
rakita Aug 29, 2024
4cf869a
Merge branch 'refs/heads/v42-upstream' into scroll-evm-executor/v42-u…
lightsing Sep 3, 2024
6e349a9
fix
lightsing Sep 3, 2024
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
feat(eip7702): Impl newest version of EIP (bluealloy#1695)
* latest eip7702 wip

* add code loading handler

* WIP adding is_delegate_cold flag

* feat: add StateLoad and Eip7702CodeLoad

* feat: add gas accounting among other things

* clippy,fmt, op test

* path to latest alloy-eips

* comment eip7702 decode tests

* Eip7702 format starts with 0xEF0100

* typo

* fix(eip7702): fix empty or eip7702 code check

* Type Eip7702s to Eip7702

* Corrent comments

* switch new and new_raw Eip7702Bytecode

* propagate last commit

* nit: rename fn

* fix(eip7702): set delegated code on call (bluealloy#1706)

* type change, return eip7702 raw on Bytecode::bytecode

* eip7702 delegation test

* Cleanup, refactor sstore gas calc

* doc

* chore: add AuthList json format

* fix initial eip7702 gas, fix eip7702 refund on revert

* small refactor

* fix refund cnt

* error handling, EIP-3607 fix, wip on auth validity

* add auth validity check, fix EIP-3607 fix

* switch tests

* missing comment

* fix tests

* rm println

* remove skip of required fields

* docs, test meta dat
  • Loading branch information
rakita authored Aug 29, 2024
commit 8094c45fc71e7f2deba8bf2c45fb74e40257c802
27 changes: 18 additions & 9 deletions Cargo.lock

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

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

[patch.crates-io]
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "fd159f6" }
4 changes: 2 additions & 2 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use revm::{
db::BenchmarkDB,
inspector_handle_register,
inspectors::TracerEip3155,
primitives::{eof::EofDecodeError, Address, Bytecode, TxKind},
primitives::{Address, Bytecode, BytecodeDecodeError, TxKind},
Evm,
};
use std::io::Error as IoError;
Expand All @@ -26,7 +26,7 @@ pub enum Errors {
#[error(transparent)]
Io(#[from] IoError),
#[error(transparent)]
EofError(#[from] EofDecodeError),
BytecodeDecodeError(#[from] BytecodeDecodeError),
}

/// Evm runner command allows running arbitrary evm bytecode.
Expand Down
20 changes: 1 addition & 19 deletions bins/revme/src/cmd/statetest/models/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloy_rlp::{Decodable, Error as RlpError, Header};
use revm::primitives::{AccessList, Bytes, Signature, SignedAuthorization, TxKind, U256};
use std::vec::Vec;

/// TODO remove it when new tests are generated that has a Authorization json field.
/// [EIP-7702 Set Code Transaction](https://eips.ethereum.org/EIPS/eip-7702)
///
/// Set EOA account code for one transaction
Expand Down Expand Up @@ -112,22 +113,3 @@ impl TxEip7702 {
Ok(tx)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn decode_eip7702_tx() {
let tx_bytes = hex::decode("f8c2018080078398968094a94f5374fce5edbc8e2a8697c15331677e6ebf0b8080c0f85df85b01940000000000000000000000000000000000001000c18001a08171c0ded912d4f458b8115618c18f3f430f414919c73b4daa693c47fd325414a0787741e1621bcb9cb58ece039ad73f41d9422aa259ed53c2b0bd30dc7ff09be780a00e6c8f4d73b175887e1f21cc00bf0f8243af18aed208ec0a4562ee60e7f85736a03f8e8f1b01fcd6d3a988877e80dc17fad16274447f4211ed74b41e8789ae70cd").unwrap();
let tx = TxEip7702::decode(&mut tx_bytes.as_slice()).unwrap();
assert_eq!(tx.authorization_list.len(), 1);
}

#[test]
fn test_eip7702_tx() {
let tx_bytes = hex::decode("f8c2018080078398968094a94f5374fce5edbc8e2a8697c15331677e6ebf0b8080c0f85df85b80940000000000000000000000000000000000001000c10180a09e833a19cf7ac609d713ffeb8d5cd327237ef5cb4ac9524c53195423e348629fa0632893e4b18b32faf56972dc3568c3a3869dcf9eb9c282a637173475d19e8d2f01a05d6eea7691335a6bb066613d5c33a27bd1cbc89feb472b6dd437aca6aec73282a013c492943ea0fce77a20b1d554eac087fee37fa27b0f8294b13fb3162a0fb175").unwrap();
let tx = TxEip7702::decode(&mut tx_bytes.as_slice()).unwrap();
assert_eq!(tx.authorization_list.len(), 1);
}
}
18 changes: 14 additions & 4 deletions bins/revme/src/cmd/statetest/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,25 @@ pub struct TransactionParts {

#[serde(default)]
pub access_lists: Vec<Option<AccessList>>,

//#[serde(default)]
// TODO EIP-7702 when added enable serde `deny_unknown_fields`.
//pub authorization_list: Vec<Option<Vec<TestAuthorization>>>,
#[serde(default)]
pub authorization_list: Vec<Authorization>,
#[serde(default)]
pub blob_versioned_hashes: Vec<B256>,
pub max_fee_per_blob_gas: Option<U256>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Authorization {
chain_id: U256,
address: Address,
nonce: U256,
v: U256,
r: U256,
s: U256,
signer: Option<Address>,
}

#[cfg(test)]
mod tests {

Expand Down
101 changes: 56 additions & 45 deletions crates/interpreter/src/gas/calc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use revm_primitives::eip7702;

use super::constants::*;
use crate::{
num_words,
primitives::{AccessListItem, SpecId, U256},
SelfDestructResult,
AccountLoad, Eip7702CodeLoad, SStoreResult, SelfDestructResult, StateLoad,
};

/// `const` Option `?`.
Expand All @@ -18,37 +20,37 @@ macro_rules! tri {
/// `SSTORE` opcode refund calculation.
#[allow(clippy::collapsible_else_if)]
#[inline]
pub fn sstore_refund(spec_id: SpecId, original: U256, current: U256, new: U256) -> i64 {
pub fn sstore_refund(spec_id: SpecId, vals: &SStoreResult) -> i64 {
if spec_id.is_enabled_in(SpecId::ISTANBUL) {
// EIP-3529: Reduction in refunds
let sstore_clears_schedule = if spec_id.is_enabled_in(SpecId::LONDON) {
(SSTORE_RESET - COLD_SLOAD_COST + ACCESS_LIST_STORAGE_KEY) as i64
} else {
REFUND_SSTORE_CLEARS
};
if current == new {
if vals.is_new_eq_present() {
0
} else {
if original == current && new.is_zero() {
if vals.is_original_eq_present() && vals.is_new_zero() {
sstore_clears_schedule
} else {
let mut refund = 0;

if !original.is_zero() {
if current.is_zero() {
if !vals.is_original_zero() {
if vals.is_present_zero() {
refund -= sstore_clears_schedule;
} else if new.is_zero() {
} else if vals.is_new_zero() {
refund += sstore_clears_schedule;
}
}

if original == new {
if vals.is_original_eq_new() {
let (gas_sstore_reset, gas_sload) = if spec_id.is_enabled_in(SpecId::BERLIN) {
(SSTORE_RESET - COLD_SLOAD_COST, WARM_STORAGE_READ_COST)
} else {
(SSTORE_RESET, sload_cost(spec_id, false))
};
if original.is_zero() {
if vals.is_original_zero() {
refund += (SSTORE_SET - gas_sload) as i64;
} else {
refund += (gas_sstore_reset - gas_sload) as i64;
Expand All @@ -59,7 +61,7 @@ pub fn sstore_refund(spec_id: SpecId, original: U256, current: U256, new: U256)
}
}
} else {
if !current.is_zero() && new.is_zero() {
if !vals.is_present_zero() && vals.is_new_zero() {
REFUND_SSTORE_CLEARS
} else {
0
Expand Down Expand Up @@ -123,9 +125,9 @@ pub const fn verylowcopy_cost(len: u64) -> Option<u64> {

/// `EXTCODECOPY` opcode cost calculation.
#[inline]
pub const fn extcodecopy_cost(spec_id: SpecId, len: u64, is_cold: bool) -> Option<u64> {
pub const fn extcodecopy_cost(spec_id: SpecId, len: u64, load: Eip7702CodeLoad<()>) -> Option<u64> {
let base_gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
warm_cold_cost(is_cold)
warm_cold_cost_with_delegation(load)
} else if spec_id.is_enabled_in(SpecId::TANGERINE) {
700
} else {
Expand Down Expand Up @@ -187,24 +189,15 @@ pub const fn sload_cost(spec_id: SpecId, is_cold: bool) -> u64 {

/// `SSTORE` opcode cost calculation.
#[inline]
pub fn sstore_cost(
spec_id: SpecId,
original: U256,
current: U256,
new: U256,
gas: u64,
is_cold: bool,
) -> Option<u64> {
pub fn sstore_cost(spec_id: SpecId, vals: &SStoreResult, gas: u64, is_cold: bool) -> Option<u64> {
// EIP-1706 Disable SSTORE with gasleft lower than call stipend
if spec_id.is_enabled_in(SpecId::ISTANBUL) && gas <= CALL_STIPEND {
return None;
}

if spec_id.is_enabled_in(SpecId::BERLIN) {
// Berlin specification logic
let mut gas_cost = istanbul_sstore_cost::<WARM_STORAGE_READ_COST, WARM_SSTORE_RESET>(
original, current, new,
);
let mut gas_cost = istanbul_sstore_cost::<WARM_STORAGE_READ_COST, WARM_SSTORE_RESET>(vals);

if is_cold {
gas_cost += COLD_SLOAD_COST;
Expand All @@ -213,26 +206,24 @@ pub fn sstore_cost(
} else if spec_id.is_enabled_in(SpecId::ISTANBUL) {
// Istanbul logic
Some(istanbul_sstore_cost::<INSTANBUL_SLOAD_GAS, SSTORE_RESET>(
original, current, new,
vals,
))
} else {
// Frontier logic
Some(frontier_sstore_cost(current, new))
Some(frontier_sstore_cost(vals))
}
}

/// EIP-2200: Structured Definitions for Net Gas Metering
#[inline]
fn istanbul_sstore_cost<const SLOAD_GAS: u64, const SSTORE_RESET_GAS: u64>(
original: U256,
current: U256,
new: U256,
vals: &SStoreResult,
) -> u64 {
if new == current {
if vals.is_new_eq_present() {
SLOAD_GAS
} else if original == current && original.is_zero() {
} else if vals.is_original_eq_present() && vals.is_original_zero() {
SSTORE_SET
} else if original == current {
} else if vals.is_original_eq_present() {
SSTORE_RESET_GAS
} else {
SLOAD_GAS
Expand All @@ -241,8 +232,8 @@ fn istanbul_sstore_cost<const SLOAD_GAS: u64, const SSTORE_RESET_GAS: u64>(

/// Frontier sstore cost just had two cases set and reset values.
#[inline]
fn frontier_sstore_cost(current: U256, new: U256) -> u64 {
if current.is_zero() && !new.is_zero() {
fn frontier_sstore_cost(vals: &SStoreResult) -> u64 {
if vals.is_present_zero() && !vals.is_new_zero() {
SSTORE_SET
} else {
SSTORE_RESET
Expand All @@ -251,12 +242,12 @@ fn frontier_sstore_cost(current: U256, new: U256) -> u64 {

/// `SELFDESTRUCT` opcode cost calculation.
#[inline]
pub const fn selfdestruct_cost(spec_id: SpecId, res: SelfDestructResult) -> u64 {
pub const fn selfdestruct_cost(spec_id: SpecId, res: StateLoad<SelfDestructResult>) -> u64 {
// EIP-161: State trie clearing (invariant-preserving alternative)
let should_charge_topup = if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) {
res.had_value && !res.target_exists
res.data.had_value && !res.data.target_exists
} else {
!res.target_exists
!res.data.target_exists
};

// EIP-150: Gas cost changes for IO-heavy operations
Expand Down Expand Up @@ -288,16 +279,24 @@ pub const fn selfdestruct_cost(spec_id: SpecId, res: SelfDestructResult) -> u64
/// * Transfer value gas. If value is transferred and balance of target account is updated.
/// * If account is not existing and needs to be created. After Spurious dragon
/// this is only accounted if value is transferred.
///
/// account_load.is_empty will be accounted only if hardfork is SPURIOUS_DRAGON and
/// there is transfer value.
///
/// This means that [`crate::OpCode::EXTSTATICCALL`],
/// [`crate::OpCode::EXTDELEGATECALL`] that dont transfer value will not be
/// effected by this field.
///
/// [`crate::OpCode::CALL`], [`crate::OpCode::EXTCALL`] use this field.
///
/// While [`crate::OpCode::STATICCALL`], [`crate::OpCode::DELEGATECALL`],
/// [`crate::OpCode::CALLCODE`] need to have this field hardcoded to false
/// as they were present before SPURIOUS_DRAGON hardfork.
#[inline]
pub const fn call_cost(
spec_id: SpecId,
transfers_value: bool,
is_cold: bool,
new_account_accounting: bool,
) -> u64 {
pub const fn call_cost(spec_id: SpecId, transfers_value: bool, account_load: AccountLoad) -> u64 {
// Account access.
let mut gas = if spec_id.is_enabled_in(SpecId::BERLIN) {
warm_cold_cost(is_cold)
warm_cold_cost_with_delegation(account_load.load)
} else if spec_id.is_enabled_in(SpecId::TANGERINE) {
// EIP-150: Gas cost changes for IO-heavy operations
700
Expand All @@ -311,7 +310,7 @@ pub const fn call_cost(
}

// new account cost
if new_account_accounting {
if account_load.is_empty {
// EIP-161: State trie clearing (invariant-preserving alternative)
if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) {
// account only if there is value transferred.
Expand All @@ -336,6 +335,18 @@ pub const fn warm_cold_cost(is_cold: bool) -> u64 {
}
}

/// Berlin warm and cold storage access cost for account access.
///
/// If delegation is Some, add additional cost for delegation account load.
#[inline]
pub const fn warm_cold_cost_with_delegation(load: Eip7702CodeLoad<()>) -> u64 {
let mut gas = warm_cold_cost(load.state_load.is_cold);
if let Some(is_cold) = load.is_delegate_account_cold {
gas += warm_cold_cost(is_cold);
}
gas
}

/// Memory expansion cost calculation for a given memory length.
#[inline]
pub const fn memory_gas_for_len(len: usize) -> u64 {
Expand Down Expand Up @@ -400,7 +411,7 @@ pub fn validate_initial_tx_gas(

// EIP-7702
if spec_id.is_enabled_in(SpecId::PRAGUE) {
initial_gas += authorization_list_num * PER_AUTH_BASE_COST;
initial_gas += authorization_list_num * eip7702::PER_EMPTY_ACCOUNT_COST;
}

initial_gas
Expand Down
Loading