Fraxlend (Frax Finance) contest - SaharAP's results

Fraxlend: A permissionless lending platform and the final piece of the Frax Finance Defi Trinity.

General Information

Platform: Code4rena

Start Date: 12/08/2022

Pot Size: $50,000 USDC

Total HM: 15

Participants: 120

Period: 5 days

Judge: Justin Goro

Total Solo HM: 6

Id: 153

League: ETH

Frax Finance

Findings Distribution

Researcher Performance

Rank: 71/120

Findings: 2

Award: $67.00

🌟 Selected for report: 0

🚀 Solo Findings: 0

1. Multiplication before division

Solidity integer division might truncate. As a result, performing multiplication before division can sometimes avoid loss of precision.

Proof of Concept

_isSolvent

You can first multiply LTV_PRECISION with the result of (_borrowerAmount * _exchangeRate) and then divide the result by EXCHANGE_PRECISION.

1. Define constant variables as constant

A state variable whose value has been assigned at the time of declaration should be defined as constant to save gas.

Proof of Concept

FraxlendPairCore.sol FraxlendPairDeployer.sol

Define version, DEFAULT_MAX_LTV , GLOBAL_MAX_LTV , and DEFAULT_LIQ_FEE as constant.

2. Not to initialize uint variables to zero

Uint variable's default value is zero. So, you can save gas by just defining uint variables.

Proof of Concept

initialize() getAllPairAddresses() getCustomStatuses() globalPause() setRateContractWhitelist() setFraxlendDeployerWhitelist()

You can just define uint256 i in for loops without initializing it to zero.

3. Use unchecked block if possible

Use unchecked blocks for arithmetic operations that can't underflow/overflow.

Proof of Concept

initialize() setRateContractWhitelist() setFraxlendDeployerWhitelist()

You can put ++i or i++ in for loops in an unchecked block.

4. Use !=0 instead of > 0

!= 0 is a cheaper operation compared to > 0, when dealing with uint. > 0 can be replaced with != 0 for gas optimization.

Proof of Concept

borrowAsset() requireValidInitData()

Replace > 0 with != 0 when comparing unsigned integer variables to save gas.

5. Define variables as immutable

When a variable is just set once during deployment, it can be defined as immutable to save gas.

Proof of Concept

FraxlendPairDeployer.sol

Define CIRCUIT_BREAKER_ADDRESS, COMPTROLLER_ADDRESS, and TIME_LOCK_ADDRESS as immutable.

6. Use custom errors instead of require() statements with revert strings.

Using custom errors can save gas instead of using string errors.

Proof of Concept

requireValidInitData()

Use custom errors instead of require() statements with revert strings.

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