Swaps are not split when trade crosses target price #216
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
cmichel
Vulnerability details
The protocol uses two amplifier values A1 and A2 for the swap, depending on the target price, see
SwapUtils.determineA
.The swap curve is therefore a join of two different curves at the target price.
When doing a trade that crosses the target price, it should first perform the trade partially with A1 up to the target price, and then the rest of the trade order with A2.
However, the
SwapUtils.swap / _calculateSwap
function does not do this, it only uses the "new A", seegetYC
step 5.Impact
Trades that cross the target price and would lead to a new amplifier being used are not split up and use the new amplifier for the entire trade.
This can lead to a worse (better) average execution price than manually splitting the trade into two transactions, first up to but below the target price, and a second one with the rest of the trader order size, using both A1 and A2 values.
In the worst case, it could even be possible to make the entire trade with one amplifier and then sell the swap result again using the other amplifier making a profit.
Recommended Mitigation Steps
Trades that lead to a change in amplifier value need to be split up into two trades using both amplifiers to correctly calculate the swap result.
The text was updated successfully, but these errors were encountered: