Skip to content
DoS Audit finding Intermediate

Last withdrawer can be prevented from withdrawing their assets

The stBTC contract calculates share value using total assets that include tBTC sent directly to the MezoAllocator but not yet allocated to the portal. An attacker can donate a tiny amount of tBTC to the allocator, inflating total assets so that the last user's redemption reverts due to an arithmetic underflow.

trachev Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#34748 [SC-Low] Last withdrawer can be prevented from withdrawing their assets

Submitted on Aug 23rd 2024 at 12:50:40 UTC by @trachev for Audit Comp | Acre

Description

Brief/Intro

By donating dust to the `MezoAllocator` contract a malicious actor can prevent a user from redeeming their shares.

Vulnerability Details

The number of assets that a share is worth is calculated using the `totalAssets` function of stBTC. `totalAsssets` returns the tBTC balance of stBTC, the `totalDebt` and `dispatcher.totalAssets()`. `dispatcher.totalAssets()` includes tBTC deposited into `MezoPortal` and also tBTC sent directly to `MezoAllocator` that are yet to be allocated to the portal. The issue is that those tBTC cannot be withdrawn from `MezoAllocator` until they have been allocated to the portal. As a result, they can make a user's shares be worth more than the total assets that can actually be withdrawn. This attack can be repeated multiple times as it requires an extremely small amount of dust to make the function revert, in the PoC only 100 wei is used.

Impact Details

If there is only one depositor in stBTC, they can be prevented from withdrawing. The user is griefed and the attack can be performed repeatedly.

References

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

Proof of Concept

Proof of Concept

Place this code in the `MezoAllocator.test.ts` file, inside of the "MezoAllocator" describe block.

describe("POC_last_withdraw_fails", () => { beforeAfterSnapshotWrapper()

it("Should revert when last user withdraws", async () => {
  let assetsToDeposit = to1e18(1n)
  await tbtc.mint(depositor.address, assetsToDeposit)

  await tbtc
    .connect(depositor)
    .approve(await stbtc.getAddress(), assetsToDeposit)
    

  //depositor deposits in stbts
  await stbtc
    .connect(depositor)
    .deposit(assetsToDeposit, depositor.address)

  //allocate to mezo portal
  await mezoAllocator.connect(maintainer).allocate()

  //mint dust (only 100 wei, with 2 wei reverts as well), 
  //that is yet to be allocated, so that the total assets is inflated
  await tbtc.mint(mezoAllocator, 100)

  //reverts with a panic code 0x11 due to an arithmetic oveflow
  await stbtc.connect(depositor).redeem(await stbtc.balanceOf(depositor.address), depositor.address, depositor.address)
})

})

The original report as published on Immunefi, by trachev. 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 total assets calculation includes tBTC sent to MezoAllocator that has not yet been allocated to the portal and therefore cannot be withdrawn, causing a mismatch between reported and withdrawable assets.

Impact

The last remaining depositor can be prevented from withdrawing their assets, and the attack can be repeated with minimal cost.

What the attacker needed

Attacker can send tBTC to MezoAllocator; victim is the last depositor in stBTC

How it was found

  1. Deposit tBTC into stBTC.
  2. Allocate the deposited tBTC to the Mezo portal.
  3. Send a tiny amount of tBTC directly to the MezoAllocator contract.
  4. Attempt to redeem all stBTC shares as the last depositor.

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 you deposit money into a shared pool, you get shares that represent your portion. The pool's total value is used to work out how much each share is worth. Here, the total value included some money that was not actually available to pay out, so when the last person tried to take their money, the maths failed and the withdrawal was blocked.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by trachev

View all

2 more disclosed reports, 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.