[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.
Submitted by WatchPug
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
- Alice deposited
1,000,000 VUSDtoInsuranceFund; - Gov called
syncDeps()and setvusdto the address ofVUSDv2; - Alice called
withdraw()with all thesharesand get back0 VUSDv2.
As a result, Alice suffered a fund loss of 1,000,000 VUSD.
Recommended Mitigation Steps
- Consider making
vusdunchangeable; - If a possible migration of
vusdmust be considered, consider changing thesyncDeps()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.
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
- Alice deposited 1,000,000 VUSD to InsuranceFund.
- Governance called syncDeps() and set vusd to the address of VUSDv2.
- 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.