Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First PublicVault depositor can be front-run and have part of their deposit stolen #509

Closed
code423n4 opened this issue Jan 19, 2023 · 3 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-588 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-01-astaria/blob/main/src/PublicVault.sol#L251-L265
https://github.com/AstariaXYZ/astaria-gpl/blob/4b49fe993d9b807fe68b3421ee7f2fe91267c9ef/src/ERC4626-Cloned.sol#L112

Vulnerability details

Description

The first deposit with a totalSupply of zero shares will mint shares equal to the deposited amount.

File: lib/gpl/src/ERC4626-Cloned.sol

112:     return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets());

Link to Code

File: PublicVault.sol

    function deposit(uint256 amount, address receiver)
      public
      override(ERC4626Cloned)
      whenNotPaused
      returns (uint256)
    {
      VIData storage s = _loadVISlot();
      if (s.allowListEnabled) {
        require(s.allowList[receiver]);
      }

      uint256 assets = totalAssets();

      return super.deposit(amount, receiver);
    }

Link to Code

Problems with the code:

  1. Integer division negatively affect the user.
  2. Can be manipulated to cause a large loss, specifically for first victim.

Impact

It can lead to some part of Fund getting stolen from First Depositor (which will be the LP Provider).

Proof of Concept

Consider the following situation:

  1. Attacker deposits 1 wei of WETH.
  2. Next, Attacker transfers 100 WETH to the contract.
  3. Victim deposits 200 WETH.
  4. Attacker withdraws 1 share.

Here is the Detail analysis of the above PoC done by Spearbit.

This analysis confirms this clear Path of attack which can be used by the attacker.

Tools Used

Manual Review

Recommended Mitigation Steps

  1. Need to Enforce a minimum deposit that can't be withdrawn.
  2. So, mint some of the initial amount to the zero address.
  3. Most legit first depositors will mint thousands of shares, so not a big cost.
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 19, 2023
code423n4 added a commit that referenced this issue Jan 19, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as primary issue

@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Jan 23, 2023
@c4-judge c4-judge added duplicate-588 and removed primary issue Highest quality submission among a set of duplicates labels Jan 23, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #588

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 24, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-588 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants