SwapperImpl.sol contract uses discount oracle pricing to incentivize third parties to automatically convert multi-token revenue into a single token & forward to beneficiary. The price of the user's exchange tokens is calculated by $oracle.
But in the _transferToTrader function, directly use quoteParams_.quotePair.base as tokenToTrader (the base and queto are not sorted). In some cases, the token pair used to calculate the price and the actual transfer is opposite, and the attacker can use this to steal the funds in the contract.
For example,
Suppose there are TokenA and TokenB, their addresses are 0xAAAA and 0xBBBB respectively, and their values are 100 USDC and 1 USDC respectively
The attacker packs them into a QuoteParams and passes them to the flash function
J4de
high
SwapperImpl.sol#_transferToTrader
price may not match expectationsSummary
SwapperImpl.sol#_transferToTrader
price may not match expectationsVulnerability Detail
SwapperImpl.sol
contract uses discount oracle pricing to incentivize third parties to automatically convert multi-token revenue into a single token & forward to beneficiary. The price of the user's exchange tokens is calculated by$oracle
.The
_getQuoteAmount
function will sort the addresses of the two tokens from small to large.But in the
_transferToTrader
function, directly usequoteParams_.quotePair.base
astokenToTrader
(the base and queto are not sorted). In some cases, the token pair used to calculate the price and the actual transfer is opposite, and the attacker can use this to steal the funds in the contract.For example,
Suppose there are TokenA and TokenB, their addresses are
0xAAAA
and0xBBBB
respectively, and their values are 100 USDC and 1 USDC respectivelyThe attacker packs them into a
QuoteParams
and passes them to theflash
function$oracle.getQuoteAmounts
will sort the tokens when calculating the price, and the obtained quantity isThen, the attacker can obtain 1000 TokenB (worth 100,000 USDC) and consume 10 TokenA (worth 10 USDC)
Impact
Attackers can steal funds inside the contract
Code Snippet
https://github.com/0xSplits/splits-swapper/blob/83ce1124767a097aac37d1cd162a9b27bbc48701/src/SwapperImpl.sol#L227-L255
Tool used
Manual Review
Recommendation
It is recommended that the
flash
function transfer also sort the tokens to maintain consistency with the calculated price