20,000 USDC
View results
Submission Details
Severity: gas
Valid

Structs can be optimised

Summary

Existing struct layout is wanting for better optimization.

Vulnerability Details

The variable ordering and size in existing structs can be optimized. As an example, consider the Loan struct. Inside it, the fields interestRate, startTimestamp, auctionStartTimestamo and auctionLength can be stored in smaller uints. All four of these can be stored in uint64 instead of uint256. Reason being, the interest rate is a small value, and all time-stamp related fields will never realistically need more than type(uint64).max which is 18446744073709551615 seconds.

Impact

Gas

Tools Used

Manual Review

Recommendation

Optimize struct variables. After our aforementioned optimizations, the Loan struct would look like this:

struct Loan {
/// @notice address of the lender
address lender;
/// @notice address of the borrower
address borrower;
/// @notice address of the loan token
address loanToken;
/// @notice address of the collateral token
address collateralToken;
/// @notice the amount borrowed
uint256 debt;
/// @notice the amount of collateral locked in the loan
uint256 collateral;
/// @notice the interest rate of the loan per second (in debt tokens)
uint64 interestRate;
/// @notice the timestamp of the loan start
uint64 startTimestamp;
/// @notice the timestamp of a refinance auction start
uint64 auctionStartTimestamp;
/// @notice the refinance auction length
uint64 auctionLength;
}

We saved 2 storage slots with this simple optimization.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.