function order will also have an impact on gas consumption. Because this contract, there is a difference in order of the function
so this implementation below can be using for saving more gas (±12 gas)
Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.
require(ls.dexWhitelist[_swapData[i].approveTo] == true, "Contract call not allowed!");
require(ls.dexWhitelist[_swapData[i].callTo] == true, "Contract call not allowed!");
Using require instead of Assert for saving more gas
Assert-style exceptions consume all gas available to the call. on other hand, using require-style exception will not consume any gas.
it would be saving more gas by using require instead of assert.
https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/LiFiDiamond.sol#L12-L13
function order will also have an impact on gas consumption. Because this contract, there is a difference in order of the function so this implementation below can be using for saving more gas (±12 gas)
Tool Used
Remix
POC
can be changed into :
Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.
Tools Used
Remix
Occurances
instead of using operator && on single require check. using additional require check can save more gas.
Tool Used
Remix
POC
can be changed to :
require
instead ofAssert
for saving more gasAssert-style exceptions consume all gas available to the call. on other hand, using require-style exception will not consume any gas. it would be saving more gas by using require instead of assert.
Tool Used
Remix
POC
https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/WithdrawFacet.sol#L30 https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/WithdrawFacet.sol#L34
change to
https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/AnyswapFacet.sol#L20 This implementation can be used for saving more gas (24 gas)
Tool Used
Remix
POC
change to :
SafeERC20.function
to saving more gashttps://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/WithdrawFacet.sol#L9
this implementation can be used for another gas opt
Tool used
Remix
POC
by not declare :
and change at : https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/WithdrawFacet.sol#L35
its cheaper to using type(uint).max instead of using 2**256-1 calculation for unlimited approval
POC : LibAsset.sol #L15
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibAsset.sol#L15
Every reason string takes at least 32 bytes. Use short reason strings that fits in 32 bytes or it will become more expensive.
Occurance :
calldata
can be usingmemory
for saving more gashttps://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/CBridgeFacet.sol#L57 This implementation can be using for saving more gas.
Tool used
Remix
POC
can be changed to