Function addNewTranche() should use protocolFee from Loan struct
The addNewTranche function uses the current protocol fee fraction instead of the fee stored in the Loan struct when a loan was issued. This could cause inconsistent fee collection if the admin updates the protocol fee.
Originally disclosed on Code4rena
Submitted by minhquanym
The protocol fee value is recorded and stored in the Loan struct when a new loan is issued. However, when adding a new tranche, the function uses the current value of protocolFee.fraction instead of the value stored in the Loan struct. This could result in inconsistencies in fee collection, as the protocol fee value might be updated by the admin, while the value stored in the Loan struct remains unchanged.
if (_renegotiationOffer.fee > 0) {
/// @dev Cached
ProtocolFee memory protocolFee = _protocolFee;
ERC20(_loan.principalAddress).safeTransferFrom(
_renegotiationOffer.lender,
protocolFee.recipient,
_renegotiationOffer.fee.mulDivUp(protocolFee.fraction, _PRECISION) // @audit Use protocolFee from Loan instead
);
}
Proof of Concept
The protocol fee value is stored in the Loan struct when a new loan is opened.
function _processOffersFromExecutionData(
...
) ... {
Loan memory loan = Loan(
_borrower,
_tokenId,
_nftCollateralAddress,
_principalAddress,
totalAmount,
block.timestamp,
_duration,
tranche,
protocolFee.fraction
);
}
Recommended Mitigation Steps
Consider using _loan.protocolFee instead of protocolFee.fraction in the addNewTranche() function.
addNewTrancheusesprotocolFeefrom struct.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The addNewTranche function reads the protocol fee from the current global state rather than from the loan's stored protocolFee field.
Impact
This could result in inconsistencies in fee collection, as the protocol fee value might be updated by the admin while the value stored in the Loan struct remains unchanged.
What the attacker needed
Admin updates protocol fee after loan creation
The fix
The addNewTranche function was fixed to use the protocolFee from the Loan struct.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a loan is created, the protocol fee is saved with it. Later, when adding a new tranche to that loan, the code mistakenly uses the latest fee setting instead of the saved one. This means the fee charged might not match what was agreed when the loan started.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.