Skip to content
Business logic Audit finding Intermediate

The design of wibBTC is not fully compatible with the current Curve StableSwap pool

The wibBTC token's balance changes automatically as its pricePerShare increases, but the Curve StableSwap pool records balances only at deposit/withdrawal, so the pool's stored balance diverges from the actual token balance. This can cause liquidity providers to receive less than expected when removing liquidity.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by gzeon

Per the documentation, wibBTC is designed for a Curve StableSwap pool. However, the design of wibBTC makes the balances change dynamically and automatically. This is unusual for an ERC20 token, and it’s not fully compatible with the current Curve StableSwap pool.

Specifically, a Curve StableSwap pool will maintain the balances of its coins based on the amount of tokens added, removed, and exchanged each time. In another word, it can not adopt the dynamic changes of the balances that happened automatically.

The pool’s actual dynamic balance of wibBTC will deviate from the recorded balance in the pool contract as the pricePerShare increases.

Furthermore, there is no such way in Curve StableSwap similar to the sync() function of UNI v2, which will force sync the stored reserves to match the balances.

PoC

Given:

  • The current pricePerShare is: 1;
  • The Curve pool is newly created with 0 liquidity;
  • Alice added 100 wibBTC and 100 wBTC to the Curve pool; Alice holds 100% of the pool;
  • After 1 month with no activity (no other users, no trading), and the pricePerShare of ibBTC increases to 1.2;
  • Alice removes all the liquidity from the Curve pool.

While it’s expected to receive 150 wibBTC and 100 wBTC, Alice actually can only receive 100 wibBTC and 100 wBTC.

Recommended Mitigation Steps

Consider creating a revised version of the Curve StableSwap contract that can handle dynamic balances properly.

dapp-whisperer (BadgerDAO) confirmed:

We will be creating a custom pool that takes this into account based on the rate_multiplier variable on the MetaPools.

The original report as published on Code4rena, by WatchPug. 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 Curve StableSwap pool assumes token balances are static and does not account for tokens whose balances change dynamically, such as wibBTC whose balance grows with pricePerShare.

Impact

Liquidity providers could receive less than expected when removing liquidity because the pool's recorded balance does not reflect the actual dynamic balance of wibBTC.

What the attacker needed

WibBTC token with increasing pricePerShare; Curve StableSwap pool for wibBTC; liquidity provider adds and later removes liquidity

The fix

The project should create a revised version of the Curve StableSwap contract that can handle dynamic balances properly, as the team confirmed they will do.

How it was found

  1. The Curve pool is newly created with 0 liquidity and pricePerShare is 1.
  2. Alice adds 100 wibBTC and 100 wBTC to the pool, holding 100% of the pool.
  3. After 1 month with no activity, the pricePerShare of ibBTC increases to 1.2.
  4. Alice removes all liquidity from the pool.
  5. Alice receives only 100 wibBTC and 100 wBTC instead of the expected 150 wibBTC and 100 wBTC.

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.

Some tokens, like wibBTC, automatically increase in value over time, so the number of tokens you hold stays the same but each token is worth more. A Curve pool, however, keeps a fixed record of how many tokens it holds and does not update that record when the token's value changes. This mismatch means that when you take your money out, you might get less than you should.

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 WatchPug

View all

197 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.