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

eof: Change kind_data from 0x04 to 0xff #1177

Merged
merged 1 commit into from
Apr 9, 2025
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
22 changes: 19 additions & 3 deletions lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
constexpr uint8_t TYPE_SECTION = 0x01;
constexpr uint8_t CODE_SECTION = 0x02;
constexpr uint8_t CONTAINER_SECTION = 0x03;
// TODO: kind_data is now 0xff, but we're still using a 4-element array to hold
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is resolved and the TODO removed in a subsequent PR

// decoded header info about sections (EOFSectionHeaders). Refactor to not
// depend on section kinds being contiguous.
constexpr uint8_t DATA_SECTION_KIND = 0xff;
constexpr uint8_t DATA_SECTION = 0x04;
constexpr uint8_t MAX_SECTION = DATA_SECTION;
constexpr uint8_t NUM_SECTIONS = DATA_SECTION;
constexpr auto CODE_SECTION_NUMBER_LIMIT = 1024;
constexpr auto CONTAINER_SECTION_NUMBER_LIMIT = 256;
constexpr auto MAX_STACK_HEIGHT = 0x03FF;
Expand All @@ -36,7 +40,7 @@
constexpr auto STACK_SIZE_LIMIT = 1024;
constexpr uint8_t NON_RETURNING_FUNCTION = 0x80;

using EOFSectionHeaders = std::array<std::vector<uint16_t>, MAX_SECTION + 1>;
using EOFSectionHeaders = std::array<std::vector<uint16_t>, NUM_SECTIONS + 1>;

