code-423n4 / 2022-10-traderjoe-findings

2 stars 0 forks source link

Gas Optimizations #130

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas optimization report

[G-01] Usage of uint256 instead of boolean state variable in storage and/or save a slot

You can save one slot by packing variable creationUnlocked with address state variables LBPairImplementation (L32) or feeRecipient (L34).

Or (resp and) you can change boolean state variable into a uint256 (resp uint64) to save gas from Gwarmaccess (100 gas) for the extra SLOAD plus it avoids Gsset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past.

[G-02] Set to payable permissionened functions that are guaranteed to revert for normal users

For example, this change only on function sweep in contract LBRouter.sol saves 2609 gas on deployement cost of the contract LBRouter and on average 22gas in function sweep usage.

I. Case for modifier onlyFactoryOwner

  1. Function sweep in LBRouter.sol and change in interface ILBRouter.sol

  2. Function sweepLBToken in LBRouter.sol and change in interface ILBRouter.sol

II. Case for modifier onlyFactory

  1. Function setFeesParameters in LBRPair.sol and change in interface ILBRouter.sol

  2. Function forceDecay in LBRPair.sol and change in interface ILBRouter.sol

[G-03] Postfixed index in loops are less gas efficient (i++/j++ and i--/j--) compared to prefixed index in loops

Saves 5 gas for each loop using postfixed indexes.

  1. LBQuoter.sol

  2. LBRouter.sol

GalloDaSballo commented 2 years ago

2k from packing, rest I'm ignoring

c4-judge commented 1 year ago

GalloDaSballo marked the issue as grade-b