[G-01] Unnecessary variable initialization of default value
When variable is not initialized, it will have its default values.
Example: 0 for uint, false for bool and address(0) for address
By removing this default values you will save about 5 gas.
I suggest removing default value initialization for following variables.
MyStrategy.sol
118: for(uint i = 0; i < length; i++){
300: for (uint256 i = 0; i < _claims.length; i++) {
317: for (uint256 i = 0; i < _claims.length; i++) {
For example these can change to:
for (uint256 i; i < _claims.length; i++) {
[G-02] Save Gas in For-Loops by storing array's length as a variable
3 gas per iteration can be saved by storing an array's length as a variable before
the for-loop.
Issue found at:
MyStrategy.sol
300: for (uint256 i = 0; i < _claims.length; i++) {
317: for (uint256 i = 0; i < _claims.length; i++) {
For example, I suggest changing it to:
length = _claims.length
for (uint i; i < length; i++) {
[G-03] ++i costs less gas than i++
It is better to use ++i than i++ when possible since it costs less gas.
It saves about 5 gas per iteration.
Issue found at:
MyStrategy.sol
118: for(uint i = 0; i < length; i++){
300: for (uint256 i = 0; i < _claims.length; i++) {
317: for (uint256 i = 0; i < _claims.length; i++) {
[G-04] Not Defining Variables to Reduce Gas
Certain variables is defined even though they are used only once.
Remove these unnecessary variables to save gas.
It saves about 10 gas for each variable (Total 100gas).
For cases where it will reduce the readability, one can use comments to help describe
what the code is doing.
Issues found at MyStrategy.sol
Remove toSend variable of sweepRewardToken function
[G-05] Reduce the long revert strings of error messages
By keeping the revert strings within 32 bytes will save you gas since each slot is 32 bytes
and cost about 20k gas.
Following are revert strings that are more than 32 bytes.
MyStrategy.sol
184: require(
185: balanceOfPool() == 0 && LOCKER.balanceOf(address(this)) == 0,
186: "You have to wait for unlock or have to manually rebalance out of it"
[G-06] Use require instead of &&
When there are multiple conditions in require statement, break down the require statement into
multiple require statements instead of using && can save gas. (saves about 50 gas)
Issue found at
184: require(
185: balanceOfPool() == 0 && LOCKER.balanceOf(address(this)) == 0,
186: "You have to wait for unlock or have to manually rebalance out of it"
187: );
For example these can be changed to
require(balanceOfPool() == 0);
require(LOCKER.balanceOf(address(this)) == 0, "You have to wait for unlock or have to manually rebalance out of it");
[G-01] Unnecessary variable initialization of default value
When variable is not initialized, it will have its default values. Example: 0 for uint, false for bool and address(0) for address By removing this default values you will save about 5 gas.
I suggest removing default value initialization for following variables.
For example these can change to:
[G-02] Save Gas in For-Loops by storing array's length as a variable
3 gas per iteration can be saved by storing an array's length as a variable before the for-loop.
Issue found at:
For example, I suggest changing it to:
[G-03] ++i costs less gas than i++
It is better to use ++i than i++ when possible since it costs less gas. It saves about 5 gas per iteration.
Issue found at:
[G-04] Not Defining Variables to Reduce Gas
Certain variables is defined even though they are used only once. Remove these unnecessary variables to save gas. It saves about 10 gas for each variable (Total 100gas). For cases where it will reduce the readability, one can use comments to help describe what the code is doing.
Issues found at MyStrategy.sol
For mitigation, simply don't define variable that is used only once. Below is mitigation example of above 1.
[G-05] Reduce the long revert strings of error messages
By keeping the revert strings within 32 bytes will save you gas since each slot is 32 bytes and cost about 20k gas.
Following are revert strings that are more than 32 bytes.
[G-06] Use require instead of &&
When there are multiple conditions in require statement, break down the require statement into multiple require statements instead of using && can save gas. (saves about 50 gas)
Issue found at
For example these can be changed to