Skip to content
Smart contracts Audit finding Intermediate

Verifyswapcalldata cant verify the output token of the swap

The ZeroXSwapVerifier contract checks that the sell token matches the strategy's target token and that slippage is within bounds, but never checks the buy token declared in the swap struct. A valid 0x calldata could therefore execute a swap that returns a different, unintended output token.

farismaulana Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

58418 sc low verifyswapcalldata cant verify the output token of the swap

Submitted on Nov 2nd 2025 at 07:03:51 UTC by @farismaulana for Audit Comp | Alchemix V3

Description

Brief/Intro

the purpose of ZeroXSwapVerifier is to verify the calldata from 0x protocol. but the verifier only verify what is already verified in the 0x internal verification. there are no check if the output of swap calldata is the one that a Strategy wants.

Vulnerability Details

for instance the _verifyBasicSellToPool :

Solidity
    function _verifyBasicSellToPool(bytes memory action, address owner, address targetToken, uint256 maxSlippageBps) internal view {
        (address sellToken, uint256 bps, , , ) = abi.decode(
            _slice(action, 4),
            (address, uint256, address, uint256, bytes)
        );

        require(sellToken == targetToken, "IT");
        require(bps <= maxSlippageBps, "Slippage too high");
    }

it only check that the sellToken match the targetToken , as we know that the sellToken is the token a strategy wants to sell, so it is necessary for the strategy to have this token in the first place because if its not then the swap should revert.

the issue is that the prior function does not forward the buyToken that is inside SlippageAndActions struct. this is a crucial data to make sure the output of a swap match the intent of strategy. if this not checked then a valid calldata from 0x protocol can still be executed even though that the output token completely different.

Impact Details

it is possible for a swap to result to unintended output token/worthless token because there are no check if the output token is inded what the strategy intent to have after the swap.

References

https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/utils/ZeroXSwapVerifier.sol#L195C1-L203C6

Proof of Concept

Proof of Concept

we can see in the code that the buyToken is not checked.

so the PoC can be straight forward. add to src/test/ZeroXSwapVerifier.t.sol :

Solidity
    function testBuyTokenNotVerified() public {
        uint256 bps = 1000;
        address recipient = makeAddr("recipient");
        address buyToken = makeAddr("buyToken");
        address randomBuyToken = makeAddr("randomBuyToken");

        bytes memory action = abi.encodeWithSelector(
            BASIC_SELL_TO_POOL,
            address(token),
            bps, // bps
            recipient,
            0,
            ""
        );
        
        // create output buyToken
        ZeroXSwapVerifier.SlippageAndActions memory saa = ZeroXSwapVerifier.SlippageAndActions({
            recipient: recipient,
            buyToken: buyToken,
            minAmountOut: 0,
            actions: new bytes[](1)
        });
        saa.actions[0] = action;
        
        bytes memory _calldata = abi.encodeWithSelector(EXECUTE_SELECTOR, saa, new bytes[](0));

        // verify the _calldata 
        bool verified = ZeroXSwapVerifier.verifySwapCalldata(
            _calldata,
            owner, 
            address(token), 
            bps // 1000 bps = 10% max slippage
        );
        assertTrue(verified);

        // create output randomBuyToken
        saa = ZeroXSwapVerifier.SlippageAndActions({
            recipient: recipient,
            buyToken: randomBuyToken,
            minAmountOut: 0,
            actions: new bytes[](1)
        });
        saa.actions[0] = action;
        
        _calldata = abi.encodeWithSelector(EXECUTE_SELECTOR, saa, new bytes[](0));

        // verify the _calldata 
        verified = ZeroXSwapVerifier.verifySwapCalldata(
            _calldata,
            owner, 
            address(token), 
            bps // 1000 bps = 10% max slippage
        );
        assertTrue(verified);
    }

the calldata is verified only if the sellToken == targetToken and bps <= maxSlippageBps . there are no verification for the buyToken or output token.

The original report as published on Immunefi, by farismaulana. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the verifier only re-checks fields already validated by 0x and omits the buy token from the SlippageAndActions struct, so the intended output token is never compared against the swap.

Impact

A swap could return an unintended or worthless output token, potentially temporarily freezing funds or leaving the contract unable to operate for lack of the expected token.

What the attacker needed

A valid 0x swap calldata; slippage within the allowed maximum

The fix

The verifier should also check that the buy token in the SlippageAndActions struct matches the output token the strategy intends.

How it was found

  1. Build a swap action selling the target token with slippage within the allowed maximum.
  2. Wrap it in a SlippageAndActions struct with an arbitrary buy token.
  3. Encode the execute calldata and pass it to verifySwapCalldata.
  4. Observe the calldata is accepted even though the buy token differs from the intended one.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A verifier is meant to double-check swap instructions before they run. Here it only confirmed which token was being sold, not which token should come back, so a swap could hand back something worthless instead of what was wanted.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by farismaulana

View all

28 more disclosed reports, best first.

More from Alchemix V3

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.