Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

0xDjango - First depositor can break minting of shares #140

Closed
sherlock-admin opened this issue Jul 3, 2023 · 3 comments
Closed

0xDjango - First depositor can break minting of shares #140

sherlock-admin opened this issue Jul 3, 2023 · 3 comments
Labels
Low/Info A valid Low/Informational severity issue Non-Reward This issue will not receive a payout Sponsor Confirmed The sponsor acknowledged this issue is valid

Comments

@sherlock-admin
Copy link
Contributor

0xDjango

high

First depositor can break minting of shares

Summary

The common "first depositor" vulnerability is found in InsuranceFund.depositFor(). The first account to deposit into the insurance fund can steal value from subsequent depositors by:

  • Minting 1 wei shares
  • Directly transferring assets into the contract to inflate the poolValue
  • Subsequent depositors deposit assets but are minted 0 shares due to precision loss
  • First depositor steals the assets

Vulnerability Detail

The depositor's shares are calculated via:

        if (_pool == 0) {
            shares = amount;
        } else {
            shares = amount * _totalSupply / _pool;
        }

Upon first deposit, the _pool value will be 0. The attacker will transact with an amount = 1 wei to mint 1 wei of shares. Then the attacker will transfer some value of asset directly to the contract. For this example, the attacker transfers 10,000 USDC.

Next, a subsequent depositor attempts to mint shares with 5,000 VUSD.

shares = 5000 ether * 1 wei / 10,000 ether = 0 due to precision loss.

The attacker can now withdraw the second depositor's assets.

Impact

  • Theft of deposits

Code Snippet

https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/InsuranceFund.sol#L104-L108

Tool used

Manual Review

Recommendation

Mint a certain number of shares and transfer them to address(0) within the initialize() function.

@github-actions github-actions bot added High A valid High severity issue Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Jul 10, 2023
This was referenced Jul 10, 2023
@0xshinobii 0xshinobii added the Sponsor Confirmed The sponsor acknowledged this issue is valid label Jul 18, 2023
@0xshinobii
Copy link

This issue was already mentioned in code arena audit. As done in v1, this will be fixed by adding the initial amount to the insurance fund from Hubble at the time of deployment.

@hrishibhat
Copy link

@ctf-sec this issue was already reported in the previous contest. Shouldn't this be low?

@hrishibhat
Copy link

hrishibhat commented Aug 4, 2023

Considering this a low issue since it was already found in the previous audit.
https://github.com/sherlock-audit/2023-04-hubble-exchange#q-please-provide-links-to-previous-audits-if-any
And this is acknowledged to by the protocol.
#140 (comment)

@sherlock-admin sherlock-admin added Non-Reward This issue will not receive a payout and removed Reward A payout will be made for this issue labels Aug 4, 2023
@sherlock-admin2 sherlock-admin2 removed High A valid High severity issue Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Aug 6, 2023
@sherlock-admin2 sherlock-admin2 added the Low/Info A valid Low/Informational severity issue label Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Low/Info A valid Low/Informational severity issue Non-Reward This issue will not receive a payout Sponsor Confirmed The sponsor acknowledged this issue is valid
Projects
None yet
Development

No branches or pull requests

4 participants