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: 58/59
Findings: 1
Award: $63.00
🌟 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
63.0043 USDC - $63.00
Context: AnyswapFacet.sol#L35-L66, AnyswapFacet.sol#L74-L123, CBridgeFacet.sol#L57-L84, CBridgeFacet.sol#L92-L134, GenericSwapFacet.sol#L22-L43, HopFacet.sol#L61-L87, HopFacet.sol#L95-L126, NXTPFacet.sol#L46-L76, NXTPFacet.sol#L85-L115, WithdrawFacet.sol#L20-L38
Description: Several functions across multiple contracts have a public visibility and can be marked with external visibility to save gas.
Recommendation: Change the functions visibility to external to save gas.
Context: DexManagerFacet.sol#L30-L40, DexManagerFacet.sol#L44-L58, DexManagerFacet.sol#L62-L77, Swapper.sol#L12-L23, LibDiamond.sol#L62-L81, LibDiamond.sol#L83-L99, LibDiamond.sol#L101-L118, LibDiamond.sol#L120-L130
Description: One can save gas by caching the array length (in stack) and using that set variable in the loop.
Recommendation:
Simply do something like so before the for loop: uint length = variable.length
. Then add length
in place of variable.length
in the for loop.
Description: Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool to help find alternative function names with lower Method IDs while keeping the original name intact.
Recommendation:
Find a lower method ID name for the most called functions for example mostCalled()
vs. mostCalled_41q()
is cheaper by 44 gas.
#0 - H3xept
2022-04-06T14:42:29Z
Fixed in previous commit.
#1 - H3xept
2022-04-06T14:43:26Z
Fixed in previous commit.
#2 - H3xept
2022-04-06T14:58:04Z
We internally decided to avoid this as the gas savings do not justify the resulting less-readable code
#3 - H3xept
2022-04-08T14:38:33Z
Duplicate of #44
#4 - H3xept
2022-04-08T15:06:08Z
Duplicate of #197