Gas Optimizations #115
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
valid
Caching the length in for loops
This reduce gas cost as show here https://forum.openzeppelin.com/t/a-collection-of-gas-optimisation-tricks/19966/5
https://github.com/Badger-Finance/vested-aura/blob/d504684e4f9b56660a9e6c6dfb839dcebac3c174/contracts/MyStrategy.sol#L288-L343
Can be optimized to
Should use solidity ^0.8.4 instead of 0.6 with SafeMathUpgradeable
It provide more readable, more security and better gas utilization if you use solidity 0.8.
_amount.mul(9_980).div(MAX_BPS)
can be replaced with_amount * 9_980 / MAX_BPS
in solidity 0.8 while providing better gas cost, underflow and overflow guard.This reduce gas cost as show here https://forum.openzeppelin.com/t/a-collection-of-gas-optimisation-tricks/19966/5
Safemath by default from 0.8.0 (can be more gas efficient than some library-based safemath.)
Consider using custom errors instead of revert strings (Upgrade to solidity ^0.8.4 first)
This reduce gas cost as show here https://forum.openzeppelin.com/t/a-collection-of-gas-optimisation-tricks/19966/5
Solidity 0.8.4 introduced custom errors. They are more gas efficient than revert strings, when it comes to deployment cost as well as runtime cost when the revert condition is met. Use custom errors instead of revert strings for gas savings.
Any require statement in your code can be replaced with custom error for example,
Can be replaced with
The text was updated successfully, but these errors were encountered: