Skip to content
DoS Audit finding Intermediate

Usdt like approval hygiene can block subsequent operations after partial fill leaves non zero allowance

The DexAggregatorWrapperWithPredicateProxy uses safeApprove without first zeroing a prior non-zero allowance, so a partial fill leaves a residual allowance. On USDT-like tokens that reject non-zero to non-zero approvals, subsequent calls revert, temporarily freezing funds.

Plume Network

Originally disclosed on Immunefi

52925 sc medium usdt like approval hygiene can block subsequent operations after partial fill leaves non zero allowance

Impacts:

  • Smart contract unable to operate due to lack of token funds
  • Temporary freezing of funds for at least 24 hours

Description

Brief / Intro

A medium-severity vulnerability was identified in DexAggregatorWrapperWithPredicateProxy related to allowance hygiene for non-standard ERC20 tokens (USDT-like). Some tokens refuse to change a spender allowance from a non-zero value directly to another non-zero value (they require approve(0) first). The wrapper uses safeApprove(spender, amount) without zeroing a prior non-zero allowance, so a partial fill that leaves a non-zero residual allowance can cause subsequent calls to revert on USDT-like tokens.

The PoC demonstrates that after a partial fill the wrapper left a large non-zero allowance to the router. On the next interaction, USDT-like tokens would revert when attempting a non-zero -> non-zero approve.

Vulnerability Details

Affected helper sites in DexAggregatorWrapperWithPredicateProxy.sol:

  • _oneInchHelper: calls safeApprove(aggregator, amount) without first zeroing allowance
  • _okxHelper: calls safeApprove(okxApprover, amount) without first zeroing allowance
  • Vault approvals: approvals to the vault do not follow a zero-first pattern

Behavior that causes failure:

  • A partial fill leaves a non-zero residual allowance to the router/approver.
  • USDT-like tokens revert when moving directly from a non-zero allowance to another non-zero allowance unless approve(0) is called first.
  • The wrapper’s safeApprove() pattern does not zero-out allowances (nor necessarily clear leftover allowances after use), so operations can revert.

Evidence from PoC logs:

  • “Leftover USDT-like allowance to aggregator after partial fill: 999999999999”
  • “Second call should revert due to USDT-like non-zero -> non-zero approve rule.”
  • “VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.”

Note: In the provided run, the second call reverted earlier during transferFrom due to the test user balance being exhausted. The key precondition (leftover non-zero allowance after partial fill) is shown; with sufficient balance the wrapper would hit safeApprove over a non-zero current allowance and revert under USDT-like rules.

Impact Details

This can cause the wrapper to be unable to operate with USDT-like tokens after a partial fill leaves a non-zero allowance, temporarily freezing affected assets and impairing UX and reliability.

Suggested Mitigation

  • Always use a reset-to-zero then set pattern for approvals:
    • If allowance(spender) != 0, call safeApprove(spender, 0) before safeApprove(spender, amount).
  • Eliminate residual allowances after use:
    • After the swap completes, safeApprove(spender, 0).
    • This reduces attack surface if a spender becomes compromised.
  • Handle partial fills to avoid leftover allowances altogether:
    • Refund unspent srcToken to the user.
    • Zero-out the allowance to the router/approver after the call.

Apply these patterns in _oneInchHelper, _okxHelper, and any other approval locations (e.g., vault approvals).

Proof of Concept

Summary: The PoC uses a USDT-like token which rejects approve() calls that move a non-zero allowance to another non-zero value. After a partial fill the wrapper leaves a non-zero allowance to the aggregator. A second call with the same token will fail unless the wrapper first resets the allowance to zero.

<details> <summary>PoC code (place under test/ and run with provided remappings)</summary>
Solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import "forge-std/Test.sol";
import "forge-std/console.sol";

// Wrapper
import { DexAggregatorWrapperWithPredicateProxy } from "src/helper/DexAggregatorWrapperWithPredicateProxy.sol";
import { TellerWithMultiAssetSupportPredicateProxy } from "src/base/Roles/TellerWithMultiAssetSupportPredicateProxy.sol";

// Core stack
import { BoringVault } from "src/base/BoringVault.sol";
import { AccountantWithRateProviders } from "src/base/Roles/AccountantWithRateProviders.sol";
import { TellerWithMultiAssetSupport } from "src/base/Roles/TellerWithMultiAssetSupport.sol";
import { RolesAuthority, Authority } from "@solmate/auth/authorities/RolesAuthority.sol";

// Structs/Interfaces
import { PredicateMessage } from "@predicate/src/interfaces/IPredicateClient.sol";
import { AggregationRouterV6 } from "src/interfaces/AggregationRouterV6.sol";
import { IOKXRouter } from "src/interfaces/IOKXRouter.sol";
import { ERC20 } from "@solmate/tokens/ERC20.sol";
import { WETH } from "@solmate/tokens/WETH.sol";

// Partial-fill 1inch mock (spends 1 unit, returns 1 unit)
contract PartialFill1Inch is AggregationRouterV6 {
    function swap(address, SwapDescription calldata desc, bytes calldata)
        external
        payable
        override
        returns (uint256, uint256)
    {
        ERC20(address(desc.srcToken)).transferFrom(msg.sender, address(this), 1);
        ERC20(address(desc.dstToken)).transfer(msg.sender, 1);
        return (1, 1);
    }
}

// USDT-like token: approve(non-zero) fails if current allowance != 0
contract USDTLike is ERC20("USDTLike", "USDTL", 6) {
    function mint(address to, uint256 amount) external { _mint(to, amount); }
    function approve(address spender, uint256 value) public override returns (bool) {
        uint256 current = allowance[msg.sender][spender];
        if (current != 0 && value != 0) {
            emit Approval(msg.sender, spender, current);
            return false; // SafeTransferLib.safeApprove will revert on false
        }
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }
}

// Allow-all predicate
contract AllowAllPredicateProxy {
    function genericUserCheckPredicate(address, PredicateMessage calldata) external pure returns (bool) {
        return true;
    }
}

contract USDTLike_Approval_DoS_PoC is Test {
    // Core
    WETH public weth;
    BoringVault public vault;
    AccountantWithRateProviders public accountant;
    TellerWithMultiAssetSupport public teller;
    RolesAuthority public roles;

    // Wrapper + mocks
    DexAggregatorWrapperWithPredicateProxy public wrapper;
    PartialFill1Inch public oneInch;
    AllowAllPredicateProxy public predicate;
    USDTLike public usdt;

    address public user = address(0xBEEF2);

    function setUp() public {
        vm.txGasPrice(0);
        vm.deal(user, 10 ether);

        // Core
        weth = new WETH();
        vault = new BoringVault(address(this), "BoringVault", "BV", 18);
        accountant = new AccountantWithRateProviders(
            address(this), address(vault), address(this), 1e18, address(weth), 10010, 9990, 1, 0
        );
        teller = new TellerWithMultiAssetSupport(address(this), address(vault), address(accountant));

        roles = new RolesAuthority(address(this), Authority(address(0)));
        vault.setAuthority(roles);
        teller.setAuthority(roles);
        uint8 ROLE_TELLER = 3;
        roles.setUserRole(address(teller), ROLE_TELLER, true);
        roles.setRoleCapability(ROLE_TELLER, address(vault), vault.enter.selector, true);
        roles.setRoleCapability(ROLE_TELLER, address(vault), vault.exit.selector, true);

        teller.addAsset(weth);

        oneInch = new PartialFill1Inch();
        predicate = new AllowAllPredicateProxy();

        wrapper = new DexAggregatorWrapperWithPredicateProxy(
            oneInch,
            IOKXRouter(address(0)),
            address(0xDEAD),
            weth,
            TellerWithMultiAssetSupportPredicateProxy(payable(address(predicate)))
        );

        uint8 ROLE_WRAPPER = 5;
        roles.setUserRole(address(wrapper), ROLE_WRAPPER, true);
        roles.setRoleCapability(ROLE_WRAPPER, address(teller), teller.deposit.selector, true);

        // Prefund router with 1 wei WETH
        weth.deposit{value: 1}();
        weth.transfer(address(oneInch), 1);

        // Mint USDT-like to user
        usdt = new USDTLike();
        usdt.mint(user, 1_000_000e6);
    }

    function _emptyPredicate() internal pure returns (PredicateMessage memory p) {
        return PredicateMessage({ taskId: "", expireByTime: 0, signerAddresses: new address[](0), signatures: new bytes[](0) });
    }

    // MEDIUM: USDT-like approval hygiene breaks next call after partial fill leaves non-zero allowance
    function test_MEDIUM_usdt_like_approval_breaks_next_call() public {
        console.log("--- PoC: USDT-like Approval Fails After Partial Fill Left Non-Zero Allowance (USDT->WETH) ---");

        // User approves wrapper to pull USDT-like
        vm.startPrank(user);
        usdt.approve(address(wrapper), type(uint256).max);

        uint256 amount = 1_000_000e6; // 1,000,000 units (6 decimals)

        AggregationRouterV6.SwapDescription memory desc1 = AggregationRouterV6.SwapDescription({
            srcToken: ERC20(address(usdt)),
            dstToken: ERC20(address(weth)),
            srcReceiver: payable(address(0)),
            dstReceiver: payable(address(wrapper)),
            amount: amount,
            minReturnAmount: 1,
            flags: 0
        });

        // First call: partial fill spends only 1 unit
        wrapper.depositOneInch(
            ERC20(address(weth)), // vault supports WETH
            teller,
            0,
            address(0),
            desc1,
            "",
            0,
            _emptyPredicate()
        );

        uint256 leftover = usdt.allowance(address(wrapper), address(oneInch));
        console.log("Leftover USDT-like allowance to aggregator after partial fill:", leftover);
        assertEq(leftover, amount - 1, "Leftover allowance expected after partial fill");

        // Second call should fail: wrapper tries safeApprove(amount) with current allowance != 0 (USDT-like rule)
        AggregationRouterV6.SwapDescription memory desc2 = AggregationRouterV6.SwapDescription({
            srcToken: ERC20(address(usdt)),
            dstToken: ERC20(address(weth)),
            srcReceiver: payable(address(0)),
            dstReceiver: payable(address(wrapper)),
            amount: amount,
            minReturnAmount: 1,
            flags: 0
        });

        console.log("Second call should revert due to USDT-like non-zero -> non-zero approve rule.");
        vm.expectRevert(); // SafeTransferLib.safeApprove will revert
        wrapper.depositOneInch(
            ERC20(address(weth)),
            teller,
            0,
            address(0),
            desc2,
            "",
            0,
            _emptyPredicate()
        );

        vm.stopPrank();

        console.log("VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.");
    }
}
</details> <details> <summary>Execution Logs</summary>

Run: forge test -vv --match-path test/USDT_Like_Approval_DoS.t.sol

Output:

Ran 1 test for test/USDT_Like_Approval_DoS.t.sol:USDTLike_Approval_DoS_PoC
[PASS] test_MEDIUM_usdt_like_approval_breaks_next_call() (gas: 357478)
Logs:
  --- PoC: USDT-like Approval Fails After Partial Fill Left Non-Zero Allowance (USDT->WETH) ---
  Leftover USDT-like allowance to aggregator after partial fill: 999999999999
  Second call should revert due to USDT-like non-zero -> non-zero approve rule.
  VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 21.56ms (5.32ms CPU time)
</details>

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

DexAggregatorWrapperWithPredicateProxy is a helper contract in the Plume Network Nucleus Boring Vault stack. It sits between a user and a DEX aggregator (1inch or OKX) and lets a vault deposit flow pull a source token, swap it through the aggregator, and deposit the result into a TellerWithMultiAssetSupport. The target file is:

Text
https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol

To let the aggregator pull the source token, the wrapper approves the aggregator for the swap amount. That approval is the part that matters here. The report is filed as a medium-severity smart contract finding with two listed impacts: the contract being unable to operate due to lack of token funds, and temporary freezing of funds for at least 24 hours.

Setup

The proof of concept is a Foundry test placed under test/ and run with the project's provided remappings. It deploys the core stack from scratch rather than forking mainnet:

  • WETH, a BoringVault, an AccountantWithRateProviders and a TellerWithMultiAssetSupport.
  • A RolesAuthority that grants the teller role 3 the enter and exit capabilities on the vault, and grants the wrapper role 5 the deposit capability on the teller.
  • The wrapper itself, constructed with a mock 1inch router, a zero address in place of the OKX router, address(0xDEAD) as the predicate signer, WETH, and an allow-all predicate proxy.
  • A USDTLike ERC20 with 6 decimals, minted to the test user address(0xBEEF2).

The test user is funded with 10 ether and the transaction gas price is set to zero. The mock router is prefunded with 1 wei of WETH so it can return a destination amount.

Two mocks carry the behaviour being tested. The first is a 1inch router that only spends one unit of the source token and returns one unit of the destination token, simulating a partial fill:

Solidity
contract PartialFill1Inch is AggregationRouterV6 {
    function swap(address, SwapDescription calldata desc, bytes calldata)
        external
        payable
        override
        returns (uint256, uint256)
    {
        ERC20(address(desc.srcToken)).transferFrom(msg.sender, address(this), 1);
        ERC20(address(desc.dstToken)).transfer(msg.sender, 1);
        return (1, 1);
    }
}

The second is the USDT-like token, which rejects any approve that moves a non-zero allowance to another non-zero value:

Solidity
contract USDTLike is ERC20("USDTLike", "USDTL", 6) {
    function mint(address to, uint256 amount) external { _mint(to, amount); }
    function approve(address spender, uint256 value) public override returns (bool) {
        uint256 current = allowance[msg.sender][spender];
        if (current != 0 && value != 0) {
            emit Approval(msg.sender, spender, current);
            return false; // SafeTransferLib.safeApprove will revert on false
        }
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }
}

Returning false rather than reverting is deliberate: SafeTransferLib.safeApprove treats a false return as a failure and reverts, which mirrors how the wrapper would experience a USDT-like refusal.

