Skip to content

Commit

Permalink
Change EOF data section kind to 0x04
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed May 4, 2023
1 parent 100c8f9 commit b42e168
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 133 deletions.
4 changes: 3 additions & 1 deletion lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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;
Expand Down Expand Up @@ -565,6 +565,8 @@ std::string_view get_error_message(EOFValidationError err) noexcept
return "type_section_missing";
case EOFValidationError::code_section_missing:
return "code_section_missing";
case EOFValidationError::unknown_section_id:
return "unknown_section_id";
case EOFValidationError::data_section_missing:
return "data_section_missing";
case EOFValidationError::zero_section_size:
Expand Down
1 change: 1 addition & 0 deletions lib/evmone/eof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum class EOFValidationError
header_terminator_missing,
type_section_missing,
code_section_missing,
unknown_section_id,
data_section_missing,
zero_section_size,
section_headers_not_terminated,
Expand Down
10 changes: 5 additions & 5 deletions test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ TEST(eof, read_valid_eof1_header)
uint16_t data_size;
};
const TestCase test_cases[] = {
{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 1, 0},
{"EF00 01 010004 0200010006 030000 00 00000400 600160005500", 4, 6, 0},
{"EF00 01 010004 0200010001 030001 00 00000000 00 00 AA", 4, 1, 1},
{"EF00 01 010004 0200010006 030004 00 00000000 600160005500 AABBCCDD", 4, 6, 4},
{"EF00 01 010004 0200010100 031000 00 00000000" + std::string(256, '0') +
{"EF00 01 010004 0200010001 040000 00 00000000 00", 4, 1, 0},
{"EF00 01 010004 0200010006 040000 00 00000400 600160005500", 4, 6, 0},
{"EF00 01 010004 0200010001 040001 00 00000000 00 00 AA", 4, 1, 1},
{"EF00 01 010004 0200010006 040004 00 00000000 600160005500 AABBCCDD", 4, 6, 4},
{"EF00 01 010004 0200010100 041000 00 00000000" + std::string(256, '0') +
std::string(4096, 'F'),
4, 256, 4096},
};
Expand Down
226 changes: 113 additions & 113 deletions test/unittests/eof_validation_test.cpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/unittests/evm_eof_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions test/unittests/evm_eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion test/utils/bytecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b42e168

Please sign in to comment.