Function: _swapUniswapV2(byte[1] dexId, uint256 fromAmount, byte[] payload)
This decodes the payload and conducts the swaps.
Inputs
dexId
Constraints: Should be either 0x01 or 0x02,
Impact: The ID for the DEX being used (0x01 for UniswapV2, 0x02 for SushiSwap).
fromAmount
Constraints: No constraints,
Impact: The amount of the
fromToken
being swapped.
payload
Constraints: Should be encoded in the correct format ---
abi.encode(address[] path, uint256 minAmountOut)
.Impact: The encoded payload for the swap.
Branches and code coverage (including function calls)
Intended branches
The function correctly determines the
initCodeHash
and factory based on thedexId
.The swap ratios and amounts are calculated correctly.
Negative behavior
The function reverts if the final
amountOut
is less thantoAmountMin
.
Function call analysis
_getPair(fromToken, toToken, initCodeHash, factory)
What is controllable?
fromToken
andtoToken
.If return value controllable, how is it used and how can it go wrong? The return value is used as an address for the pair; if manipulated, it can lead to swapping on the wrong pair.
What happens if it reverts, reenters, or does other unusual control flow? If this reverts, the entire call fails --- no reentrancy issues.
IUniswapPair(pairs[i]).getReserves()
What is controllable?
pairs[i]
.If return value controllable, how is it used and how can it go wrong? The return value (
reserveA
andreserveB
) impacts the calculation of swap amounts; this cannot be controlled.What happens if it reverts, reenters, or does other unusual control flow? If this reverts, the entire call fails --- no reentrancy issues.
SafeTransferLib.safeTransfer(ERC20(path[0]), pairs[0], fromAmount)
What is controllable?
path[0]
,pairs[0]
, andfromAmount
.If return value controllable, how is it used and how can it go wrong? N/A.
What happens if it reverts, reenters, or does other unusual control flow? If this reverts, the entire call fails --- no reentrancy issues.
_executeSwap(path, pairs, amounts)
What is controllable?
path
,pairs
, andamounts
.If return value controllable, how is it used and how can it go wrong? N/A.
What happens if it reverts, reenters, or does other unusual control flow? If this reverts, the entire call fails --- no reentrancy issues.