Platform: Code4rena
Start Date: 27/05/2022
Pot Size: $75,000 USDC
Total HM: 20
Participants: 58
Period: 7 days
Judge: GalloDaSballo
Total Solo HM: 15
Id: 131
League: ETH
Rank: 37/58
Findings: 2
Award: $171.81
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x29A, 0xNazgul, 0xf15ers, BowTiedWardens, Chom, Funen, Kaiziron, Kumpa, MiloTruck, Picodes, Ruhum, SecureZeroX, Sm4rty, SmartSek, StyxRave, WatchPug, Waze, asutorufos, bardamu, berndartmueller, c3phas, catchup, cccz, codexploder, cryptphi, defsec, delfin454000, dipp, fatherOfBlocks, gzeon, hake, hansfriese, hyh, masterchief, oyc_109, sach1r0, sashik_eth, shenwilly, simon135, unforgiven
113.8755 USDC - $113.88
!= 0
costs less gas compared to > 0
for unsigned integers in require
statements with the optimizer enabled (6 gas)
Proof: While it may seem that > 0
is cheaper than !=
,
this is only true without the optimizer enabled and outside a require
statement. If you enable the optimizer at 10k AND you’re in a require
statement, this will save gas. You can see this tweet for more proofs: https://twitter.com/gzeon/status/1485428085885640706
I suggest changing > 0
with != 0
here:
contracts/BkdLocker.sol:91: require(amount > 0, Error.INVALID_AMOUNT); contracts/BkdLocker.sol:92: require(totalLockedBoosted > 0, Error.NOT_ENOUGH_FUNDS); contracts/BkdLocker.sol:137: require(length > 0, "No entries"); contracts/pool/LiquidityPool.sol:469: require(underlyingAmount > 0, Error.INVALID_AMOUNT); contracts/pool/LiquidityPool.sol:471: require(lpToken_.balanceOf(account) > 0, Error.INSUFFICIENT_BALANCE); contracts/pool/LiquidityPool.sol:514: require(mintedLp >= minTokenAmount && mintedLp > 0, Error.INVALID_AMOUNT); contracts/pool/LiquidityPool.sol:538: require(redeemLpTokens > 0, Error.INVALID_AMOUNT); contracts/testing/MockVotingEscrow.sol:35: require(_balances[msg.sender] > 0, "a lock needs to first be created"); contracts/testing/MockErc20Strategy.sol:64: require(currentBalance > 0, "Invalid amount to withdraw"); contracts/testing/MockErc20Strategy.sol:74: require(amount > 0, "Invalid amount to transfer"); contracts/testing/MockEthStrategy.sol:65: require(currentBalance > 0, "Invalid amount to withdraw"); contracts/tokenomics/VestedEscrow.sol:84: require(unallocatedSupply > 0, "No reward tokens in contract"); contracts/tokenomics/KeeperGauge.sol:140: require(totalClaimable > 0, Error.ZERO_TRANSFER_NOT_ALLOWED); contracts/tokenomics/AmmGauge.sol:104: require(amount > 0, Error.INVALID_AMOUNT); contracts/tokenomics/AmmGauge.sol:125: require(amount > 0, Error.INVALID_AMOUNT); contracts/tokenomics/AmmConvexGauge.sol:158: require(amount > 0, Error.INVALID_AMOUNT); contracts/tokenomics/AmmConvexGauge.sol:171: require(amount > 0, Error.INVALID_AMOUNT); contracts/vault/Vault.sol:163: require(amount > 0, Error.INVALID_AMOUNT); contracts/actions/topup/TopUpActionFeeHandler.sol:123: require(totalClaimable > 0, Error.NOTHING_TO_CLAIM); contracts/actions/topup/TopUpAction.sol:214: require(record.singleTopUpAmount > 0, Error.INVALID_AMOUNT); contracts/actions/topup/TopUpAction.sol:535: require(position.totalTopUpAmount > 0, Error.INSUFFICIENT_BALANCE);
Also, please enable the Optimizer.
#0 - GalloDaSballo
2022-06-20T00:35:59Z
Agree but it's a gas report
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, Chom, Dravee, Fitraldys, Funen, Kaiziron, MiloTruck, Picodes, Randyyy, RoiEvenHaim, SecureZeroX, Sm4rty, SmartSek, StyxRave, Tadashi, Tomio, Waze, asutorufos, berndartmueller, c3phas, catchup, csanuragjain, defsec, delfin454000, djxploit, fatherOfBlocks, gzeon, hake, hansfriese, oyc_109, robee, sach1r0, sashik_eth, scaraven, simon135
57.93 USDC - $57.93
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Here, I suggest storing the array’s length in a variable before the for-loop, and use it instead:
contracts/RewardHandler.sol:42: for (uint256 i; i < pools.length; i = i.uncheckedInc()) { contracts/access/RoleManager.sol:82: for (uint256 i; i < roles.length; i = i.uncheckedInc()) { contracts/testing/MockFeeBurner.sol:27: for (uint256 i; i < tokens.length; i++) { contracts/zaps/PoolMigrationZap.sol:22: for (uint256 i; i < newPools_.length; ++i) { contracts/zaps/PoolMigrationZap.sol:39: for (uint256 i; i < oldPoolAddresses_.length; ) { contracts/tokenomics/VestedEscrow.sol:94: for (uint256 i; i < amounts.length; i = i.uncheckedInc()) { contracts/tokenomics/FeeBurner.sol:56: for (uint256 i; i < tokens_.length; i = i.uncheckedInc()) { contracts/tokenomics/InflationManager.sol:116: for (uint256 i; i < stakerVaults.length; i = i.uncheckedInc()) { contracts/StakerVault.sol:259: for (uint256 i; i < actions.length; i = i.uncheckedInc()) { contracts/actions/topup/TopUpKeeperHelper.sol:45: for (uint256 i; i < users.length; i = i.uncheckedInc()) { contracts/actions/topup/TopUpKeeperHelper.sol:48: for (uint256 j; j < positions.length; j = j.uncheckedInc()) { contracts/actions/topup/TopUpKeeperHelper.sol:74: for (uint256 i; i < keys.length; i = i.uncheckedInc()) { contracts/actions/topup/TopUpAction.sol:191: for (uint256 i; i < protocols.length; i = i.uncheckedInc()) {
Cache teh array's length in for-loops
#0 - GalloDaSballo
2022-06-17T22:42:17Z
13 * 3 gas = 39