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

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

Gas Optimizations #131

code423n4 opened this issue Jun 3, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) 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

[G-01] Unnecessary check for positive value

Description

A uint256 value can not be negative, hence there is no need to check for it.

Findings

tokenomics/InflationManager.sol#L589

totalLpPoolWeight = totalLpPoolWeight > 0 ? totalLpPoolWeight : 0;

tokenomics/InflationManager.sol#L602

totalAmmTokenWeight = totalAmmTokenWeight > 0 ? totalAmmTokenWeight : 0;

tokenomics/InflationManager.sol#L575

totalKeeperPoolWeight = totalKeeperPoolWeight > 0 ? totalKeeperPoolWeight : 0;

Recommended mitigation steps

Remove the check and use the value directly to save gas.

[G-02] Unnecessary poolCheckpoint function call

The AmmGauge and KeeperGauge contracts call the function poolCheckpoint() within the kill() function. Therefore, functions which call this kill() function do not have to additionally call the poolCheckpoint() function.

Description

A uint256 value can not be negative, hence there is no need to check for it.

Findings

tokenomics/InflationManager.sol#L427
tokenomics/InflationManager.sol#L461

Recommended mitigation steps

Remove the call to poolCheckpoint() to save gas.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) 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

[G-01] Unnecessary check for positive value

I agree, because these are Storage value set to the same value, the gas saved is 100 per instance
300

[G-02] Unnecessary poolCheckpoint function call

I agree, but would have liked to see a POC with detailed gas savings, in lack of it will give it 200 gas (low estimate)

Total Gas Saved

500

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