Backed Protocol contest - saian's results

Protocol for peer to peer NFT-Backed Loans.

General Information

Platform: Code4rena

Start Date: 05/04/2022

Pot Size: $30,000 USDC

Total HM: 10

Participants: 47

Period: 3 days

Judge: gzeon

Total Solo HM: 4

Id: 106

League: ETH

Backed Protocol

Findings Distribution

Researcher Performance

Rank: 25/47

Findings: 1

Award: $127.38

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

127.3764 USDC - $127.38

Labels

bug
G (Gas Optimization)
sponsor acknowledged

External Links

Gas Optimizations

1. constant variable can be immutable

expressions assigned to constant variables are replaced where its used and executed when referenced, the variable can be changed to immutable so that it is executed once

Proof of concept

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L24

/// See {INFTLoanFacilitator-SCALAR}. uint256 public immutable override SCALAR = 10 ** INTEREST_RATE_DECIMALS;
Mitigation

the constant variable can be changed to immutable

2. revert string can be 32 bytes

Revert string takes a minimum of 32 bytes, increasing the string size increases gas during deployment and when the revert condition is met

Proof of concept

Some examples in code

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L84

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L86

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L118

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L122

Mitigation

Reduce the size of the strings or use custom errors

3. Reduce storage reads and save gas

Variables that are read multiple times in a code block can be cached and re-used instead of reading from storage to save gas

Proof of concept

requiredImprovementRate in

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L174-L178

lendTicketContract in

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L198-L222

Mitigation

storage value can be stored in a temporary variable and re-used

4. constant expression can be replaced by value

Impact

In updateOriginationFeeRate expression with integer constants and constant variable can be replaced by the result to save gas, and the expression can be added to the comments

Proof of concept

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L307

// require(_originationFeeRate <= 5 * (10 ** (INTEREST_RATE_DECIMALS - 2)), "NFTLoanFacilitator: max fee 5%");

Mitigation

the expression can be replaced by the final value

5. > can be replaced by != to save gas

!= save gas compared to > with uint in require statements, uint can be less than zero > can be replaced with !=

Proof of concept

https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L321

require(_improvementRate != 0, 'NFTLoanFacilitator: 0 improvement rate');

Mitigation

> can be replaced by != in the require statement

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