Skip to content
Business logic Audit finding Intermediate

Controller.setCap sets wrong vault balance

The Controller.setCap function reduced the recorded vault balance by the whole strategy balance rather than only the excess amount withdrawn. This made the vault balance understated, so depositors received too many shares and could later redeem them for more than they put in, draining tokens from the vault.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The Controller.setCap function sets a cap for a strategy and withdraws any excess amounts (_diff). The vault balance is decreased by the entire strategy balance instead of by this _diff:

// @audit why not sub _diff?
_vaultDetails[_vault].balance = _vaultDetails[_vault].balance.sub(_balance);

Impact

The _vaultDetails[_vault].balance variable does not correctly track the actual vault balances anymore, it will usually underestimate the vault balance. This variable is used in Controller.balanceOf(), which in turn is used in Vault.balance(), which in turn is used to determine how many shares to mint / amount to receive when redeeming shares. If the value is less, users will lose money as they can redeem fewer tokens. Also, an attacker can deposit and will receive more shares than they should receive. They can then wait until the balance is correctly updated again and withdraw their shares for a higher amount than they deposited. This leads to the vault losing tokens.

Recommended Mitigation Steps

Sub the _diff instead of the balance: _vaultDetails[_vault].balance = _vaultDetails[_vault].balance.sub(_diff);

Haz077 (yAxis) confirmed and patched:

Already fixed in code-423n4/2021-09-yaxis#1

GalloDaSballo (judge) commented:

Finding is valid, has been mitigated by sponsor as of 14 days ago

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 code subtracted the full strategy balance from the vault balance instead of subtracting only the excess amount being withdrawn.

Impact

The vault balance is understated, so users can redeem fewer tokens and an attacker can deposit for excess shares and later withdraw more than deposited, causing the vault to lose tokens.

What the attacker needed

Attacker can deposit into the vault; setCap is called with excess to withdraw

The fix

The balance should be reduced by the excess amount only, not the whole strategy balance; the report says this was patched.

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 keeps a running record of how much money it holds, and that record decides how many shares each person gets when they deposit. Here the record was reduced by too much, so the vault looked poorer than it really was. That let someone deposit and get extra shares, then cash them out later for a profit at the vault's expense.

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