Skip to content

chore(DONOTMERGE): Show tests failing when using history_by_block_hash #15631

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

Closed
Closed
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion testing/ef-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
ethereum-tests
9 changes: 8 additions & 1 deletion testing/ef-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ asm-keccak = [
[dependencies]
reth-chainspec.workspace = true
reth-primitives.workspace = true
reth-db = { workspace = true, features = ["mdbx", "test-utils", "disable-lock"] }
reth-db = { workspace = true, features = [
"mdbx",
"test-utils",
"disable-lock",
] }
reth-db-api.workspace = true
reth-db-common.workspace = true
reth-provider = { workspace = true, features = ["test-utils"] }
reth-stages.workspace = true
reth-evm-ethereum.workspace = true
reth-evm.workspace = true
reth-ethereum-consensus.workspace = true
reth-revm = { workspace = true, features = ["std"] }

Expand All @@ -36,6 +42,7 @@ alloy-rlp.workspace = true
alloy-primitives.workspace = true
alloy-eips.workspace = true
alloy-consensus.workspace = true
alloy-genesis.workspace = true

walkdir.workspace = true
serde.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"SimpleTx_Cancun" : {
"_info" : {
"comment" : "",
"filling-rpc-server" : "evm version 1.14.4-unstable-3d8028a6-20240513",
"filling-tool-version" : "retesteth-0.3.2-cancun+commit.cae6bc33.Linux.g++",
"generatedTestHash" : "837301e28e17d2f6f47c0692ca9c6014fe41c573376866807cb7ec9479047236",
"lllcversion" : "Version: 0.5.14-develop.2023.7.11+commit.c58ab2c6.mod.Linux.g++",
"solidity" : "Version: 0.8.21+commit.d9974bed.Linux.g++",
"source" : "src/BlockchainTestsFiller/ValidBlocks/bcValidBlockTest/SimpleTxFiller.json",
"sourceHash" : "930e4ab655caa0b7be2b842eb649227e2370804466ce4b59514474824dd70e7a"
},
"blocks" : [
{
"blockHeader" : {
"baseFeePerGas" : "0x0e",
"blobGasUsed" : "0x00",
"bloom" : "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "0x00",
"excessBlobGas" : "0x00",
"extraData" : "0x42",
"gasLimit" : "0x2fefd8",
"gasUsed" : "0x5208",
"hash" : "0x2eea30bb0f2ff08a7ef4d56881f4505d50c02a1e904408f6f054152d048aaace",
"mixHash" : "0x0000000000000000000000000000000000000000000000000000000000020000",
"nonce" : "0x0000000000000000",
"number" : "0x01",
"parentBeaconBlockRoot" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x8cbc69e33bd85b1f8d7bc6cae8f1d4502b74cfd0cd5f24a558c0d0c257c69daa",
"receiptTrie" : "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2",
"stateRoot" : "0xc38d881219a710cef8ba02b496f9211c657fbe8c18de3909d353cdc1a8d4e16f",
"timestamp" : "0x54c99069",
"transactionsTrie" : "0x2b2fa1d2e13bdd645394906fd2737efa1f8f5e007a73e601e6db2ce4e1817d06",
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"withdrawalsRoot" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
},
"blocknumber" : "1",
"chainname" : "default",
"rlp" : "0xf902a5f9023ba08cbc69e33bd85b1f8d7bc6cae8f1d4502b74cfd0cd5f24a558c0d0c257c69daaa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0c38d881219a710cef8ba02b496f9211c657fbe8c18de3909d353cdc1a8d4e16fa02b2fa1d2e13bdd645394906fd2737efa1f8f5e007a73e601e6db2ce4e1817d06a0056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008001832fefd88252088454c9906942a000000000000000000000000000000000000000000000000000000000000200008800000000000000000ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000f863f861808203e882c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ca0446eb869f0f7f365d5fa3e649c42eba5f9b3f66092c0841e74bd6092ea08342da0626c0c7cb722f7b8aed94db18bed4f14fe2300bf7f68ce8f40e285914db6d273c0c0",
"transactions" : [
{
"data" : "0x",
"gasLimit" : "0xc350",
"gasPrice" : "0x03e8",
"nonce" : "0x00",
"r" : "0x446eb869f0f7f365d5fa3e649c42eba5f9b3f66092c0841e74bd6092ea08342d",
"s" : "0x626c0c7cb722f7b8aed94db18bed4f14fe2300bf7f68ce8f40e285914db6d273",
"sender" : "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"to" : "0x095e7baea6a6c7c4c2dfeb977efac326af552d87",
"v" : "0x1c",
"value" : "0x0a"
}
],
"uncleHeaders" : [
],
"withdrawals" : [
]
}
],
"genesisBlockHeader" : {
"baseFeePerGas" : "0x10",
"blobGasUsed" : "0x00",
"bloom" : "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "0x00",
"excessBlobGas" : "0x00",
"extraData" : "0x42",
"gasLimit" : "0x2fefd8",
"gasUsed" : "0x00",
"hash" : "0x8cbc69e33bd85b1f8d7bc6cae8f1d4502b74cfd0cd5f24a558c0d0c257c69daa",
"mixHash" : "0x0000000000000000000000000000000000000000000000000000000000020000",
"nonce" : "0x0000000000000000",
"number" : "0x00",
"parentBeaconBlockRoot" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"stateRoot" : "0x53c881003b15376a1d1d235531d20bfccc8f1bdce9caeb6a6c5ac64a9c9b1e93",
"timestamp" : "0x54c98c81",
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"withdrawalsRoot" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
},
"genesisRLP" : "0xf9023ff90239a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a053c881003b15376a1d1d235531d20bfccc8f1bdce9caeb6a6c5ac64a9c9b1e93a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008080832fefd8808454c98c8142a0000000000000000000000000000000000000000000000000000000000002000088000000000000000010a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000c0c0c0",
"lastblockhash" : "0x2eea30bb0f2ff08a7ef4d56881f4505d50c02a1e904408f6f054152d048aaace",
"network" : "Cancun",
"postState" : {
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02" : {
"balance" : "0x00",
"code" : "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
"nonce" : "0x01",
"storage" : {
"0x12e2" : "0x54c98c81",
"0x16ca" : "0x54c99069"
}
},
"0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "0x0a",
"code" : "0x",
"nonce" : "0x00",
"storage" : {
}
},
"0x8888f1f195afa192cfee860698584c030f4c9db1" : {
"balance" : "0x013bf2d0",
"code" : "0x",
"nonce" : "0x00",
"storage" : {
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0x0252cb74b6",
"code" : "0x",
"nonce" : "0x01",
"storage" : {
}
}
},
"pre" : {
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02" : {
"balance" : "0x00",
"code" : "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
"nonce" : "0x01",
"storage" : {
"0x12e2" : "0x54c98c81"
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0x02540be400",
"code" : "0x",
"nonce" : "0x00",
"storage" : {
}
}
},
"sealEngine" : "NoProof"
}
}
113 changes: 76 additions & 37 deletions testing/ef-tests/src/cases/blockchain_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ use crate::{
models::{BlockchainTest, ForkSpec},
Case, Error, Suite,
};
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_primitives::U64;
use alloy_rlp::Decodable;
use rayon::iter::{ParallelBridge, ParallelIterator};
use reth_chainspec::ChainSpec;
use reth_ethereum_consensus::EthBeaconConsensus;
use reth_db_common::init::init_genesis;
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_primitives::{BlockBody, SealedBlock, StaticFileSegment};
use reth_provider::{
providers::StaticFileWriter, test_utils::create_test_provider_factory_with_chain_spec,
DatabaseProviderFactory, HashingWriter, StaticFileProviderFactory,
DatabaseProviderFactory, ExecutionOutcome, HashingWriter, OriginalValuesKnown, StateWriter,
StaticFileProviderFactory, StorageLocation,
};
use reth_stages::{stages::ExecutionStage, ExecInput, Stage};
use reth_revm::database::StateProviderDatabase;
use std::{collections::BTreeMap, fs, path::Path, sync::Arc};

/// A handler for the blockchain test suite.
Expand Down Expand Up @@ -85,36 +90,65 @@ impl Case for BlockchainTestCase {
.par_bridge()
.try_for_each(|case| {
// Create a new test database and initialize a provider for the test case.
let chain_spec: Arc<ChainSpec> = Arc::new(case.network.into());
let provider = create_test_provider_factory_with_chain_spec(chain_spec.clone())
.database_provider_rw()
.unwrap();
let mut chain_spec: ChainSpec = case.network.into();

// Insert initial test state into the provider.
provider.insert_historical_block(
SealedBlock::<reth_primitives::Block>::from_sealed_parts(
case.genesis_block_header.clone().into(),
BlockBody::default(),
)
.try_recover()
.unwrap(),
)?;
case.pre.write_to_db(provider.tx_ref())?;

// Initialize receipts static file with genesis
{
let static_file_provider = provider.static_file_provider();
let mut receipts_writer =
static_file_provider.latest_writer(StaticFileSegment::Receipts).unwrap();
receipts_writer.increment_block(0).unwrap();
receipts_writer.commit_without_sync_all().unwrap();
}
let gen_accounts: BTreeMap<_, _> = case
.pre
.iter()
.map(|(addr, acc)| (addr.clone(), GenesisAccount::from(acc.clone())))
.collect();

let genesis_block = SealedBlock::<reth_primitives::Block>::from_sealed_parts(
case.genesis_block_header.clone().into(),
BlockBody::default(),
)
.try_recover()
.unwrap();

// Fix-up chain_spec -- TODO: This is hacky, clean up
chain_spec.genesis = Genesis {
config: chain_spec.genesis.config,
nonce: U64::from_be_bytes(genesis_block.nonce.0).to::<u64>(),
timestamp: genesis_block.timestamp,
extra_data: genesis_block.extra_data.clone(),
gas_limit: genesis_block.gas_limit.clone(),
difficulty: genesis_block.clone().difficulty,
mix_hash: genesis_block.clone().mix_hash,
coinbase: genesis_block.clone_header().beneficiary,
alloc: gen_accounts.clone(),
base_fee_per_gas: genesis_block.base_fee_per_gas.map(|x| x as u128),
excess_blob_gas: genesis_block.excess_blob_gas,
blob_gas_used: genesis_block.blob_gas_used,
number: Some(genesis_block.number),
};
chain_spec.genesis_header = genesis_block.clone_sealed_header();

let chain_spec_genesis_hash = chain_spec.genesis_hash();

let chain_spec = Arc::new(chain_spec);

let factory = create_test_provider_factory_with_chain_spec(chain_spec.clone());

assert_eq!(
chain_spec_genesis_hash,
genesis_block.hash_slow(),
"shouldn't these hashes be the same?"
);
Comment on lines +131 to +136
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected these to be the same, I get:

  left: 0xc0f91ac7900ffb638fdf6d1f20dc4a210294debe5bb4e9096390d852ab378304
 right: 0x8cbc69e33bd85b1f8d7bc6cae8f1d4502b74cfd0cd5f24a558c0d0c257c69daa

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the chain_spec is derived from the ForkId, so it is using the default genesis block for that fork instead of the genesis block header in the json file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see then:

  • The execution spec tests define a genesis block header, and a network parameter (eg Cancun)
  • There was code to convert the network parameter into a ChainSpec which has a genesis block based off of mainnet
  • history_by_block_hash seemed to have been looking for the genesis block hash based off of the ChainSpec, whereas we saved the genesis block block hash that corresponds to the one in the execution spec test json file.
  • I haven't checked, but I'm guessing latest() was looking at what we saved in the database and ignoring the ChainSpec


init_genesis(&factory).unwrap();

let provider = factory.database_provider_rw().unwrap();

// Decode and insert blocks, creating a chain of blocks for the test case.
let mut blocks = Vec::new();
let last_block = case.blocks.iter().try_fold(None, |_, block| {
let decoded =
SealedBlock::<reth_primitives::Block>::decode(&mut block.rlp.as_ref())?;
provider.insert_historical_block(decoded.clone().try_recover().unwrap())?;
let recovered = decoded.clone().try_recover().unwrap();
provider.insert_historical_block(recovered.clone())?;

blocks.push(recovered);

Ok::<Option<SealedBlock>, Error>(Some(decoded))
})?;
provider
Expand All @@ -124,16 +158,21 @@ impl Case for BlockchainTestCase {
.commit_without_sync_all()
.unwrap();

// Execute the execution stage using the EVM processor factory for the test case
// network.
let _ = ExecutionStage::new_with_executor(
reth_evm_ethereum::execute::EthExecutorProvider::ethereum(chain_spec.clone()),
Arc::new(EthBeaconConsensus::new(chain_spec)),
)
.execute(
&provider,
ExecInput { target: last_block.as_ref().map(|b| b.number), checkpoint: None },
);
let executor_provider = EthExecutorProvider::ethereum(chain_spec);
for block in blocks {
let state_provider = provider.history_by_block_hash(block.parent_hash)?;
let state_db = StateProviderDatabase(state_provider);
let executor = executor_provider.executor(state_db);

// Execute all blocks in a batch
if let Ok(output) = executor.execute(&block) {
provider.write_state(
&ExecutionOutcome::single(block.number, output),
OriginalValuesKnown::Yes,
StorageLocation::StaticFiles,
)?;
}
}

// Validate the post-state for the test case.
match (&case.post_state, &case.post_state_hash) {
Expand Down
Loading
Loading