vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.84k stars 788 forks source link

Assembly Optimization's Condition Could Be Restricted #4110

Open ritzdorf opened 4 months ago

ritzdorf commented 4 months ago

Version Information

_stack_peephole_opts() try to perform several optimizations as long as i < len(assembly) - 2, however, the last two optimizations could, in theory, be performed even if i == len(assembly) - 1 given that they only access assembly[i] and assembly[i+1].

if (
    isinstance(assembly[i], str)
    and assembly[i].startswith("SWAP")
    and assembly[i] == assembly[i + 1]
):
    changed = True
    del assembly[i : i + 2]
if assembly[i] == "SWAP1" and assembly[i + 1].lower() in COMMUTATIVE_OPS:
    changed = True
    del assembly[i]