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

Open
code423n4 opened this issue May 2, 2022 · 0 comments
Open

Gas Optimizations #97

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

Comments

@code423n4
Copy link
Contributor

Title: && is less efficient

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/supervaults/contracts/SuperVault.sol#L344

Recommended Mitigation Steps:
Change to:

	require(proxy != address(0), "SV201"); 
	require(router != address(0), "SV201"); 

========================================================================

Title: Caching .length for loop can save gas

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/dex/DexAddressProvider.sol#L16

Recommended Mitigation Steps:
Change to:

    uint256 Length = dexes.length;
    for (uint256 i; i < Length; i++) {

========================================================================

Title: Using unchecked and prefix increment

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/dex/DexAddressProvider.sol#L16

Recommended Mitigation Steps:
Change to:

	for (uint256 i; i < dexes.length;) {
       	  _dexMapping[i] = Dex({ proxy: dexes[i].proxy, router: dexes[i].router });
	  unchecked{
          ++i; //@audit-info: Place here with unchecked
        }
    }
  }

========================================================================

Title: Using != is more gas efficient

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L122
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L145
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L288

Recommended Mitigation Steps:

    require(_amount != 0, "IV100");

========================================================================

Title: Using < is cheaper than <=

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L138
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L219
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L285

Recommended Mitigation Steps:
just use < can save gas

========================================================================

Title: unnecessary value set. the default value of uint is 0.

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/inception/InceptionVaultsCore.sol#L218

Recommended Mitigation Steps:
remove 0 value can save gas

========================================================================

Title: Unused variable

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/oracles/GUniLPOracle.sol#L16

Recommended Mitigation Steps:
Remove it can save gas

========================================================================

Title: unnecessary value set.The default value of bool is false

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/libraries/ABDKMath64x64.sol#L222

Recommended Mitigation Steps:
remove false

========================================================================

Title: Using storage to declare Struct variable inside function

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L81
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L92

Recommended Mitigation Steps:
instead of caching UserInfo to memory. read it directly from storage.

    UserInfo storage _userInfo = _users[_user];

========================================================================

Title: Using calldata to store struct data type can save gas

Proof of Concept:
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L69
https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L231

Recommended Mitigation Steps:
Change memory to calldata

========================================================================

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 2, 2022
code423n4 added a commit that referenced this issue May 2, 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)
Projects
None yet
Development

No branches or pull requests

1 participant