ERRORNEOUS minOut
CALCULATION IN THE RdpxV2Core._curveSwap
FUNCTION BREAKS THE EXPECTED BEHAVIOUR OF THE PROTOCOL
#1613
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
downgraded by judge
Judge downgraded the risk level of this issue
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/main/contracts/core/RdpxV2Core.sol#L545-L549
Vulnerability details
Impact
The
RdpxV2Core._curveSwap
function is used to swap token A to token B based on the value of the_ethToDpxEth
Boolean variable._ethToDpxEth
value denotes whether swap is from ETH to dpxETH or dpxETH to ETH.Before the actual
dpxEthCurvePool.exchange
happens theminOut
value is calculated as slippage protection as shown below:If the
_ethToDpxEth is true
which means the swap is from Eth to dpxEth, the_amount
is multiplied by value returned fromgetDpxEthPrice()
. Here the_amount
is inEth
andgetDpxEthPrice()
value is inEth/DpxEth
unit with 1e8 precision. Hence it is clear this calculation is wrong. Because we want to multiply the_amount
(Eth value) by thegetEthPrice()
value and not by thegetDpxEthPrice()
value. BecausegetEthPrice()
returns thedpxEth/Eth
value in 1e8 precision which is the correct value to use to multiply the Eth_amount
to obtain the minOut value indpxEth
units.Similarly if the
_ethToDpxEth is false
which means the swap is from dpxEth to Eth, the_amount
is multiplied by value returned fromgetEthPrice()
. Here the_amount
is indpxEth
andgetEthPrice()
value is indpxEth/Eth
unit with 1e8 precision. Hence it is clear this calculation is wrong. Because we want to multiply the_amount
(dpxEth value) by thegetDpxEthPrice()
value and not by thegetEthPrice()
value. BecausegetDpxEthPrice()
returns theEth/dpxEth
value in 1e8 precision which is the correct value to use to multiply the dpxEth_amount
to obtain the minOut value inEth
units.Above error in calculating the value of
minOut
could prompt thedpxEthCurvePool.exchange
transaction to revert since we are providing the wrong slippage protection value to the actual swap happening in theexchange
transaction.This will prompt the
_curveSwap
transaction to behave in unexpected manner thus breaking the protocol unexpectedly.Proof of Concept
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/core/RdpxV2Core.sol#L545-L549
Tools Used
Manual Review and VSCode
Recommended Mitigation Steps
Hence it is recommended to correct the
minOut
value in theRdpxV2Core._curveSwap
function as shown below:The above change will ensure the correct
minOut
value is calculated based on the Boolean value of_ethToDpxEth
thus ensuring successful execution of theRdpxV2Core._curveSwap
transaction.Assessed type
Other
The text was updated successfully, but these errors were encountered: