You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use uint256(1) and uint256(2) for true/false to avoid a Gwarmaccess (100 gas) for the extra SLOAD, and to avoid Gsset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past
13. Use a solidity version of at least 0.8.13 to get the ability to use using for with a list of free functions
14. using private rather than public for constants, saves gas
If needed, the values can be read from the verified contract source code, or if there are multiple values there can be a single getter function that returns a tuple of the values of all currently-public constants. Saves 3406-3606 gas in deployment gas due to the compiler not having to create non-payable getter functions for deployment calldata, not having to store the bytes of the value outside of where it’s used, and not adding another entry to the method ID table
1. using
calldata
instead ofmemory
for read-only arguments in external functions saves gasMIMOFlashloan.sol#L51
MIMOManagedAction.sol#L116
MIMOAutoAction.sol#L93
MIMOManagedRebalance.sol#L143
MIMOManagedRebalance.sol#L180
MIMOAutoRebalance.sol#L166
MIMOAutoRebalance.sol#L167
MIMOAutoRebalance.sol#L205
MIMOAutoRebalance.sol#L206
MIMOAutoRebalance.sol#L237
MIMOAutoRebalance.sol#L263
2.
abi.encode()
is less efficient thanabi.encodepacked()
MIMOEmptyVault.sol#L49
MIMOLeverage.sol#L54
MIMORebalance.sol#L49
MIMOManagedRebalance.sol#L65
MIMOAutoRebalance.sol#L73
3. not using the named return variables when a function returns, wastes deployment gas
4. using
bools
for storage incurs overheadhttps://github.com/OpenZeppelin/openzeppelin-contracts/blob/58f635312aa21f947cae5f8578638a85aa2519f5/contracts/security/ReentrancyGuard.sol#L23-L27
Use uint256(1) and uint256(2) for true/false to avoid a Gwarmaccess (100 gas) for the extra SLOAD, and to avoid Gsset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past
MIMOAutoAction.sol#L17
MIMOAutoAction.sol#L55
MIMOProxy.sol#L24
MIMOProxy.sol#L78
MIMOProxy.sol#L108
MIMOProxy.sol#L133
MIMOProxyFactory.sol#L24
5. state variables only set in the constructor should be declared immutable
avoids a gsset (20000 gas)
6. state variables should be cached in stack variables rather than re-reading them from storage
owner
7. can make the variable outside the loop to save gas
8.
<array>.length
should not be looked up in every loop of a for-loop9.
++i
costs less gas thani++
, especially when it’s used in for-loops (--i/i-- too)Saves 6 gas per loop
10. it costs more gas to initialize non-constant/non-immutable variables to zero than to let the default of zero be applied
11.
++i/i++
should beunchecked{++i}/unchecked{i++}
when it is not possible for them to overflow, as is the case when used in for-loop and while-loops12. Use a solidity version of at least 0.8.10 to have
external
calls skip contract existence checks if the external call has a return valueonly in files
13. Use a solidity version of at least 0.8.13 to get the ability to use
using for
with a list of free functions14. using private rather than public for constants, saves gas
If needed, the values can be read from the verified contract source code, or if there are multiple values there can be a single getter function that returns a tuple of the values of all currently-public constants. Saves 3406-3606 gas in deployment gas due to the compiler not having to create non-payable getter functions for deployment calldata, not having to store the bytes of the value outside of where it’s used, and not adding another entry to the method ID table
The text was updated successfully, but these errors were encountered: