-
Notifications
You must be signed in to change notification settings - Fork 3
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
RdpxV2Core._curveSwap incorrectly calculates minOut, inviting MEV attack #1416
Comments
bytes032 marked the issue as duplicate of #2172 |
bytes032 marked the issue as sufficient quality report |
bytes032 marked the issue as duplicate of #970 |
GalloDaSballo marked the issue as nullified |
Frontrunning weirdness |
According to Judge's comment on this issue #496 , I believe this issue can also fall into the same category of race condition.
|
GalloDaSballo marked the issue as partial-50 |
Formula is correct Explanation is not |
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L545-L549
Vulnerability details
Impact
The logics to compute
minOut
based on_ethToDpxEth
direction are put in wrong order. Put it in details, when_ethToDpxEth
is True,minOut
is supposed to beminDpxEthOut
which should be computed by multiplyingethAmountIn
withethPrice
instead ofDpxEthPrice
as depicted at Lines 546-547. We can estimate how much smaller theminOut
is compared to the correct one via following equation:This means, for every
x%
drop ofgetDpxEthPrice
, we would trade with an compounded drop of(x^2)%
below market price. This will open the trade to MEV attack.In the case of
lowerDepeg
, if certain conditions are met, an attacker can sandwich the transaction with a pump-and-dump ofDpxEth
, resulting in a suboptimal amount ofDpxEth
tokens received from the trade which makes the re-pegging process cost more resources.In the case of
upperDepeg
, similar conditions can be exploited, allowing an attacker to manipulate theEth
price.Proof of Concept
Scenario for lowerDepeg:
Alice initiates a
lowerDepeg
transaction with specific conditions met:getDpxEthPrice < 1e8
and_ethToDpxEth = true
.An attacker, Bob, monitors the pending transactions and identifies Alice's
lowerDepeg
transaction.Bob quickly submits a transaction that sandwiches Alice's transaction with a pump-and-dump of
DpxEth
, manipulating the price.Alice's transaction goes through but with a suboptimal amount of
DpxEth
tokens received, making the re-peg less efficient.Scenario for upperDepeg:
Alice initiates an
upperDepeg
transaction with specific conditions met:getEthPrice < 1e8
.Bob, the attacker, spots Alice's transaction.
Bob quickly submits a transaction that manipulates the
Eth
price, making Alice's transaction suboptimal in terms ofEth
received.Alice's transaction results in receiving fewer
Eth
tokens than expected.Tools Used
Manual Review
Recommended Mitigation Steps
To mitigate this vulnerability, consider switching the logic in the
_ethToDpxEth
cases to ensure that theminAmount
is set correctly for bothlowerDepeg
andupperDepeg
functions.Assessed type
MEV
The text was updated successfully, but these errors were encountered: