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

Open
code423n4 opened this issue Feb 23, 2022 · 0 comments
Open

Gas Optimizations #85

code423n4 opened this issue Feb 23, 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

GAS OPTIMIZATION FINDINGS

  • Consider changing constant declarations to immutable declaration for GAS savings for repetitive function calls;
    AMM.sol:16
    AMM.sol:17
    ClearingHouse.sol:15
    InsuranceFund.sol:16
    InsuranceFund.sol:17
    MarginAccount.sol:31
    MarginAccount.sol:34
    MarginAccountHelper.sol:13

  • Consider caching the array.length outside the loop function for GAS savings
    ClearingHouse.sol:122
    ClearingHouse.sol:130
    ClearingHouse.sol:170
    ClearingHouse.sol:194
    ClearingHouse.sol:251
    ClearingHouse.sol:263
    ClearingHouse.sol:277
    MarginAccount.sol:331
    MarginAccount.sol:373
    MarginAccount.sol:552
    BatchLiquidator.sol:25
    BatchLiquidator.sol:31
    BatchLiquidator.sol:37
    Disperse.sol:9
    Disperse.sol:18
    Disperse.sol:21
    Disperse.sol:27
    Disperse.sol:32
    Executor.sol:19

  • Use unchecked {++i} instead of i++ for GAS savings inside loops
    ClearingHouse.sol:122
    ClearingHouse.sol:130
    ClearingHouse.sol:170
    ClearingHouse.sol:194
    ClearingHouse.sol:251
    ClearingHouse.sol:263
    ClearingHouse.sol:277
    MarginAccount.sol:331
    MarginAccount.sol:373
    MarginAccount.sol:552
    BatchLiquidator.sol:25
    BatchLiquidator.sol:31
    BatchLiquidator.sol:37
    Disperse.sol:9
    Disperse.sol:18
    Disperse.sol:21
    Disperse.sol:27
    Disperse.sol:32
    Executor.sol:19

  • Do not use strings more than 32 bytes for GAS savings. Consider refactoring below;
    Interfaces.sol:26
    Interfaces.sol:65
    Interfaces.sol:75
    Interfaces.sol:85

  • Remove reduntant “1 hours” at AMM.sol:726

Consider removing “1 hours” and re-writing the statement as;
if (_state == AMMState.Active) {
nextFundingTime = ((_blockTimestamp() + fundingPeriod) )
}

  • ClearingHouse.sol:214

Consider removing reduntant var “toInsurance” and restate the code as;

marginAccount.transferOutVusd(_msgSender(), (liquidationFee/2);

  • ClearingHouse.sol:290

Consider declaring and assigning unRealizedPnL same time at line 291 inside parenthesis.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Feb 23, 2022
code423n4 added a commit that referenced this issue Feb 23, 2022
@atvanguard atvanguard added the duplicate This issue or pull request already exists label Feb 26, 2022
@CloudEllie CloudEllie reopened this Mar 30, 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

3 participants