Skip to content

Commit

Permalink
Move CALLF immediate argument validation to validate_instructions() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 authored Jun 18, 2023
1 parent 367c51c commit 1f8823e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ EOFValidationError validate_instructions(
if (i >= code.size())
return EOFValidationError::truncated_instruction;
}
else if (op == OP_CALLF)
{
const auto fid = read_uint16_be(&code[i + 1]);
if (fid >= header.types.size())
return EOFValidationError::invalid_code_section_index;
i += 2;
}
else if (op == OP_DATALOADN)
{
const auto index = read_uint16_be(&code[i + 1]);
Expand Down Expand Up @@ -328,9 +335,6 @@ std::variant<EOFValidationError, int32_t> validate_max_stack_height(
{
const auto fid = read_uint16_be(&code[i + 1]);

if (fid >= code_types.size())
return EOFValidationError::invalid_code_section_index;

stack_height_required = static_cast<int8_t>(code_types[fid].inputs);
stack_height_change =
static_cast<int8_t>(code_types[fid].outputs - stack_height_required);
Expand Down
9 changes: 9 additions & 0 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@ TEST(eof_valication, max_stack_heigh)
}
}

TEST(eof_validation, EOF1_callf_truncated)
{
EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 B0"),
EOFValidationError::truncated_instruction);

EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00 00000000 B000"),
EOFValidationError::truncated_instruction);
}

TEST(eof_validation, callf_invalid_code_section_index)
{
EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 b0000100"),
Expand Down

0 comments on commit 1f8823e

Please sign in to comment.