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 26, 2023
1 parent daf1fcc commit 8c54d59
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 135 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
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
Loading

0 comments on commit 8c54d59

Please sign in to comment.