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 #76

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

Gas Optimizations #76

code423n4 opened this issue Jun 1, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Gas Report

[G-01] Unnecessary use of SafeMath

Underflows/overflows cannot happen in solidity >=0.8.0, therefore SafeMath is redundant.

[G-02] for loop gas optimisation

BaseRewardPool.sol#L199-L201

       for (uint256 i = 0; i < extraRewards.length; i++) {
            IRewards(extraRewards[i]).stake(_for, _amount);
        }

Gas could be saved by:

  • Not initialising variable to default value of zero
  • Caching array length
  • Using a prefix (++i) instead of a postfix (i++)
  • Unchecking increment count

Example:

uint length = extraRewards.length;
for (uint256 i; i < length;) {
    IRewards(extraRewards[i]).stake(_for, _amount);
		unchecked { ++i; }
}

[G-03] Unnecessary boolean declaration

Booster.sol#L352

require(pool.shutdown == false, "pool is closed");

pool.shutdown == false can be changed to !pool.shutdown.

[G-04] Zero address check location could be more gas efficient

Booster.sol#L352-L360

        require(pool.shutdown == false, "pool is closed");

        //send to proxy to stake
        address lptoken = pool.lptoken;
        IERC20(lptoken).safeTransferFrom(msg.sender, staker, _amount);

        //stake
        address gauge = pool.gauge;
        require(gauge != address(0), "!gauge setting");

require(gauge != address(0), "!gauge setting"); could be set prior to //send to proxy to stake to save the gas used in safeTransferFrom in case gauge == address(0).

[G-05] Parameters could be immutable

VeTokenMinter.sol#L18

Parameters such as totalCliffs, reductionCliff, veToken and maxTime could be made immutable to save gas.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 1, 2022
code423n4 added a commit that referenced this issue Jun 1, 2022
@GalloDaSballo
Copy link
Collaborator

4 * 2100 = 8400 from immutable

Rest is negligible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants