Gas Optimizations #86
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Catching The Array Length Prior To Loop.
Description
One can save gas by caching the array length (in stack) and using that set variable in the loop. They are as follows:
In AccountAccessController.sol There is:
allowAccounts() and blockAccounts().
Recommendation
Simply do something like so before the for loop:
uint length = _accounts.length
. Then addlength
in place of_accounts.length
in the for loop.Pragma Directive Ordering
Description
Pragma directive can not go after import directives. This can be found in the following contracts:
CollateralDepositRecord.sol
DepositHook.sol
WithdrawHook.sol
Recommendation
Move the pragma directive prior to import directives.
Unused Function Parameter
Description
There is an unused function parameter in the following contracts functions:
In DepositHook.sol
The function hook()
unused parameter uint256 _initialAmount
remove the _amount variable passed through collataral.sol
informational/maybe gas since it cuts byte code?
In WithdrawHook.sol
The function hook
Both have an unused parameter of
uint256 _initialAmount
.Recommendation
In both
hook()
functionsuint256 _initialAmount
can be removed to save some gas.Along with the removal of the
_amount
variable being passed to them through Collateral.sol in the functions deposit() and withdraw().Function Ordering via Method ID
Description
As noted in the "Gas Optimization Notes" there is a list of each contracts most called functions since this is known one could simply save gas by function ordering via Method ID
Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool to help find alternative function names with lower Method IDs while keeping the original name intact.
Recommendation
Find a lower method ID name for the most called functions for example
mostCalled()
vs.mostCalled_41q()
is cheaper by 44 gas.The text was updated successfully, but these errors were encountered: