Skip to content
Smart contracts Audit finding Intermediate

InsuranceFund depositors can be priced out & deposits can be stolen

The InsuranceFund deposit function mints shares based on the contract's VUSD balance, allowing an attacker to inflate the share price and steal deposits. An attacker can deposit a tiny amount, directly transfer a large amount of VUSD to the contract, causing subsequent deposits to mint zero shares, then withdraw their single share to take the entire pool balance.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by danb

https://github.com/code-423n4/2022-02-hubble/blob/8c157f519bc32e552f8cc832ecc75dc381faa91e/contracts/InsuranceFund.sol#L44-L54

The InsuranceFund.deposit function mints initial shares equal to the deposited amount. The deposit / withdraw functions also use the VUSD contract balance for the shares computation. (balance() = vusd.balanceOf(address(this)))

It’s possible to increase the share price to very high amounts and price out smaller depositors.

Proof of Concept

  • deposit(_amount = 1): Deposit the smallest unit of VUSD as the first depositor. Mint 1 share and set the total supply and VUSD balance to 1.
  • Perform a direct transfer of 1000.0 VUSD to the InsuranceFund. The balance() is now 1000e6 + 1
  • Doing any deposits of less than 1000.0 VUSD will mint zero shares: shares = _amount * _totalSupply / _pool = 1000e6 * 1 / (1000e6 + 1) = 0.
  • The attacker can call withdraw(1) to burn their single share and receive the entire pool balance, making a profit. (balance() * _shares / totalSupply() = balance())

I give this a high severity as the same concept can be used to always steal the initial insurance fund deposit by frontrunning it and doing the above-mentioned steps, just sending the frontrunned deposit amount to the contract instead of the fixed 1000.0. They can then even repeat the steps to always frontrun and steal any deposits.

Recommended Mitigation Steps

The way UniswapV2 prevents this is by requiring a minimum deposit amount and sending 1000 initial shares to the zero address to make this attack more expensive. The same mitigation can be done here.

atvanguard (Hubble) 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 share price calculation uses the contract's token balance, which can be inflated by direct transfers, without a minimum deposit or initial share burn.

Impact

An attacker could steal the initial insurance fund deposit and potentially repeat the attack to steal any deposits by frontrunning them.

What the attacker needed

Attacker is first depositor; attacker can directly transfer VUSD

How it was found

  1. Deposit the smallest unit of VUSD as the first depositor, minting 1 share.
  2. Directly transfer a large amount of VUSD to the InsuranceFund, increasing its balance.
  3. Subsequent deposits of less than the inflated amount mint zero shares.
  4. The attacker withdraws their single share to receive the entire pool balance.

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 the value of a share in a fund can be manipulated. An attacker puts in a tiny amount first, then sends a large amount directly to the fund, making each share very expensive. Later depositors get zero shares for their money, and the attacker can withdraw everything.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by cmichel

View all

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

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.