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

Gas Optimizations #270

Open
code423n4 opened this issue May 25, 2022 · 0 comments
Open

Gas Optimizations #270

code423n4 opened this issue May 25, 2022 · 0 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Issue: Require message is too long
Explanation: The require messages below can be shortened to 32 characters or fewer (as shown) to save gas

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L197

        require(_rewardsToken != address(stakingToken), "Cannot add StakingToken as reward");

Change message to Can't add StakingToken as reward

Issue: Should use != 0 instead of > 0 in a require statement if variable is an unsigned integer (uint)
Explanation: != 0 should be used where possible since > 0 costs more gas

require(_amount > 0 occurs in all 7 lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/Aura.sol#L68

        require(_amount > 0, "Must mint something");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L121

        require(_amount > 0, "RewardPool : Cannot stake 0");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L139

        require(_amount > 0, "RewardPool : Cannot stake 0");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L259

        require(_amount > 0, "Cannot stake 0");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraMerkleDrop.sol#L122

        require(_amount > 0, "!amount");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/CrvDepositor.sol#L169

        require(_amount > 0,"!>0");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/BaseRewardPool.sol#L211

        require(_amount > 0, 'RewardPool : Cannot stake 0');

Change _amount > 0 to _amount != 0 in each case

require(amount > 0 occurs in both lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L157

        require(amount > 0, "RewardPool : Cannot withdraw 0");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/BaseRewardPool.sol#L227

        require(amount > 0, 'RewardPool : Cannot withdraw 0');

Change amount > 0 to amount != 0 in both cases

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L210

        require(rewardsAvailable > 0, "!balance");

Change rewardsAvailable > 0 to rewardsAvailable != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L359

        require(amt > 0, "Nothing locked");

Change amt > 0 to amt != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L385

        require(length > 0, "no locks");

Change length > 0 to length != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L431

        require(locked > 0, "no exp locks");

Change locked > 0 to locked != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L471

        require(len > 0, "Nothing to delegate");

Change len > 0 to len != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraPenaltyForwarder.sol#L52

        require(bal > 0, "!empty");

Change bal > 0 to bal != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/BalLiquidityProvider.sol#L70

        require(balAfter > 0, "!mint");

Change balAfter > 0 to balAfter != 0

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/PoolManagerSecondaryProxy.sol#L104

        require(weight > 0, "must have weight");

Change weight > 0 to weight != 0

Issue: Use of '&&' within a require function
Explanation: Dividing the require into separate requires instead of using '&&' will save gas

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraStakingProxy.sol#L90

        require(_outputBps > 9000 && _outputBps < 10000, "Invalid output bps");

Recommendation:

        require(_outputBps > 9000, "Invalid output bps");
        require( _outputBps < 10000, "Invalid output bps");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraStakingProxy.sol#L159

        require(_token != crv && _token != cvx && _token != cvxCrv, "not allowed");

Recommendation:

        require(_token != crv, "not allowed");
        require( _token != cvx, "not allowed");
        require( _token != cvxCrv, "not allowed");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraStakingProxy.sol#L203

        require(address(_token) != crv && address(_token) != cvxCrv, "not allowed");

Recommendation:

        require(address(_token) != crv, "not allowed");
        require(address(_token) != cvxCrv, "not allowed");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/BalLiquidityProvider.sol#L48

        require(_request.assets.length == 2 && _request.maxAmountsIn.length == 2, "!valid");

Recommendation:

        require(_request.assets.length == 2, "!valid");
        require(_request.maxAmountsIn.length == 2, "!valid");

There are two opportunities to save gas in the require below:

  1. Use != 0 instead of > 0
  2. Divide the require into two separate requires instead of using '&&'

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/BalLiquidityProvider.sol#L57

            require(bal > 0 && bal == _request.maxAmountsIn[i], "!bal");

Recommendation:

            require(bal != 0, "!bal");
            require(bal == _request.maxAmountsIn[i], "!bal");

There are similar opportunities to save gas in the require below:

  1. Use != 0 instead of > 0
  2. Divide the require into two separate requires instead of using '&&'

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/ExtraRewardsDistributor.sol#L171

        require(_index > 0 && _index < rewardEpochs[_token].length - 1, "!past");

Recommendation:

        require(_index != 0, "!past");
        require( _index < rewardEpochs[_token].length - 1, "!past");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L220

        require(lockRewards != address(0) && rewardFactory != address(0), "!initialised");

Recommendation:

        require(lockRewards != address(0), "!initialised");
        require(rewardFactory != address(0), "!initialised");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L222

        require(_feeToken != address(0) && _feeDistro != address(0), "!addresses");

Recommendation:

        require(_feeToken != address(0), "!addresses");
        require( _feeDistro != address(0), "!addresses");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L278

        require(_lockFees >= 300 && _lockFees <= 1500, "!lockFees");

Recommendation:

        require(_lockFees >= 300, "!lockFees");
        require( _lockFees <= 1500, "!lockFees");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L279

        require(_stakerFees >= 300 && _stakerFees <= 1500, "!stakerFees");

Recommendation:

        require(_stakerFees >= 300, "!stakerFees");
        require( _stakerFees <= 1500, "!stakerFees");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L280

        require(_callerFees >= 10 && _callerFees <= 100, "!callerFees");

Recommendation:

        require(_callerFees >= 10, "!callerFees");
        require( _callerFees <= 100, "!callerFees");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L313

        require(msg.sender==poolManager && !isShutdown, "!add");

Recommendation:

        require(msg.sender==poolManager, "!add");
        require(!isShutdown, "!add");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L314

        require(_gauge != address(0) && _lptoken != address(0),"!param");

Recommendation:

        require(_gauge != address(0),"!param");
        require( _lptoken != address(0),"!param");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/PoolManagerSecondaryProxy.sol#L111

        require(!usedMap[_lptoken] && !usedMap[_gauge], "cant force used pool");

Recommendation:

        require(!usedMap[_lptoken], "cant force used pool");
        require(!usedMap[_gauge], "cant force used pool");

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/StashFactoryV2.sol#L83

        require(!isV1 && !isV2 && !isV3,"stash version mismatch");

Recommendation:

        require(!isV1,"stash version mismatch");
        require(!isV2,"stash version mismatch");
        require(!isV3,"stash version mismatch");

Issue: Variables should not be initialized to their default values
Explanation: For example, initializing uint variables to their default value of 0 is unnecessary and costs gas

public pendingPenalty is initialized to zero in both lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L35

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraMerkleDrop.sol#L29

    uint256 public pendingPenalty = 0;

Change to uint256 public pendingPenalty;

public periodFinish is initialized to zero in all three lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L38

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraMerkleDrop.sol#L29

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VirtualBalanceRewardPool.sol#L89

    uint256 public periodFinish = 0;

Change to uint256 public periodFinish;

public rewardRate is initialized to zero in all three lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L39

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VirtualBalanceRewardPool.sol#L90

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VirtualBalanceRewardPool.sol#L90

    uint256 public rewardRate = 0;

Change to uint256 public rewardRate;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L72

    uint256 public queuedCvxCrvRewards = 0;

Change to uint256 public queuedCvxCrvRewards;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L540

                    uint256 unlocksSinceLatestCkpt = 0;

Change to uint256 unlocksSinceLatestCkpt;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L114

    bool public isShutdown = false;

Change to bool public isShutdown;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L381

        uint256 reward = 0;

Change to uint256 reward;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L485

        uint256 futureUnlocksSum = 0;

Change to uint256 futureUnlocksSum;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L630

        uint256 low = 0;

Change to uint256 low;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraVestedEscrow.sol#L33

    bool public initialised = false;

Change to bool public initialised;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraVestedEscrow.sol#L99

        uint256 totalAmount = 0;

Change to uint256 totalAmount;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/ExtraRewardsDistributor.sol#L231

        uint256 claimableTokens = 0;

Change to uint256 claimableTokens;

public queuedRewards is initialized to zero in both lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/BaseRewardPool.sol#L75

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VirtualBalanceRewardPool.sol#L93

    uint256 public queuedRewards = 0;

Change to uint256 public queuedRewards;

public currentRewards is initialized to zero in both lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/BaseRewardPool.sol#L76

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VirtualBalanceRewardPool.sol#L94

    uint256 public currentRewards = 0;

Change to uint256 public currentRewards;

public historicalRewards is initialized to zero in both lines below:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/BaseRewardPool.sol#L77

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VirtualBalanceRewardPool.sol#L95

    uint256 public historicalRewards = 0;

Change to uint256 public historicalRewards;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L29

    uint256 public platformFee = 0; //possible fee to build treasury

Change to uint256 public platformFee; //possible fee to build treasury

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/ConvexMasterChef.sol#L63

    uint256 public totalAllocPoint = 0;

Change to uint256 public totalAllocPoint;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/CrvDepositor.sol#L36

    uint256 public incentiveCrv = 0;

Change to uint256 public incentiveCrv;

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/VoterProxy.sol#L308

        uint256 _balance = 0;

Change to uint256 _balance;

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 25, 2022
code423n4 added a commit that referenced this issue May 25, 2022
@0xMaharishi 0xMaharishi added the duplicate This issue or pull request already exists label May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants