Skip to content
Business logic Audit finding Intermediate

Malicious users can block repay debt transactions with no cost

The repayDebt function calculates the assets to repay using a conversion rate that can be manipulated by transferring a tiny amount of tBTC directly to the contract. An attacker can front-run a repayment with a 2 wei transfer, causing the calculated assets to exceed the recorded debt and making the repayment revert.

brivan Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#34712 [SC-Medium] Malicious users can block repay debt transactions with no cost

Submitted on Aug 21st 2024 at 18:18:25 UTC by @brivan for Audit Comp | Acre

Description

Brief

The `repayDebt` function can be exploited by malicious users to block debt repayments by manipulating the conversion rate with minimal cost. This allows attackers to indefinitely prevent legitimate debtors from repaying their debts.

Vulnerability Details

Authorized debtors can call the `mintDebt` function to mint shares, which they are required to repay later. This function tracks the amount of assets in debt as follows: ```solidity function mintDebt( uint256 shares, address receiver ) public whenNotPaused returns (uint256 assets) { assets = convertToAssets(shares);

// Increase the debt of the debtor.

>>> currentDebt[msg.sender] += assets;

// ...

} ``` Debtors can subsequently call the `repayDebt` function to repay their debt. The amount of debt to be repaid is calculated based on the current conversion rate: ```solidity function repayDebt( uint256 shares ) public whenNotPaused returns (uint256 assets) { >>> assets = convertToAssets(shares);

// Check the current debt of the debtor.

>>> if (currentDebt[msg.sender] < assets) { revert ExcessiveDebtRepayment( msg.sender, currentDebt[msg.sender], assets ); } // Decrease the debt of the debtor. currentDebt[msg.sender] -= assets;

// ...

} ``` The check `if (currentDebt[msg.sender] < assets)` in the `repayDebt` function can be exploited by malicious users to front-run the transaction. By transferring a small amount of `tBTC` (e.g., 2 wei) directly to the `stBTC` contract, the conversion rate can be manipulated, causing the `assets` value returned by `convertToAssets(shares)` to exceed the current debt. This results in the `repayDebt` transaction reverting due to the `ExcessiveDebtRepayment` error. Note that a minimal transfer of `tBTC` (equivalent to 2 wei) is sufficient to block the debt repayment.

Consider the following scenario, demonstrated by a runnable Proof of Concept (PoC) included with this submission:

  1. Bob is authorized to incur a debt of `100`. He calls `mintDebt` to mint 100 shares, and the debt is recorded based on the current conversion rate.

  2. Later, Bob decides to repay his debt and initiates a transaction to call `repayDebt`.

    2.1 Alice, a malicious actor, front-runs Bob’s transaction by transferring `2 wei` of `tBTC` to the `stBTC` contract, thereby increasing the conversion rate

    2.2 When Bob’s transaction begins executing, the `assets` value calculated by `convertToAssets(shares)` is now higher than his recorded debt, causing the transaction to revert: ```solidity assets = convertToAssets(shares); if (currentDebt[msg.sender] < assets) {revert ExcessiveDebtRepayment( msg.sender, currentDebt[msg.sender], assets );} ```

This attack incurs no significant cost to the malicious user, as Alice only needs to slightly increase the `stBTC` assets (by 2 wei) just before the `repayDebt` function is executed.

Impact Details

Malicious users can indefinitely block `repayDebt` transactions at no significant cost.

References

https://github.com/thesis/acre/blob/dc156f5a7f02142c1f80627267d14a26e5c99b30/solidity/contracts/stBTC.sol#L350-L353

Proof of Concept

Copy and paste the following test case into `test/stBTC.test.ts`: ```ts describe("repayDebt", () => { beforeAfterSnapshotWrapper()

  it.only(&quot;pocc&quot;, async () &#x3D;&gt; {
    const debtAllowance &#x3D; to1e18(100)
    await stbtc
      .connect(governance)
      .updateDebtAllowance(externalMinter.address, debtAllowance)
    await stbtc
      .connect(externalMinter)
      .mintDebt(debtAllowance, externalMinter.address)

    await tbtc.connect(depositor1).transfer(stbtc, 2) // transfers 2wei equivalent

    await expect(
      stbtc.connect(externalMinter).repayDebt(debtAllowance),
    ).to.be.revertedWithCustomError(stbtc, &quot;ExcessiveDebtRepayment&quot;)
  })

// ... } ```

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

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 repayment check compares the recalculated asset value against the stored debt without accounting for small donations that alter the conversion rate.

Impact

Malicious users can indefinitely block repayDebt transactions at no significant cost.

What the attacker needed

Attacker can front-run transactions; attacker has 2 wei of tBTC

How it was found

  1. Bob calls mintDebt to create a debt of 100 shares.
  2. Bob initiates a transaction to call repayDebt.
  3. Alice front-runs Bob's transaction by transferring 2 wei of tBTC to the stBTC contract.
  4. Bob's transaction executes, but the recalculated assets exceed his recorded debt, causing a revert with ExcessiveDebtRepayment.

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 user owes a debt in a smart contract and tries to repay it. The amount they owe is recalculated at the moment of repayment using a shared exchange rate. An attacker can send a tiny amount of the underlying token to the contract just before the repayment, which slightly changes that rate. This makes the recalculated debt appear larger than what is recorded, so the repayment is rejected and the user cannot pay back.

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 brivan

View all

1 more disclosed report, best first.

More from Acre

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.