Assessment reports>SushiSwap RouteProcessor3>Threat Models>processRouteInternal

Function: processRouteInternal(address tokenIn, uint256 amountIn, address tokenOut, uint256 amountOutMin, address to, bytes memory route)

This private function handles calls to the processRoute and transferValueAndprocessRoute public functions.

It processes the route defined by the caller one step at a time, performing the requested operations by dispatching the task to appropriate subfunctions.

Inputs

  • tokenIn

    • Control: Arbitrary.

    • Constraints: Should be an ERC20 token address or 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.

    • Impact: Determines the asset used as input for applyPermit and input balance checks.

  • amountIn

    • Control: Arbitrary.

    • Constraints: None.

    • Impact: Determines the amount of input asset to be used by the route.

  • tokenOut

    • Control: Arbitrary.

    • Constraints: Should be an ERC20 token address or 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.

    • Impact: Determines the asset used as output for the transaction.

  • amountOutMin

    • Control: Arbitrary.

    • Constraints: None.

    • Impact: Determines the minimum amount of output asset resulting from the transaction (slippage protection).

  • to

    • Control: Arbitrary.

    • Constraints: None.

    • Impact: Determines the intented recipient of the output asset.

  • route

    • Control: Arbitrary.

    • Constraints: None.

    • Impact: Determines the route (sequence of operations and parameters) to be used.

Branches and code coverage (including function calls)

The function first reads the initial input and output balances to be used at the end for the slippage protection checks.

The route byte buffer is read to identify the required steps in the route. Every step is represented by a byte in the stream (with values from 1 to 6), followed by the data required to perform that step. Only the first byte required to identify the required operation is read by processRouteInternal; the route byte stream is passed to functions implementing the details of each specific operation.

Finally, the function reads the final balances and ensures they satisfy the minimum expected values to protect against slippage, MEV, and other risks.

Intended branches

  • ERC20 swap operations using address(this) balance are handled (processMyERC20).

  • ERC20 swap operations using the msg.sender balance are handled (processUserERC20).

  • ETH swap operations using the address(this) balance are handled (processNative).

  • ERC20 operations using the address(this) balance already in the pool are handled (processOnePool).

  • Swap operations with Bento tokens are handled (processInsideBento).

  • ERC20 permit operations are handled (applyPermit).

  • Anti-slippage checks are performed.

Negative behavior

  • Invalid operations (commandCode not between 1 and 6) cause a revert.

  • Unexpected final input balance causes a revert.

  • Unexpected final output balance causes a revert.

Zellic © 2024Back to top ↑