CallbackValidation

Validates that callbacks originate from legitimate VinuSwap pools.

Source: contracts/periphery/libraries/CallbackValidation.sol

Purpose

During swaps and mints, the pool calls back to the caller to receive tokens. This library ensures the callback is from a legitimate pool and not a malicious contract.

Functions

verifyCallback

function verifyCallback(
    address factory,
    address tokenA,
    address tokenB,
    uint24 fee
) internal view returns (IVinuSwapPool pool)

Verifies msg.sender is a valid pool deployed by the factory.

Parameters:

  • factory - VinuSwap factory address

  • tokenA - First token address

  • tokenB - Second token address

  • fee - Pool fee tier

Returns:

  • pool - The verified pool contract

Reverts: If msg.sender is not the expected pool address.

verifyCallback (PoolKey overload)

Same as above but accepts a PoolKey struct.

Usage

In SwapRouter

In NonfungiblePositionManager

Security

Without callback validation, an attacker could:

  1. Deploy a malicious contract mimicking a pool

  2. Call your callback handler

  3. Trick you into sending tokens to the attacker

The validation ensures:

  • msg.sender matches the computed pool address

  • The pool was deployed by the legitimate factory

Implementation

Last updated