_curveSwap() wrong formula #1802
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
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L546
Vulnerability details
Impact
RdpxV2Core._curveSwap
An error in the formula for calculating the minimum amount ofminOut
fordpxEth
may cause the slippage protection to fail.Proof of Concept
_curveSwap()
The code implementation is as follows:From the code above we know that if
_ethToDpxEth=true
uses the formulaminOut = (((_amount * getDpxEthPrice()) / 1e8) - (((_amount * getDpxEthPrice()) * slippageTolerance) / 1e16))
but
getDpxEthPrice()
is thedpxEth
price.The correct formula should be
_amount * 1e8 / getDpxEthPrice()
Tools Used
Recommended Mitigation Steps
Assessed type
Context
The text was updated successfully, but these errors were encountered: