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

Open
code423n4 opened this issue Apr 27, 2022 · 1 comment
Open

Gas Optimizations #89

code423n4 opened this issue Apr 27, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

  1. Reorder Struct for saving more gas

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L52

This implementation below can saving more gas instead

##Recommendation Mitigation

    struct Weight {
        uint32 currentCycle;
        uint112 storedWeight;
        uint112 currentWeight;
    }
  1. change uint256 i = 0 into uint i for saving more gas

using this implementation can saving more gas for each loops.

##Tool Used
Manual Review

##Recommended Mitigation
Change it

##Occurances

src/token/ERC20MultiVotes.sol#L346
src/token/ERC20Gauges.sol#L134
src/token/ERC20Gauges.sol#L184
src/token/ERC20Gauges.sol#L307
src/token/ERC20Gauges.sol#L384
src/token/ERC20Gauges.sol#L564

  1. Saving gas by removing = 0

https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L354

If a variable was not set/initialized, it is assumed to have default value to 0
this implementation was used for saving more gas by removing = 0

##TOOLS USED
Manual Review

##Mitigation Step
Remove = 0

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Apr 27, 2022
code423n4 added a commit that referenced this issue Apr 27, 2022
@thomas-waite
Copy link
Collaborator

thomas-waite commented Jul 14, 2022

Much prefer explicitly sized variables over uint even if it does cost a bit more gas. How does that struct difference save gas?

@thomas-waite thomas-waite added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Jul 14, 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 G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

2 participants