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

Open
code423n4 opened this issue Mar 30, 2022 · 3 comments
Open

Gas Optimizations #201

code423n4 opened this issue Mar 30, 2022 · 3 comments
Assignees
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix)

Comments

@code423n4
Copy link
Contributor

GAS OPTIMIZATION for LIFI by PeritoFlores

Avoid using the tautology ==true and change ==false for !

Some part of the code you are using == true and ==false. You can remove ==true and change ==false for ! to save gas

Swapper.sol#LOC16

            ls.dexWhitelist[_swapData[i].approveTo] == true && ls.dexWhitelist[_swapData[i].callTo] == true,

DDexManagerFacet.sol#LOC20

    if (s.dexWhitelist[_dex] == true) {

DexManagerFacer.sol#LOC34

        if (s.dexWhitelist[_dexs[i]] == true) {

DexManagerFacer.sol#LOC47

if (s.dexWhitelist[_dex] == false) {

DexManagerFacer.sol#LOC66

if (s.dexWhitelist[_dexs[i]] == false) {

Using uint8 instead of uint256 cost more gas and can even cause an overflow.

You are using uint8 for some loops

for (uint8 i; i < _swapData.length; i++) {               Swaper.sol#L14


​ for (uint8 i; i < _tokens.length; i++) { HopFacets.sol#L48

First of all, in case that you send an array of more than 256 the transaction will revert with an overflow . Suppose that this case is unlikely.

EVM works with 256 bits word so every operation is on a uint256, unless you are packing variables using a shorter variable cost more gas.
So I believe that using uint8 have no benefits.

Sugestion

change uint8 for uint.
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Mar 30, 2022
code423n4 added a commit that referenced this issue Mar 30, 2022
@H3xept H3xept self-assigned this Apr 1, 2022
@H3xept
Copy link
Collaborator

H3xept commented Apr 1, 2022

Re: Avoid using the tautology ==true and change ==false for !

Fixed by lifinance/lifi-contracts@4651609d65add358a2b9edf8f393f18735163139

@ezynda3 ezynda3 closed this as completed Apr 1, 2022
@H3xept
Copy link
Collaborator

H3xept commented Apr 8, 2022

Re Redundant literal boolean comparisons

Duplicate of #39

@H3xept
Copy link
Collaborator

H3xept commented Apr 11, 2022

Re uintx to uint256

Duplicate of #196

@H3xept H3xept added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Apr 11, 2022
@H3xept H3xept reopened this Apr 11, 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) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix)
Projects
None yet
Development

No branches or pull requests

2 participants