To convert tokenB to tokenA, the inverse of tokenAPrice needs to be used. Formula above would give a negligible value for mintokenAAmount causing a huge slippage loss on tokenA (rDPX).
Proof of Concept
In the above case, tokenA corresponds to RDPX and tokenB corresponds to WETH. If we assume RDPX as $20 and ETH as $2000, rdpx:ETH = 0.01, ie 1 RDPX = 0.01 ETH. If amountB/2 is 1 ETH, then minTokenAAmount gives a value of 0.01 instead of 100 (for simplicity, I assume slippageTolerance=0). This would mean that this swap effectively has no slippage protection and bots can frontrun this transaction to cause significant slippage on RDPX.
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/reLP/ReLPContract.sol#L273
Vulnerability details
Impact
In line 273 of
ReLPContract
,minTokenBAmount
is calculated as:In the above,
tokenAInfo.tokenAPrice
is calculated in Line 221 as:To convert tokenB to tokenA, the inverse of
tokenAPrice
needs to be used. Formula above would give a negligible value formintokenAAmount
causing a huge slippage loss on tokenA (rDPX).Proof of Concept
In the above case, tokenA corresponds to
RDPX
and tokenB corresponds toWETH
. If we assume RDPX as $20 and ETH as $2000, rdpx:ETH = 0.01, ie 1 RDPX = 0.01 ETH. IfamountB/2
is 1 ETH, thenminTokenAAmount
gives a value of 0.01 instead of 100 (for simplicity, I assumeslippageTolerance=0
). This would mean that this swap effectively has no slippage protection and bots can frontrun this transaction to cause significant slippage on RDPX.Tools Used
Manual
Recommended Mitigation Steps
Recommend the following changes:
Assessed type
Uniswap