diff --git a/lib/evmone/eof.cpp b/lib/evmone/eof.cpp index 1cd548e8f8..1eb3470e23 100644 --- a/lib/evmone/eof.cpp +++ b/lib/evmone/eof.cpp @@ -326,7 +326,7 @@ std::variant validate_instructi if (op == OP_RETURNCONTRACT) { - if (kind == ContainerKind::runtime || kind == ContainerKind::initcode_runtime) + if (kind == ContainerKind::runtime) return EOFValidationError::incompatible_container_kind; } @@ -335,7 +335,7 @@ std::variant validate_instructi } else if (op == OP_RETURN || op == OP_STOP) { - if (kind == ContainerKind::initcode || kind == ContainerKind::initcode_runtime) + if (kind == ContainerKind::initcode) return EOFValidationError::incompatible_container_kind; } else @@ -676,8 +676,7 @@ EOFValidationError validate_eof1( { if (main_container == container) return EOFValidationError::toplevel_container_truncated; - if (container_kind == ContainerKind::initcode || - container_kind == ContainerKind::initcode_runtime) + if (container_kind == ContainerKind::initcode) return EOFValidationError::eofcreate_with_truncated_container; } @@ -689,14 +688,14 @@ EOFValidationError validate_eof1( const bool eofcreate = subcontainer_referenced_by_eofcreate[subcont_idx]; const bool returncontract = subcontainer_referenced_by_returncontract[subcont_idx]; + if (eofcreate && returncontract) + return EOFValidationError::ambiguous_container_kind; if (!eofcreate && !returncontract) return EOFValidationError::unreferenced_subcontainer; - auto subcontainer_kind = ContainerKind::initcode_runtime; - if (!eofcreate) - subcontainer_kind = ContainerKind::runtime; - else if (!returncontract) - subcontainer_kind = ContainerKind::initcode; + const auto subcontainer_kind = + (eofcreate ? ContainerKind::initcode : ContainerKind::runtime); + assert(subcontainer_kind == ContainerKind::initcode || returncontract); container_queue.push({subcontainer, subcontainer_kind}); } diff --git a/lib/evmone/eof.hpp b/lib/evmone/eof.hpp index a7d69b7bfb..8bc7dd6dc3 100644 --- a/lib/evmone/eof.hpp +++ b/lib/evmone/eof.hpp @@ -152,9 +152,6 @@ enum class ContainerKind : uint8_t initcode, /// Container that uses STOP/RETURN. Can be returned by RETURNCONTRACT. runtime, - /// Container that uses only REVERT/INVALID or does not terminate execution. - /// Can be used in any context. - initcode_runtime, }; /// Determines the EOF version of the container by inspecting container's EOF prefix. diff --git a/test/unittests/eof_validation.cpp b/test/unittests/eof_validation.cpp index 781f17d940..1ecaa28ca9 100644 --- a/test/unittests/eof_validation.cpp +++ b/test/unittests/eof_validation.cpp @@ -109,8 +109,6 @@ std::string_view to_string(ContainerKind container_kind) noexcept return "runtime"; case (ContainerKind::initcode): return "initcode"; - case (ContainerKind::initcode_runtime): - return "initcode_runtime"; } return ""; } diff --git a/test/unittests/eof_validation_test.cpp b/test/unittests/eof_validation_test.cpp index df5bb608a8..1a0fc16a76 100644 --- a/test/unittests/eof_validation_test.cpp +++ b/test/unittests/eof_validation_test.cpp @@ -1390,81 +1390,6 @@ TEST_F(eof_validation, runtime_container_returncontract) add_test_case(factory_container, EOFValidationError::incompatible_container_kind); } -TEST_F(eof_validation, initcode_runtime_container_stop) -{ - const auto runtime_container = eof_bytecode(OP_STOP); - - add_test_case(runtime_container, ContainerKind::initcode_runtime, - EOFValidationError::incompatible_container_kind); - - const auto initcontainer = - eof_bytecode(eofcreate() + returncontract(0, 0, 0), 4).container(runtime_container); - - add_test_case( - initcontainer, ContainerKind::initcode, EOFValidationError::incompatible_container_kind); - - const auto factory_code = eofcreate() + OP_STOP; - const bytecode factory_container = eof_bytecode(factory_code, 4).container(initcontainer); - - add_test_case(factory_container, EOFValidationError::incompatible_container_kind); -} - -TEST_F(eof_validation, initcode_runtime_container_return) -{ - const auto runtime_container = eof_bytecode(ret(0, 0), 2); - - add_test_case(runtime_container, ContainerKind::initcode_runtime, - EOFValidationError::incompatible_container_kind); - - const auto initcontainer = - eof_bytecode(eofcreate() + returncontract(0, 0, 0), 4).container(runtime_container); - - add_test_case( - initcontainer, ContainerKind::initcode, EOFValidationError::incompatible_container_kind); - - const auto factory_code = eofcreate() + OP_STOP; - const bytecode factory_container = eof_bytecode(factory_code, 4).container(initcontainer); - - add_test_case(factory_container, EOFValidationError::incompatible_container_kind); -} - -TEST_F(eof_validation, initcode_runtime_container_revert) -{ - const auto runtime_container = - eof_bytecode(returncontract(0, 0, 0), 2).container(eof_bytecode(OP_INVALID)); - - add_test_case(runtime_container, ContainerKind::initcode_runtime, - EOFValidationError::incompatible_container_kind); - - const auto initcontainer = - eof_bytecode(eofcreate() + returncontract(0, 0, 0), 4).container(runtime_container); - - add_test_case( - initcontainer, ContainerKind::initcode, EOFValidationError::incompatible_container_kind); - - const auto factory_code = eofcreate() + OP_STOP; - const bytecode factory_container = eof_bytecode(factory_code, 4).container(initcontainer); - - add_test_case(factory_container, EOFValidationError::incompatible_container_kind); -} - -TEST_F(eof_validation, initcode_runtime_container_returncontract) -{ - const auto runtime_container = eof_bytecode(revert(0, 0), 2); - - add_test_case(runtime_container, ContainerKind::initcode_runtime, EOFValidationError::success); - - const auto initcontainer = - eof_bytecode(eofcreate() + returncontract(0, 0, 0), 4).container(runtime_container); - - add_test_case(initcontainer, ContainerKind::initcode, EOFValidationError::success); - - const auto factory_code = eofcreate() + OP_STOP; - const bytecode factory_container = eof_bytecode(factory_code, 4).container(initcontainer); - - add_test_case(factory_container, EOFValidationError::success); -} - TEST_F(eof_validation, eofcreate_stop_and_returncontract) { const auto runtime_container = eof_bytecode(OP_INVALID);