Skip to content

Commit 1f8823e

Browse files
authored
Move CALLF immediate argument validation to validate_instructions() (#662)
1 parent 367c51c commit 1f8823e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/evmone/eof.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ EOFValidationError validate_instructions(
224224
if (i >= code.size())
225225
return EOFValidationError::truncated_instruction;
226226
}
227+
else if (op == OP_CALLF)
228+
{
229+
const auto fid = read_uint16_be(&code[i + 1]);
230+
if (fid >= header.types.size())
231+
return EOFValidationError::invalid_code_section_index;
232+
i += 2;
233+
}
227234
else if (op == OP_DATALOADN)
228235
{
229236
const auto index = read_uint16_be(&code[i + 1]);
@@ -328,9 +335,6 @@ std::variant<EOFValidationError, int32_t> validate_max_stack_height(
328335
{
329336
const auto fid = read_uint16_be(&code[i + 1]);
330337

331-
if (fid >= code_types.size())
332-
return EOFValidationError::invalid_code_section_index;
333-
334338
stack_height_required = static_cast<int8_t>(code_types[fid].inputs);
335339
stack_height_change =
336340
static_cast<int8_t>(code_types[fid].outputs - stack_height_required);

test/unittests/eof_validation_test.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,15 @@ TEST(eof_valication, max_stack_heigh)
725725
}
726726
}
727727

728+
TEST(eof_validation, EOF1_callf_truncated)
729+
{
730+
EXPECT_EQ(validate_eof("EF0001 010004 0200010001 030000 00 00000000 B0"),
731+
EOFValidationError::truncated_instruction);
732+
733+
EXPECT_EQ(validate_eof("EF0001 010004 0200010002 030000 00 00000000 B000"),
734+
EOFValidationError::truncated_instruction);
735+
}
736+
728737
TEST(eof_validation, callf_invalid_code_section_index)
729738
{
730739
EXPECT_EQ(validate_eof("EF0001 010004 0200010004 030000 00 00000000 b0000100"),

0 commit comments

Comments
 (0)