20,000 USDC
View results
Submission Details
Severity: gas

Remove duplicated code with internal function

Summary

The same chunk on code is repeated 2 times, in function giveLoan and buyLoan.

Vulnerability Details

File: src/Lender.sol
// In function giveLoan, from:
405: emit Repaid(
// To line:
430: );
// In function buyLoan, from:
507: emit Repaid(
// To line:
532: );

Impact

Gas reduction on deploy and easier code understanding with these replacements.

Tools Used

Manual review.

Recommendations

Create the internal function replacing the ranged lines on 'Vulnerability Details'.

// This function replaces the final code at the 2 function mentioned
function _updateLoanInfo(
Loan memory loan,
uint loanId,
Pool memory pool,
uint lenderInterest,
uint protocolInterest,
uint totalDebt
) internal {
emit Repaid(
loan.borrower,
loan.lender,
loanId,
loan.debt + lenderInterest + protocolInterest,
loan.collateral,
loan.interestRate,
loan.startTimestamp
);
// update the loan with the new info
loans[loanId].lender = pool.lender;
loans[loanId].interestRate = pool.interestRate;
loans[loanId].startTimestamp = block.timestamp;
loans[loanId].auctionStartTimestamp = type(uint256).max;
loans[loanId].debt = totalDebt;
emit Borrowed(
loan.borrower,
pool.lender,
loanId,
loans[loanId].debt,
loans[loanId].collateral,
pool.interestRate,
block.timestamp
);
}

Support

FAQs

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

Give us feedback!