-
Notifications
You must be signed in to change notification settings - Fork 0
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
Gas Optimizations #36
Comments
Tested this out and it was the same when optimizations were used. Not valid. |
This would break functionality. Invalid. |
This would break functionality. Invalid. |
Leaving as is, internal functions are cleaner, probably is valid though |
These are variables. Invalid. |
#1 Using mutiple require instead of using operator
&&
for saving gasinstead of using operator && on single require check. using mutiple require check can save more gas.
POC it can be seen from this report here :
code-423n4/2022-01-timeswap-findings#89
Tool Used
remix
Mitigation Step
occurence :
change to
#2. Using nonces[owner_] can saving more gas
https://github.com/maple-labs/erc20/blob/main/contracts/ERC20.sol#L92
it can be simplified using
nonces[owner_]
instead of usingnonces[owner_]++
and saving more gas for deploy but it would be decreasing the nonce.##Tool Used
Manual Review / Remix
##Mitigation Step
Remove ++
#3. using > instead of >=
instead of using
>=
it can be use>
so this implementation can saving more gas.##Recommended Mitigation Step
change >= into >
##Occurance
#4.unused
_transfer
&_approve
in internal function and change into external for saving more gashttps://github.com/maple-labs/erc20/blob/main/contracts/ERC20.sol
in solmate ERC20 internal function was used for only mint and burning logic, but in ERC20.sol was used approve and transfer. but it can be the same solmate ERC20 implementation for saving more gas
##POC
https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol
Tool Used
Manual Review / Remix.
Recommended Mitigation Step
E.x :
Remove _transfer from internal function and use this instead
#5. State variables can be set as immutable
in the following file xMPL.sol, variable that could be set immutable to save gas
##Tool used
Manual Review
Mitigation Step
add Immutable
The text was updated successfully, but these errors were encountered: