Skip to content
Business logic Audit finding Advanced

Missing Validation of OKX Swap Output Token in function _okxHelper()

The _okxHelper function in a smart contract wrapper decodes the output amount from an OKX swap call without verifying that the swap's destination token matches the expected supported asset. If the wrapper already holds the supported asset, a malicious operator could supply calldata that swaps a cheap token but returns a large amount, causing the vault to pull the real asset and mint shares at near-zero cost.

Paludo0x Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

50027 sc insight missing validation of okx swap output token in function okxhelper

Submitted on Jul 21st 2025 at 08:21:14 UTC by @Paludo0x for Attackathon | Plume Network

Description

Vulnerability Details

The _okxHelper function never verifies that the swap’s toToken matches the declared supportedAsset.

The wrapper’s _okxHelper function decodes only the amount returned by an OKX Router swap call, without ever checking that the swap’s toToken matches the expected supportedAsset.

If the wrapper contract already holds supportedAssetAmount of supportedAsset (for any reason), a malicious operator can submit calldata swapping a cheap token, decode the returned amount as supportedAssetAmount, and then the vault will pull the real supportedAsset out of the wrapper—minting shares at near-zero cost. In the worst case, this steals full-value shares for almost no input.

Impact Details

  • Failure-only scenario: If the wrapper does not hold pre-existing supportedAssetAmount, the subsequent vault.enter (or safeTransferFrom) will revert, making the entire call fail.
  • Exploit scenario: If the wrapper holds supportedAssetAmount of the supported token, the operator calls _okxHelper with malicious calldata swapping a low-value token (e.g. 1 USDC) but returning supportedAssetAmount as the decoded result, the vault pulls the existing supportedAssetAmount and mints shares accordingly—netting full-value shares for a trivial cost.
  • Severity: Low (requires a trusted operator to submit malformed calldata). Note: the 1inch path enforces this check:
if (desc.dstToken != supportedAsset || desc.dstReceiver != address(this)) revert();

Proof of Concept

{% stepper %} {% step %}

Overview of how the function behaves

Inside _okxHelper(), the contract:

  • Reads the OKX call selector via assembly.
  • Approves the input token (or WETH) to the OKX approver.
  • Executes (bool success, bytes memory result) = okxRouter.call(okxCallData);
  • Decodes only the returned uint256 supportedAssetAmount = abi.decode(result, (uint256));
  • Approves the vault to pull supportedAssetAmount of the assumed supportedAsset.

At no point does the code extract or verify the destination token argument embedded in okxCallData. {% endstep %}

{% step %}

Code excerpt (relevant function)

function _okxHelper(
    ERC20 supportedAsset,
    address teller,
    address fromToken,
    uint256 fromTokenAmount,
    bytes calldata okxCallData,
    uint256 nativeValueToWrap
)
    internal
    returns (uint256 supportedAssetAmount)
{
    bytes4 selector;
    assembly {
        selector := calldataload(okxCallData.offset)
    }

    if (
        selector == SMART_SWAP_BY_ORDER_ID_SELECTOR || selector == SMART_SWAP_TO_SELECTOR
            || selector == UNISWAP_V3_SWAP_TO_SELECTOR || selector == UNISWAP_V3_SWAP_TO_WITH_PERMIT_SELECTOR
            || selector == UNXSWAP_BY_ORDER_ID_SELECTOR || selector == UNXSWAP_TO_SELECTOR
    ) {
        bool useNative = _checkAndMintNativeAmount(nativeValueToWrap);
        if (useNative) {
            if (fromToken != address(canonicalWrapToken) || fromTokenAmount != nativeValueToWrap) {
                revert DexAggregatorWrapper__OkxSwapFailed();
            }
            // Use standard approve (as requested)
            canonicalWrapToken.approve(okxApprover, nativeValueToWrap);
        } else {
            // Cast fromToken address to ERC20 to use the library
            ERC20 depositAsset = ERC20(fromToken);

            // Use safeTransferFrom
            depositAsset.safeTransferFrom(msg.sender, address(this), fromTokenAmount);

            // Use standard approve (as requested) for the OKX approver
            depositAsset.safeApprove(okxApprover, fromTokenAmount);
        }

        // Execute the swap with the provided calldata
        (bool success, bytes memory result) = address(okxRouter).call(okxCallData);
        if (!success) {
            assembly {
                revert(add(result, 32), mload(result))
            }
        }

        // Decode the return value
        supportedAssetAmount = abi.decode(result, (uint256));

        // Approve teller's vault to spend the supported asset
        // Cast teller address to TellerWithMultiAssetSupport to call vault()
        address vaultAddress = address(TellerWithMultiAssetSupport(payable(teller)).vault());
        if (vaultAddress == address(0)) {
            revert("DexAggregatorWrapper: Invalid vault address for approval");
        }
        // Use standard approve (as requested)
        supportedAsset.safeApprove(vaultAddress, supportedAssetAmount);

        // Return value needs to be here since it's declared in the function signature
        return supportedAssetAmount;
    } else {
        revert DexAggregatorWrapper__UnsupportedOkxFunction();
    }
    // Note: If the selector doesn't match, the function will revert above, so no explicit return needed here.
}

{% endstep %}

{% step %}

Why this is exploitable

  • The function never inspects okxCallData to verify the destination token or receiver.
  • A malicious calldata can be crafted so the OKX router call returns an arbitrary uint256 (e.g., a large supportedAssetAmount) while actually swapping to a different token/value.
  • If the wrapper already holds the real supportedAssetAmount, the vault will pull the real supported asset (because the wrapper has it) while the operator only provided a cheap input token—resulting in minting shares against real assets with negligible cost. {% endstep %}

{% step %}

Comparison with 1inch handling

The _oneInchHelper() function includes an explicit check:

if (desc.dstToken != supportedAsset || desc.dstReceiver != address(this)) {
    revert DexAggregatorWrapper__InvalidSwapDescription();
}

This check prevents the described exploit for 1inch paths because the destination token and receiver must match expectations. _okxHelper() lacks an equivalent verification. {% endstep %}

{% step %}

Outcome

  • If the wrapper does not hold the declared supportedAssetAmount, the call will likely revert (failure-only scenario).
  • If the wrapper does hold that balance, an attacker or malicious/trusted operator can craft calldata to mint full-value shares for negligible cost (exploit scenario). {% endstep %} {% endstepper %}

Suggested Mitigation (not exhaustive)

  • Verify the destination token and receiver encoded in okxCallData match supportedAsset and address(this) before relying on the decoded return value, similar to the 1inch handler.
  • Parse and validate the calldata fields relevant to destination token/receiver for supported OKX selectors prior to executing the call.
  • Where direct parsing is infeasible for a selector, consider rejecting that selector (or route) or requiring an on-chain verified description object (like 1inch's desc) to be provided and validated.

References

{% hint style="info" %} This report maintains the original author's details and findings. No links or code were modified from the original report. {% endhint %}

The original report as published on Immunefi, by Paludo0x. 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 function fails to validate that the destination token and receiver encoded in the OKX calldata match the expected supported asset and the wrapper address, unlike the 1inch handler which performs such a check.

Impact

If the wrapper holds the supported asset, an attacker could mint full-value shares for almost no input; otherwise the call reverts.

What the attacker needed

Wrapper holds supported asset; trusted operator submits calldata

The fix

The function should verify that the destination token and receiver in the OKX calldata match the supported asset and the wrapper address, similar to the 1inch handler.

How it was found

  1. The wrapper contract holds some amount of the supported asset.
  2. A malicious operator submits calldata to _okxHelper that swaps a cheap token but returns a large amount as the decoded result.
  3. The function approves the vault to pull that large amount of the supported asset.
  4. The vault pulls the existing supported asset from the wrapper and mints shares accordingly.

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.

This is a smart contract that helps users swap tokens and deposit them into a vault. The function that handles swaps from a service called OKX trusts the amount returned by the swap without checking which token was actually received. If the contract already holds some of the expected token, someone could trick it into thinking a cheap swap produced a large amount, and then take the real tokens.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Paludo0x

View all

42 more disclosed reports, best first.

More from Plume Network

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.