Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eip7702): Impl newest version of EIP #1695

Merged
merged 37 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9d2855f
latest eip7702 wip
rakita Aug 7, 2024
bd2f4ee
add code loading handler
rakita Aug 7, 2024
6fa2fb0
WIP adding is_delegate_cold flag
rakita Aug 8, 2024
5020d9f
feat: add StateLoad and Eip7702CodeLoad
rakita Aug 9, 2024
5db4074
feat: add gas accounting among other things
rakita Aug 9, 2024
6a91562
clippy,fmt, op test
rakita Aug 9, 2024
9e3735b
Merge remote-tracking branch 'origin/main' into eip7702
rakita Aug 9, 2024
05940a8
Merge remote-tracking branch 'origin/main' into eip7702
rakita Aug 9, 2024
cab9bb1
path to latest alloy-eips
rakita Aug 9, 2024
43918ca
comment eip7702 decode tests
rakita Aug 9, 2024
a466e2f
Eip7702 format starts with 0xEF0100
rakita Aug 10, 2024
16c3933
typo
rakita Aug 10, 2024
18548c5
fix(eip7702): fix empty or eip7702 code check
rkrasiuk Aug 15, 2024
e665984
Merge pull request #1705 from bluealloy/rkrasiuk/fix-empty-and-eip770…
rkrasiuk Aug 15, 2024
9efccc4
Type Eip7702s to Eip7702
rakita Aug 15, 2024
b9b8f27
Corrent comments
rakita Aug 15, 2024
071e285
switch new and new_raw Eip7702Bytecode
rakita Aug 15, 2024
a69e173
propagate last commit
rakita Aug 15, 2024
7c4196d
nit: rename fn
rakita Aug 15, 2024
7e3c47d
fix(eip7702): set delegated code on call (#1706)
rkrasiuk Aug 15, 2024
d2111c6
type change, return eip7702 raw on Bytecode::bytecode
rakita Aug 15, 2024
caadc71
eip7702 delegation test
rakita Aug 15, 2024
502d6d1
Cleanup, refactor sstore gas calc
rakita Aug 27, 2024
6e7868c
doc
rakita Aug 27, 2024
2609442
chore: add AuthList json format
rakita Aug 27, 2024
2b5331f
fix initial eip7702 gas, fix eip7702 refund on revert
rakita Aug 27, 2024
61b3567
small refactor
rakita Aug 27, 2024
3098302
fix refund cnt
rakita Aug 27, 2024
54a21a6
error handling, EIP-3607 fix, wip on auth validity
rakita Aug 28, 2024
53d4143
add auth validity check, fix EIP-3607 fix
rakita Aug 28, 2024
f56ff19
Merge remote-tracking branch 'origin/main' into eip7702
rakita Aug 28, 2024
1cec60d
switch tests
rakita Aug 28, 2024
c427b99
missing comment
rakita Aug 28, 2024
af5e112
fix tests
rakita Aug 28, 2024
7a2a01c
rm println
rakita Aug 28, 2024
9db723e
remove skip of required fields
rakita Aug 28, 2024
4add28b
docs, test meta dat
rakita Aug 29, 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
21 changes: 15 additions & 6 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
32 changes: 16 additions & 16 deletions bins/revme/src/cmd/statetest/models/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,21 @@ impl TxEip7702 {
}
}

#[cfg(test)]
mod tests {
use super::*;
// #[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 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);
}
}
// #[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);
// }
// }
35 changes: 21 additions & 14 deletions crates/interpreter/src/gas/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::constants::*;
use crate::{
num_words,
primitives::{AccessListItem, SpecId, U256},
SelfDestructResult,
AccountLoad, Eip7702CodeLoad, SelfDestructResult, StateLoad,
};

/// `const` Option `?`.
Expand Down Expand Up @@ -123,9 +123,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 @@ -251,12 +251,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 @@ -289,15 +289,10 @@ pub const fn selfdestruct_cost(spec_id: SpecId, res: SelfDestructResult) -> u64
/// * If account is not existing and needs to be created. After Spurious dragon
/// this is only accounted if value is transferred.
#[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 +306,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 +331,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
Loading
Loading