code-423n4 / 2022-05-backd-findings

0 stars 0 forks source link

QA Report #91

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

> 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.INVALIDAMOUNT); 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.

GalloDaSballo commented 2 years ago

Agree but it's a gas report