G-4 Loops can be implement more efficient.
Saving gas by caching the length. If the length of the array doesn't change inside the loop.
Example of recommended implementation.
uint length = arr.length;
for (uint i; i < length; i++) {
//Operations not effecting the length of the array.
G-5 Avoid Initialization of Loop Index If It Is 0 to Save Gas
The local variable used as for loop index doesn't need to be initialized to 0 because the default value is 0.
G-1 Variables: No need to initialize variables that have default variables. Variables that are not set or initialize variables will have default variables like
bool
withfalse
andaddress(0)
for address. https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DLocker.sol#:~:text=bool%20public%20isShutdown%20%3D%20false%3BG-2
++1
cost less gas compared toi++
ori+= 1
I suggest using ++i instead of i++ to increment the value of an uint variable.G-3
!= 0
is a cheaper operation compared to> 0
, when dealing with uint. https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#:~:text=.sender)%20%7B-,require(_amount%20%3E%200%2C%20%22RewardPool%20%3A%20Cannot%20stake%200%22)%3B,-//also%20stake%20toG-4 Loops can be implement more efficient. Saving gas by caching the length. If the length of the array doesn't change inside the loop. Example of recommended implementation.
uint length = arr.length;
for (uint i; i < length; i++) {
//Operations not effecting the length of the array.
}
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#:~:text=also%20stake%20to%20linked%20rewards-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20extraRewards.length%3B%20i,%7D,-_totalSupply%20%3D%20_totalSupply.addG-5 Avoid Initialization of Loop Index If It Is 0 to Save Gas The local variable used as for loop index doesn't need to be initialized to 0 because the default value is 0.
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#:~:text=//also%20stake%20to%20linked%20rewards-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20extraRewards.length%3B%20i%2B%2B)%20%7B,-IRewards(extraRewards%5Bi%5D).stake(msg
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#:~:text=//also%20stake%20to%20linked%20rewards-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20extraRewards.length%3B%20i%2B%2B)%20%7B,-IRewards(extraRewards%5Bi%5D).stake(_for
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#:~:text=for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20poolInfo.length%3B%20i%2B%2B)%20%7B