-
Notifications
You must be signed in to change notification settings - Fork 164
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
CairoVM runner is not checking Relocatable
offset i16
overflow during runtime
#1848
Comments
A few comments:
Emphasis mine. As you may see, offsets are not mandated to be Further, from the original VM source code we can extract the explicit bound on segment size, which indirectly becomes the bound for the offset inside a given segment: |
Sorry my bad copied link from wrong tab your is the one i intended to paste |
Ok i see you are right here let me try to reproduce the issue locally, will write soon. |
My guess is that Casm generated by the runner assumes that offset is always small and uses wrong addressing mode. |
It seems like this bug is caused by overflows in the runner. This issue can be closed. |
Fair enough. |
Bug Description
When running programs with array inputs, the Cairo VM loads the input into a newly allocated memory segment. However, if the input exceeds
i16::MAX
, an issue occurs where the runner uses an offset of typeusize
, allowing it to pass thechecked_add
checks. The problem arises because the Cairo VM’s registers are of typei16
, which cannot hold values beyondi16::MAX
. This results in overflow issues when the input exceeds thei16
limit.Expected Behavior
The VM should handle inputs in a way that ensures memory addresses and offsets are properly checked against the
i16
register limits, preventing overflows.Proposed Solution
Relocatable
type fromusize
toi16
, ensuring that all memory addresses conform to thei16
register limits.i16
overflow to ensure the VM handles out-of-bound memory addresses gracefully without breaking the program.Reference code can be found here.
The
i16
registers design is detailed in section 2.4 of the Cairo Paper.Additional Context
This overflow issue results from the disparity between the
usize
offset type in the runner and thei16
registers in the VM. Ensuring consistency or adding appropriate checks would prevent this problem.Let me know your thoughts on this approach.
Cheers!
The text was updated successfully, but these errors were encountered: