Skip to content
Smart contracts Audit finding Intermediate

Early depositors to DnGmxSeniorVault can manipulate exchange rates to steal funds from later depositors

The vault's share price is calculated by dividing total assets by total shares, allowing the first depositor to mint a tiny number of shares and then donate a large amount of aUSDC to inflate the share price. Later depositors then receive fewer shares than they should due to rounding, and the attacker can profit from the difference.

tives Follow with __141345__, GimelSec and 7 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-rage-trade-judging/issues/37

Found by

tives, __141345__, GimelSec, cccz, clems4ever, ctf_sec, peanuts, joestakey, rvierdiiev, 0x52

Summary

To calculate the exchange rate for shares in DnGmxSeniorVault it divides the total supply of shares by the totalAssets of the vault. The first deposit can mint a very small number of shares then donate aUSDC to the vault to grossly manipulate the share price. When later depositor deposit into the vault they will lose value due to precision loss and the adversary will profit.

Vulnerability Detail

function convertToShares(uint256 assets) public view virtual returns (uint256) {
    uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.

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

Share exchange rate is calculated using the total supply of shares and the totalAsset. This can lead to exchange rate manipulation. As an example, an adversary can mint a single share, then donate 1e8 aUSDC. Minting the first share established a 1:1 ratio but then donating 1e8 changed the ratio to 1:1e8. Now any deposit lower than 1e8 (100 aUSDC) will suffer from precision loss and the attackers share will benefit from it.

This same vector is present in DnGmxJuniorVault.

Impact

Adversary can effectively steal funds from later users

Code Snippet

https://github.com/sherlock-audit/2022-10-rage-trade/blob/main/dn-gmx-vaults/contracts/vaults/DnGmxSeniorVault.sol#L211-L221

Tool used

Manual Review

Recommendation

Initialize should include a small deposit, such as 1e6 aUSDC that mints the share to a dead address to permanently lock the exchange rate:

    aUsdc.approve(address(pool), type(uint256).max);
    IERC20(asset).approve(address(pool), type(uint256).max);

+   deposit(1e6, DEAD_ADDRESS);

Discussion

0xDosa

We will ensure a guarded launch process that safeguards the first deposit to avoid being manipulated.

Evert0x

We are still considering it a valid issue as the guarded launch process is out of scope.

The original report as published on Sherlock, by tives. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 share price using total assets and total shares without protecting against manipulation of the initial exchange rate.

Impact

The attacker can effectively steal funds from later depositors.

What the attacker needed

Attacker is first depositor; attacker can donate aUSDC to vault

The fix

The vault should be initialized with a small deposit (e.g., 1e6 aUSDC) that mints shares to a dead address to permanently lock the exchange rate.

How it was found

  1. Attacker mints a single share by making the first deposit.
  2. Attacker donates a large amount of aUSDC directly to the vault, changing the ratio to 1:1e8.
  3. Later depositors deposit less than 1e8 aUSDC and suffer precision loss, benefiting the attacker's share.

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 vault where people deposit funds and get shares in return. The share price is based on how much money is in the vault divided by the number of shares. An attacker can be the first to deposit a tiny amount, then donate a large sum directly to the vault, making each share very expensive. When others deposit, they get fewer shares than they should because of rounding, and the attacker can later withdraw more than they put in.

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 tives

View all

1 more disclosed report, best first.

More from Rage Trade

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.