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(levm): pectra-devnet6 eftests #1877

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions crates/vm/levm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ETH_TEST_URL := https://github.com/ethereum/tests.git
ETH_TEST_TAG := v14.1
COMMIT_LEGACY_TESTS_FOR_TAG := b2e6c9e

STATETEST_VERSION := pectra-devnet-5%40v1.1.0
STATETEST_NET := pectra-devnet-5
STATETEST_VERSION := pectra-devnet-6%40v1.0.0
STATETEST_NET := pectra-devnet-6
STATETEST_ARTIFACT := fixtures_$(STATETEST_NET).tar.gz
STATETEST_URL := https://github.com/ethereum/execution-spec-tests/releases/download/$(STATETEST_VERSION)/fixtures_$(STATETEST_NET).tar.gz

Expand Down
48 changes: 14 additions & 34 deletions crates/vm/levm/src/opcode_handlers/environment.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
call_frame::CallFrame,
constants::SET_CODE_DELEGATION_BYTES,
errors::{InternalError, OpcodeResult, VMError},
gas_cost::{self},
memory::{self, calculate_memory_size},
utils::{access_account, has_delegation, word_to_address},
utils::{access_account, word_to_address},
vm::VM,
};
use ethrex_common::{types::Fork, U256};
Expand Down Expand Up @@ -294,19 +293,14 @@ impl VM {
address,
);

// https://eips.ethereum.org/EIPS/eip-7702#delegation-designation
let is_delegation = has_delegation(&account_info)?;

current_call_frame.increase_consumed_gas(gas_cost::extcodesize(
address_was_cold,
self.env.config.fork,
)?)?;

current_call_frame.stack.push(if is_delegation {
SET_CODE_DELEGATION_BYTES[..2].len().into()
} else {
account_info.bytecode.len().into()
})?;
current_call_frame
.stack
.push(account_info.bytecode.len().into())?;

Ok(OpcodeResult::Continue { pc_increment: 1 })
}
Expand Down Expand Up @@ -334,9 +328,6 @@ impl VM {

let new_memory_size = calculate_memory_size(dest_offset, size)?;

// https://eips.ethereum.org/EIPS/eip-7702#delegation-designation
let is_delegation = has_delegation(&account_info)?;

current_call_frame.increase_consumed_gas(gas_cost::extcodecopy(
size,
new_memory_size,
Expand All @@ -349,11 +340,9 @@ impl VM {
return Ok(OpcodeResult::Continue { pc_increment: 1 });
}

let bytecode = if is_delegation {
SET_CODE_DELEGATION_BYTES[..2].into()
} else {
account_info.bytecode
};
// If the bytecode is a delegation designation, it will copy the marker (0xef0100) || address.
// https://eips.ethereum.org/EIPS/eip-7702#delegation-designation
let bytecode = account_info.bytecode;

let mut data = vec![0u8; size];
if offset < bytecode.len().into() {
Expand Down Expand Up @@ -467,29 +456,20 @@ impl VM {
address,
);

// https://eips.ethereum.org/EIPS/eip-7702#delegation-designation
let is_delegation = has_delegation(&account_info)?;

current_call_frame.increase_consumed_gas(gas_cost::extcodehash(
address_was_cold,
self.env.config.fork,
)?)?;

if is_delegation {
let hash =
U256::from_big_endian(keccak(&SET_CODE_DELEGATION_BYTES[..2]).as_fixed_bytes());
current_call_frame.stack.push(hash)?;
} else {
// An account is considered empty when it has no code and zero nonce and zero balance. [EIP-161]
if account_info.is_empty() {
current_call_frame.stack.push(U256::zero())?;
return Ok(OpcodeResult::Continue { pc_increment: 1 });
}

let hash = U256::from_big_endian(keccak(account_info.bytecode).as_fixed_bytes());
current_call_frame.stack.push(hash)?;
// An account is considered empty when it has no code and zero nonce and zero balance. [EIP-161]
if account_info.is_empty() {
current_call_frame.stack.push(U256::zero())?;
return Ok(OpcodeResult::Continue { pc_increment: 1 });
}

let hash = U256::from_big_endian(keccak(account_info.bytecode).as_fixed_bytes());
current_call_frame.stack.push(hash)?;

Ok(OpcodeResult::Continue { pc_increment: 1 })
}
}
Loading