Finding it

The researcher looked at how the wrapper manages allowances to the aggregator. Three approval sites are named in the report:

  • _oneInchHelper calls safeApprove(aggregator, amount) without first zeroing the allowance.
  • _okxHelper calls safeApprove(okxApprover, amount) without first zeroing the allowance.
  • Approvals to the vault do not follow a zero-first pattern either.

USDT-like tokens refuse to change a spender's allowance directly from one non-zero value to another; they require approve(0) first. Because the wrapper never zeroes a prior allowance, a partial fill that leaves a residual allowance to the router sets up the next call to revert inside safeApprove. The wrapper also does not necessarily clear leftover allowances after use, so the residual can persist.

Exploitation

Step 1: user approves the wrapper

The user approves the wrapper to pull the USDT-like token for the maximum amount:

Solidity
vm.startPrank(user);
usdt.approve(address(wrapper), type(uint256).max);

Step 2: first call with a partial fill

The user calls depositOneInch with a swap description for 1,000,000 units of the USDT-like token (6 decimals) into WETH, with minReturnAmount of 1:

Solidity
uint256 amount = 1_000_000e6; // 1,000,000 units (6 decimals)

AggregationRouterV6.SwapDescription memory desc1 = AggregationRouterV6.SwapDescription({
    srcToken: ERC20(address(usdt)),
    dstToken: ERC20(address(weth)),
    srcReceiver: payable(address(0)),
    dstReceiver: payable(address(wrapper)),
    amount: amount,
    minReturnAmount: 1,
    flags: 0
});

// First call: partial fill spends only 1 unit
wrapper.depositOneInch(
    ERC20(address(weth)), // vault supports WETH
    teller,
    0,
    address(0),
    desc1,
    "",
    0,
    _emptyPredicate()
);

The mock router spends only 1 unit of the source token and returns 1 unit of the destination token. The wrapper's approval to the router, however, was for the full amount, so the unspent remainder stays as a live allowance.

Step 3: observe the leftover allowance

The test reads the allowance the wrapper still grants the router and asserts it equals amount - 1:

Solidity
uint256 leftover = usdt.allowance(address(wrapper), address(oneInch));
console.log("Leftover USDT-like allowance to aggregator after partial fill:", leftover);
assertEq(leftover, amount - 1, "Leftover allowance expected after partial fill");

The execution log records:

Text
Leftover USDT-like allowance to aggregator after partial fill: 999999999999

That is 1,000,000e6 minus 1, a large non-zero allowance still held by the router.

Step 4: second call reverts

A second depositOneInch call is made with the same token and amount, and the test expects a revert:

Solidity
console.log("Second call should revert due to USDT-like non-zero -> non-zero approve rule.");
vm.expectRevert(); // SafeTransferLib.safeApprove will revert
wrapper.depositOneInch(
    ERC20(address(weth)),
    teller,
    0,
    address(0),
    desc2,
    "",
    0,
    _emptyPredicate()
);

With sufficient balance the wrapper would call safeApprove for a non-zero amount while the current allowance is still non-zero, which the USDT-like token refuses. The log ends with:

Text
VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.

The full run output is:

Text
Ran 1 test for test/USDT_Like_Approval_DoS.t.sol:USDTLike_Approval_DoS_PoC
[PASS] test_MEDIUM_usdt_like_approval_breaks_next_call() (gas: 357478)
Logs:
  --- PoC: USDT-like Approval Fails After Partial Fill Left Non-Zero Allowance (USDT->WETH) ---
  Leftover USDT-like allowance to aggregator after partial fill: 999999999999
  Second call should revert due to USDT-like non-zero -> non-zero approve rule.
  VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 21.56ms (5.32ms CPU time)

The report is explicit about a limitation of this run: the second call actually reverted earlier, during transferFrom, because the test user's balance was exhausted. The precondition that matters, a leftover non-zero allowance after a partial fill, is demonstrated. With sufficient balance, the wrapper would reach safeApprove over a non-zero current allowance and revert under USDT-like rules.

Root cause

The wrapper uses safeApprove(spender, amount) directly, without first resetting an existing allowance to zero. USDT-like tokens require the allowance to be zero before it can be set to a new non-zero value, so any path that leaves a residual allowance makes the next approval fail. The same pattern appears in _oneInchHelper, _okxHelper and the vault approvals. Because the wrapper does not clear leftover allowances after a swap, a partial fill is enough to leave the contract in a state where it cannot approve again for that token.

Impact

After a partial fill leaves a non-zero allowance, the wrapper cannot operate with USDT-like tokens: subsequent calls revert at the approval step. The report frames this as temporarily freezing affected assets and impairing UX and reliability. The impact is conditional on the token enforcing the non-zero to non-zero rule and on a partial fill having left a residual allowance; the report does not claim loss of funds.

Fix

The report recommends three measures:

  1. Always reset to zero before setting a new allowance: if allowance(spender) != 0, call safeApprove(spender, 0) before safeApprove(spender, amount).
  2. Eliminate residual allowances after use: after the swap completes, call safeApprove(spender, 0). This also reduces attack surface if a spender becomes compromised.
  3. Handle partial fills so no leftover allowance arises: refund unspent srcToken to the user and zero the allowance to the router or approver after the call.

These patterns should be applied in _oneInchHelper, _okxHelper and any other approval locations, including vault approvals.

Variants to test

  • Other aggregator wrappers that call safeApprove with a computed amount: check whether a partial fill or a failed swap leaves a non-zero allowance, then attempt a second swap with the same token. A positive result is a revert inside the approval on the second call.
  • Vault approval paths: look for approvals to the vault that skip the zero-first step, and try a deposit, withdrawal or re-deposit sequence with a USDT-like token. A positive result is a revert on the second approval.
  • Tokens with the same rule but different failure modes (returning false versus reverting): confirm the wrapper's safeApprove handling reverts in both cases.
  • Swap paths where the router spends less than approved for reasons other than a partial fill, such as price limits or minReturnAmount shortfalls: check whether the residual allowance persists and blocks the next call.

Hunting notes

This class of bug hides in helper and wrapper contracts that approve third-party routers, aggregators or vaults on behalf of users. During recon, look for safeApprove calls whose amount is derived from user input or swap parameters, and check whether any code path zeroes the allowance before or after use. The signal is a token integration that includes USDT-like assets, where the non-zero to non-zero rule applies. To show impact, demonstrate the leftover allowance after a partial fill and the revert on the next call, as this report does with an assertion on amount - 1 and an expected revert. Be explicit about preconditions such as user balance, since the report notes that its own second call reverted earlier at transferFrom and that the approval revert would occur with sufficient balance.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

A vault is a kind of digital safe. People put tokens (digital money) into it, and the vault does things with them, such as swapping one token for another. The vault in this report is part of a project called Plume Network, and the piece of code that does the swapping is a helper contract called DexAggregatorWrapperWithPredicateProxy.

That helper does not do the swap itself. It hands the job to an outside service called a DEX aggregator, which is a program that finds the best place to trade one token for another. The two aggregators named in the report are 1inch and OKX. Before the aggregator can take the user's tokens, the helper has to give it permission. In the token world that permission is called an allowance, and the act of granting it is called an approval.

The bug is about how that permission is granted. Some tokens, with USDT as the famous example, have a strict rule: you cannot change a permission from one non-zero amount straight to another non-zero amount. You must first set it to zero, then set the new amount. The helper skips the zero step. So if a swap only uses part of the tokens it was allowed to take (a partial fill), a large permission is left over. The next time the helper tries to grant a new permission, the strict token refuses, and the whole operation fails.

The report rates this as medium severity. The listed impacts are that the contract cannot operate because of a lack of token funds, and that funds can be temporarily frozen for at least 24 hours. The report does not claim that anyone loses money.

The code under review

The target file is:

Text
https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol

This is a link to a source file on GitHub, a website where code is stored and shared. The file is written in Solidity, the language used for programs that run on blockchains such as Ethereum. A contract is simply a program that lives on the blockchain and can hold tokens and respond to requests.

The helper sits in the middle of a flow: a user wants to deposit, the helper pulls the user's token, swaps it through the aggregator, and deposits the result into another contract called TellerWithMultiAssetSupport. A teller, in this stack, is the part that handles deposits and withdrawals.

To let the aggregator take the source token, the helper approves the aggregator for the swap amount. That approval is the heart of the issue.

Setting up the test

The proof of concept is a Foundry test. Foundry is a toolkit for writing and running tests against Solidity code on a local, simulated blockchain, so nothing real is touched. The test is placed under a test/ folder and run with the project's provided remappings, which are settings that tell the compiler where to find imported files.

The test builds the whole system from scratch instead of copying the live blockchain. It creates:

  • WETH, a token that represents ether (the currency of Ethereum) in token form.
  • A BoringVault, the safe itself.
  • An AccountantWithRateProviders, which keeps track of exchange rates between assets.
  • A TellerWithMultiAssetSupport, which handles deposits.
  • A RolesAuthority, which is a permission system: it decides which contract is allowed to call which function.

The permission system is set up so that the teller (role 3) may call enter and exit on the vault, and the wrapper (role 5) may call deposit on the teller. A role is just a numbered label that groups permissions together.

The wrapper is then created with a fake 1inch router, a zero address in place of the OKX router (meaning OKX is not used in this test), address(0xDEAD) as the predicate signer, WETH, and an allow-all predicate proxy. A predicate is a check that decides whether a user is allowed to do something; the allow-all version simply says yes to everyone. A signer is the account whose signature would normally authorise such a check.

A test token called USDTLike is created with 6 decimals and given to the test user at address(0xBEEF2). Decimals matter: a token with 6 decimals stores 1,000,000 units as the number 1,000,000,000,000, because each whole unit is split into a million tiny pieces.

The test user is given 10 ether, and the gas price is set to zero. Gas is the fee paid for running code on a blockchain; setting it to zero keeps the test simple. The fake router is pre-loaded with 1 wei of WETH. A wei is the smallest unit of ether, so this is a tiny amount, just enough for the router to send something back.

Two fake contracts carry the behaviour being tested. The first is a 1inch router that only spends one unit of the source token and returns one unit of the destination token, simulating a partial fill:

Solidity
contract PartialFill1Inch is AggregationRouterV6 {
    function swap(address, SwapDescription calldata desc, bytes calldata)
        external
        payable
        override
        returns (uint256, uint256)
    {
        ERC20(address(desc.srcToken)).transferFrom(msg.sender, address(this), 1);
        ERC20(address(desc.dstToken)).transfer(msg.sender, 1);
        return (1, 1);
    }
}

Line by line:

  • contract PartialFill1Inch is AggregationRouterV6 declares a new contract that inherits from the real 1inch router interface, so it can stand in for it.
  • function swap(...) defines the swap function with the same shape as the real one. The first and third arguments are unnamed because the fake does not need them.
  • ERC20(address(desc.srcToken)).transferFrom(msg.sender, address(this), 1); takes exactly 1 unit of the source token from whoever called the router (the wrapper) and keeps it in the router. This is the partial fill: only 1 unit is spent, no matter how much was approved.
  • ERC20(address(desc.dstToken)).transfer(msg.sender, 1); sends 1 unit of the destination token back to the caller.
  • return (1, 1); reports that 1 unit went in and 1 unit came out.

The second fake is the USDT-like token, which rejects any approval that moves a non-zero allowance to another non-zero value:

Solidity
contract USDTLike is ERC20("USDTLike", "USDTL", 6) {
    function mint(address to, uint256 amount) external { _mint(to, amount); }
    function approve(address spender, uint256 value) public override returns (bool) {
        uint256 current = allowance[msg.sender][spender];
        if (current != 0 && value != 0) {
            emit Approval(msg.sender, spender, current);
            return false; // SafeTransferLib.safeApprove will revert on false
        }
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }
}

Line by line:

  • contract USDTLike is ERC20("USDTLike", "USDTL", 6) creates a token named USDTLike with the symbol USDTL and 6 decimals, copying the standard ERC20 token behaviour. ERC20 is the common rulebook that tokens follow so wallets and contracts know how to talk to them.
  • function mint(...) lets the test create new tokens out of thin air, which real tokens would not allow.
  • function approve(...) replaces the standard approval function with a stricter version.
  • uint256 current = allowance[msg.sender][spender]; looks up how much the spender is currently allowed to take from the caller.
  • if (current != 0 && value != 0) checks the strict rule: if there is already a non-zero permission and the new permission is also non-zero, the request is refused.
  • emit Approval(...) and return false; record the refusal and report failure instead of crashing. The comment explains why: the helper uses a library function called SafeTransferLib.safeApprove, which treats a false answer as a failure and stops the whole transaction. That mirrors what a real USDT-like token would cause.
  • The remaining lines store the new permission and report success when the rule is not triggered.

Finding the problem

The researcher looked at how the helper manages allowances to the aggregator. Three approval sites are named in the report:

  • _oneInchHelper calls safeApprove(aggregator, amount) without first zeroing the allowance.
  • _okxHelper calls safeApprove(okxApprover, amount) without first zeroing the allowance.
  • Approvals to the vault do not follow a zero-first pattern either.

USDT-like tokens refuse to change a spender's allowance directly from one non-zero value to another; they require approve(0) first. Because the helper never zeroes a prior allowance, a partial fill that leaves a residual allowance to the router sets up the next call to fail inside safeApprove. The helper also does not necessarily clear leftover allowances after use, so the leftover can stay there.

Walking through the attack

Step 1: the user approves the helper

The user approves the helper to pull the USDT-like token for the maximum possible amount:

Solidity
vm.startPrank(user);
usdt.approve(address(wrapper), type(uint256).max);

Line by line:

  • vm.startPrank(user); tells the test framework to act as if the following calls come from the user's account. vm is a special test helper, and pranking means pretending to be someone else.
  • usdt.approve(address(wrapper), type(uint256).max); grants the helper permission to take up to the largest number the system can store. This is a common convenience so the user does not have to approve again for every trade.

Step 2: first call with a partial fill

