Platform: Code4rena
Start Date: 24/03/2022
Pot Size: $75,000 USDC
Total HM: 15
Participants: 59
Period: 7 days
Judge: gzeon
Id: 103
League: ETH
Rank: 55/59
Findings: 1
Award: $70.70
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Dravee
Also found by: 0v3rf10w, 0xDjango, 0xNazgul, 0xkatana, ACai, CertoraInc, FSchmoede, Funen, Hawkeye, IllIllI, Jujic, Kenshin, PPrieditis, Picodes, SolidityScan, TerrierLover, Tomio, WatchPug, catchup, csanuragjain, defsec, dimitri, hake, hickuphh3, kenta, minhquanym, obront, peritoflores, rayn, rfa, robee, saian, samruna, tchkvsky, teryanarmen, ych18
70.6981 USDC - $70.70
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/Swapper.sol#L14
for (uint8 i; i < _swapData.length; i++) { require( ls.dexWhitelist[_swapData[i].approveTo] == true && ls.dexWhitelist[_swapData[i].callTo] == true, "Contract call not allowed!" ); LibSwap.swap(_lifiData.transactionId, _swapData[i]); }
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/HopFacet.sol#L48-L50
for (uint8 i; i < _tokens.length; i++) { s.hopBridges[_tokens[i]] = _bridgeConfigs[i]; }
Usage of uint8 increases the gas fee. If switching this to uint256 is possible for the product, it can reduce the gas fee.
Just use uint256 instead of uint8.
for (uint256 i; i < _swapData.length; i++) { require( ls.dexWhitelist[_swapData[i].approveTo] == true && ls.dexWhitelist[_swapData[i].callTo] == true, "Contract call not allowed!" ); LibSwap.swap(_lifiData.transactionId, _swapData[i]); }
for (uint256 i; i < _tokens.length; i++) { s.hopBridges[_tokens[i]] = _bridgeConfigs[i]; }
Gas fees of methods and deployments are decreased by using uint256 instead of uint8.
Contract | Methods | Before | After | Change |
---|---|---|---|---|
AnyswapFacet | swapAndStartBridgeTokensViaAnyswap | 238904 | 238872 | -32 |
CBridgeFacet | swapAndStartBridgeTokensViaCBridge | 315598 | 315557 | -41 |
DiamondCutFacet | diamondCut | 252812 | 252800 | -12 |
GenericSwapFacet | swapTokensGeneric | 254149 | 254108 | -41 |
HopFacet | startBridgeTokensViaHop | 215293 | 215289 | -4 |
HopFacet | swapAndStartBridgeTokensViaHop | 357016 | 356975 | -41 |
NXTPFacet | swapAndStartBridgeTokensViaNXTP | 357455 | 357414 | - |
Contract | Before | After | Change |
---|---|---|---|
HopFacet | 1482624 | 1476996 | -5628 |
NXTPFacet | 1754544 | 1750853 | -3691 |
== true
check is not needed at _executeSwaps function in Swapper.solhttps://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/Swapper.sol#L16
require( ls.dexWhitelist[_swapData[i].approveTo] == true && ls.dexWhitelist[_swapData[i].callTo] == true, "Contract call not allowed!" );
When checking boolean value, it does not need to check == true
.
Following code has same meaning.
require( ls.dexWhitelist[_swapData[i].approveTo] && ls.dexWhitelist[_swapData[i].callTo], "Contract call not allowed!" );
Confirmed that the gas fees of deployments and methods decreased.
!= 0
instead of > 0
can reduce the gas fee slightlyhttps://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
Use != 0
instead of > 0
. Example code is as follows:
require(contractSize != 0, _errorMessage);
Confirmed that the gas fees of deployments and methods decreased.
== true
or == false
at DexManagerFacet.sol
== true
is usedhttps://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L20
if (s.dexWhitelist[_dex] == true) { return; }
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L34
if (s.dexWhitelist[_dexs[i]] == true) { continue; }
== false
is usedhttps://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L47
if (s.dexWhitelist[_dex] == false) { return; }
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/DexManagerFacet.sol#L66
if (s.dexWhitelist[_dexs[i]] == false) { continue; }
== true
is usedif (s.dexWhitelist[_dex]) { return; }
if (s.dexWhitelist[_dexs[i]]) { continue; }
== false
is usedif (!s.dexWhitelist[_dex]) { return; }
if (!s.dexWhitelist[_dexs[i]]) { continue; }
Confirmed that the gas fees of deployments and methods slightly decreased.
#0 - H3xept
2022-04-05T07:37:39Z
Fixed in lifinance/lifi-contracts@3c1558ef50a19cfbbdd6d616d18322dae0bef6ba
#1 - H3xept
2022-04-11T11:54:04Z
Duplicate of #196