Gas Optimizations #45
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Gas Report
G-01: use unchecked when incrementing for loop variable
Since the loop's iterator can't realistically overflow because of the loop's condition, you can increment it in an unchecked block to save gas:
Just search for "for (" in your
.sol
files to find all the relevant instancesG-02: increment using ++i instead of i++ consistently
Using
++i
saves gas because you don't have to cache the original value in memory. You already use it in some places but not consistently.G-03: use solmate's ERC20 contract
solmate's contracts are optimized for gas usage. They are more efficient than OZ's contracts. Consider switching to them. It will save gas for all the ERC20 transfers, burns, etc.
https://github.com/transmissions11/solmate
G-04: remove unnecessary require statement in XC20Wrapper.sol
In
XC20Wrapper.unwrap()
the function checks whether the caller has enough tokens to burn before calling theburn()
function. But, the burn function will simply revert if the user doesn't have enough. Explicitly checking for that is a waste of gas.https://github.com/code-423n4/2022-07-axelar/blob/main/xc20/contracts/XC20Wrapper.sol#L85
The text was updated successfully, but these errors were encountered: