Gas Optimizations #141
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
!=0
cost less gas compared to>0
mitigation: use
!=
instead of>
details/POC:
>0
can be replaced with!=0
because all unsigned integers that are not equal to zero are all positive values which means it is always greater than zero.reference: [https://github.com/code-423n4/2021-12-maple-findings/issues/75]
affected codes:
/contracts/AuraBalRewardPool.sol#L121
/contracts/AuraBalRewardPool.sol#L139
/contracts/AuraBalRewardPool.sol#L157
/contracts/AuraBalRewardPool.sol#L210
/contracts/AuraClaimZap.sol#L196
/contracts/AuraClaimZap.sol#L200
/contracts/AuraClaimZap.sol#L218
/contracts/AuraClaimZap.sol#L221
/contracts/AuraLocker.sol#L210
/contracts/AuraLocker.sol#L259
/contracts/AuraLocker.sol#L309
/contracts/AuraLocker.sol#L359
/contracts/AuraLocker.sol#L385
/contracts/AuraLocker.sol#L400
/contracts/AuraLocker.sol#L443
/contracts/AuraLocker.sol#L471
/contracts/AuraLocker.sol#L496
/contracts/AuraLocker.sol#L520
/contracts/AuraLocker.sol#L664
/contracts/AuraLocker.sol#L726
/contracts/AuraLocker.sol#L822
/contracts/AuraLocker.sol#L851
/contracts/AuraMerkleDrop.sol#L122
/contracts/AuraPenaltyForwarder.sol#L52
/contracts/AuraStakingProxy.sol#L177
/contracts/AuraStakingProxy.sol#L185
/contracts/AuraStakingProxy.sol#L207
/contracts/AuraVestedEscrow.sol#L118
/contracts/BalLiquidityProvider.sol#L57
/contracts/BalLiquidityProvider.sol#L70
/contracts/ExtraRewardsDistributor.sol#L149
/contracts/ExtraRewardsDistributor.sol#L171
/contracts/Aura.sol#L68
--i
cost less gas compared toi--
mitigation: Use
--i
instead ofi--
to decrement the value of uint variableaffected codes:
/contracts/AuraLocker.sol#L497
/contracts/AuraLocker.sol#L726
/contracts/AuraLocker.sol#L664
++i
cost less gas compared toi++
mitigation: Use
++i
instead ofi++
to increment the value of uint variablereference: code-423n4/2021-12-nftx-findings#195
affected codes:
/contracts/AuraVestedEscrow.sol#L100
/contracts/BalLiquidityProvider.sol#L51
/contracts/ExtraRewardsDistributor.sol#L233
/contracts/AuraLocker.sol#L174
/contracts/AuraLocker.sol#L306
/contracts/AuraLocker.sol#L410
/contracts/AuraLocker.sol#L696
/contracts/AuraLocker.sol#L773
No need to name the returns
details: Using both named returns and a return statement isn't necessary
mitigation: change
returns (uint256 amount)
toreturns (uint256)
affected code:
/contracts/AuraLocker.sol#L648
same issue:
/contracts/AuraLocker.sol#L712
No need to explicitly initialize variables with their default values
details: When variables are not set, it is assumed to have it's default value(0 for uint, false for bool, address(0) for address...).
mitigation: change
uint public pendingPenalty = 0
touint public pendingPenalty
affected code:
/contracts/AuraBalRewardPool.sol#L35
same issue:
/contracts/AuraBalRewardPool.sol#L38
/contracts/AuraBalRewardPool.sol#L39
/contracts/AuraLocker.sol#L72
/contracts/AuraLocker.sol#L114
/contracts/AuraLocker.sol#L174
/contracts/AuraLocker.sol#L485
/contracts/AuraLocker.sol#L630
/contracts/AuraLocker.sol#L773
/contracts/AuraMerkleDrop.sol#29
/contracts/AuraVestedEscrow.sol#L33
/contracts/AuraVestedEscrow.sol#L99
/contracts/AuraVestedEscrow.sol#L100
/contracts/ExtraRewardsDistributor.sol#L231
.length in a loop can be extracted into a variable and used where necessary to reduce the number of storage reads
solution:
uint locksLength = locks.length;
for (uint256 i = nextUnlockIndex; i < locksLength; i++) { if (locks[i].unlockTime > block.timestamp) { if (idx == 0) { lockData = new LockedBalance[](locksLength - i);
affected code:
/contracts/AuraLocker.sol#L696-699
reference: code-423n4/2021-10-union-findings#92
The text was updated successfully, but these errors were encountered: