Using single total native reserve variable for synth and non-synth reserves of VaderPoolV2 can lead to losses for synth holders
The pool used a single total native reserve variable for both synth minters and liquidity providers, so when a non-synth LP exited they could withdraw native assets deposited by synth minters. A large enough LP exit could leave synth minters with substantially less native asset than they deposited, causing losses for synth holders.
Submitted by hyh, also found by certora
Users that mint synths do provide native assets, increasing native reserve pool, but do not get any liquidity shares issued. In the same time, an exit of non-synth liquidity provider yields releasing a proportion of all current reserves to him.
Whenever an exit of non-synth LP is substantial enough, the system will have much less native asset regarding the cumulative deposit of synth holders. That is, when a LP entered he provided a share of current reserves, both native and foreign, and got the corresponding liquidity shares in return. Suppose then big enough amounts of synths were minted, providing correspondingly big enough amount of native assets. If the LP now wants to exit, he will obtain a part of total native assets, including a part of the amount that was provided by synth minter. If the exit is big enough there will be substantially less native assets left to reimburse the synth minter than he initially provided. This is not reversible: the synth minters lost their native assets to LP that exited.
Proof of Concept
There are three types of mint/burn: NFT, fungible and synths. First two get LP shares, the latter gets synths. Whenever NFT or fungible LP exits, it gets a proportion of combined reserves. That is, some of native reserves were deposited by synth minters, but it is not accounted anyhow, only one total reserve number per asset is used.
Suppose the following scenario, Alice wants to provide liquidity, while Bob wants to mint synths:
- Alice deposits both sides to a pool, 100 USDV and 100 foreign.
- Bob deposit 100 USDV and mints some foreign Synth.
- LP withdraws 95% of her liquidity shares. As she owns the pool liquidity, she gets 95% of USDV and foreign total reserves, 190 USDV and 95 foreign. Alice received almost all of her and Bob’s USDV.
- If Bob burn his synth and withdraw, he will get a tiny fraction of USDV he deposited (calculated by VaderMath.calculateSwap, we use its terms):
https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex/math/VaderMath.sol#L98 x = 100, X = 0.05 * 200 = 10, Y = 0.05 * 100 = 5. Swap outcome, how much USDV will Bob get, is x * Y * X / (x + X) ^ 2 = 100 * 5 * 10 / (110^2) = 0.4 (rounded).
The issue is that synth provided and LP provided USDV aren’t accounted separately, total reserves number if used everywhere instead:
Synth minters provide native asset, say USDV, to the system: https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/VaderPoolV2.sol#L187
Synth minters get synths and no LP shares, while to account for their deposit, the total USDV balance is increased: https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/VaderPoolV2.sol#L187
When LP enters, it gets liquidity shares proportionally to current reserves (NFT mint, notice the reserveNative, which is BasePoolV2’s pair.reserveNative, total amount of native asset in the Pool): https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/BasePoolV2.sol#L497
When LP exits, it gets a proportion of current reserves back (NFT burn): https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/BasePoolV2.sol#L223
The same happens when fungible LP mints (same reserveNative): https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/VaderPoolV2.sol#L336 And burns: https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/VaderPoolV2.sol#L401
Recommended Mitigation Steps
Account for LP provided liquidity separately from total amount variables, i.e. use only LP provided native reserves variables in LP shares mint and burn calculations. That should suffice as total amount of native assets is still to be used elsewhere, whenever the whole pool is concerned, for example, in rescue function, swap calculations and so forth.
SamSteinGG (Vader) acknowledged
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 pool used a single total native reserve variable for both LP-provided and synth-provided native assets, so LP share mint and burn calculations included synth deposits that LPs never contributed.
Impact
Synth minters could lose their native assets to exiting non-synth LPs, with the loss being irreversible once the LP has exited.
What the attacker needed
A non-synth LP with a large share of the pool; synth minters have deposited native assets; LP exits after synth minting
The fix
The LP share mint and burn calculations should use only LP-provided native reserve variables, keeping total native reserves for other pool-wide uses such as swaps and rescue functions.
How it was found
- Alice deposits 100 USDV and 100 foreign tokens into the pool as a liquidity provider.
- Bob deposits 100 USDV and mints foreign synths, receiving no LP shares.
- Alice withdraws 95% of her liquidity shares and receives 95% of total reserves, including Bob's USDV.
- Bob burns his synth and withdraws, receiving only a tiny fraction of the USDV he deposited.
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.
A liquidity pool holds two kinds of assets: native tokens and foreign tokens. Some users add both kinds and receive pool shares; others add only native tokens to create synthetic assets (synths) and receive no pool shares. The bug is that the pool tracked only one total native reserve, so when a share-holding user left, they could take some of the native tokens that synth creators had put in, leaving synth creators short.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.