Skip to content

Commit

Permalink
Merge branch 'main' into l2/print-rich-wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
tomip01 authored Feb 21, 2025
2 parents d34bfd0 + 51b7dcb commit da1d4f7
Show file tree
Hide file tree
Showing 35 changed files with 306 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_l1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
include:
- name: "Rpc Compat tests"
simulation: ethereum/rpc-compat
test_pattern: /eth_chainId|eth_getTransactionByBlockHashAndIndex|eth_getTransactionByBlockNumberAndIndex|eth_getCode|eth_getStorageAt|eth_call|eth_getTransactionByHash|eth_getBlockByHash|eth_getBlockByNumber|eth_createAccessList|eth_getBlockTransactionCountByNumber|eth_getBlockTransactionCountByHash|eth_getBlockReceipts|eth_getTransactionReceipt|eth_blobGasPrice|eth_blockNumber|ethGetTransactionCount|debug_getRawHeader|debug_getRawBlock|debug_getRawTransaction|debug_getRawReceipts|eth_estimateGas|eth_getBalance|eth_sendRawTransaction|eth_getProof|eth_getLogs|eth_syncing
test_pattern: /debug_getRawBlock|debug_getRawHeader|debug_getRawReceipts|debug_getRawTransaction|eth_blobBaseFee|eth_blockNumber|eth_call|eth_chainId|eth_createAccessList|eth_estimateGas|eth_getBalance|eth_getBlockByHash|eth_getBlockByNumber|eth_getBlockReceipts|eth_getBlockTransactionCountByHash|eth_getBlockTransactionCountByNumber|eth_getCode|eth_getLogs|eth_getProof|eth_getStorageAt|eth_getTransactionByBlockHashAndIndex|eth_getTransactionByBlockNumberAndIndex|eth_getTransactionByHash|eth_getTransactionCount|eth_getTransactionReceipt|eth_sendRawTransaction|eth_syncing
- name: "Devp2p discv4 tests"
simulation: devp2p
test_pattern: discv4
Expand Down
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ stop-localnet-silent:
@kurtosis enclave stop $(ENCLAVE) >/dev/null 2>&1 || true
@kurtosis enclave rm $(ENCLAVE) --force >/dev/null 2>&1 || true

HIVE_REVISION := feb4333db7fe9f6dc161326ebb11957d4306d2f9
HIVE_REVISION := b21c217ba5f48949b6b64ef28f7fb11e40584652
# Shallow clones can't specify a single revision, but at least we avoid working
# the whole history by making it shallow since a given date (one day before our
# target revision).
Expand Down
4 changes: 3 additions & 1 deletion cmd/ef_tests/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ethrex-blockchain.workspace = true
ethrex-common.workspace = true
ethrex-storage.workspace = true
ethrex-rlp.workspace = true
ethrex-vm.workspace = true

serde.workspace = true
serde_json.workspace = true
Expand All @@ -22,7 +23,8 @@ datatest-stable = "0.2.9"
path = "./lib.rs"

[features]
default = ["c-kzg"]
default = ["c-kzg", "blst"]
blst = ["ethrex-vm/blst"]
c-kzg = ["ethrex-blockchain/c-kzg"]

[[test]]
Expand Down
19 changes: 11 additions & 8 deletions cmd/ef_tests/blockchain/tests/cancun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ fn parse_and_execute_all(path: &Path) -> datatest_stable::Result<()> {
}

datatest_stable::harness!(
parse_and_execute_until_cancun,
parse_and_execute_all,
"vectors/cancun/",
r"eip1153_tstore/.*/.*\.json",
parse_and_execute_until_cancun,
parse_and_execute_all,
"vectors/cancun/",
r"eip4788_beacon_root/.*/.*\.json",
// TODO: Here we are still filtering some Prague and Cancun-Prague transition tests
// after fixing them, the testing function should be replaced in favour of
// `parse_and_execute_all`
parse_and_execute_until_cancun,
"vectors/cancun/",
r"eip5656_mcopy/.*/.*\.json",
parse_and_execute_until_cancun,
r"eip4844_blobs/.*/.*\.json",
parse_and_execute_all,
"vectors/cancun/",
r"eip7516_blobgasfee/.*/.*\.json",
parse_and_execute_until_cancun,
r"eip5656_mcopy/.*/.*\.json",
parse_and_execute_all,
"vectors/cancun/",
r"eip6780_selfdestruct/.*/.*\.json",
parse_and_execute_until_cancun,
parse_and_execute_all,
"vectors/cancun/",
r"eip4844_blobs/.*/.*\.json",
r"eip7516_blobgasfee/.*/.*\.json",
);
21 changes: 11 additions & 10 deletions cmd/ef_tests/blockchain/tests/prague.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ef_tests_blockchain::{

// TODO: enable these tests once the evm is updated.
const SKIPPED_TEST: [&str; 2] = [
"tests/prague/eip6110_deposits/test_deposits.py::test_deposit[fork_Prague-blockchain_test-multiple_deposit_from_same_eoa_last_reverts]",
"tests/prague/eip6110_deposits/test_deposits.py::test_deposit[fork_Prague-blockchain_test-multiple_deposit_from_same_eoa_first_reverts]",
"tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_contract_create[fork_Prague-blockchain_test]",
"tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_non_empty_storage[fork_Prague-blockchain_test-zero_nonce]",
];

#[allow(dead_code)]
Expand All @@ -27,6 +27,9 @@ fn parse_and_execute(path: &Path) -> datatest_stable::Result<()> {
}

datatest_stable::harness!(
parse_and_execute,
"vectors/prague/eip2537_bls_12_381_precompiles",
r".*/.*\.json",
parse_and_execute,
"vectors/prague/eip2935_historical_block_hashes_from_state",
r".*/.*\.json",
Expand All @@ -39,15 +42,13 @@ datatest_stable::harness!(
parse_and_execute,
"vectors/prague/eip7251_consolidations",
r".*/.*\.json",
// TODO: enable these tests once the evm is updated.
// parse_and_execute,
// "vectors/prague/eip2537_bls_12_381_precompiles",
// r".*/.*\.json",
// TODO: enable these tests once the evm is updated.
// parse_and_execute,
// "vectors/prague/eip7623_increase_calldata_cost",
// r".*/.*\.json",
parse_and_execute,
"vectors/prague/eip7623_increase_calldata_cost",
r".*/.*\.json",
parse_and_execute,
"vectors/prague/eip7685_general_purpose_el_requests",
r".*/.*\.json",
parse_and_execute,
"vectors/prague/eip7702_set_code_tx",
r".*/.*\.json",
);
2 changes: 1 addition & 1 deletion cmd/ef_tests/blockchain/tests/shanghai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn parse_and_execute(path: &Path) -> datatest_stable::Result<()> {
let tests = parse_test_file(path);

for (test_key, test) in tests {
if test.network < Network::Merge || test.network >= Network::Prague {
if test.network < Network::Merge {
// Discard this test
continue;
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/ef_tests/blockchain/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,7 @@ impl From<Account> for GenesisAccount {
fn from(val: Account) -> Self {
GenesisAccount {
code: val.code,
storage: val
.storage
.into_iter()
.map(|(k, v)| (H256(k.to_big_endian()), v))
.collect(),
storage: val.storage,
balance: val.balance,
nonce: val.nonce.as_u64(),
}
Expand Down
1 change: 1 addition & 0 deletions cmd/ef_tests/state/runner/levm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub fn prepare_vm_for_tx(
coinbase: test.env.current_coinbase,
timestamp: test.env.current_timestamp,
prev_randao: test.env.current_random,
difficulty: test.env.current_difficulty,
chain_id: U256::from(1),
base_fee_per_gas: test.env.current_base_fee.unwrap_or_default(),
gas_price: effective_gas_price(test, &tx)?,
Expand Down
6 changes: 1 addition & 5 deletions cmd/ef_tests/state/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,7 @@ impl From<&EFTestPreValue> for GenesisAccount {
fn from(value: &EFTestPreValue) -> Self {
Self {
code: value.code.clone(),
storage: value
.storage
.iter()
.map(|(k, v)| (H256::from_slice(&k.to_big_endian()), *v))
.collect(),
storage: value.storage.clone(),
balance: value.balance,
nonce: value.nonce.as_u64(),
}
Expand Down
12 changes: 6 additions & 6 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ mod smoke_test;

use error::{ChainError, InvalidBlockError};
use ethrex_common::constants::GAS_PER_BLOB;
use ethrex_common::types::requests::Requests;
use ethrex_common::types::requests::{compute_requests_hash, EncodedRequests, Requests};
use ethrex_common::types::{
compute_receipts_root, compute_requests_hash, validate_block_header,
validate_cancun_header_fields, validate_prague_header_fields,
validate_pre_cancun_header_fields, Block, BlockHash, BlockHeader, BlockNumber, ChainConfig,
EIP4844Transaction, Receipt, Transaction,
compute_receipts_root, validate_block_header, validate_cancun_header_fields,
validate_prague_header_fields, validate_pre_cancun_header_fields, Block, BlockHash,
BlockHeader, BlockNumber, ChainConfig, EIP4844Transaction, Receipt, Transaction,
};
use ethrex_common::H256;

Expand Down Expand Up @@ -82,7 +81,8 @@ pub fn validate_requests_hash(
return Ok(());
}

let computed_requests_hash = compute_requests_hash(requests);
let encoded_requests: Vec<EncodedRequests> = requests.iter().map(|r| r.encode()).collect();
let computed_requests_hash = compute_requests_hash(&encoded_requests);
let valid = header
.requests_hash
.map(|requests_hash| requests_hash == computed_requests_hash)
Expand Down
24 changes: 17 additions & 7 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use ethrex_common::{
constants::GAS_PER_BLOB,
types::{
calculate_base_fee_per_blob_gas, calculate_base_fee_per_gas, compute_receipts_root,
compute_requests_hash, compute_transactions_root, compute_withdrawals_root,
requests::Requests, BlobsBundle, Block, BlockBody, BlockHash, BlockHeader, BlockNumber,
ChainConfig, MempoolTransaction, Receipt, Transaction, Withdrawal, DEFAULT_OMMERS_HASH,
compute_transactions_root, compute_withdrawals_root,
requests::{compute_requests_hash, EncodedRequests, Requests},
BlobsBundle, Block, BlockBody, BlockHash, BlockHeader, BlockNumber, ChainConfig,
MempoolTransaction, Receipt, Transaction, Withdrawal, DEFAULT_OMMERS_HASH,
DEFAULT_REQUESTS_HASH,
},
Address, Bloom, Bytes, H256, U256,
Expand Down Expand Up @@ -178,6 +179,7 @@ pub struct PayloadBuildContext<'a> {
pub remaining_gas: u64,
pub receipts: Vec<Receipt>,
pub requests: Vec<Requests>,
pub requests_hash: Option<H256>,
pub block_value: U256,
base_fee_per_blob_gas: U256,
pub blobs_bundle: BlobsBundle,
Expand All @@ -198,6 +200,7 @@ impl<'a> PayloadBuildContext<'a> {
remaining_gas: payload.header.gas_limit,
receipts: vec![],
requests: vec![],
requests_hash: None,
block_value: U256::zero(),
base_fee_per_blob_gas: U256::from(base_fee_per_blob_gas),
payload,
Expand Down Expand Up @@ -491,13 +494,23 @@ fn apply_plain_transaction(
}

pub fn extract_requests(context: &mut PayloadBuildContext) -> Result<(), EvmError> {
if !context
.chain_config()?
.is_prague_activated(context.payload.header.timestamp)
{
return Ok(());
};

let requests = get_evm_backend_or_default().extract_requests(
&context.receipts,
context.evm_state,
&context.payload.header,
&mut context.block_cache,
);
context.requests = requests?;
let encoded_requests: Vec<EncodedRequests> =
context.requests.iter().map(|r| r.encode()).collect();
context.requests_hash = Some(compute_requests_hash(&encoded_requests));

Ok(())
}
Expand All @@ -517,10 +530,7 @@ fn finalize_payload(context: &mut PayloadBuildContext) -> Result<(), ChainError>
context.payload.header.transactions_root =
compute_transactions_root(&context.payload.body.transactions);
context.payload.header.receipts_root = compute_receipts_root(&context.receipts);
context.payload.header.requests_hash = context
.chain_config()?
.is_prague_activated(context.payload.header.timestamp)
.then_some(compute_requests_hash(&context.requests));
context.payload.header.requests_hash = context.requests_hash;
context.payload.header.gas_used = context.payload.header.gas_limit - context.remaining_gas;
Ok(())
}
Expand Down
13 changes: 10 additions & 3 deletions crates/common/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ impl From<GenesisAccount> for Account {
nonce: genesis.nonce,
},
code: genesis.code,
storage: genesis.storage,
storage: genesis
.storage
.iter()
.map(|(k, v)| (H256(k.to_big_endian()), *v))
.collect(),
}
}
}
Expand Down Expand Up @@ -144,9 +148,12 @@ impl RLPDecode for AccountState {
}
}

pub fn compute_storage_root(storage: &HashMap<H256, U256>) -> H256 {
pub fn compute_storage_root(storage: &HashMap<U256, U256>) -> H256 {
let iter = storage.iter().filter_map(|(k, v)| {
(!v.is_zero()).then_some((Keccak256::digest(k).to_vec(), v.encode_to_vec()))
(!v.is_zero()).then_some((
Keccak256::digest(k.to_big_endian()).to_vec(),
v.encode_to_vec(),
))
});
Trie::compute_hash_from_unsorted_iter(iter)
}
Expand Down
15 changes: 1 addition & 14 deletions crates/common/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
};
use crate::{
constants::MIN_BASE_FEE_PER_BLOB_GAS,
types::{requests::Requests, Receipt, Transaction},
types::{Receipt, Transaction},
Address, H256, U256,
};
use bytes::Bytes;
Expand All @@ -16,7 +16,6 @@ use ethrex_rlp::{
structs::{Decoder, Encoder},
};
use ethrex_trie::Trie;
use k256::sha2::{Digest, Sha256};
use keccak_hash::keccak;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -262,18 +261,6 @@ pub fn compute_withdrawals_root(withdrawals: &[Withdrawal]) -> H256 {
Trie::compute_hash_from_unsorted_iter(iter)
}

// See https://github.com/ethereum/EIPs/blob/2a6b6965e64787815f7fffb9a4c27660d9683846/EIPS/eip-7685.md?plain=1#L62.
pub fn compute_requests_hash(requests: &[Requests]) -> H256 {
let mut hasher = Sha256::new();
for request in requests {
let request_bytes = request.to_bytes();
if request_bytes.len() > 1 {
hasher.update(Sha256::digest(request_bytes));
}
}
H256::from_slice(&hasher.finalize())
}

impl RLPEncode for BlockBody {
fn encode(&self, buf: &mut dyn bytes::BufMut) {
Encoder::new(buf)
Expand Down
6 changes: 3 additions & 3 deletions crates/common/types/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub struct GenesisAccount {
#[serde(default, with = "crate::serde_utils::bytes")]
pub code: Bytes,
#[serde(default)]
pub storage: HashMap<H256, U256>,
pub storage: HashMap<U256, U256>,
#[serde(deserialize_with = "crate::serde_utils::u256::deser_hex_or_dec_str")]
pub balance: U256,
#[serde(default, with = "crate::serde_utils::u64::hex_str")]
Expand Down Expand Up @@ -450,7 +450,7 @@ mod tests {
let addr_b_storage = &genesis.alloc[&addr_b].storage;
assert_eq!(
addr_b_storage.get(
&H256::from_str(
&U256::from_str(
"0x0000000000000000000000000000000000000000000000000000000000000022"
)
.unwrap()
Expand All @@ -464,7 +464,7 @@ mod tests {
);
assert_eq!(
addr_b_storage.get(
&H256::from_str(
&U256::from_str(
"0x0000000000000000000000000000000000000000000000000000000000000038"
)
.unwrap()
Expand Down
Loading

0 comments on commit da1d4f7

Please sign in to comment.