Skip to content
Business logic Audit finding Intermediate

StakedCitadel doesn’t use correct balance for internal accounting

The StakedCitadel contract's balance() function returns only the vault's token balance, not the vault plus strategy balance, so share minting and burning use an incorrect denominator. An attacker can deposit a small amount to make the balance non-zero and then deposit more to receive far more shares than deserved, allowing them to withdraw more tokens than they should.

Ruhum Follow

Originally disclosed on Code4rena

Submitted by Ruhum, also found by cccz, wuwe1, VAD37, TrungOre, shenwilly, minhquanym, kyliek, danb, gs8nrv, and rayn

https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L291-L295

https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L772-L776

https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L881-L893

Impact

The StakedCitadel contract’s balance() function is supposed to return the balance of the vault + the balance of the strategy. But, it only returns the balance of the vault. The balance is used to determine the number of shares that should be minted when depositing funds into the vault and the number of shares that should be burned when withdrawing funds from it.

Since most of the funds will be located in the strategy, the vault’s balance will be very low. Some of the issues that arise from this:

You can’t deposit to a vault that already minted shares but has no balance of the underlying token:

  1. fresh vault with 0 funds and 0 shares
  2. Alice deposits 10 tokens. She receives 10 shares back (https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L887-L888)
  3. Vault’s tokens are deposited into the strategy (now balance == 0 and totalSupply == 10)
  4. Bob tries to deposit but the transaction fails because the contract tries to divide by zero: https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L890 (pool == balance())

You get more shares than you should

  1. fresh vault with 0 funds and 0 shares
  2. Alice deposits 10 tokens. She receives 10 shares back (https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L887-L888)
  3. Vault’s tokens are deposited into the strategy (now balance == 0 and totalSupply == 10)
  4. Bob now first transfers 1 token to the vault so that the balance is now 1 instead of 0.
  5. Bob deposits 5 tokens. He receives 5 * 10 / 1 == 50 shares: https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L890

Now, the vault received 15 tokens. 10 from Alice and 5 from Bob. But Alice only has 10 shares while Bob has 50. Thus, Bob can withdraw more tokens than he should be able to.

It simply breaks the whole accounting of the vault.

Proof of Concept

The comment says that it should be vault’s + strategy’s balance: https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L291-L295

Here’s another vault from the badger team where the function is implemented correctly: https://github.com/Badger-Finance/badger-vaults-1.5/blob/main/contracts/Vault.sol#L262

Recommended Mitigation Steps

Add the strategy’s balance to the return value of thebalance() function like here.

GalloDaSballo (BadgerDAO) confirmed and commented:

Agree balance must have been changed by mistake or perhaps earn should not transfer to a strategy either would work


The original report as published on Code4rena, by Ruhum. 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 balance() function returns only the vault's own token balance instead of the sum of the vault and strategy balances, so share calculations use a denominator that is usually zero or artificially small.

Impact

An attacker could obtain more shares than they should and later withdraw more tokens than they deposited, breaking the vault's accounting; the report also notes that deposits can fail entirely when the vault balance is zero.

What the attacker needed

Vault has shares but zero token balance; attacker can transfer tokens directly to the vault

The fix

The balance() function should be fixed to return the vault balance plus the strategy balance, as in the referenced Badger vault implementation.

How it was found

  1. Start with a fresh vault that has zero funds and zero shares.
  2. Alice deposits 10 tokens and receives 10 shares.
  3. The vault's tokens are moved into the strategy, leaving the vault balance at zero while total supply is 10.
  4. Bob transfers 1 token directly to the vault so its balance becomes 1 instead of 0.
  5. Bob deposits 5 tokens and receives 50 shares because the calculation uses the vault balance of 1.

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 vault is a smart contract that holds other people's tokens and gives them shares in return. The number of shares you get should depend on the total tokens the vault controls, but here it only counted tokens sitting directly in the vault, not tokens moved to a separate strategy contract. By sending a tiny amount first, an attacker could make the maths produce far too many shares for themselves.

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 Ruhum

View all

55 more disclosed reports, best first.

More from Badger Citadel 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.