Skip to content

Commit 05c9a23

Browse files
authored
Merge pull request #471 from ethereum/format-magic-merge
EIP-3540: Merge FORMAT and MAGIC
2 parents 28738f4 + ff1e16f commit 05c9a23

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/evmone/eof.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace evmone
1313
{
1414
namespace
1515
{
16-
constexpr uint8_t FORMAT = 0xef;
17-
constexpr uint8_t MAGIC = 0x00;
16+
constexpr uint8_t MAGIC[] = {0xef, 0x00};
1817
constexpr uint8_t TERMINATOR = 0x00;
1918
constexpr uint8_t CODE_SECTION = 0x01;
2019
constexpr uint8_t DATA_SECTION = 0x02;
@@ -35,7 +34,7 @@ std::pair<EOFSectionHeaders, EOFValidationError> validate_eof_headers(bytes_view
3534
uint8_t section_id = 0;
3635
EOFSectionHeaders section_headers{};
3736
const auto container_end = container.end();
38-
auto it = container.begin() + 1 + sizeof(MAGIC) + 1; // FORMAT + MAGIC + VERSION
37+
auto it = container.begin() + std::size(MAGIC) + 1; // MAGIC + VERSION
3938
while (it != container_end && state != State::terminated)
4039
{
4140
switch (state)
@@ -144,20 +143,20 @@ size_t EOF1Header::code_begin() const noexcept
144143
assert(code_size != 0);
145144

146145
if (data_size == 0)
147-
return 7; // EF + MAGIC + VERSION + SECTION_ID + SIZE + TERMINATOR
146+
return 7; // MAGIC + VERSION + SECTION_ID + SIZE + TERMINATOR
148147
else
149-
return 10; // EF + MAGIC + VERSION + SECTION_ID + SIZE + SECTION_ID + SIZE + TERMINATOR
148+
return 10; // MAGIC + VERSION + SECTION_ID + SIZE + SECTION_ID + SIZE + TERMINATOR
150149
}
151150

152151
bool is_eof_code(bytes_view code) noexcept
153152
{
154-
return code.size() > 1 && code[0] == FORMAT && code[1] == MAGIC;
153+
return code.size() > 1 && code[0] == MAGIC[0] && code[1] == MAGIC[1];
155154
}
156155

157156
EOF1Header read_valid_eof1_header(bytes_view::const_iterator code) noexcept
158157
{
159158
EOF1Header header;
160-
const auto code_size_offset = 4; // FORMAT + MAGIC + VERSION + CODE_SECTION_ID
159+
const auto code_size_offset = 4; // MAGIC + VERSION + CODE_SECTION_ID
161160
header.code_size =
162161
static_cast<uint16_t>((code[code_size_offset] << 8) | code[code_size_offset + 1]);
163162
if (code[code_size_offset + 2] == 2) // is data section present
@@ -171,7 +170,7 @@ EOF1Header read_valid_eof1_header(bytes_view::const_iterator code) noexcept
171170

172171
uint8_t get_eof_version(bytes_view container) noexcept
173172
{
174-
return (container.size() >= 3 && container[0] == FORMAT && container[1] == MAGIC) ?
173+
return (container.size() >= 3 && container[0] == MAGIC[0] && container[1] == MAGIC[1]) ?
175174
container[2] :
176175
0;
177176
}

0 commit comments

Comments
 (0)