huff-language / huffmate

A library of modern, hyper-optimized, and extensible Huff contracts with extensive testing and documentation built by Huff maintainers.
https://github.com/pentagonxyz/huffmate
MIT License
437 stars 55 forks source link

Opti: remove double iszero before jumpi #117

Open obatirou opened 1 year ago

obatirou commented 1 year ago

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: