Skip to content
Business logic Audit finding Intermediate

BadgerYieldSource balanceOfToken share calculation seems wrong

The balanceOfToken function in BadgerYieldSource incorrectly calculates a user's redeemable badger balance by using only the small amount of badger held directly in the badgerSett contract, ignoring funds deployed to strategies. This causes the reported balance to be far lower than the actual redeemable amount, leading to errors in integrations that rely on it.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

When suppling to the BadgerYieldSource, some amount of badger is deposited to badgerSett and one receives badgerSett share tokens in return which are stored in the balances mapping of the user. So far this is correct.

The balanceOfToken function should then return the redeemable balance in badger for the user’s badgerSett balance. It computes it as the pro-rata share of the user balance (compared to the total-supply of badgerSett) on the badger in the vault:

balances[addr].mul(
  badger.balanceOf(address(badgerSett))
).div(
  badgerSett.totalSupply()
)

However, badger.balanceOf(address(badgerSett)) is only a small amount of badger that is deployed in the vault (“Sett”) due to most of the capital being deployed to the strategies. Therefore, it under-reports the actual balance:

Typically, a Sett will keep a small portion of deposited funds in reserve to handle small withdrawals cheaply. Badger Docs

Any contract or user calling the balanceOf function will receive a value that is far lower than the actual balance. Using this value as a basis for computations will lead to further errors in the integrations.

Recommend using badgerSett.balance() instead of badger.balanceOf(address(badgerSett)) to also account for “the balance in the Sett, the Controller, and the Strategy”.

asselstine (PoolTogether) confirmed

The original report as published on Code4rena, by cmichel. 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 function used the badger token balance of the badgerSett contract instead of the total underlying assets held by the Sett, which includes funds in strategies.

Impact

Any contract or user calling balanceOf will receive a value far lower than the actual balance, leading to further errors in integrations that use this value.

What the attacker needed

None

The fix

The function should use badgerSett.balance() instead of badger.balanceOf(address(badgerSett)) to account for the balance in the Sett, Controller, and Strategy.

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 report is about a smart contract that tells users how much of a token they can withdraw. The contract made a mistake by only counting the tokens kept in a small reserve, not the tokens that were lent out to earn interest. So users saw a much smaller balance than they really had.

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 cmichel

View all

196 more disclosed reports, best first.

More from PoolTogether

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.