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

Open
code423n4 opened this issue Feb 7, 2022 · 2 comments
Open

Gas Optimizations #84

code423n4 opened this issue Feb 7, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Gas optimisation

  • ConvexStakingWrapper
    1. In the addRewards function, you should store IRewardStaking(convexBooster).poolInfo(_pid) into a locally scoped variable so it is cheaper to retrieve mainPool (line 94) and lptoken (line 98).
    2. In the addRewards function, you should use extraToken on line 131 instead of calling IRewardStaking(extraPool).rewardToken() to retrieve it again.
  • MasterChef
    1. This require statement require(_token != address(0), "zero address"); in the add() function is IMO not required because only the owner can call this function.
    2. This require statement require(user.amount > 0, "MasterChef: nothing to withdraw"); in the withdraw() function is not needed because if user.amount is actually 0, the function will still work correctly as intended since the next require statement will ensure that the user cannot withdraw more than his balance.
    3. This if branch if (_amount > 0) in the withdraw() function is also not needed because user.amount is not modified when _amount is 0.
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Feb 7, 2022
code423n4 added a commit that referenced this issue Feb 7, 2022
@GalloDaSballo
Copy link
Collaborator

In the addRewards function, you should store IRewardStaking(convexBooster).poolInfo(_pid) into a locally scoped variable so it is cheaper to retrieve mainPool (line 94) and lptoken (line 98).

Wouldn't actually save gas as both slots are read separately

In the addRewards function, you should use extraToken on line 131 instead of calling IRewardStaking(extraPool).rewardToken() to retrieve it again.

Would save 97 gas

This require statement require(_token != address(0), "zero address"); in the add() function is IMO not required because only the owner can call this function.

Refreshing take but ultimately will give 0 as someone else would argue the opposite and have a point

This require statement require(user.amount > 0, "MasterChef: nothing to withdraw"); in the withdraw() function is not needed because if user.amount is actually 0, the function will still work correctly as intended since the next require statement will ensure that the user cannot withdraw more than his balance.

Same as above, valid argument, no points

This if branch if (_amount > 0) in the withdraw() function is also not needed because user.amount is not modified when _amount is 0.

This saves 3 gas (pays 3 to save 6)
3

@GalloDaSballo
Copy link
Collaborator

100 gas saved

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