size_t eof_header_size(const EOFSectionHeaders& headers) noexcept
{
Expand Down Expand Up @@ -99,6 +103,12 @@
case State::section_id:
{
section_id = *it++;
// kind_data is 0xff but we need to use a contiguous index until we refactor away
// the EOFSectionHeaders array type
if (section_id == DATA_SECTION_KIND)
section_id = DATA_SECTION;
else if (section_id == DATA_SECTION)
section_id = DATA_SECTION_KIND;

// Skip optional sections.
if (section_id != expected_section_id && expected_section_id == CONTAINER_SECTION)
Expand Down Expand Up @@ -804,7 +814,13 @@
auto it = container.begin() + std::size(EOF_MAGIC) + 1; // MAGIC + VERSION
while (*it != TERMINATOR)
{
const auto section_id = *it++;
auto section_id = *it++;
// kind_data is 0xff but we need to use a contiguous index until we refactor away
// the EOFSectionHeaders array type
if (section_id == DATA_SECTION_KIND)
section_id = DATA_SECTION;
else if (section_id == DATA_SECTION)
section_id = DATA_SECTION_KIND;

Check warning on line 823 in lib/evmone/eof.cpp

View check run for this annotation

Codecov / codecov/patch

lib/evmone/eof.cpp#L823

Added line #L823 was not covered by tests
if (section_id == CODE_SECTION || section_id == CONTAINER_SECTION)
{
const auto code_section_num = read_uint16_be(it);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ DUP1,4
${PREFIX}/validate_eof PROPERTIES PASS_REGULAR_EXPRESSION
"contract validation failure")

add_test(NAME ${PREFIX}/validate_eof_success COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,validate_eof run --rev 14 EF00010100040200010001040000000080000000)
add_test(NAME ${PREFIX}/validate_eof_success COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,validate_eof run --rev 14 EF00010100040200010001FF0000000080000000)
set_tests_properties(
${PREFIX}/validate_eof_success PROPERTIES PASS_REGULAR_EXPRESSION
"Result: success")

add_test(NAME ${PREFIX}/validate_eof_create COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,validate_eof run --rev 14 --create EF00010100040200010001040000000080000000)
add_test(NAME ${PREFIX}/validate_eof_create COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,validate_eof run --rev 14 --create EF00010100040200010001FF0000000080000000)
set_tests_properties(
${PREFIX}/validate_eof_create PROPERTIES PASS_REGULAR_EXPRESSION
"contract validation failure")

add_test(NAME ${PREFIX}/validate_eof_create_success COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,validate_eof run --rev 14 --create EF00010100040200010004030001001404000000008000025F5FEE00EF00010100040200010001040000000080000000)
add_test(NAME ${PREFIX}/validate_eof_create_success COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,validate_eof run --rev 14 --create EF000101000402000100040300010014FF000000008000025F5FEE00EF00010100040200010001FF0000000080000000)
set_tests_properties(
${PREFIX}/validate_eof_create_success PROPERTIES PASS_REGULAR_EXPRESSION
"Result: success")
Expand Down
4 changes: 2 additions & 2 deletions test/integration/eofparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ set(PREFIX ${PROJECT_NAME}/integration/eofparse)

string(REPLACE ";" " " CROSSCOMPILING_EMULATOR "${CMAKE_CROSSCOMPILING_EMULATOR}")

add_test(NAME ${PREFIX}/minimal_eof COMMAND sh -c "echo EF0001.010004 0200010001 040000 00,00800000 FE | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
add_test(NAME ${PREFIX}/minimal_eof COMMAND sh -c "echo EF0001.010004 0200010001 FF0000 00,00800000 FE | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
set_tests_properties(${PREFIX}/minimal_eof PROPERTIES PASS_REGULAR_EXPRESSION "OK fe")

add_test(NAME ${PREFIX}/two_code_sections COMMAND sh -c "echo EF0001 010008 02000200030001 040000 00 00800000,00800000 E50001,00 | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
add_test(NAME ${PREFIX}/two_code_sections COMMAND sh -c "echo EF0001 010008 02000200030001 FF0000 00 00800000,00800000 E50001,00 | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
set_tests_properties(${PREFIX}/two_code_sections PROPERTIES PASS_REGULAR_EXPRESSION "OK e50001,00")

add_test(NAME ${PREFIX}/eof_version_unknown COMMAND sh -c "echo EF00.FF | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
Expand Down
4 changes: 2 additions & 2 deletions test/integration/eofparse/two_errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Example input file to eofparse tool. Two of the following lines contain EOF validation errors.

# Minimal valid EOF container.
EF0001 010004 0200010001 040000 00 00800000 00
EF0001 010004 0200010001 FF0000 00 00800000 00

# Mandatory sections missing
EF0001 00

# Code section not terminated
EF0001 010004 0200010001 040000 00 00800000 5b
EF0001 010004 0200010001 FF0000 00 00800000 5b
18 changes: 9 additions & 9 deletions test/unittests/eof_example_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST_F(state_transition, eof_examples_minimal)
// | |
// version | Header terminator
// | |___________ | |
"EF00 01 01 0004 02 0001 0001 04 0000 00 00 80 0000 00"
"EF00 01 01 0004 02 0001 0001 FF 0000 00 00 80 0000 00"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
// | Header: data section 0 bytes long
// | |
Expand Down Expand Up @@ -60,7 +60,7 @@ TEST_F(state_transition, eof_examples_static_relative_jump_loop)
// | |
// version | Header terminator
// | |___________ | |
"EF00 01 01 0004 02 0001 0003 04 0000 00 00 80 0000 E0FFFD"
"EF00 01 01 0004 02 0001 0003 FF 0000 00 00 80 0000 E0FFFD"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
// | Header: data section 0 bytes long
// | |
Expand Down Expand Up @@ -98,7 +98,7 @@ TEST_F(state_transition, eof_examples_callf)
// | | |
// version | Header terminator | |
// | |________________ | |_____________ |
"EF00 01 01 0008 02 0002 0006 0001 04 0000 00 00 80 0001 01 01 0001 602A E30001 00 E4"
"EF00 01 01 0008 02 0002 0006 0001 FF 0000 00 00 80 0001 01 01 0001 602A E30001 00 E4"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// | Header: data section 0 bytes long
// | |
Expand Down Expand Up @@ -137,7 +137,7 @@ TEST_F(state_transition, eof_examples_creation_tx)
// | |
// version | Header terminator
// | |___________ | |________
"EF00 01 01 0004 02 0001 0004 03 0001 0014 04 0000 00 00 80 0002 5F5F EE00"
"EF00 01 01 0004 02 0001 0004 03 0001 0014 FF 0000 00 00 80 0002 5F5F EE00"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
// | | Header: data section 0 bytes long
// | | |
Expand All @@ -148,7 +148,7 @@ TEST_F(state_transition, eof_examples_creation_tx)
//
//////////////////
// Deployed container (contract doing nothing, see Example 1)
"EF00 01 01 0004 02 0001 0001 04 0000 00 00 80 0000 00");
"EF00 01 01 0004 02 0001 0001 FF 0000 00 00 80 0000 00");

// Put the initcontainer in the `data` field of the transaction, appending some calldata.
tx.data = initcontainer + "ABCDEF";
Expand Down Expand Up @@ -179,7 +179,7 @@ TEST_F(state_transition, eof_examples_eofcreate)
// | |
// version | Header terminator
// | |___________ | |____________________
"EF00 01 01 0004 02 0001 0008 03 0001 0030 04 0000 00 00 80 0004 5F 5F 5F 60FF EC00 00"
"EF00 01 01 0004 02 0001 0008 03 0001 0030 FF 0000 00 00 80 0004 5F 5F 5F 60FF EC00 00"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
// | | Header: data section 0 bytes long
// | | |
Expand All @@ -197,7 +197,7 @@ TEST_F(state_transition, eof_examples_eofcreate)
// | |
// version | Header terminator
// | |___________ | |_________
"EF00 01 01 0004 02 0001 0004 03 0001 0014 04 0000 00 00 80 0002 5F 5F EE00"
"EF00 01 01 0004 02 0001 0004 03 0001 0014 FF 0000 00 00 80 0002 5F 5F EE00"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
// | | Header: data section 0 bytes long
// | | |
Expand All @@ -208,7 +208,7 @@ TEST_F(state_transition, eof_examples_eofcreate)
//
//////////////////
// Deployed container (contract doing nothing, see Example 1)
"EF00 01 01 0004 02 0001 0001 04 0000 00 00 80 0000 00");
"EF00 01 01 0004 02 0001 0001 FF 0000 00 00 80 0000 00");

// Tests the code is valid EOF and when called with initcodes creates a new contract.
tx.to = To;
Expand Down Expand Up @@ -237,7 +237,7 @@ TEST_F(state_transition, eof_examples_data)
// | |
// version | Header terminator Data section
// | |___________ | |________ |_________________________________________________________________
"EF00 01 01 0004 02 0001 0004 04 0021 00 00 80 0001 D10000 00 454F462068617320736F6D65206772656174206578616D706C6573206865726521"
"EF00 01 01 0004 02 0001 0004 FF 0021 00 00 80 0001 D10000 00 454F462068617320736F6D65206772656174206578616D706C6573206865726521"
// |‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
// | Header: data section 33 bytes long
// | |
Expand Down
44 changes: 22 additions & 22 deletions test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,44 @@
const auto eofcreate_256_size = static_cast<uint16_t>(eofcreate_256.size() / 2);

const TestCase test_cases[] = {
{"EF00 01 010004 0200010001 040000 00 00800000 00", 4, 0, {1}, {}},
{"EF00 01 010004 0200010006 040000 00 00800002 600160005500", 4, 0, {6}, {}},
{"EF00 01 010004 0200010001 040001 00 00800000 00 AA", 4, 1, {1}, {}},
{"EF00 01 010004 0200010006 040004 00 00800002 600160005500 AABBCCDD", 4, 4, {6}, {}},
{"EF00 01 01000C 020003000300030003 040000 00 008000000080000000800000 E50001 E50002 "
{"EF00 01 010004 0200010001 FF0000 00 00800000 00", 4, 0, {1}, {}},

Check warning on line 53 in test/unittests/eof_test.cpp

View check run for this annotation

Codecov / codecov/patch

test/unittests/eof_test.cpp#L53

Added line #L53 was not covered by tests
{"EF00 01 010004 0200010006 FF0000 00 00800002 600160005500", 4, 0, {6}, {}},
{"EF00 01 010004 0200010001 FF0001 00 00800000 00 AA", 4, 1, {1}, {}},
{"EF00 01 010004 0200010006 FF0004 00 00800002 600160005500 AABBCCDD", 4, 4, {6}, {}},
{"EF00 01 01000C 020003000300030003 FF0000 00 008000000080000000800000 E50001 E50002 "
"5B5B00",
12, 0, {3, 3, 3}, {}},
{"EF00 01 01000C 020003000300030003 040004 00 008000000080000000800000 E50001 E50002 "
{"EF00 01 01000C 020003000300030003 FF0004 00 008000000080000000800000 E50001 E50002 "
"5B5B00 FFFFFFFF",
12, 4, {3, 3, 3}, {}},
{"EF00 01 010004 0200010100 041000 00 00800000" + hex(255 * bytecode("5B")) + "00" +
{"EF00 01 010004 0200010100 FF1000 00 00800000" + hex(255 * bytecode("5B")) + "00" +
std::string(8192, 'F'),
4, 4096, {256}, {}},
{"EF00 01 010400 020100" + hex(256 * bytecode("0003")) + " 041000 00 " +
{"EF00 01 010400 020100" + hex(256 * bytecode("0003")) + " FF1000 00 " +
hex(256 * bytecode("00800000")) + code_sections_256 + std::string(8192, 'F'),
4 * 256, 4096, std::vector<uint16_t>(256, 3), {}},
{"EF00 01 010004 0200010007 0300010014 040000 00 00800004 5F5F5F5FEC0000 "
"EF000101000402000100010400000000800000FE",
{"EF00 01 010004 0200010007 0300010014 FF0000 00 00800004 5F5F5F5FEC0000 "
"EF00010100040200010001FF00000000800000FE",
4, 0, {7}, {20}},
{"EF00 01 010004 0200010015 030003001400160018 040000 00 00800004 "
{"EF00 01 010004 0200010015 030003001400160018 FF0000 00 00800004 "
"5F5F5F5FEC00505F5F5F5FEC01505F5F5F5FEC0200 "
"EF000101000402000100010400000000800000FE EF0001010004020001000304000000008000025F5FFD "
"EF00010100040200010005040000000080000260015F55FE",
"EF00010100040200010001FF00000000800000FE EF00010100040200010003FF000000008000025F5FFD "
"EF00010100040200010005FF0000000080000260015F55FE",
4, 0, {21}, {20, 22, 24}},
{"EF00 01 010004 0200010015 030003001400160018 040003 00 00800004 "
{"EF00 01 010004 0200010015 030003001400160018 FF0003 00 00800004 "
"5F5F5F5FEC00505F5F5F5FEC01505F5F5F5FEC0200 "
"EF000101000402000100010400000000800000FE EF0001010004020001000304000000008000025F5FFD "
"EF00010100040200010005040000000080000260015F55FE ddeeff",
"EF00010100040200010001FF00000000800000FE EF00010100040200010003FF000000008000025F5FFD "
"EF00010100040200010005FF0000000080000260015F55FE ddeeff",
4, 3, {21}, {20, 22, 24}},
{"EF00 01 01000C 020003000300030015 030003001400160018 040003 00 008000000080000000800004 "
{"EF00 01 01000C 020003000300030015 030003001400160018 FF0003 00 008000000080000000800004 "
"E50001 E50002 5F5F5F5FEC00505F5F5F5FEC01505F5F5F5FEC0200 "
"EF000101000402000100010400000000800000FE "
"EF0001010004020001000304000000008000025F5FFD "
"EF00010100040200010005040000000080000260015F55FE ddeeff",
"EF00010100040200010001FF00000000800000FE "
"EF00010100040200010003FF000000008000025F5FFD "
"EF00010100040200010005FF0000000080000260015F55FE ddeeff",
12, 3, {3, 3, 21}, {20, 22, 24}},
{"EF00 01 010004 020001" + hex(big_endian(eofcreate_256_size)) + "030100" +
hex(256 * bytecode("0014")) + "040000 00 00800004" + eofcreate_256 +
hex(256 * bytecode("EF000101000402000100010400000000800000FE")),
hex(256 * bytecode("0014")) + "FF0000 00 00800004" + eofcreate_256 +
hex(256 * bytecode("EF00010100040200010001FF00000000800000FE")),
4, 0, {eofcreate_256_size}, std::vector<uint16_t>(256, 20)},
};

Expand Down
Loading