sujithsomraaj / lifi-stargate-v2-audit

3 Day Review [10 Jun 2024 - 13 Jun 2024]
0 stars 0 forks source link

Inlining internal functions in `StargateFacetV2` will save significant gas #5

Open sujithsomraaj opened 5 months ago

sujithsomraaj commented 5 months ago

Context: StargateFacetV2.sol#L144, StargateFacetV2.sol#L157

Description: The two internal functions _validateDestinationCallFlag and _getRouterAddress are used only in one instance and could hence be inlined.

By inlining the functions, the overall contract bytecode will be reduced, and the execution gas costs will decrease by more than 80 GAS units.

[PASS] testBase_CanSwapAndBridgeNativeTokensxsad() (gas: 447569) --> no inline

[PASS] testBase_CanSwapAndBridgeNativeTokensxsad() (gas: 447501) --> after inlining

Recommendation: Consider moving the two functions inside the _startBridge function to save additional gas costs.

LI.FI:

Researcher:

0xDEnYO commented 5 months ago

Yes, makes complete sense. In an earlier version there were several usages but I optimized that and forgot to inline the function. Good spotting !!!

I will include your suggestions to harvest the whopping 0.015% gas savings (your definition of "significant" gas savings is a bit funny 😆)