-
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
calculates minOut
variable incorrectly which will cause the protocol to lose money on Curve swaps
#970
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
duplicate-1558
edited-by-warden
high quality report
This report is of especially high quality
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Comments
code423n4
added
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
labels
Sep 3, 2023
bytes032 marked the issue as duplicate of #2172 |
bytes032 marked the issue as not a duplicate |
bytes032 marked the issue as primary issue |
c4-pre-sort
added
the
primary issue
Highest quality submission among a set of duplicates
label
Sep 12, 2023
This was referenced Sep 12, 2023
Closed
bytes032 marked the issue as high quality report |
c4-pre-sort
added
the
high quality report
This report is of especially high quality
label
Sep 14, 2023
c4-sponsor
added
the
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
label
Sep 25, 2023
witherblock (sponsor) confirmed |
c4-judge
added
duplicate-1558
and removed
primary issue
Highest quality submission among a set of duplicates
labels
Oct 18, 2023
GalloDaSballo marked issue #1558 as primary and marked this issue as a duplicate of 1558 |
GalloDaSballo marked the issue as satisfactory |
c4-judge
added
the
satisfactory
satisfies C4 submission criteria; eligible for awards
label
Oct 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
duplicate-1558
edited-by-warden
high quality report
This report is of especially high quality
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L544-L558
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/reLP/ReLPContract.sol#L273-L275
Vulnerability details
When
dpxETH
depegs, then eitherupperDepeg
orlowerDepeg
can be called in order to bring backdpxETH-ETH
peg. Both functions internally call_curveSwap
, which performs a swap on Curve.minOut
is one of the parameters passed to Curve and is used in order to protect protocol from too big slippage. However, it is calculated incorrectly.It is calculated in the following way:
Assume that
1 dpxETH = 1.25 ETH
in order to illustrate that. Also, assume thatslippageTolerance = 0.5%
. Then, if we want to swap1 ETH
fordpxETH
,minOut
will equal1.25 - 1.25 * 0.005 = 1.24375
(t's becausegetDpxEthPrice
returnsdpxETH
price inETH
instead of the other way around). So, in the scenario when1 dpxETH = 1.25 ETH <=> 0.8 dpxETH = 1 ETH
,_curveSwap
function will demand at least1.24375 dpxETH
for1 ETH
while the price of1 ETH
is0.8 dpxETH
.In reality, we would like to swap
dpxETH
forETH
in case1 dpxETH = 1.25 ETH
, but it can be easily calculated that in that case,minOut = 0.796
, instead of1.24375
(we swap1 dpxETH = 1.25 ETH
and we only demand0.796 ETH
in return).In the given example,
minOut
will equal0.796
instead of1.24375
, which is36.32%
slippage instead of0.5%
. In reality, however,upperDepeg
andlowerDepeg
will probably be called when thedpxETH
price is1%
off and in such a case,minOut = 0.985
instead of1.005
, which is~2.5%
slippage instead of0.5%
. Anyway, the slippage will be too big.Note: Similar error is present in the
ReLPContract::reLP
function whenmintokenAAmount
is calculated for the second time (see the second link I've provided at the beginning).Impact
Swaps on Curve will have incorrect
minOut
which will open up arbitrage opportunities and will make it possible that the protocol will just receive less money than it should each time swaps are performed.Proof of Concept
Please set the function
_curveSwap
topublic
(not necessary, but will be easier to test this way, so that we don't have to callupperDepeg
orlowerDepeg
).The point of this test is to show that
minOut
is calculated incorrectly and the test shows the scenario where we swapETH
fordpxETH
where1 dpxETH = 1.25 ETH
(in reality, the opposite swap would be performed as I wrote earlier, but the point of this test is just to show thatminOut
is calculated incorrectly).Tools Used
VS Code
Recommended Mitigation Steps
Change:
to:
Assessed type
Math
The text was updated successfully, but these errors were encountered: