diff --git a/test/integration/statetest/CMakeLists.txt b/test/integration/statetest/CMakeLists.txt index 691a2cd8fe..ec3bbe9663 100644 --- a/test/integration/statetest/CMakeLists.txt +++ b/test/integration/statetest/CMakeLists.txt @@ -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 @@ -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" +) diff --git a/test/integration/statetest/eof/invalid_eof_in_state.json b/test/integration/statetest/eof/invalid_eof_in_state.json new file mode 100644 index 0000000000..db0384bd14 --- /dev/null +++ b/test/integration/statetest/eof/invalid_eof_in_state.json @@ -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" + ] + } + } +} diff --git a/test/statetest/CMakeLists.txt b/test/statetest/CMakeLists.txt index fb68c46593..0de4004010 100644 --- a/test/statetest/CMakeLists.txt +++ b/test/statetest/CMakeLists.txt @@ -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 diff --git a/test/statetest/statetest_runner.cpp b/test/statetest/statetest_runner.cpp index 53e9195e9b..9863d9de1f 100644 --- a/test/statetest/statetest_runner.cpp +++ b/test/statetest/statetest_runner.cpp @@ -5,6 +5,7 @@ #include "../state/mpt_hash.hpp" #include "../state/rlp.hpp" #include "statetest.hpp" +#include #include namespace evmone::test @@ -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(res)) EXPECT_EQ(logs_hash(get(res).logs), expected.logs_hash);