Skip to content

Commit

Permalink
Make RJUMPV's static part of immediate checked via instr::traits
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jun 6, 2023
1 parent 48044f8 commit 6c08a08
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ EOFValidationError validate_instructions(

if (i + instr::traits[op].immediate_size >= code.size())
return EOFValidationError::truncated_instruction;

if (op == OP_RJUMPV)
{
if (i + 1 >= code.size())
return EOFValidationError::truncated_instruction;

const auto count = code[i + 1];
if (count < 1)
return EOFValidationError::invalid_rjumpv_count;
Expand Down Expand Up @@ -276,7 +274,7 @@ bool validate_rjump_destinations(bytes_view code) noexcept
else if (op == OP_RJUMPV)
{
const auto count = code[i + 1];
imm_size += size_t{1} /* count */ + count * REL_OFFSET_SIZE /* tbl */;
imm_size += count * REL_OFFSET_SIZE /* tbl */;
const size_t post_pos = i + 1 + imm_size;

for (size_t k = 0; k < count * REL_OFFSET_SIZE; k += REL_OFFSET_SIZE)
Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/instructions_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_RJUMP] = {"RJUMP", 2, false, 0, 0, EVMC_CANCUN};
table[OP_RJUMPI] = {"RJUMPI", 2, false, 1, -1, EVMC_CANCUN};
table[OP_RJUMPV] = {
"RJUMPV", 0 /* WARNING: immediate_size is dynamic */, false, 1, -1, EVMC_CANCUN};
"RJUMPV", 1 /* 1 byte static immediate + dynamic immediate */, false, 1, -1, EVMC_CANCUN};

table[OP_PUSH0] = {"PUSH0", 0, false, 0, 1, EVMC_SHANGHAI};

Expand Down
2 changes: 2 additions & 0 deletions test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ constexpr void validate_traits_of() noexcept
static_assert(tr.immediate_size == Op - OP_PUSH1 + 1);
else if constexpr (Op == OP_RJUMP || Op == OP_RJUMPI || Op == OP_CALLF)
static_assert(tr.immediate_size == 2);
else if constexpr (Op == OP_RJUMPV)
static_assert(tr.immediate_size == 1);
else if constexpr (Op == OP_DUPN || Op == OP_SWAPN)
static_assert(tr.immediate_size == 1);
else if constexpr (Op == OP_DATALOADN)
Expand Down

0 comments on commit 6c08a08

Please sign in to comment.