LI.FI contest - 0xNazgul's results

Bridge & DEX Aggregation.

General Information

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

LI.FI

Findings Distribution

Researcher Performance

Rank: 58/59

Findings: 1

Award: $63.00

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

63.0043 USDC - $63.00

Labels

bug
G (Gas Optimization)
resolved
sponsor acknowledged

External Links

Functions Visibility Can Be Declared External

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.

Catching The Array Length Prior To Loop

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.

Function Ordering via Method ID

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

Re Functions Visibility Can Be Declared External

Fixed in previous commit.

#1 - H3xept

2022-04-06T14:43:26Z

Re Catching The Array Length Prior To Loop:

Fixed in previous commit.

#2 - H3xept

2022-04-06T14:58:04Z

Re Function Ordering via Method ID

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

Re Catching The Array Length Prior To Loop

Duplicate of #44

#4 - H3xept

2022-04-08T15:06:08Z

Re Functions Visibility Can Be Declared External

Duplicate of #197

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter