++i costs less gas compared to i++. about 5 gas per iteration.
BkdLocker.sol
310,45: for (uint256 i = 0; i < length; i++) {
Controller.sol
117,45: for (uint256 i = 0; i < numActions; i++) {
StakerVault.sol
260,49: for (uint256 i = 0; i < actions.length; i++) {
RoleManager.sol
80,47: for (uint256 i = 0; i < roles.length; i++) {
TopUpAction.sol
188,51: for (uint256 i = 0; i < protocols.length; i++) {
456,41: for (uint256 i = 0; i < length; i++) {
479,41: for (uint256 i = 0; i < length; i++) {
506,42: for (uint256 i = 0; i < howMany; i++) {
891,41: for (uint256 i = 0; i < length; i++) {
TopUpKeeperHelper.sol
43,51: for (uint256 i = 0; i < users.length; i++) {
72,46: for (uint256 i = 0; i < keys.length; i++) {
93,41: for (uint256 i = 0; i < length; i++) {
165,41: for (uint256 i = 0; i < length; i++) {
CompoundHandler.sol
135,48: for (uint256 i = 0; i < assets.length; i++) {
CTokenRegistry.sol
61,49: for (uint256 i = 0; i < ctokens.length; i++) {
ConvexStrategyBase.sol
313,57: for (uint256 i = 0; i < _rewardTokens.length(); i++) {
380,57: for (uint256 i = 0; i < _rewardTokens.length(); i++) {
MockStableSwap.sol
30,36: for (uint256 i = 0; i < 3; i++) {
42,36: for (uint256 i = 0; i < 2; i++) {
70,36: for (uint256 i = 0; i < 3; i++) {
InflationManager.sol
91,41: for (uint256 i = 0; i < length; i++) {
105,41: for (uint256 i = 0; i < length; i++) {
109,54: for (uint256 i = 0; i < stakerVaults.length; i++) {
114,41: for (uint256 i = 0; i < length; i++) {
166,41: for (uint256 i = 0; i < length; i++) {
191,41: for (uint256 i = 0; i < length; i++) {
259,41: for (uint256 i = 0; i < length; i++) {
283,41: for (uint256 i = 0; i < length; i++) {
357,41: for (uint256 i = 0; i < length; i++) {
381,41: for (uint256 i = 0; i < length; i++) {
404,41: for (uint256 i = 0; i < length; i++) {
445,41: for (uint256 i = 0; i < length; i++) {
KeeperGauge.sol
155,52: for (uint256 i = startEpoch; i < endEpoch; i++) {
VestedEscrow.sol
93,49: for (uint256 i = 0; i < amounts.length; i++) {
EnumerableExtensions.sol
21,38: for (uint256 i = 0; i < len; i++) {
34,38: for (uint256 i = 0; i < len; i++) {
92,38: for (uint256 i = 0; i < len; i++) {
105,38: for (uint256 i = 0; i < len; i++) {
118,38: for (uint256 i = 0; i < len; i++) {
131,38: for (uint256 i = 0; i < len; i++) {
!= 0 use less gas than > 0 for unsigned ints in require():
Gas Optimizations
++i
use less gas thani++
:++i
costs less gas compared toi++
. about 5 gas per iteration.!= 0
use less gas than> 0
for unsigned ints inrequire()
:Assign
0
touint256
:Default value of
uint256
is0
. you can delete= 0
for saving some gas.Use Custom Errors to save Gas:
Custom errors from Solidity 0.8.4 are cheaper than
require
messages. https://blog.soliditylang.org/2021/04/21/custom-errors/