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

pengun - Dca.vy: Stealing User Funds Provided for DCA by Creating a New Pool and Manipulating Price #58

Closed
sherlock-admin opened this issue Jul 5, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jul 5, 2023

pengun

high

�Dca.vy: Stealing User Funds Provided for DCA by Creating a New Pool and Manipulating Price

Summary

In execute_dca_order function of Dca.vy contract which allows users to exploit DCA trades by creating custom tokens, manipulating pool prices, and consequently, draining user funds.

Vulnerability Detail

The execute_dca_order function enables the execution of DCA trades. It uses the Uniswap pool's TWAP price calculated by the _calc_min_amount_out function to ensure that trades are conducted at an appropriate price.

Users can specify a trading path of up to three lengths. An attacker can exploit this by creating custom tokens, manipulating pool prices, and consequently draining funds intended for DCA trades.

The _calc_min_amount_out function serves as a sort of slippage control, but since users can define the trade path, an attacker can set this value to 0 and drain user funds. If the result of getTwap is 0, _calc_min_amount_out is calculated as 0.

twap_value: uint256 = Univ3Twap(TWAP).getTwap(_path, _fees, _twap_length)

The vulnerability occurs when getSqrtTwapX96 from Univ3Twap.sol returns a value so large that it results in zero for the TWAP. This behavior can be observed on the Arbitrum mainnet.

An exploitation scenario could look like this:

  1. User A places a DCA order to buy a certain amount of WBTC with USDT every day.
  2. The attacker deploys token B, creates a USDT-token B pair, and sets the value of token B to be extremely high.
  3. The attacker creates a token B-WBTC pool and sets the value of token B to be extremely low.
  4. The attacker executes the DCA order with the path set to [USDT, token B, WBTC].
  5. min_amount_out is set to 0, and User A receives almost no WBTC.
  6. The attacker withdraws from the LP, draining User A's funds.

Impact

The exploit can lead to substantial financial loss for users who engage in DCA trades as they could lose their funds to attackers who manipulate token prices.

Code Snippet

https://github.com/sherlock-audit/2023-06-unstoppable/blob/main/unstoppable-dex-audit/contracts/spot-dex/Dca.vy#L268
https://github.com/sherlock-audit/2023-06-unstoppable/blob/main/unstoppable-dex-audit/contracts/utils/Univ3Twap.sol#L55
https://github.com/sherlock-audit/2023-06-unstoppable/blob/main/unstoppable-dex-audit/contracts/utils/Univ3Twap.sol#L41-L49

Tool used

Manual Review

Recommendation

To prevent such exploitation, it is recommended to adopt an external price feed, such as Chainlink oracle, when calculating min_amount_out. This ensures that the trades are based on accurate and trusted price data that is less susceptible to manipulation.

Duplicate of #182

@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jul 10, 2023
@sherlock-admin2 sherlock-admin2 added the Reward A payout will be made for this issue label Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

2 participants