_curveSwap: getDpxEthPrice and getEthPrice is in wrong order #1558
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
M-05
primary issue
Highest quality submission among a set of duplicates
selected for report
This submission will be included/highlighted in the audit report
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/core/RdpxV2Core.sol#L545
Vulnerability details
Impact
When
_curveSwap
is called withminAmount = 0
(upperDepeg/lowerDepeg use the default slippage 0.5%), theminOut
will be a wrong value which leads to slippage protect failure.Proof of Concept
In
_curveSwap
, the getDpxEthPrice and getEthPrice is in wrong order:When
_ethToDpxEth
is true, we swap eth for dpxeth. However, we use getDpxEthPrice, which is dpxeth's price in eth (dpxeth/eth). Also, when we swap dpxeth for eth, we use getEthPrice which is eth's price in dpxeth.Below is a PoC that demonstrates we get the wrong slippage when calling
upperDepeg
with default slippage tolerance:Output:
Tools Used
Manual Review.
Recommended Mitigation Steps
Reverse the order:
Assessed type
Context
The text was updated successfully, but these errors were encountered: