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

Opti: remove double iszero before jumpi #117

Open
2 of 5 tasks
obatirou opened this issue Mar 24, 2023 · 0 comments
Open
2 of 5 tasks

Opti: remove double iszero before jumpi #117

obatirou opened this issue Mar 24, 2023 · 0 comments

Comments

@obatirou
Copy link
Contributor

obatirou commented Mar 24, 2023

Overview

There are several contracts where there are two iszero in a row before a jumpi to conditionally jump if a value is different from 0. But those are not necessary.
From evm.codes:

b: the program counter will be altered with the new value only if this value is different from 0. Otherwise, the program counter is simply incremented and the next instruction will be executed.

For example, in case of a call (delegate, static, or classic), they return success:

success: return 0 if the sub context reverted, 1 otherwise.

So, if there is a jumpi just after a call, there is no need to do iszero iszero.
Using the success directly from the stack is sufficient.
Removing those double iszero could save 2 instructions each times those macros are called.

Todo

Contracts where there are possible improvements:

  • ERC4626 (see PR)
  • ERC1967Upgrade (see PR)
  • ERC20_TRANSFER (utils)
  • SSTORE2_WRITE (after a create but same principle applies)
  • ERC721 (check if an address is != address(0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant