Backd Tokenomics contest - Sm4rty's results

Maximize the power of your assets and start earning yield

General Information

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

Backd

Findings Distribution

Researcher Performance

Rank: 37/58

Findings: 2

Award: $171.81

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

113.8755 USDC - $113.88

Labels

bug
QA (Quality Assurance)
resolved
sponsor confirmed

External Links

> 0 is less efficient than != 0 for unsigned integers (with proof)

!= 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:

Instances:

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

Awards

57.93 USDC - $57.93

Labels

bug
G (Gas Optimization)
sponsor disputed

External Links

An array’s length should be cached to save gas in for-loops

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:

Instances:

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()) {

Recomendation:

Cache teh array's length in for-loops

#0 - GalloDaSballo

2022-06-17T22:42:17Z

13 * 3 gas = 39

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter