Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA Report #91

Open
code423n4 opened this issue Jun 3, 2022 · 1 comment
Open

QA Report #91

code423n4 opened this issue Jun 3, 2022 · 1 comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

> 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.

@code423n4 code423n4 added bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Jun 3, 2022
code423n4 added a commit that referenced this issue Jun 3, 2022
@chase-manning chase-manning added sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) labels Jun 6, 2022
@GalloDaSballo
Copy link
Collaborator

Agree but it's a gas report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants