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

statetest: Validate EOF containers in test state #593

Merged
merged 1 commit into from
Mar 26, 2023
Merged
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
10 changes: 10 additions & 0 deletions test/integration/statetest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
set(PREFIX ${PREFIX}/statetest)
set(TESTS1 ${CMAKE_CURRENT_SOURCE_DIR}/tests1)
set(TESTS2 ${CMAKE_CURRENT_SOURCE_DIR}/tests2)
set(TESTS_EOF ${CMAKE_CURRENT_SOURCE_DIR}/eof)

add_test(
NAME ${PREFIX}/no_arguments
Expand Down Expand Up @@ -82,3 +83,12 @@ set_tests_properties(
${PREFIX}/trace PROPERTIES
PASS_REGULAR_EXPRESSION [=[\{"pc":4,"op":1,"opName":"ADD","gas":0x5c872,"stack":\["0x1","0x1"\],"memorySize":0\}]=]
)

add_test(
NAME ${PREFIX}/invalid_eof_in_state
COMMAND evmone-statetest ${TESTS_EOF}/invalid_eof_in_state.json
)
set_tests_properties(
${PREFIX}/invalid_eof_in_state PROPERTIES
PASS_REGULAR_EXPRESSION "EOF container at 0x0000000000000000000000000000000000bade0f is invalid"
)
56 changes: 56 additions & 0 deletions test/integration/statetest/eof/invalid_eof_in_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"invalid_eof_in_state": {
"_info": {},
"env": {
"currentBaseFee": "0x0a",
"currentCoinbase": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty": "0x020000",
"currentGasLimit": "0xff112233445566",
"currentNumber": "0x01",
"currentRandom": "0x0000000000000000000000000000000000000000000000000000000000020000",
"currentTimestamp": "0x03e8"
},
"post": {
"Cancun": [
{
"hash": "0xe8010ce590f401c9d61fef8ab05bea9bcec24281b795e5868809bc4e515aa530",
"indexes": {
"data": 0,
"gas": 0,
"value": 0
},
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
}
]
},
"pre": {
"0xbadE0F": {
"balance": "0x0",
"code": "0xEF0001FE",
"nonce": "0x00",
"storage": {}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x0de0b6b3a7640000",
"code": "0x",
"nonce": "0x00",
"storage": {}
}
},
"transaction": {
"data": [
"0x"
],
"gasLimit": [
"0x061a80"
],
"gasPrice": "0x0a",
"nonce": "0x00",
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"to": "0xbadE0F",
"value": [
"0x0186a0"
]
}
}
}
1 change: 1 addition & 0 deletions test/statetest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_sources(

add_executable(evmone-statetest)
target_link_libraries(evmone-statetest PRIVATE evmone::statetestutils evmone GTest::gtest)
target_include_directories(evmone-statetest PRIVATE ${evmone_private_include_dir})
target_sources(
evmone-statetest PRIVATE
statetest.cpp
Expand Down
17 changes: 17 additions & 0 deletions test/statetest/statetest_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../state/mpt_hash.hpp"
#include "../state/rlp.hpp"
#include "statetest.hpp"
#include <evmone/eof.hpp>
#include <gtest/gtest.h>

namespace evmone::test
Expand All @@ -25,6 +26,22 @@ void run_state_test(const StateTransitionTest& test, evmc::VM& vm)
const auto tx = test.multi_tx.get(expected.indexes);
auto state = test.pre_state;

// Validate deployed EOF containers before running state test.
// Any invalid EOF in state make the test incorrect.
for (const auto& [addr, acc] : state.get_accounts())
{
if (is_eof_container(acc.code))
{
if (const auto result = validate_eof(rev, acc.code);
result != EOFValidationError::success)
{
throw std::invalid_argument(
"EOF container at " + hex0x(addr) +
" is invalid: " + std::string(get_error_message(result)));
}
}
}

const auto res = state::transition(state, test.block, tx, rev, vm);
if (holds_alternative<state::TransactionReceipt>(res))
EXPECT_EQ(logs_hash(get<state::TransactionReceipt>(res).logs), expected.logs_hash);
Expand Down