isCoolerCallback can be bypassed
The Cooler contract's clearRequest function checks that the lender implements the CoolerCallback interface by calling isCoolerCallback(), but a malicious contract can simply return true without implementing the required callback functions. This allows a lender to force a loan into default by making repayLoan and rollLoan revert, enabling the lender to claim the borrower's collateral.
0xbepresent Follow with BugHunter101, Delvir0 and 18 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-08-cooler-judging/issues/187
Found by
0xbepresent, BugHunter101, Delvir0, Hama, Ignite, Kow, Mlome, Vagner, banditx0x, castle_chain, deadrxsezzz, detectiveking, evilakela, harisnabeel, jah, klaus, libratus, mert_eren, ni8mare, nmirchev8, ubermensch
The lender can bypass CoolerCallback.isCoolerCallback() validation without implements the CoolerCallback abstract.
In the provided example, this may force the loan to default.
Vulnerability Detail
The CoolerCallback.isCoolerCallback() is intended to ensure that the lender implements the CoolerCallback abstract at line 241 when the parameter isCallback_ is true.
function clearRequest(
uint256 reqID_,
bool repayDirect_,
bool isCallback_
) external returns (uint256 loanID) {
Request memory req = requests[reqID_];
// If necessary, ensure lender implements the CoolerCallback abstract.
if (isCallback_ && !CoolerCallback(msg.sender).isCoolerCallback()) revert NotCoolerCallback();
// Ensure loan request is active.
if (!req.active) revert Deactivated();
// Clear the loan request in memory.
req.active = false;
// Calculate and store loan terms.
uint256 interest = interestFor(req.amount, req.interest, req.duration);
uint256 collat = collateralFor(req.amount, req.loanToCollateral);
uint256 expiration = block.timestamp + req.duration;
loanID = loans.length;
loans.push(
Loan({
request: req,
amount: req.amount + interest,
unclaimed: 0,
collateral: collat,
expiry: expiration,
lender: msg.sender,
repayDirect: repayDirect_,
callback: isCallback_
})
);
// Clear the loan request storage.
requests[reqID_].active = false;
// Transfer debt tokens to the owner of the request.
debt().safeTransferFrom(msg.sender, owner(), req.amount);
// Log the event.
factory().newEvent(reqID_, CoolerFactory.Events.ClearRequest, 0);
}
https://github.com/sherlock-audit/2023-08-cooler/blob/main/Cooler/src/Cooler.sol#L233-L275
However, this function doesn't provide any protection. The lender can bypass this check without implementing the CoolerCallback abstract by calling the Cooler.clearRequest() function using a contract that implements the isCoolerCallback() function and returns a true value.
For example:
contract maliciousLender {
function isCoolerCallback() pure returns(bool) {
return true;
}
function operation(
address _to,
uint256 reqID_
) public {
Cooler(_to).clearRequest(reqID_, true, true);
}
function onDefault(uint256 loanID_, uint256 debt, uint256 collateral) public {}
}
By being the loan.lender with implement only onDefault() function, this will cause the repayLoan() and rollLoan() methods to fail due to revert at onRepay() and onRoll() function. The borrower cannot repay and the loan will be defaulted.
After the loan default, the attacker can execute claimDefault() to claim the collateral.
Furthermore, there is another method that allows lenders to bypass the CoolerCallback.isCoolerCallback() function which is loan ownership transfer.
/// @notice Approve transfer of loan ownership rights to a new address.
/// @param to_ address to be approved.
/// @param loanID_ index of loan in loans[].
function approveTransfer(address to_, uint256 loanID_) external {
if (msg.sender != loans[loanID_].lender) revert OnlyApproved();
// Update transfer approvals.
approvals[loanID_] = to_;
}
/// @notice Execute loan ownership transfer. Must be previously approved by the lender.
/// @param loanID_ index of loan in loans[].
function transferOwnership(uint256 loanID_) external {
if (msg.sender != approvals[loanID_]) revert OnlyApproved();
// Update the load lender.
loans[loanID_].lender = msg.sender;
// Clear transfer approvals.
approvals[loanID_] = address(0);
}
Normally, the lender who implements the CoolerCallback abstract may call the Cooler.clearRequest() with the _isCoolerCallback parameter set to true to execute logic when a loan is repaid, rolled, or defaulted.
But the lender needs to change the owner of the loan, so they call the approveTransfer() and transferOwnership() functions to the contract that doesn't implement the CoolerCallback abstract (or implement only onDefault() function to force the loan default), but the loan.callback flag is still set to true.
Thus, this breaks the business logic since the three callback functions don't need to be implemented when the isCoolerCallback() is set to true according to the dev note in the CoolerCallback abstract below:
/// @notice Allows for debt issuers to execute logic when a loan is repaid, rolled, or defaulted. /// @dev The three callback functions must be implemented if
isCoolerCallback()is set to true.
Impact
-
The lender forced the Loan become default to get the collateral token, owner lost the collateral token.
-
Bypass the
isCoolerCallbackvalidation.
Code Snippet
https://github.com/sherlock-audit/2023-08-cooler/blob/main/Cooler/src/Cooler.sol#L241
https://github.com/sherlock-audit/2023-08-cooler/blob/main/Cooler/src/Cooler.sol#L338-L343
https://github.com/sherlock-audit/2023-08-cooler/blob/main/Cooler/src/Cooler.sol#L347-L354
Tool used
Manual Review
Recommendation
Only allowing callbacks from the protocol-trusted address (eg., Clearinghouse contract).
Disable the transfer owner of the loan when the loan.callback is set to true.
Discussion
Oot2k
Duplicate of 30
Oot2k
Reorder issues
0xRusowsky
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 contract relies on a self-reported boolean from the lender's contract to verify interface implementation, without verifying that the required callback functions are actually implemented.
Impact
The lender can force the loan to default and claim the collateral, causing the borrower to lose their collateral.
What the attacker needed
Lender deploys a malicious contract; borrower accepts a loan request
The fix
The contract should only allow callbacks from a protocol-trusted address and should disable loan ownership transfer when the callback flag is set.
How it was found
- Deploy a malicious contract that implements isCoolerCallback() returning true and only the onDefault() callback function.
- Call clearRequest() with isCallback_ set to true to create a loan with the callback flag enabled.
- The borrower attempts to repay or roll the loan, but the calls revert because onRepay() and onRoll() are not implemented.
- The loan defaults, and the malicious lender calls claimDefault() to seize the collateral.
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.
In a smart contract, a lender can pretend to support a feature that lets them be notified when a borrower repays or defaults. The contract only checks that the lender says 'yes, I support it' by calling a function that returns true, but it never checks that the lender actually implements the required notification functions. So a malicious lender can say yes, then ignore the notifications, causing the borrower's repayment attempts to fail and the loan to default, letting the lender take the collateral.
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.