Skip to content
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

fix(levm): prevent unsafe arithmetic #1095

Merged
merged 155 commits into from
Nov 14, 2024
Merged

Conversation

maximopalopoli
Copy link
Contributor

@maximopalopoli maximopalopoli commented Nov 6, 2024

Motivation

The idea is to prevent arithmetic overflows and underflows in the levm code.

Description

Design desitions:

  • For the gas increment I used checked_add and added a ConsumedGasOverflow error.
  • For depth used checked_add and the StackOverflow error
  • In the VM::execute method I decided to do not raise an error, because the previous behavior was to do not raise errors, so used the saturating functions
  • For opcode operations used InvalidOpcode error

Closes #1075

maximopalopoli and others added 7 commits November 11, 2024 12:59
**Motivation**

<!-- Why does this pull request exist? What are its goals? -->
- The objective is to run ef tests without panicking, so that they don't
interrupt execution.

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->
Some reasons tests panicked:
- Trying to resize memory to a very high number that the system doesn't
tolerate
- This was fixed by just resizing only if the gas limit allows it. The
EVM doesn't have a "max" memory size, this max is limited by the gas
avaiable. Opcodes that didn't have gas implemented were a problem so I
partially implemented gas costs for them, just for their memory
expansion cost.
- Trying to add with overflow 
- For this error normal addition was replaced for `checked_add` and
returned an error if it overflowed.

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #issue_number

---------

Co-authored-by: ilitteri <[email protected]>
Base automatically changed from levm_fixes to main November 12, 2024 21:37
@ilitteri ilitteri added this pull request to the merge queue Nov 14, 2024
Merged via the queue into main with commit 108163a Nov 14, 2024
18 checks passed
@ilitteri ilitteri deleted the levm/fix/prevent-unsafe-arithmetic branch November 14, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LEVM: make operations safe
5 participants