Skip to content
Business logic Audit finding Intermediate

removeToken would break the vault/protocol.

The Manager contract's removeToken function lacks safety checks, so removing a token while a vault holds it locks those tokens and corrupts the vault's accounting. An attacker or careless admin could call it to make user balances unwithdrawable and crash the share price.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005

Impact

There’s no safety check in Manager.sol’s removeToken. Manager.sol#L454-L487

  1. The token would be locked in the original vault. Given the current design, the vault would keep a ratio of total amount to save the gas. Once the token is removed at manager contract, these token would lost.
  2. Controller’s balanceOf would no longer reflects the real value. Controller.sol#L488-L495 While _vaultDetails[msg.sender].balance; remains the same, user can nolonger withdraw those amount.
  3. Share price in the vault would decrease drastically. The share price is calculated as totalValue / totalSupply Vault.sol#L217. While the totalSupply of the share remains the same, the total balance has drastically decreased.

Calling removeToken way would almost break the whole protocol if the vault has already started. I consider this is a high-risk issue.

Proof of Concept

We can see how the vault would be affected with below web3.py script.

print(vault.functions.balanceOfThis().call())
print(vault.functions.totalSupply().call())
manager.functions.removeToken(vault.address, dai.address).transact()
print(vault.functions.balanceOfThis().call())
print(vault.functions.totalSupply().call())

output

100000000000000000000000
100000000000000000000000
0
100000000000000000000000

Tools Used

Hardhat

Recommended Mitigation Steps

Remove tokens from a vault would be a really critical job. I recommend the team cover all possible cases and check all components’ states (all vault/ strategy/ controller’s state) in the test.

Some steps that I try to come up with that is required to remove TokenA from a vault.

  1. Withdraw all tokenA from all strategies (and handle it correctly in the controller).
  2. Withdraw all tokenA from the vault.
  3. Convert all tokenA that’s collected in the previous step into tokenB.
  4. Transfer tokenB to the vault and compensate the transaction fee/slippage cost to the vault.

transferAndCall (yAxis) acknowledged:

Removing a token is understood as a critical (and possibly nuclear) operation within this architecture. We knew we would have to first withdraw all of the identified token from strategies, but what was missed was converting that token to another (without withdrawing, as that would be too much centralization).

Proposed method of resolution:

  • Withdraw all tokenA from all strategies (this sends it to the vault)
  • Swap tokenA for tokenB in the vault (requires implementing a new function to be called by the strategist)
  • Remove the token via the Manager function

transferAndCall (yAxis) confirmed and patched:

Please review https://github.com/code-423n4/2021-09-yaxis/pull/5 to check resolution.

GalloDaSballo (judge) commented:

Removing a token can cause accounting errors, stuck funds and break some of the functionality

Adding additional checks to prevent removing the token until all tokens have been migrated may be the simplest path forward

Sponsor has mitigated by adding custom functionality, however it is up to them to enforce that the vault has no token left before removing it, adding a couple extra checks may provide a guarantee against admin privileged abuses

The original report as published on Code4rena, by jonah1005. 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 removeToken function deletes a token from the vault's accounting without first withdrawing or converting the token's balance, leaving funds stranded and totals inconsistent.

Impact

Tokens held by the vault become locked, user balances can no longer be withdrawn, and the vault's share price drops sharply; the report says this would almost break the whole protocol if the vault has already started.

What the attacker needed

Manager privileges to call removeToken; vault already holds the token

The fix

The team added a process to withdraw tokens from strategies, swap them in the vault, and then remove the token, and the judge suggested extra checks to ensure no tokens remain before removal.

How it was found

  1. Check the vault's token balance and total supply.
  2. Call removeToken on the manager for the vault and that token.
  3. Check the vault's balance and total supply again; the balance is zero while supply is unchanged.

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 users' tokens and tracks how much each user owns. The manager contract can remove a token from the vault's list, but it does not first move the tokens out. If tokens are still inside, they become stuck and the vault's records no longer match reality, so users cannot withdraw and the value per share drops.

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 jonah1005

View all

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