Skip to content
Business logic Audit finding Advanced

Redemptions are inconsistent with other cdp’s operations

Redemptions in the eBTC CDP system are not subject to the same collateral-ratio checks as other CDP operations, so a redemption can reduce the system's total collateral ratio and push it into recovery mode. An attacker could use this to trigger recovery mode unintentionally, though the report notes the scenario is unlikely.

0xRobocop Follow with ether_sky

Originally disclosed on Code4rena

Submitted by 0xRobocop, also found by ether_sky

Most actions that modify the (ICR) of a Collateralized Debt Position (CDP) must adhere to specific regulations to maintain the system’s stability. For instance, closing a CDP or decreasing its collateral is not permitted if it would trigger the system’s recovery mode, or if the system is already in that mode.

However, the rules for redemptions are less stringent. The only conditions are that both the system and the CDPs undergoing redemption must have an TCR and ICR above the MCR. So, it is possible to redeem a cdp that is actually helping the system to stay healthy.

Proof of Concept

Follow the next steps to run the coded proof of concept:

  • Copy and paste the following test under test/CdpManagerTest.js:
    it.only("redeemCollateral(): Is inconsistent with other cdp behaviors", async () => {
        await contracts.collateral.deposit({from: A, value: dec(1000, 'ether')});
        await contracts.collateral.approve(borrowerOperations.address, mv._1Be18BN, {from: A});
        await contracts.collateral.deposit({from: B, value: dec(1000, 'ether')});
        await contracts.collateral.approve(borrowerOperations.address, mv._1Be18BN, {from: B});
        await contracts.collateral.deposit({from: C, value: dec(1000, 'ether')});
        await contracts.collateral.approve(borrowerOperations.address, mv._1Be18BN, {from: C});

        // @audit-info Current BTC / ETH price is 1.
        const newPrice = dec(1, 18);
        await priceFeed.setPrice(newPrice)

        // @audit-info Open some CDPs.
        await borrowerOperations.openCdp(dec(400, 18), A, A, dec(1000, 'ether'), { from: A })
        await borrowerOperations.openCdp(dec(75, 18), B, B, dec(100, 'ether'), { from: B })
        await borrowerOperations.openCdp(dec(75, 18), C, C, dec(100, 'ether'), { from: C })

        let _aCdpId = await sortedCdps.cdpOfOwnerByIndex(A, 0);
        let _bCdpId = await sortedCdps.cdpOfOwnerByIndex(B, 0);
        let _cCdpId = await sortedCdps.cdpOfOwnerByIndex(C, 0);

        const price = await priceFeed.getPrice()

        const currentTCR = await cdpManager.getSyncedTCR(price);
        console.log("TCR of the system before price reduction: " + currentTCR.toString())

        // @audit-info Some price reduction.
        const newPrice2 = dec(6, 17);
        await priceFeed.setPrice(newPrice2)

        const price2 = await priceFeed.getPrice()

        const currentTCR2 = await cdpManager.getSyncedTCR(price2);
        console.log("TCR of the system after price reduction" + currentTCR2.toString())

        // @audit-info All cdps are in the linked list.
        assert.isTrue(await sortedCdps.contains(_aCdpId))
        assert.isTrue(await sortedCdps.contains(_bCdpId))
        assert.isTrue(await sortedCdps.contains(_cCdpId))

        await cdpManager.setBaseRate(0)

        // @audit-info Redemption of 400 eBTC.
        const EBTCRedemption = dec(400, 18)
        await th.redeemCollateralAndGetTxObject(A, contracts, EBTCRedemption, GAS_PRICE, th._100pct)

        // @audit-info Redemption will happen to A's position because B and C ICRs are below MCR.
        assert.isFalse(await sortedCdps.contains(_aCdpId))
        assert.isTrue(await sortedCdps.contains(_bCdpId))
        assert.isTrue(await sortedCdps.contains(_cCdpId))

        // @audit-issue UNDERCOLLATERALIZED
        const currentTCR3 = await cdpManager.getSyncedTCR(price2);
        console.log("TCR after redemption: " + currentTCR3.toString())
      })

This proof of concept highlights a significant risk: a situation where the entire system becomes undercollateralized. Although the likelihood of this occurring is low, there are other, more probable scenarios to consider. One such scenario involves executing one or multiple redemptions that push the system into recovery mode.

Currently, there’s a redemption fee in place that escalates the cost of withdrawing large amounts of collateral, serving as a financial deterrent to potential manipulation. However, this is primarily an economic obstacle. Given that eBTC aims to be a fundamental component for Bitcoin in the Ethereum DeFi ecosystem, it’s crucial to ensure that redemptions do not jeopardize the system’s stability.

It should also be noted that the RiskDao’s analysis regarding redemptions does not extend to situations where redemptions are strategically used to affect the system’s collateralization.

Recommended Mitigation Steps

Redemptions should have the same rules for other cdp changes. For example:

  • Redeeming should not let the system in RM
  • Redeeming should not be possible if the system is in RM unless it makes the system to get out of RM

Alex the Entreprenerd (Badger) confirmed and commented:

I believe the finding to be valid, under the specific circumstance of:

  • CDPs with Bad Debt
  • No CDPs with ICR > MCR and ICR < CCR

A redemption can cause TCR to decrease and trigger recovery mode.

This is extremely unlikely as it’s irrational for people to redeem instead of liquidate, however it could be used to trigger Recovery Mode in unintended way.

Additionally, the issue is not fixable as bad debt redistributions could be so big as to trigger RM separately and that’s not avoidable.

I appreciate the time taken by the Warden and believe this will have to be sorted by reserving some amount of eBTC for Bad Debt Liquidations as means to “clean up” those risky CDPs, I believe this can be done profitable for the DAO in place of redemptions and as such believe we will:

  • Add the check to prevent directly triggering RM
  • Assume it will still be possible to trigger RM directly
  • Monitor this situation
  • Have some eBTC to perform said liquidations to avoid this scenario under most reasonable conditions

Note: See full discussion here.


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

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 redemption function lacks the same recovery-mode checks that other CDP-modifying operations have, allowing it to reduce the system's total collateral ratio below the minimum.

Impact

A redemption could push the system into recovery mode, but the report and the maintainer note this is extremely unlikely and requires specific conditions such as bad debt and no CDPs with ICR between MCR and CCR.

What the attacker needed

CDPs with bad debt; No CDPs with ICR between MCR and CCR; Redemption instead of liquidation

The fix

The maintainer plans to add a check to prevent directly triggering recovery mode, but acknowledges it may still be possible and will monitor the situation.

How it was found

  1. Set up three CDPs with different collateral amounts and a starting price.
  2. Reduce the price so that two CDPs fall below the minimum collateral ratio.
  3. Perform a redemption of 400 eBTC.
  4. Observe that the redemption targets the healthy CDP and the system's total collateral ratio drops, potentially into recovery mode.

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 CDP is a loan backed by collateral; if the collateral's value falls too low compared to the debt, the system enters a 'recovery mode' to protect itself. Most actions that change a CDP's collateral ratio are blocked if they would cause recovery mode, but redemptions (where someone swaps eBTC for collateral) are not checked the same way. This means a redemption could accidentally push the whole system into recovery mode.

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 0xRobocop

View all

15 more disclosed reports, best first.

More from eBTC Zap Router

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.