Gas Optimizations #20
Labels
bug
Something isn't working
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
Use uint256 instead of uint8 at for loop at Swapper.sol and HopFacet.sol
Target codebase
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/Swapper.sol#L14
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/HopFacet.sol#L48-L50
Usage of uint8 increases the gas fee. If switching this to uint256 is possible for the product, it can reduce the gas fee.
Proposed implementations
Just use uint256 instead of uint8.
Gas improvements
Gas fees of methods and deployments are decreased by using uint256 instead of uint8.
Methods - average gas change
Deployments - average gas change
== true
check is not needed at _executeSwaps function in Swapper.solTarget codebase
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/Swapper.sol#L16
When checking boolean value, it does not need to check
== true
.Proposed implementations
Following code has same meaning.
Gas improvements
Confirmed that the gas fees of deployments and methods decreased.
Usage of
!= 0
instead of> 0
can reduce the gas fee slightlyTarget codebase
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/HopFacet.sol#L109
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/AnyswapFacet.sol#L92
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/AnyswapFacet.sol#L105
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/CBridgeFacet.sol#L105
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/CBridgeFacet.sol#L116
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/NXTPFacet.sol#L98
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibAsset.sol#L67
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibDiamond.sol#L84
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibDiamond.sol#L102
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibDiamond.sol#L121
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibDiamond.sol#L189
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibDiamond.sol#L196
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibDiamond.sol#L212
Proposed implementations
Use
!= 0
instead of> 0
. Example code is as follows:Gas improvements
Confirmed that the gas fees of deployments and methods decreased.
Avoid using
== true
or== false
atDexManagerFacet.sol
Target codebase
Where
== true
is usedhttps://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L20
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L34
Where
== false
is usedhttps://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L47
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L66
Proposed implementations
Where
== true
is usedWhere
== false
is usedGas improvements
Confirmed that the gas fees of deployments and methods slightly decreased.
The text was updated successfully, but these errors were encountered: