The user overpays the USDA amount for downside protection while withdrawing
The withdraw function in BorrowLib.sol requires users to repay the full debt amount, including the portion that should be covered by the protocol's downside protection. As a result, users overpay the USDA amount for downside protection when withdrawing.
0x37 Follow with 0x73696d616f, John44 and 9 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/1004
Found by
0x37, 0x73696d616f, John44, LordAlive, Pablo, ParthMandale, PeterSR, Ruhum, futureHack, jah, nuthan2x, t.aksoy
Summary
The protocol provides >= 20% downside protection on the collateral depending on the volatility of collateral. However, users should pay USDA amount for downside protection, while withdrawing and protocol doesn't cover downside protection.
Root Cause
In the BorrowLib.sol withdraw() function, users return usda and receive collateral. Although protocol covers 20% downside protection, users should return amount of downsideProtected.
Let's see line 867 and line 878, and calculate total usda amount users should hold: burnValue + (borrowerDebt - depositDetail.borrowedAmount) + discountedCollateral = depositDetail.borrowedAmount - discountedCollateral + (borrowerDebt - depositDetail.borrowedAmount) + discountedCollateral = borrowerDebt.
As result, users should return full debt(borrowerDebt) and the protocol doesn't cover downsideProtected.
function withdraw(
ITreasury.DepositDetails memory depositDetail,
IBorrowing.BorrowWithdraw_Params memory params,
IBorrowing.Interfaces memory interfaces
) external returns (IBorrowing.BorrowWithdraw_Result memory) {
...
// Calculate the USDa to burn
867 uint256 burnValue = depositDetail.borrowedAmount - discountedCollateral;
// Burn the USDa from the Borrower
bool success = interfaces.usda.burnFromUser(msg.sender, burnValue);
if (!success) revert IBorrowing.Borrow_BurnFailed();
...
//Transfer the remaining USDa to the treasury
878 bool transfer = interfaces.usda.transferFrom(
msg.sender,
address(interfaces.treasury),
(borrowerDebt - depositDetail.borrowedAmount) + discountedCollateral
);
if (!transfer) revert IBorrowing.Borrow_USDaTransferFailed();
...
}
Internal pre-conditions
External pre-conditions
Attack Path
Impact
Users should return usda amount for downside protection and the protocol doesn't cover downside protection.
Mitigation
Deduct downside protection.
function withdraw(
ITreasury.DepositDetails memory depositDetail,
IBorrowing.BorrowWithdraw_Params memory params,
IBorrowing.Interfaces memory interfaces
) external returns (IBorrowing.BorrowWithdraw_Result memory) {
...
// Calculate the USDa to burn
uint256 burnValue = depositDetail.borrowedAmount - discountedCollateral;
// Burn the USDa from the Borrower
bool success = interfaces.usda.burnFromUser(msg.sender, burnValue);
if (!success) revert IBorrowing.Borrow_BurnFailed();
...
//Transfer the remaining USDa to the treasury
bool transfer = interfaces.usda.transferFrom(
msg.sender,
address(interfaces.treasury),
- (borrowerDebt - depositDetail.borrowedAmount) + discountedCollateral
+ (borrowerDebt - depositDetail.borrowedAmount - downsideProtected) + discountedCollateral
);
if (!transfer) revert IBorrowing.Borrow_USDaTransferFailed();
...
}
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 calculates the USDA to transfer from the user without subtracting the downsideProtected amount, so the user repays the full debt instead of the reduced amount.
What the attacker needed
User has an active borrow position
The fix
The withdraw function should deduct the downsideProtected amount from the USDA transferred from the user.
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 you borrow, the protocol promises to cover part of any loss if the collateral value drops. But when you withdraw, the code makes you pay back the full amount you borrowed, including the part the protocol was supposed to cover. So you end up paying more than you should.
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.