Skip to content
Business logic Audit finding Intermediate

WrappedIbbtcEth contract will use stalled price for mint/burn if updatePricePerShare wasn’t run properly

The WrappedIbbtcEth contract uses a price per share that is updated by an external function, and if that function is not run for a while, the price becomes stale. An attacker can mint tokens at the outdated price, wait for the price to be updated, and then burn them for a profit.

hyh Follow

Originally disclosed on Code4rena

Submitted by hyh, also found by cmichel, gpersoon, leastwood, hack3r-0m, kenzo, WatchPug, and loop

Impact

Malicious user can monitor SetPricePerShare event and, if it was run long enough time ago and market moved, but, since there were no SetPricePerShare fired, the contract’s pricePerShare is outdated, so a user can mint() with pricePerShare that is current for contract, but outdated for market, then wait for price update and burn() with updated pricePerShare, yielding risk-free profit at expense of contract holdings.

Proof of Concept

WrappedIbbtcEth updates pricePerShare variable by externally run updatePricePerShare function. The variable is then used in mint/burn/transfer functions without any additional checks, even if outdated/stalled. This can happen if the external function wasn’t run for any reason. The variable is used via balanceToShares function: WrappedIbbtcEth.sol L155

This is feasible as updatePricePerShare to be run by off-chain script being a part of the system, and malfunction of this script leads to contract exposure by stalling the price. The malfunction can happen both by internal reasons (bugs) and by external ones (any system-level dependencies, network outrages). updatePricePerShare function: WrappedIbbtcEth.sol L72

Recommended Mitigation Steps

The risk comes with system design. Wrapping price updates with contract level variable for gas costs minimization is a viable approach, but it needs to be paired with corner cases handling. One of the ways to reduce the risk is as follows:

Introduce a threshold variable for maximum time elapsed since last pricePerShare update to WrappedIbbtcEth contract.

Then 2 variants of transferFrom and transfer functions can be introduced, both check condition {now - time since last price update < threshold}. If condition holds both variants, do the transfer. If it doesn’t, then the first variant reverts, while the second do costly price update. I.e. it will be cheap transfer (that works only if price is recent) and full transfer (that is similar to the first when price is recent, but do price update on its own when price is stalled). This way, this full transfer is guaranteed to run and is usually cheap, costing more if price is stalled and it does the update.

After this, whenever scheduled price update malfunctions (for example because of network conditions), the risk will be limited by market volatility during threshold time at maximum, i.e. capped.

See issue page for example code:

dapp-whisperer (BadgerDAO) confirmed:

Agreed, appreciate the thorough breakdown. We will add a “max staleness” to the ppfs update.

I do see some merit in the idea of “updating when needed” at expense of the next user, but due to interface considerations we’d like to keep that consistent for users. In practice, we will run a bot to ensure timely updates.

The pps updates are small and infrequent.

The original report as published on Code4rena, by hyh. 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

The contract relies on an externally triggered price update and does not check whether the price is stale before using it in mint, burn, or transfer operations.

Impact

An attacker could make a risk-free profit at the expense of the contract's holdings if the price update mechanism fails.

What the attacker needed

Price update not run for a while; market price has moved

The fix

The contract should be modified to check the staleness of the price and either revert or trigger an update if the price is too old, as suggested in the report and confirmed by the project.

How it was found

  1. Monitor the SetPricePerShare event to detect when the price was last updated.
  2. If the price is outdated and the market has moved, call mint() using the stale price.
  3. Wait for the price to be updated to the current market price.
  4. Call burn() using the updated price to realise a profit.

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.

This contract lets people deposit one token and get another token in return, using a price per share to decide how many tokens they get. The price is supposed to be updated regularly by an outside script, but if that script fails, the price stays old. An attacker can take advantage of the old price to make a guaranteed profit.

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 hyh

View all

137 more disclosed reports, best first.

More from BadgerDAO ibBTC Wrapper contest

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.