lender could be forced to withdraw collateral even if he/she would rather wait for liquidation during default
The withdraw function in CollateralManager allows anyone to trigger a collateral withdrawal on behalf of the lender when a loan is defaulted, before the liquidation delay period ends. This forces the lender to accept collateral instead of waiting for a potential liquidation, contrary to the intended design.
0xGoodess Follow with 0xbepresent, MiloTruck and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-03-teller-judging/issues/2
Found by
0xGoodess, 0xbepresent, MiloTruck, Nyx, cducrest-brainbot, chaduke, ctf_sec, duc, innertia
Summary
lender could be forced to withdraw collateral even if he/she would rather wait for liquidation during default
Vulnerability Detail
CollateralManager.withdraw would pass if the loan is defaulted (the borrower does not pay interest in time); in that case, anyone can trigger an withdrawal on behalf of the lender before the liquidation delay period passes.
withdraw logic from CollateralManager.
* @notice Withdraws deposited collateral from the created escrow of a bid that has been successfully repaid.
* @param _bidId The id of the bid to withdraw collateral for.
*/
function withdraw(uint256 _bidId) external {
BidState bidState = tellerV2.getBidState(_bidId);
console2.log("WITHDRAW %d", uint256(bidState));
if (bidState == BidState.PAID) {
_withdraw(_bidId, tellerV2.getLoanBorrower(_bidId));
} else if (tellerV2.isLoanDefaulted(_bidId)) { @> audit
_withdraw(_bidId, tellerV2.getLoanLender(_bidId));
emit CollateralClaimed(_bidId);
} else {
revert("collateral cannot be withdrawn");
}
}
Impact
anyone can force lender to take up collateral during liquidation delay and liquidation could be something that never happen. This does not match the intention based on the spec which implies that lender has an option: 3) When the loan is fully repaid, the borrower can withdraw the collateral. If the loan becomes defaulted instead, then the lender has a 24 hour grace period to claim the collateral (losing the principal)
Code Snippet
Tool used
Manual Review
Recommendation
check that the caller is the lender
function withdraw(uint256 _bidId) external {
BidState bidState = tellerV2.getBidState(_bidId);
console2.log("WITHDRAW %d", uint256(bidState));
if (bidState == BidState.PAID) {
_withdraw(_bidId, tellerV2.getLoanBorrower(_bidId));
} else if (tellerV2.isLoanDefaulted(_bidId)) {
+++ uint256 _marketplaceId = bidState.marketplaceId;
+++ address sender = _msgSenderForMarket(_marketplaceId);
+++ address lender = tellerV2.getLoanLender(_bidId);
+++ require(sender == lender, "sender must be the lender");
_withdraw(_bidId, lender);
emit CollateralClaimed(_bidId);
} else {
revert("collateral cannot be withdrawn");
}
}
Discussion
ethereumdegen
Thank you for the feedback i will review this with the team.
ctf-sec
Escalate for 10 USDC. Impact is high, so the severity is not medium but high.
anyone can force lender to take up collateral during liquidation delay and liquidation could be something that never happen.
because the lack of access control dispute normal liquidation flow, which is clearly a high impact
https://docs.sherlock.xyz/audits/judging/judging
High: This vulnerability would result in a material loss of funds, and the cost of the attack is low (relative to the amount of funds lost). The attack path is possible with reasonable assumptions that mimic on-chain conditions. The vulnerability must be something that is not considered an acceptable risk by a reasonable protocol team.
Permissionlessly dispute the liquidation flow make "the cost of the attack low" and generate bad debts, which equal to "loss of fund". Clearly this is "not considered an acceptable risk by a reasonable protocol team"
Thanks
sherlock-admin
Escalate for 10 USDC. Impact is high, so the severity is not medium but high.
anyone can force lender to take up collateral during liquidation delay and liquidation could be something that never happen.
because the lack of access control dispute normal liquidation flow, which is clearly a high impact
https://docs.sherlock.xyz/audits/judging/judging
High: This vulnerability would result in a material loss of funds, and the cost of the attack is low (relative to the amount of funds lost). The attack path is possible with reasonable assumptions that mimic on-chain conditions. The vulnerability must be something that is not considered an acceptable risk by a reasonable protocol team.
Permissionlessly dispute the liquidation flow make "the cost of the attack low" and generate bad debts, which equal to "loss of fund". Clearly this is "not considered an acceptable risk by a reasonable protocol team"
Thanks
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Trumpero
I believe it is a medium since the lender will receive the collateral, which holds more value than the loan itself usually. If the collateral holds less value than the loan, then no one, except the lender, will be willing to liquidate this loan. The lender only miss out on the opportunity to be repaid the loan as originally expected.
ethereumdegen
Github PR: Issue 224 - Access control on collateral withdraw
hrishibhat
Escalation rejected
Valid medium As the Lead judge pointed out The impact of this issue is a medium. There is no loss of funds for the protocol, this is about being able to withdraw collateral in case the loan is defaulted during the liquidation delay. A missed out opportunity to be repaid, not a high issue
sherlock-admin
Escalation rejected
Valid medium As the Lead judge pointed out The impact of this issue is a medium. There is no loss of funds for the protocol, this is about being able to withdraw collateral in case the loan is defaulted during the liquidation delay. A missed out opportunity to be repaid, not a high issue
This issue's escalations have been rejected!
Watsons who escalated this issue will have their escalation amount deducted from their next payout.
IAm0x52
Fix looks good. Collateral can now only be withdrawn by the appropriate party. Borrower if paid in full or lender/owner of loan NFT if defaulted.
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 withdraw function lacks an access control check to ensure that only the lender can initiate a withdrawal when the loan is defaulted.
Impact
Anyone can force the lender to take collateral during the liquidation delay period, potentially causing the lender to miss out on a better recovery through liquidation, though the protocol itself does not lose funds.
What the attacker needed
Loan is defaulted; attacker can call withdraw
The fix
The withdraw function was fixed by adding a check that the caller is the lender (or owner of the loan NFT) when the loan is defaulted.
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 lending protocol, if a borrower defaults, the lender usually has a grace period to decide whether to claim the collateral or wait for a liquidation process. Here, the code allowed any user to call the withdraw function and force the collateral to be sent to the lender immediately after default, removing the lender's choice. This is a problem because the lender might prefer to wait for liquidation, which could recover more funds.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.