Malicious actor can steal funds from other depositors
Summary
Right after the InsuranceFund contract creation, the first depositor will receive exactly 1 share for 1 depositted vusd token. Then the depositor can inflate the share price to a very high amount, to price out other depositors.
Vulnerability Detail
If the ratio _totalSupply / _pool is very high when depositting, the amount of minted shares received by the depositor can be rounded down to zero. Right after the InsuranceFund contract creation, a malicious actor can frontrun the first depositor, depositing the smallest unit of VUSD token and receiving 1 share, setting the supply and VUSD balance to 1.
Then the malicious actor directly transfers a very high amount of vusd token to the InsuranceFund contract, so that the depositor after him will receive 0 shares for their deposit, because the ratio _totalSupply / _pool is now very high due to the transactions of the malicious actor before. This means the victim depositor depositted vusd tokens and received 0 shares, benefitting the malicious actor who can now burn their share and receive their funds back together with the victims funds, since the victim received 0 shares.
lemonmon
high
Malicious actor can steal funds from other depositors
Summary
Right after the
InsuranceFund
contract creation, the first depositor will receive exactly 1 share for 1 depositted vusd token. Then the depositor can inflate the share price to a very high amount, to price out other depositors.Vulnerability Detail
If the ratio
_totalSupply / _pool
is very high when depositting, the amount of minted shares received by the depositor can be rounded down to zero. Right after theInsuranceFund
contract creation, a malicious actor can frontrun the first depositor, depositing the smallest unit of VUSD token and receiving 1 share, setting the supply and VUSD balance to1
.https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L104-L105
Then the malicious actor directly transfers a very high amount of vusd token to the
InsuranceFund
contract, so that the depositor after him will receive 0 shares for their deposit, because the ratio_totalSupply / _pool
is now very high due to the transactions of the malicious actor before. This means the victim depositor depositted vusd tokens and received 0 shares, benefitting the malicious actor who can now burn their share and receive their funds back together with the victims funds, since the victim received 0 shares.https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L81-L82
https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L107
Impact
Any deposits can be frontrunned by a malicious actor and then be stolen, due to the victim depositors always receiving 0 shares for their deposit.
Code Snippet
https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L104-L105
https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L81-L82
https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L107
Tool used
Manual Review
Recommendation
Consider setting up a minimum deposit amount, so that totalSupply will be higher, making this exploit too expensive to be relevant for an attacker.
Or consider to initially deposit a certain amount of VUSD tokens.
Duplicate of #140