-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check stack height for OP_CALLF validation #619
Conversation
rodiazet
commented
Apr 19, 2023
•
edited
Loading
edited
- Add validation rule.
- Add unit tests.
- Fix already existing unit test.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #619 +/- ##
==========================================
+ Coverage 97.55% 97.56% +0.01%
==========================================
Files 88 88
Lines 8287 8338 +51
==========================================
+ Hits 8084 8135 +51
Misses 203 203
Flags with carried forward coverage won't be shown. Click here to find out more.
|
ddd195c
to
a43448e
Compare
2a0e34b
to
c7d1224
Compare
State tests currently seem to have a bug ethereum/tests#1238 (comment) |
Similar validation-time check should be added to JUMPF (but JUMPF is not merged yet: #644) |
c7d1224
to
960de10
Compare
ff73384
to
168c5ba
Compare
if (opcode == OP_CALLF) | ||
{ | ||
const auto fid = read_uint16_be(&code[i + 1]); | ||
|
||
stack_height_required = static_cast<int8_t>(code_types[fid].inputs); | ||
|
||
if (stack_height + code_types[fid].max_stack_height - stack_height_required > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of stack underflow this expression can be negative, I think it's ok, it's signed and won't underflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an unit test covering this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found any tests for stack underflow validation at all. I will add some at least for CALLF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong, it cannot be negative, because callee's max_stack_height >= inputs
168c5ba
to
d890cf6
Compare
Rebased. |
d890cf6
to
34773dc
Compare
cefad46
to
f4749a3
Compare
@@ -341,18 +342,23 @@ std::variant<EOFValidationError, int32_t> validate_max_stack_height( | |||
auto stack_height_required = instr::traits[opcode].stack_height_required; | |||
auto stack_height_change = instr::traits[opcode].stack_height_change; | |||
|
|||
auto stack_height = stack_heights[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto stack_height = stack_heights[i]; | |
const auto stack_height = stack_heights[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's modified in line 365
{ | ||
{ | ||
auto code = eof1_bytecode( | ||
512 * push(1) + OP_CALLF + bytecode{"0x0000"_hex} + 510 * OP_POP + OP_RETURN, 512); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
512 * push(1) + OP_CALLF + bytecode{"0x0000"_hex} + 510 * OP_POP + OP_RETURN, 512); | |
512 * push(1) + OP_CALLF + "0000" + 510 * OP_POP + OP_RETURN, 512); |
bytecode
can consume strings and will interpret them as hex.
f4749a3
to
450d32d
Compare
Co-authored-by: Andrei Maiboroda <[email protected]>
450d32d
to
0547115
Compare