From 15eecedf4128dc605684dd7dafbb5ab2bba142ed Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Thu, 4 May 2023 13:29:49 +0200 Subject: [PATCH] Change EOF data section kind to 0x04 --- lib/evmone/eof.cpp | 18 +- test/unittests/eof_test.cpp | 16 +- test/unittests/eof_validation_test.cpp | 242 +++++++++++------------ test/unittests/evm_eof_function_test.cpp | 12 +- test/unittests/evm_eof_test.cpp | 14 +- test/utils/bytecode.hpp | 2 +- 6 files changed, 158 insertions(+), 146 deletions(-) diff --git a/lib/evmone/eof.cpp b/lib/evmone/eof.cpp index d126f74109..70140b1ae3 100644 --- a/lib/evmone/eof.cpp +++ b/lib/evmone/eof.cpp @@ -6,6 +6,7 @@ #include "baseline_instruction_table.hpp" #include "instructions_traits.hpp" +#include #include #include #include @@ -25,7 +26,7 @@ constexpr uint8_t MAGIC[] = {0xef, 0x00}; constexpr uint8_t TERMINATOR = 0x00; constexpr uint8_t TYPE_SECTION = 0x01; constexpr uint8_t CODE_SECTION = 0x02; -constexpr uint8_t DATA_SECTION = 0x03; +constexpr uint8_t DATA_SECTION = 0x04; constexpr uint8_t MAX_SECTION = DATA_SECTION; constexpr auto CODE_SECTION_NUMBER_LIMIT = 1024; constexpr auto MAX_STACK_HEIGHT = 0x03FF; @@ -49,8 +50,19 @@ size_t eof_header_size(const EOFSectionHeaders& headers) noexcept EOFValidationError get_section_missing_error(uint8_t section_id) noexcept { - return static_cast( - static_cast(EOFValidationError::header_terminator_missing) + section_id); + switch (section_id) + { + case TERMINATOR: + return EOFValidationError::header_terminator_missing; + case TYPE_SECTION: + return EOFValidationError::type_section_missing; + case CODE_SECTION: + return EOFValidationError::code_section_missing; + case DATA_SECTION: + return EOFValidationError::data_section_missing; + default: + intx::unreachable(); + } } std::variant validate_eof_headers(bytes_view container) diff --git a/test/unittests/eof_test.cpp b/test/unittests/eof_test.cpp index 50131914c9..0655fe863c 100644 --- a/test/unittests/eof_test.cpp +++ b/test/unittests/eof_test.cpp @@ -42,18 +42,18 @@ TEST(eof, read_valid_eof1_header) section_size_1_256 += "0001"; const TestCase test_cases[] = { - {"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 0, {1}}, - {"EF00 01 010004 0200010006 030000 00 00000002 600160005500", 4, 0, {6}}, - {"EF00 01 010004 0200010001 030001 00 00000000 00 AA", 4, 1, {1}}, - {"EF00 01 010004 0200010006 030004 00 00000002 600160005500 AABBCCDD", 4, 4, {6}}, - {"EF00 01 01000C 020003000100020003 030000 00 000000000000000000000000 00 5B00 5B5B00", 12, + {"EF00 01 010004 0200010001 040000 00 00000000 00", 4, 0, {1}}, + {"EF00 01 010004 0200010006 040000 00 00000002 600160005500", 4, 0, {6}}, + {"EF00 01 010004 0200010001 040001 00 00000000 00 AA", 4, 1, {1}}, + {"EF00 01 010004 0200010006 040004 00 00000002 600160005500 AABBCCDD", 4, 4, {6}}, + {"EF00 01 01000C 020003000100020003 040000 00 000000000000000000000000 00 5B00 5B5B00", 12, 0, {1, 2, 3}}, - {"EF00 01 01000C 020003000100020003 030004 00 000000000000000000000000 00 5B00 5B5B00 " + {"EF00 01 01000C 020003000100020003 040004 00 000000000000000000000000 00 5B00 5B5B00 " "FFFFFFFF", 12, 4, {1, 2, 3}}, - {"EF00 01 010004 0200010100 031000 00 00000000" + nops_255 + "00" + std::string(8192, 'F'), + {"EF00 01 010004 0200010100 041000 00 00000000" + nops_255 + "00" + std::string(8192, 'F'), 4, 4096, {256}}, - {"EF00 01 010400 020100" + section_size_1_256 + " 031000 00 " + + {"EF00 01 010400 020100" + section_size_1_256 + " 041000 00 " + std::string(4 * 256 * 2, '0') + std::string(512, '0') + std::string(8192, 'F'), 4 * 256, 4096, std::vector(256, 1)}, }; diff --git a/test/unittests/eof_validation_test.cpp b/test/unittests/eof_validation_test.cpp index c493368f86..0243ccdbca 100644 --- a/test/unittests/eof_validation_test.cpp +++ b/test/unittests/eof_validation_test.cpp @@ -74,13 +74,13 @@ TEST(eof_validation, valid_EOF1_code_pre_shanghai) TEST(eof_validation, minimal_valid_EOF1_code) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 FE"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040000 00 00000000 FE"), EOFValidationError::success); } TEST(eof_validation, minimal_valid_EOF1_code_with_data) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030001 00 00000000 FE DA"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001 00 00000000 FE DA"), EOFValidationError::success); } @@ -90,11 +90,11 @@ TEST(eof_validation, minimal_valid_EOF1_multiple_code_sections) EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 00 00000000 00000000 FE FE"), EOFValidationError::data_section_missing); // with data section - EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 030001 00 00000000 00000000 FE FE DA"), + EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 040001 00 00000000 00000000 FE FE DA"), EOFValidationError::success); // non-void input and output types - EXPECT_EQ(validate_eof("EF0001 010010 0200040001000200020002 030000 00 " + EXPECT_EQ(validate_eof("EF0001 010010 0200040001000200020002 040000 00 " "00000000 01000001 00010001 02030003" "FE 5000 3000 8000"), EOFValidationError::success); @@ -103,7 +103,7 @@ TEST(eof_validation, minimal_valid_EOF1_multiple_code_sections) TEST(eof_validation, EOF1_types_section_missing) { EXPECT_EQ(validate_eof("EF0001 0200010001 00 FE"), EOFValidationError::type_section_missing); - EXPECT_EQ(validate_eof("EF0001 0200010001 030001 00 FE DA"), + EXPECT_EQ(validate_eof("EF0001 0200010001 040001 00 FE DA"), EOFValidationError::type_section_missing); } @@ -111,7 +111,7 @@ TEST(eof_validation, EOF1_types_section_0_size) { EXPECT_EQ( validate_eof("EF0001 010000 0200010001 00 FE"), EOFValidationError::zero_section_size); - EXPECT_EQ(validate_eof("EF0001 010000 0200010001 030001 00 FE DA"), + EXPECT_EQ(validate_eof("EF0001 010000 0200010001 040001 00 FE DA"), EOFValidationError::zero_section_size); } @@ -123,7 +123,7 @@ TEST(eof_validation, EOF1_type_section_missing) TEST(eof_validation, EOF1_code_section_missing) { EXPECT_EQ(validate_eof("EF0001 010004 00"), EOFValidationError::code_section_missing); - EXPECT_EQ(validate_eof("EF0001 010004 030001 00 00000000 DA"), + EXPECT_EQ(validate_eof("EF0001 010004 040001 00 00000000 DA"), EOFValidationError::code_section_missing); } @@ -131,12 +131,12 @@ TEST(eof_validation, EOF1_code_section_0_size) { EXPECT_EQ(validate_eof("EF0001 010004 020000 00"), EOFValidationError::zero_section_size); EXPECT_EQ( - validate_eof("EF0001 010004 020000 030001 00 DA"), EOFValidationError::zero_section_size); + validate_eof("EF0001 010004 020000 040001 00 DA"), EOFValidationError::zero_section_size); } TEST(eof_validation, EOF1_data_section_0_size) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 FE"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040000 00 00000000 FE"), EOFValidationError::success); } @@ -148,27 +148,27 @@ TEST(eof_validation, EOF1_data_section_before_code_section) TEST(eof_validation, EOF1_data_section_before_types_section) { - EXPECT_EQ(validate_eof("EF0001 030001 010004 0200010001 00 AA 00000000 FE"), + EXPECT_EQ(validate_eof("EF0001 040001 010004 0200010001 00 AA 00000000 FE"), EOFValidationError::type_section_missing); } TEST(eof_validation, EOF1_multiple_data_sections) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030001 030001 00 00000000 FE DA DA"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001 040001 00 00000000 FE DA DA"), EOFValidationError::header_terminator_missing); } TEST(eof_validation, EOF1_unknown_section) { - EXPECT_EQ(validate_eof("EF0001 040001 00 FE"), EOFValidationError::type_section_missing); + EXPECT_EQ(validate_eof("EF0001 050001 00 FE"), EOFValidationError::type_section_missing); EXPECT_EQ(validate_eof("EF0001 FF0001 00 FE"), EOFValidationError::type_section_missing); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001 00 00000000 FE 00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 050001 00 00000000 FE 00"), EOFValidationError::data_section_missing); EXPECT_EQ(validate_eof("EF0001 010004 0200010001 FF0001 00 00000000 FE 00"), EOFValidationError::data_section_missing); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030001 040001 00 00000000 FE AA 00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001 050001 00 00000000 FE AA 00"), EOFValidationError::header_terminator_missing); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030001 FF0001 00 00000000 FE AA 00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001 FF0001 00 00000000 FE AA 00"), EOFValidationError::header_terminator_missing); } @@ -183,10 +183,10 @@ TEST(eof_validation, EOF1_incomplete_section_size) EXPECT_EQ(validate_eof("EF0001 010004 02000100"), EOFValidationError::incomplete_section_size); EXPECT_EQ(validate_eof("EF0001 010004 0200010001"), EOFValidationError::section_headers_not_terminated); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 03"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 04"), EOFValidationError::section_headers_not_terminated); EXPECT_EQ( - validate_eof("EF0001 010004 0200010001 0300"), EOFValidationError::incomplete_section_size); + validate_eof("EF0001 010004 0200010001 0400"), EOFValidationError::incomplete_section_size); } TEST(eof_validation, EOF1_header_not_terminated) @@ -198,30 +198,30 @@ TEST(eof_validation, EOF1_header_not_terminated) EXPECT_EQ(validate_eof("EF0001 010004 0200"), EOFValidationError::incomplete_section_number); EXPECT_EQ( validate_eof("EF0001 010004 020001"), EOFValidationError::section_headers_not_terminated); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030001"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001"), EOFValidationError::section_headers_not_terminated); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030001 FE AA"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040001 FE AA"), EOFValidationError::header_terminator_missing); } TEST(eof_validation, EOF1_truncated_section) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010002 040000 00"), EOFValidationError::invalid_section_bodies_size); - EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00 000000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010002 040000 00 000000"), EOFValidationError::invalid_section_bodies_size); - EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00 00000000 FE"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010002 040000 00 00000000 FE"), EOFValidationError::invalid_section_bodies_size); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030002 00 00000000 FE"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040002 00 00000000 FE"), EOFValidationError::invalid_section_bodies_size); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030002 00 00000000 FE AA"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040002 00 00000000 FE AA"), EOFValidationError::invalid_section_bodies_size); } TEST(eof_validation, EOF1_code_section_offset) { const auto eof = - "EF0001 010008 02000200030001 030004 00 00000001 00000000 6001fe fe 0000 0000"_hex; + "EF0001 010008 02000200030001 040004 00 00000001 00000000 6001fe fe 0000 0000"_hex; ASSERT_EQ(validate_eof(EVMC_CANCUN, eof), EOFValidationError::success); const auto header = read_valid_eof1_header(eof); @@ -235,9 +235,9 @@ TEST(eof_validation, EOF1_code_section_offset) TEST(eof_validation, EOF1_trailing_bytes) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 FE DEADBEEF"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040000 00 00000000 FE DEADBEEF"), EOFValidationError::invalid_section_bodies_size); - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030002 00 00000000 FE AABB DEADBEEF"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040002 00 00000000 FE AABB DEADBEEF"), EOFValidationError::invalid_section_bodies_size); } @@ -254,7 +254,7 @@ TEST(eof_validation, EOF1_multiple_type_sections) EOFValidationError::code_section_missing); // Section order is must be (Types, Code+, Data) - EXPECT_EQ(validate_eof("EF0001 030002 010001 010001 030002 00 0000 FE FE 0000"), + EXPECT_EQ(validate_eof("EF0001 030002 010001 010001 040002 00 0000 FE FE 0000"), EOFValidationError::type_section_missing); } @@ -266,48 +266,48 @@ TEST(eof_validation, EOF1_type_section_not_first) EXPECT_EQ(validate_eof("EF0001 02000200010001 010004 00 FE FE 00000000"), EOFValidationError::type_section_missing); - EXPECT_EQ(validate_eof("EF0001 0200010001 010004 030003 00 FE 00000000 AABBCC"), + EXPECT_EQ(validate_eof("EF0001 0200010001 010004 040003 00 FE 00000000 AABBCC"), EOFValidationError::type_section_missing); - EXPECT_EQ(validate_eof("EF0001 0200010001 030003 010004 00 FE AABBCC 00000000"), + EXPECT_EQ(validate_eof("EF0001 0200010001 040003 010004 00 FE AABBCC 00000000"), EOFValidationError::type_section_missing); } TEST(eof_validation, EOF1_invalid_type_section_size) { - EXPECT_EQ(validate_eof("EF0001 010001 0200010001 030000 00 00 FE"), + EXPECT_EQ(validate_eof("EF0001 010001 0200010001 040000 00 00 FE"), EOFValidationError::invalid_type_section_size); - EXPECT_EQ(validate_eof("EF0001 010002 0200010001 030000 00 0000 FE"), + EXPECT_EQ(validate_eof("EF0001 010002 0200010001 040000 00 0000 FE"), EOFValidationError::invalid_type_section_size); - EXPECT_EQ(validate_eof("EF0001 010008 0200010001 030000 00 0000000000000000 FE"), + EXPECT_EQ(validate_eof("EF0001 010008 0200010001 040000 00 0000000000000000 FE"), EOFValidationError::invalid_type_section_size); - EXPECT_EQ(validate_eof("EF0001 010008 020003000100010001 030000 00 0000000000000000 FE FE FE"), + EXPECT_EQ(validate_eof("EF0001 010008 020003000100010001 040000 00 0000000000000000 FE FE FE"), EOFValidationError::invalid_type_section_size); EXPECT_EQ( validate_eof( - "EF0001 010010 020003000100010001 030000 00 00000000000000000000000000000000 FE FE FE"), + "EF0001 010010 020003000100010001 040000 00 00000000000000000000000000000000 FE FE FE"), EOFValidationError::invalid_type_section_size); } TEST(eof_validation, EOF1_invalid_section_0_type) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010003 030000 00 00010000 60005C"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010003 040000 00 00010000 60005C"), EOFValidationError::invalid_first_section_type); - EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00 01000000 5000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010002 040000 00 01000000 5000"), EOFValidationError::invalid_first_section_type); - EXPECT_EQ(validate_eof("EF0001 010004 0200010003 030000 00 02030000 60005C"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010003 040000 00 02030000 60005C"), EOFValidationError::invalid_first_section_type); } TEST(eof_validation, EOF1_too_many_code_sections) { const auto valid = "EF0001 011000" + bytecode{"020400"} + 0x400 * bytecode{"0001"} + - "030000 00" + 0x400 * bytecode{"00000000"} + 0x400 * bytecode{"FE"}; + "040000 00" + 0x400 * bytecode{"00000000"} + 0x400 * bytecode{"FE"}; EXPECT_EQ(validate_eof(valid), EOFValidationError::success); const auto invalid = "EF0001 011002" + bytecode{"020401"} + 0x401 * bytecode{"0001"} + - "030000 00" + 0x401 * bytecode{"00000000"} + 0x401 * bytecode{"FE"}; + "040000 00" + 0x401 * bytecode{"00000000"} + 0x401 * bytecode{"FE"}; EXPECT_EQ(validate_eof(invalid), EOFValidationError::too_many_code_sections); } @@ -330,7 +330,7 @@ TEST(eof_validation, EOF1_undefined_opcodes) continue; auto cont = - "EF0001 010004 0200010014 030000 00 00000000 6001" + "EF0001 010004 0200010014 040000 00 00000000 6001" "80808080808080808080808080808080 " ""_hex; @@ -359,13 +359,13 @@ TEST(eof_validation, EOF1_undefined_opcodes) EXPECT_EQ(result, expected) << hex(cont); } - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 FE"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040000 00 00000000 FE"), EOFValidationError::success); } TEST(eof_validation, EOF1_truncated_push) { - auto eof_header = "EF0001 010004 0200010001 030000 00 00000000"_hex; + auto eof_header = "EF0001 010004 0200010001 040000 00 00000000"_hex; auto& code_size_byte = eof_header[10]; for (uint8_t opcode = OP_PUSH1; opcode <= OP_PUSH32; ++opcode) { @@ -394,89 +394,89 @@ TEST(eof_validation, EOF1_truncated_push) TEST(eof_validation, EOF1_valid_rjump) { // offset = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5C000000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5C000000"), EOFValidationError::success); // offset = 3 - EXPECT_EQ(validate_eof("EF0001 010004 0200010009 030000 00 00000001 5C00036001005CFFFA"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010009 040000 00 00000001 5C00036001005CFFFA"), EOFValidationError::success); // offset = -4 - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5B5CFFFC"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5B5CFFFC"), EOFValidationError::success); } TEST(eof_validation, EOF1_valid_rjumpi) { // offset = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000001 60005D000000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000001 60005D000000"), EOFValidationError::success); // offset = 3 - EXPECT_EQ(validate_eof("EF0001 010004 0200010009 030000 00 00000001 60005D00035B5B5B00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010009 040000 00 00000001 60005D00035B5B5B00"), EOFValidationError::success); // offset = -5 - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000001 60005DFFFB00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000001 60005DFFFB00"), EOFValidationError::success); } TEST(eof_validation, EOF1_valid_rjumpv) { // table = [0] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010009 030000 00 00000001 60005E010000600100"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010009 040000 00 00000001 60005E010000600100"), EOFValidationError::success); // table = [0,3] case = 0 EXPECT_EQ( - validate_eof("EF0001 010004 020001000E 030000 00 00000001 60005E0200000003600100600200"), + validate_eof("EF0001 010004 020001000E 040000 00 00000001 60005E0200000003600100600200"), EOFValidationError::success); // table = [0,3] case = 2 EXPECT_EQ( - validate_eof("EF0001 010004 020001000E 030000 00 00000001 60025E0200000003600100600200"), + validate_eof("EF0001 010004 020001000E 040000 00 00000001 60025E0200000003600100600200"), EOFValidationError::success); // table = [0,3,-10] case = 2 EXPECT_EQ(validate_eof( - "EF0001 010004 0200010010 030000 00 00000001 60025E0300000003FFF6600100600200"), + "EF0001 010004 0200010010 040000 00 00000001 60025E0300000003FFF6600100600200"), EOFValidationError::success); } TEST(eof_validation, EOF1_rjump_truncated) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 5C"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010001 040000 00 00000000 5C"), EOFValidationError::truncated_instruction); - EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00 00000000 5C00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010002 040000 00 00000000 5C00"), EOFValidationError::truncated_instruction); } TEST(eof_validation, EOF1_rjumpi_truncated) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010003 030000 00 00000000 60005D"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010003 040000 00 00000000 60005D"), EOFValidationError::truncated_instruction); - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 60005D00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 60005D00"), EOFValidationError::truncated_instruction); } TEST(eof_validation, EOF1_rjumpv_truncated) { // table = [0] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030000 00 00000000 60005E0100"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040000 00 00000000 60005E0100"), EOFValidationError::truncated_instruction); // table = [0,3] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010007 030000 00 00000000 60005E02000000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010007 040000 00 00000000 60005E02000000"), EOFValidationError::truncated_instruction); // table = [0,3] case = 2 - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60025E020000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60025E020000"), EOFValidationError::truncated_instruction); // table = [0,3,-10] case = 2 - EXPECT_EQ(validate_eof("EF0001 010004 0200010009 030000 00 00000000 60025E0300000003FF"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010009 040000 00 00000000 60025E0300000003FF"), EOFValidationError::truncated_instruction); } @@ -490,130 +490,130 @@ TEST(eof_validation, EOF1_rjumpv_0_count) TEST(eof_validation, EOF1_rjump_invalid_destination) { // Into header (offset = -5) - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5CFFFB00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5CFFFB00"), EOFValidationError::invalid_rjump_destination); // To before code begin (offset = -13) - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5CFFF300"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5CFFF300"), EOFValidationError::invalid_rjump_destination); // To after code end (offset = 2) - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5C000200"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5C000200"), EOFValidationError::invalid_rjump_destination); // To code end (offset = 1) - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5C000100"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5C000100"), EOFValidationError::invalid_rjump_destination); // To the same RJUMP immediate (offset = -1) - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 5CFFFF00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 5CFFFF00"), EOFValidationError::invalid_rjump_destination); // To PUSH immediate (offset = -4) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005CFFFC00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005CFFFC00"), EOFValidationError::invalid_rjump_destination); } TEST(eof_validation, EOF1_rjumpi_invalid_destination) { // Into header (offset = -7) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005DFFF900"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005DFFF900"), EOFValidationError::invalid_rjump_destination); // To before code begin (offset = -15) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005DFFF100"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005DFFF100"), EOFValidationError::invalid_rjump_destination); // To after code end (offset = 2) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005D000200"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005D000200"), EOFValidationError::invalid_rjump_destination); // To code end (offset = 1) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005D000100"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005D000100"), EOFValidationError::invalid_rjump_destination); // To the same RJUMPI immediate (offset = -1) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005DFFFF00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005DFFFF00"), EOFValidationError::invalid_rjump_destination); // To PUSH immediate (offset = -4) - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030000 00 00000000 60005DFFFC00"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040000 00 00000000 60005DFFFC00"), EOFValidationError::invalid_rjump_destination); } TEST(eof_validation, EOF1_rjumpv_invalid_destination) { // table = [-23] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010008 030000 00 00000000 60005E01FFE96001"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010008 040000 00 00000000 60005E01FFE96001"), EOFValidationError::invalid_rjump_destination); // table = [-8] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010008 030000 00 00000000 60005E01FFF86001"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010008 040000 00 00000000 60005E01FFF86001"), EOFValidationError::invalid_rjump_destination); // table = [-1] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010008 030000 00 00000000 60005E01FFFF6001"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010008 040000 00 00000000 60005E01FFFF6001"), EOFValidationError::invalid_rjump_destination); // table = [2] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010008 030000 00 00000000 60005E0100026001"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010008 040000 00 00000000 60005E0100026001"), EOFValidationError::invalid_rjump_destination); // table = [3] case = 0 - EXPECT_EQ(validate_eof("EF0001 010004 0200010008 030000 00 00000000 60005E0100036001"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010008 040000 00 00000000 60005E0100036001"), EOFValidationError::invalid_rjump_destination); // table = [0,3,-27] case = 2 EXPECT_EQ( - validate_eof("EF0001 010004 020001000F 030000 00 00000000 60025E0300000003FFE56001006002"), + validate_eof("EF0001 010004 020001000F 040000 00 00000000 60025E0300000003FFE56001006002"), EOFValidationError::invalid_rjump_destination); // table = [0,3,-12] case = 2 EXPECT_EQ( - validate_eof("EF0001 010004 020001000F 030000 00 00000000 60025E0300000003FFF46001006002"), + validate_eof("EF0001 010004 020001000F 040000 00 00000000 60025E0300000003FFF46001006002"), EOFValidationError::invalid_rjump_destination); // table = [0,3,-1] case = 2 EXPECT_EQ( - validate_eof("EF0001 010004 020001000F 030000 00 00000000 60025E0300000003FFFF6001006002"), + validate_eof("EF0001 010004 020001000F 040000 00 00000000 60025E0300000003FFFF6001006002"), EOFValidationError::invalid_rjump_destination); // table = [0,3,5] case = 2 EXPECT_EQ( - validate_eof("EF0001 010004 020001000F 030000 00 00000000 60025E030000000300056001006002"), + validate_eof("EF0001 010004 020001000F 040000 00 00000000 60025E030000000300056001006002"), EOFValidationError::invalid_rjump_destination); // table = [0,3,6] case = 2 EXPECT_EQ( - validate_eof("EF0001 010004 020001000F 030000 00 00000000 60025E030000000300066001006002"), + validate_eof("EF0001 010004 020001000F 040000 00 00000000 60025E030000000300066001006002"), EOFValidationError::invalid_rjump_destination); } TEST(eof_validation, EOF1_section_order) { - // 01 02 03 - EXPECT_EQ(validate_eof("EF0001 010004 0200010006 030002 00 00000001 60005D000000 AABB"), + // 01 02 04 + EXPECT_EQ(validate_eof("EF0001 010004 0200010006 040002 00 00000001 60005D000000 AABB"), EOFValidationError::success); - // 01 03 02 - EXPECT_EQ(validate_eof("EF0001 010004 030002 0200010006 00 00000000 AABB 60005D000000"), + // 01 04 02 + EXPECT_EQ(validate_eof("EF0001 010004 040002 0200010006 00 00000000 AABB 60005D000000"), EOFValidationError::code_section_missing); - // 02 01 03 - EXPECT_EQ(validate_eof("EF0001 0200010006 010004 030002 00 60005D000000 00000000 AABB"), + // 02 01 04 + EXPECT_EQ(validate_eof("EF0001 0200010006 010004 040002 00 60005D000000 00000000 AABB"), EOFValidationError::type_section_missing); - // 02 03 01 - EXPECT_EQ(validate_eof("EF0001 0200010006 030002 010004 00 60005D000000 AABB 00000000"), + // 02 04 01 + EXPECT_EQ(validate_eof("EF0001 0200010006 040002 010004 00 60005D000000 AABB 00000000"), EOFValidationError::type_section_missing); - // 03 01 02 - EXPECT_EQ(validate_eof("EF0001 030002 010004 0200010006 00 AABB 00000000 60005D000000"), + // 04 01 0 + EXPECT_EQ(validate_eof("EF0001 040002 010004 0200010006 00 AABB 00000000 60005D000000"), EOFValidationError::type_section_missing); - // 03 02 01 - EXPECT_EQ(validate_eof("EF0001 030002 0200010006 010004 00 AABB 60005D000000 00000000"), + // 04 02 01 + EXPECT_EQ(validate_eof("EF0001 040002 0200010006 010004 00 AABB 60005D000000 00000000"), EOFValidationError::type_section_missing); } @@ -627,21 +627,21 @@ TEST(eof_validation, deprecated_instructions) TEST(eof_valication, max_arguments_count) { - EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 030000 00 00000000 7F7F007F B1 B1"), + EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 040000 00 00000000 7F7F007F B1 B1"), EOFValidationError::success); - EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 030000 00 00000000 80800080 B1 B1"), + EXPECT_EQ(validate_eof("EF0001 010008 02000200010001 040000 00 00000000 80800080 B1 B1"), EOFValidationError::inputs_outputs_num_above_limit); { - auto code = "EF0001 010008 020002000100FF 030000 00 00000000 007F007F B1" + + auto code = "EF0001 010008 020002000100FF 040000 00 00000000 007F007F B1" + 127 * bytecode{1} + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::success); } { - auto code = "EF0001 010008 02000200010101 030000 00 00000000 00800080 B1" + + auto code = "EF0001 010008 02000200010101 040000 00 00000000 00800080 B1" + 128 * bytecode{1} + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::inputs_outputs_num_above_limit); @@ -649,58 +649,58 @@ TEST(eof_valication, max_arguments_count) { auto code = - "EF0001 010008 02000200010080 030000 00 00000000 7F00007F B1" + 127 * OP_POP + OP_RETF; + "EF0001 010008 02000200010080 040000 00 00000000 7F00007F B1" + 127 * OP_POP + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::success); } { auto code = - "EF0001 010008 02000200010081 030000 00 00000000 80000080 B1" + 128 * OP_POP + OP_RETF; + "EF0001 010008 02000200010081 040000 00 00000000 80000080 B1" + 128 * OP_POP + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::inputs_outputs_num_above_limit); } } -TEST(eof_valication, max_stack_heigh) +TEST(eof_valication, max_stack_height) { { - auto code = "EF0001 010008 02000200010BFE 030000 00 00000000 000003FF B1" + + auto code = "EF0001 010008 02000200010BFE 040000 00 00000000 000003FF B1" + 0x3FF * bytecode{1} + 0x3FF * OP_POP + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::success); } { - auto code = "EF0001 010008 0200020BFE0001 030000 00 000003FF 00000000" + + auto code = "EF0001 010008 0200020BFE0001 040000 00 000003FF 00000000" + 0x3FF * bytecode{1} + 0x3FF * OP_POP + OP_RETF + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::success); } { - auto code = "EF0001 010008 02000200010C01 030000 00 00000000 00000400 B1" + + auto code = "EF0001 010008 02000200010C01 040000 00 00000000 00000400 B1" + 0x400 * bytecode{1} + 0x400 * OP_POP + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::max_stack_height_above_limit); } { - auto code = "EF0001 010008 0200020C010001 030000 00 00000400 00000000" + + auto code = "EF0001 010008 0200020C010001 040000 00 00000400 00000000" + 0x400 * bytecode{1} + 0x400 * OP_POP + OP_RETF + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::max_stack_height_above_limit); } { - auto code = "EF0001 010008 02000200010C01 030000 00 00000000 000003FF B1" + + auto code = "EF0001 010008 02000200010C01 040000 00 00000000 000003FF B1" + 0x400 * bytecode{1} + 0x400 * OP_POP + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::invalid_max_stack_height); } { - auto code = "EF0001 010008 0200020C010001 030000 00 000003FF 00000000" + + auto code = "EF0001 010008 0200020C010001 040000 00 000003FF 00000000" + 0x400 * bytecode{1} + 0x400 * OP_POP + OP_RETF + OP_RETF; EXPECT_EQ(validate_eof(code), EOFValidationError::invalid_max_stack_height); @@ -727,7 +727,7 @@ TEST(eof_valication, max_stack_heigh) TEST(eof_validation, callf_invalid_code_section_index) { - EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 b0000100"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010004 040000 00 00000000 b0000100"), EOFValidationError::invalid_code_section_index); } @@ -745,7 +745,7 @@ TEST(eof_validation, data_section_missing) TEST(eof_validation, multiple_code_sections_headers) { - EXPECT_EQ(validate_eof("0xef0001 010008 020001 0004 020001 0005 030000 00 00040000 045c0000 " + EXPECT_EQ(validate_eof("0xef0001 010008 020001 0004 020001 0005 040000 00 00040000 045c0000 " "00405c00 00002e0005"), EOFValidationError::data_section_missing); } @@ -798,7 +798,7 @@ TEST(eof_validation, many_code_sections_1023) "000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100" "010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001" "000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100" - "010001000100010001000100010001000100010001000100010001000100010300000000000000000000000000" + "010001000100010001000100010001000100010001000100010001000100010400000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" @@ -964,7 +964,7 @@ TEST(eof_validation, many_code_sections_1024) "000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100" "010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001" "000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100" - "010001000100010001000100010001000100010001000100010001000100010001030000000000000000000000" + "010001000100010001000100010001000100010001000100010001000100010001040000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" @@ -1130,7 +1130,7 @@ TEST(eof_validation, too_many_code_sections) "000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100" "010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001" "000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100" - "010001000100010001000100010001000100010001000100010001000100010001000103000000000000000000" + "010001000100010001000100010001000100010001000100010001000100010001000104000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" @@ -1251,42 +1251,42 @@ TEST(eof_validation, too_many_code_sections) TEST(eof_validation, dataloadn) { // DATALOADN{0} - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030020 00 00000001 b900005000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040020 00 00000001 b900005000" "0000000000000000111111111111111122222222222222223333333333333333"), EOFValidationError::success); // DATALOADN{1} - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030021 00 00000001 b900015000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040021 00 00000001 b900015000" "000000000000000011111111111111112222222222222222333333333333333344"), EOFValidationError::success); // DATALOADN{32} - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030040 00 00000001 b900205000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040040 00 00000001 b900205000" "0000000000000000111111111111111122222222222222223333333333333333" "0000000000000000111111111111111122222222222222223333333333333333"), EOFValidationError::success); // DATALOADN{0} - no data section - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030000 00 00000001 b900005000"), + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040000 00 00000001 b900005000"), EOFValidationError::invalid_dataloadn_index); // DATALOADN{1} - out of data section bounds - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030001 00 00000001 b900015000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040001 00 00000001 b900015000" "00"), EOFValidationError::invalid_dataloadn_index); // DATALOADN{32} - out of data section bounds - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030020 00 00000001 b900205000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040020 00 00000001 b900205000" "0000000000000000111111111111111122222222222222223333333333333333"), EOFValidationError::invalid_dataloadn_index); // DATALOADN{uint16_max} - out of data section bounds - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 030020 00 00000001 b9ffff5000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 040020 00 00000001 b9ffff5000" "0000000000000000111111111111111122222222222222223333333333333333"), EOFValidationError::invalid_dataloadn_index); // DATALOADN{32} - truncated word - EXPECT_EQ(validate_eof("EF0001 010004 0200010005 03003F 00 00000001 b900205000" + EXPECT_EQ(validate_eof("EF0001 010004 0200010005 04003F 00 00000001 b900205000" "0000000000000000111111111111111122222222222222223333333333333333" "00000000000000001111111111111111222222222222222233333333333333"), EOFValidationError::invalid_dataloadn_index); diff --git a/test/unittests/evm_eof_function_test.cpp b/test/unittests/evm_eof_function_test.cpp index d02b696ee8..291b09afef 100644 --- a/test/unittests/evm_eof_function_test.cpp +++ b/test/unittests/evm_eof_function_test.cpp @@ -15,7 +15,7 @@ TEST_P(evm, eof_function_example1) rev = EVMC_CANCUN; const auto code = - "EF00 01 010008 020002 000f 0002 030000 00" + "EF00 01 010008 020002 000f 0002 040000 00" "00000002 02010002" "6001 6008 b00001 " + ret_top() + "03b1"; @@ -35,7 +35,7 @@ TEST_P(evm, eof_function_example2) rev = EVMC_CANCUN; const auto code = - "ef0001 01000c 020003 003b 0017 001d 030000 00 00000004 01010003 01010004" + "ef0001 01000c 020003 003b 0017 001d 040000 00 00000004 01010003 01010004" "60043560003560e01c63c766526781145d001c63c6c2ea1781145d00065050600080fd50b00002600052602060" "00f350b0000160005260206000f3" "600181115d0004506001b160018103b0000181029050b1" @@ -65,7 +65,7 @@ TEST_P(evm, callf_stack_size_1024) return; rev = EVMC_CANCUN; - const auto code = bytecode{"ef0001 010008 020002 0BFF 0004 030000 00 000003FF 00000001"_hex} + + const auto code = bytecode{"ef0001 010008 020002 0BFF 0004 040000 00 000003FF 00000001"_hex} + 1023 * push(1) + OP_CALLF + bytecode{"0x0001"_hex} + 1021 * OP_POP + OP_RETURN + push(1) + OP_POP + OP_RETF; @@ -82,7 +82,7 @@ TEST_P(evm, callf_stack_overflow) rev = EVMC_CANCUN; const auto code = - bytecode{"ef0001 010008 020002 0BFF 0007 030000 00 000003FF 00000002"_hex} + // EOF header + bytecode{"ef0001 010008 020002 0BFF 0007 040000 00 000003FF 00000002"_hex} + // EOF header 1023 * push(1) + OP_CALLF + bytecode{"0x0001"_hex} + 1021 * OP_POP + OP_RETURN + 2 * push(1) + 2 * OP_POP + OP_RETF; @@ -98,7 +98,7 @@ TEST_P(evm, callf_call_stack_size_1024) return; rev = EVMC_CANCUN; - const auto code = bytecode{"ef0001 010008 020002 0007 000e 030000 00 00000001 01000002"_hex} + + const auto code = bytecode{"ef0001 010008 020002 0007 000e 040000 00 00000001 01000002"_hex} + push(1023) + OP_CALLF + bytecode{"0x0001"_hex} + OP_STOP + OP_DUP1 + OP_RJUMPI + bytecode{"0x0002"_hex} + OP_POP + OP_RETF + push(1) + OP_SWAP1 + OP_SUB + OP_CALLF + bytecode{"0x0001"_hex} + OP_RETF; @@ -115,7 +115,7 @@ TEST_P(evm, callf_call_stack_size_1025) return; rev = EVMC_CANCUN; - const auto code = bytecode{"ef0001 010008 020002 0007 000e 030000 00 00000001 01000002"_hex} + + const auto code = bytecode{"ef0001 010008 020002 0007 000e 040000 00 00000001 01000002"_hex} + push(1024) + OP_CALLF + bytecode{"0x0001"_hex} + OP_STOP + OP_DUP1 + OP_RJUMPI + bytecode{"0x0002"_hex} + OP_POP + OP_RETF + push(1) + OP_SWAP1 + OP_SUB + OP_CALLF + bytecode{"0x0001"_hex} + OP_RETF; diff --git a/test/unittests/evm_eof_test.cpp b/test/unittests/evm_eof_test.cpp index a0563490b4..f3b168850b 100644 --- a/test/unittests/evm_eof_test.cpp +++ b/test/unittests/evm_eof_test.cpp @@ -57,14 +57,14 @@ TEST_P(evm, eof1_codecopy_full) execute(code); EXPECT_STATUS(EVMC_SUCCESS); EXPECT_EQ(bytes_view(result.output_data, result.output_size), - "ef0001010004020001000c0300000000000003601f6000600039601f6000f3"_hex); + "ef0001010004020001000c0400000000000003601f6000600039601f6000f3"_hex); code = eof1_bytecode(bytecode{35} + 0 + 0 + OP_CODECOPY + ret(0, 35), 3, "deadbeef"); execute(code); EXPECT_STATUS(EVMC_SUCCESS); EXPECT_EQ(bytes_view(result.output_data, result.output_size), - "ef0001010004020001000c03000400000000036023600060003960236000f3deadbeef"_hex); + "ef0001010004020001000c04000400000000036023600060003960236000f3deadbeef"_hex); } TEST_P(evm, eof1_codecopy_header) @@ -75,14 +75,14 @@ TEST_P(evm, eof1_codecopy_header) execute(code); EXPECT_STATUS(EVMC_SUCCESS); EXPECT_EQ( - bytes_view(result.output_data, result.output_size), "ef0001010004020001000c03000000"_hex); + bytes_view(result.output_data, result.output_size), "ef0001010004020001000c04000000"_hex); code = eof1_bytecode(bytecode{15} + 0 + 0 + OP_CODECOPY + ret(0, 15), 3, "deadbeef"); execute(code); EXPECT_STATUS(EVMC_SUCCESS); EXPECT_EQ( - bytes_view(result.output_data, result.output_size), "ef0001010004020001000c03000400"_hex); + bytes_view(result.output_data, result.output_size), "ef0001010004020001000c04000400"_hex); } TEST_P(evm, eof1_codecopy_code) @@ -121,20 +121,20 @@ TEST_P(evm, eof1_codecopy_out_of_bounds) execute(code); EXPECT_STATUS(EVMC_SUCCESS); EXPECT_EQ(bytes_view(result.output_data, result.output_size), - "ef0001010004020001000c03000000000000036023600060003960236000f300000000"_hex); + "ef0001010004020001000c04000000000000036023600060003960236000f300000000"_hex); code = eof1_bytecode(bytecode{39} + 0 + 0 + OP_CODECOPY + ret(0, 39), 3, "deadbeef"); execute(code); EXPECT_STATUS(EVMC_SUCCESS); EXPECT_EQ(bytes_view(result.output_data, result.output_size), - "ef0001010004020001000c03000400000000036027600060003960276000f3deadbeef00000000"_hex); + "ef0001010004020001000c04000400000000036027600060003960276000f3deadbeef00000000"_hex); } TEST_P(evm, eof_data_only_contract) { rev = EVMC_CANCUN; - auto code = "EF0001 010004 020001 0001 03daaa 00 00000000 FE"_hex; + auto code = "EF0001 010004 020001 0001 04daaa 00 00000000 FE"_hex; const auto data_size_ptr = &code[code.find(0xda)]; intx::be::unsafe::store(data_size_ptr, uint16_t{0}); diff --git a/test/utils/bytecode.hpp b/test/utils/bytecode.hpp index 41f0efae2f..8bebf7603b 100644 --- a/test/utils/bytecode.hpp +++ b/test/utils/bytecode.hpp @@ -96,7 +96,7 @@ inline bytecode eof_header( bytecode out{bytes{0xEF, 0x00, version}}; out += "01" + big_endian(uint16_t{4}); // type header out += "02"_hex + big_endian(uint16_t{1}) + big_endian(code_size); - out += "03" + big_endian(data_size); + out += "04" + big_endian(data_size); out += "00"; out += "0000"_hex + big_endian(max_stack_height); // type section return out;