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 Jun 1, 2023
1 parent 6e2a589 commit 15eeced
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 146 deletions.
18 changes: 15 additions & 3 deletions lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "baseline_instruction_table.hpp"
#include "instructions_traits.hpp"

#include <intx/intx.hpp>
#include <algorithm>
#include <array>
#include <cassert>
Expand All @@ -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;
Expand All @@ -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<EOFValidationError>(
static_cast<uint8_t>(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<EOFSectionHeaders, EOFValidationError> validate_eof_headers(bytes_view container)
Expand Down
16 changes: 8 additions & 8 deletions test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(256, 1)},
};
Expand Down
Loading

0 comments on commit 15eeced

Please sign in to comment.