Skip to content
Business logic Audit finding Intermediate

[WP-H7] InsuranceFund#syncDeps() may cause users’ fund loss

The InsuranceFund contract allows governance to change the VUSD token address at any time, which can cause users to lose funds if the change occurs between their deposit and withdrawal. An attacker (or governance) could change the token address so that a user withdrawing shares receives a different token with zero balance.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2022-02-hubble/blob/ed1d885d5dbc2eae24e43c3ecbf291a0f5a52765/contracts/InsuranceFund.sol#L116-L119

function syncDeps(IRegistry _registry) public onlyGovernance {
    vusd = IERC20(_registry.vusd());
    marginAccount = _registry.marginAccount();
}

The Governance address can call InsuranceFund.sol#syncDeps() to change the contract address of vusd anytime.

However, since the tx to set a new address for vusd can get in between users’ txs to deposit and withdraw, in some edge cases, it can result in users’ loss of funds.

Proof of Concept

  1. Alice deposited 1,000,000 VUSD to InsuranceFund;
  2. Gov called syncDeps() and set vusd to the address of VUSDv2;
  3. Alice called withdraw() with all the shares and get back 0 VUSDv2.

As a result, Alice suffered a fund loss of 1,000,000 VUSD.

Recommended Mitigation Steps

  1. Consider making vusd unchangeable;
  2. If a possible migration of vusd must be considered, consider changing the syncDeps() to:
function syncDeps(IRegistry _registry) public onlyGovernance {
    uint _balance = balance();
    vusd = IERC20(_registry.vusd());
    require(balance() >= _balance);
    marginAccount = _registry.marginAccount();
}

atvanguard (Hubble) acknowledged and commented:

Acknowledging but yes system heavily relies on the admins to do the right thing, the right way. We might remove several such upgradeability rights during a broader refactor of the entire system.

moose-code (judge) decreased severity to Medium and commented:

Downgrading to medium as this is largely admin related.


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 contract allows the governance address to change the vusd token address without ensuring that existing balances are preserved or that the change is atomic with respect to user deposits and withdrawals.

Impact

In edge cases, a user could lose all deposited funds if the token address is changed between deposit and withdrawal; the report notes this is largely admin-related and was downgraded to medium severity.

What the attacker needed

Governance calls syncDeps(); user has deposited funds; user withdraws after token change

The fix

The report recommends making vusd unchangeable or adding a balance check after changing the token address to ensure the fund's balance does not decrease.

How it was found

  1. Alice deposited 1,000,000 VUSD to InsuranceFund.
  2. Governance called syncDeps() and set vusd to the address of VUSDv2.
  3. Alice called withdraw() with all the shares and got back 0 VUSDv2.

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 is a smart contract bug where an admin can swap the token used by a savings fund. If a user deposits one token and the admin switches to a different token before the user withdraws, the user might get nothing back. It relies on the admin acting, but the code allows it.

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