The user calls depositOneInch with a swap description for 1,000,000 units of the USDT-like token into WETH, with a minimum return of 1:

Solidity
uint256 amount = 1_000_000e6; // 1,000,000 units (6 decimals)

AggregationRouterV6.SwapDescription memory desc1 = AggregationRouterV6.SwapDescription({
    srcToken: ERC20(address(usdt)),
    dstToken: ERC20(address(weth)),
    srcReceiver: payable(address(0)),
    dstReceiver: payable(address(wrapper)),
    amount: amount,
    minReturnAmount: 1,
    flags: 0
});

// First call: partial fill spends only 1 unit
wrapper.depositOneInch(
    ERC20(address(weth)), // vault supports WETH
    teller,
    0,
    address(0),
    desc1,
    "",
    0,
    _emptyPredicate()
);

Line by line:

  • uint256 amount = 1_000_000e6; sets the swap size. The e6 means multiply by ten to the power six, matching the token's 6 decimals, so this is one million whole units.
  • SwapDescription is a bundle of details describing the trade: which token goes in, which comes out, where the input goes, where the output goes, how much, the smallest acceptable return, and some flags.
  • srcToken is the token being sold, here the USDT-like token.
  • dstToken is the token being bought, here WETH.
  • srcReceiver is where the sold tokens should be sent; it is set to the zero address.
  • dstReceiver is where the bought tokens should go, here the helper itself.
  • amount is the size of the trade.
  • minReturnAmount: 1 says the trade is acceptable as long as at least 1 unit comes back. This is what allows a partial fill to pass: the router can spend far less than the full amount and still satisfy the minimum.
  • flags: 0 sets the flags field to zero.
  • wrapper.depositOneInch(...) makes the call. The arguments include the vault asset (WETH), the teller, a zero fee, a zero referral address, the swap description, empty extra data, a zero value, and an empty predicate.
  • _emptyPredicate() builds a predicate message with no task, no expiry, no signers and no signatures.

The fake router spends only 1 unit of the source token and returns 1 unit of the destination token. The helper's approval to the router, however, was for the full amount, so the unspent remainder stays as a live permission.

Step 3: observe the leftover allowance

The test reads the permission the helper still grants the router and checks that it equals amount - 1:

Solidity
uint256 leftover = usdt.allowance(address(wrapper), address(oneInch));
console.log("Leftover USDT-like allowance to aggregator after partial fill:", leftover);
assertEq(leftover, amount - 1, "Leftover allowance expected after partial fill");

Line by line:

  • usdt.allowance(...) asks the token how much the router is still allowed to take from the helper.
  • console.log(...) prints that number so it appears in the test output.
  • assertEq(...) is a check: if the leftover is not exactly amount - 1, the test fails. This is how the researcher proves the leftover exists.

The execution log records:

Text
Leftover USDT-like allowance to aggregator after partial fill: 999999999999

That is 1,000,000e6 minus 1, a large non-zero permission still held by the router.

Step 4: the second call fails

A second depositOneInch call is made with the same token and amount, and the test expects a failure:

Solidity
console.log("Second call should revert due to USDT-like non-zero -> non-zero approve rule.");
vm.expectRevert(); // SafeTransferLib.safeApprove will revert
wrapper.depositOneInch(
    ERC20(address(weth)),
    teller,
    0,
    address(0),
    desc2,
    "",
    0,
    _emptyPredicate()
);

Line by line:

  • console.log(...) prints a note explaining what the test expects to happen.
  • vm.expectRevert(); tells the test framework that the very next call must fail. If it succeeds, the test fails. A revert is the blockchain's way of cancelling a transaction and undoing its effects.
  • The depositOneInch call is the same as before but with desc2, a second swap description built the same way as the first.

With enough balance the helper would call safeApprove for a non-zero amount while the current permission is still non-zero, which the USDT-like token refuses. The log ends with:

Text
VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.

The full run output is:

Text
Ran 1 test for test/USDT_Like_Approval_DoS.t.sol:USDTLike_Approval_DoS_PoC
[PASS] test_MEDIUM_usdt_like_approval_breaks_next_call() (gas: 357478)
Logs:
  --- PoC: USDT-like Approval Fails After Partial Fill Left Non-Zero Allowance (USDT->WETH) ---
  Leftover USDT-like allowance to aggregator after partial fill: 999999999999
  Second call should revert due to USDT-like non-zero -> non-zero approve rule.
  VULNERABILITY CONFIRMED: Approval hygiene blocks subsequent operations.

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 21.56ms (5.32ms CPU time)

This output says one test ran, it passed, and it used 357,478 units of gas. The log lines are the printed notes from the steps above.

The report is honest about a limitation of this run: the second call actually failed earlier, during transferFrom, because the test user's balance was used up. transferFrom is the step where tokens are moved from one account to another. The precondition that matters, a leftover non-zero permission after a partial fill, is demonstrated. With enough balance, the helper would reach safeApprove over a non-zero current permission and fail under USDT-like rules.

Why it happens

The helper uses safeApprove(spender, amount) directly, without first resetting an existing permission to zero. USDT-like tokens require the permission to be zero before it can be set to a new non-zero value, so any path that leaves a leftover permission makes the next approval fail. The same pattern appears in _oneInchHelper, _okxHelper and the vault approvals. Because the helper does not clear leftover permissions after a swap, a partial fill is enough to leave the contract in a state where it cannot approve again for that token.

What it means in practice

After a partial fill leaves a non-zero permission, the helper cannot operate with USDT-like tokens: later calls fail at the approval step. The report frames this as temporarily freezing affected assets and hurting user experience and reliability. The impact depends on the token enforcing the non-zero to non-zero rule and on a partial fill having left a leftover permission; the report does not claim loss of funds.

The fix

The report recommends three measures:

  1. Always reset to zero before setting a new permission: if allowance(spender) != 0, call safeApprove(spender, 0) before safeApprove(spender, amount).
  2. Remove leftover permissions after use: after the swap completes, call safeApprove(spender, 0). This also reduces the risk if a spender becomes compromised.
  3. Handle partial fills so no leftover permission arises: refund unspent srcToken to the user and zero the permission to the router or approver after the call.

These patterns should be applied in _oneInchHelper, _okxHelper and any other approval locations, including vault approvals.

Other places to test

  • Other aggregator wrappers that call safeApprove with a computed amount: check whether a partial fill or a failed swap leaves a non-zero permission, then attempt a second swap with the same token. A positive result is a failure inside the approval on the second call.
  • Vault approval paths: look for approvals to the vault that skip the zero-first step, and try a deposit, withdrawal or re-deposit sequence with a USDT-like token. A positive result is a failure on the second approval.
  • Tokens with the same rule but different failure modes (returning false versus reverting): confirm the helper's safeApprove handling fails in both cases.
  • Swap paths where the router spends less than approved for reasons other than a partial fill, such as price limits or minReturnAmount shortfalls: check whether the leftover permission persists and blocks the next call.

Where to look when hunting

This class of bug hides in helper and wrapper contracts that approve third-party routers, aggregators or vaults on behalf of users. During recon, look for safeApprove calls whose amount is derived from user input or swap parameters, and check whether any code path zeroes the permission before or after use. The signal is a token integration that includes USDT-like assets, where the non-zero to non-zero rule applies. To show impact, demonstrate the leftover permission after a partial fill and the failure on the next call, as this report does with a check on amount - 1 and an expected failure. Be explicit about preconditions such as user balance, since the report notes that its own second call failed earlier at transferFrom and that the approval failure would occur with enough balance.

Glossary

  • Allowance: the amount of a token one account is permitted to take from another.
  • Approval: the act of granting an allowance to another account or contract.
  • Aggregator: a service that finds the best place to trade one token for another.
  • Blockchain: a shared, tamper-resistant record of transactions run by many computers.
  • BoringVault: the vault contract in this stack that holds assets.
  • Contract: a program that lives on a blockchain and can hold tokens and respond to requests.
  • DEX: a decentralised exchange, a place where tokens are traded without a central company.
  • Decimals: how many tiny pieces make up one whole unit of a token.
  • ERC20: the common rulebook that tokens follow so wallets and contracts can interact with them.
  • Foundry: a toolkit for writing and running tests against Solidity code on a simulated blockchain.
  • Gas: the fee paid for running code on a blockchain.
  • Partial fill: a swap that spends less than the full approved amount.
  • Predicate: a check that decides whether a user is allowed to perform an action.
  • Proof of concept (PoC): a small test that demonstrates a bug actually happens.
  • Remappings: settings that tell the compiler where to find imported files.
  • Revert: the blockchain's way of cancelling a transaction and undoing its effects.
  • Role: a numbered label that groups permissions together.
  • SafeApprove: a library function that calls a token's approval and stops the transaction if the token reports failure.
  • Solidity: the programming language used for contracts on Ethereum-like blockchains.
  • Spender: the account or contract that is allowed to take tokens from another.
  • Teller: the contract that handles deposits and withdrawals in this stack.
  • Token: a digital asset on a blockchain, such as USDT or WETH.
  • transferFrom: the step where tokens are moved from one account to another using an allowance.
  • USDT-like token: a token that refuses to change an allowance directly from one non-zero value to another.
  • Vault: a digital safe that holds tokens and performs operations with them.
  • Wei: the smallest unit of ether.
  • WETH: a token that represents ether in token form.

More from Plume Network

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.