Skip to content
Business logic Audit finding Intermediate

In ZetaTokenConsumerTrident.strategy.sol, swapping zeta for other tokens will always revert due to incorrect exactInputSingle router method being used

The getZetaFromToken function in ZetaTokenConsumerTrident.strategy.sol calls the wrong Trident router method, exactInputSingle, which expects Bento shares rather than raw ERC-20 tokens. As a result, any attempt to swap tokens for ZETA through this function will always revert.

oakcobalt Follow

Originally disclosed on Code4rena

Submitted by oakcobalt (1, 2)

Swapping zeta for other tokens through getZetaFromToken() will always revert in ZetaTokenConsumerTrident.strategy.sol, due to calling the incorrect exactInputSingle router method.

Proof of Concept

In ZetaTokenConsumerTrident.strategy.sol, when swapping other tokens for zetaToken, getZetaFromToken() will be called and the function will first transfer inputToken from caller and approve tridentRouter to spend inputTokenAmount. Then it will call tridentRouter.exactInputSingle(params) for tridentRouter to execute token swap.

However, exactInputSingle() is the incorrect function for the use case and will always revert. In current TridentRouter.sol implementation, bento balance will be called to transfer from ZetaTokenConsumerTrident.strategy.sol first, but ZetaTokenConsumerTrident.strategy.sol doesn’t have means to deposit into bento, neither will it approve TridentRouter to manage it’s bento tokens.

//contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol
    function getZetaFromToken(
        address destinationAddress,
        uint256 minAmountOut,
        address inputToken,
        uint256 inputTokenAmount
    ) external override returns (uint256) {
...
        IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputTokenAmount);
        IERC20(inputToken).safeApprove(address(tridentRouter), inputTokenAmount);
        (address token0, address token1) = getPair(zetaToken, WETH9Address);
        address[] memory pairPools = poolFactory.getPools(token0, token1, 0, 1);
        IPoolRouter.ExactInputSingleParams memory params = IPoolRouter.ExactInputSingleParams({
            tokenIn: zetaToken,
            amountIn: zetaTokenAmount,
            amountOutMinimum: minAmountOut,
            pool: pairPools[0],
            to: destinationAddress,
            unwrap: true
        });
        //@audit tridentRouter.exactInputSingle will not transfer inputToken, but only tries to transfer bento shares which this contract has no means to deposit nor approve. This will cause transaction revert.
|>      uint256 amountOut = tridentRouter.exactInputSingle(params);
...

(https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol#L159)

//https://github.com/sushiswap/trident/blob/master/contracts/TridentRouter.sol
    function exactInputSingle(ExactInputSingleParams calldata params) public payable returns (uint256 amountOut) {
        // Prefund the pool with token A.
//@audit this modifies bento shares balances, not the actual inputToken balance
|>      bento.transfer(params.tokenIn, msg.sender, params.pool, params.amountIn);
        // Trigger the swap in the pool.
        amountOut = IPool(params.pool).swap(params.data);
        // Ensure that the slippage wasn't too much. This assumes that the pool is honest.
        if (amountOut < params.amountOutMinimum) revert TooLittleReceived();
    }
//https://etherscan.io/address/0xf5bce5077908a1b7370b9ae04adc565ebd643966#code
//@audit allowed(from) modifier will check approval allowance for caller to manage bento shares, in this case, caller will be TridentRouter, and from will be ZetaTokenConsumerTrident.strategy.sol.
    function transfer(
        IERC20 token,
        address from,
        address to,
        uint256 share
    ) public allowed(from) {
        // Checks
        require(to != address(0), "BentoBox: to not set"); // To avoid a bad UI from burning funds

        // Effects
|>      balanceOf[token][from] = balanceOf[token][from].sub(share);
        balanceOf[token][to] = balanceOf[token][to].add(share);

        emit LogTransfer(token, from, to, share);
    }

As seen above, tridentRouter.exactInputSingle() will try to modify bento shares of inputToken, instead of the actual raw erc-20, causing the transaction to revert. Any transactions or flows that involve getZetaFromToken() will fail.

Recommended Mitigation Steps

In ZetaTokenConsumerTrident.strategy.sol getZetaFromToken(), use tridentRouter.exactInputSingleWithNativeToken() instead, which is designed to handle raw ERC-20 token and will deposit into Bento on behalf of ZetaTokenConsumerTrident.strategy first and then perform the swap.

lumtis (ZetaChain) disputed and commented:

We no longer use this contract as Klaytn is not supported anymore

0xean (Judge) commented:

Screenshot 2024-01-07 at 3 44 26 PM

@lumtis While that may be the case, it was included in the audit scope as far as I can tell. Unless this is documented somewhere that I am missing the report is still valid and should be awarded (the warden did work based on the pre-determined scope of the audit).


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

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 contract uses tridentRouter.exactInputSingle, which operates on Bento shares, instead of a method that handles raw ERC-20 tokens and deposits them into Bento first.

Impact

Any transaction or flow that involves getZetaFromToken will fail, preventing swaps of other tokens for ZETA through this contract.

What the attacker needed

Contract deployed and used; caller has input tokens and approval

The fix

The contract should use tridentRouter.exactInputSingleWithNativeToken instead, which handles raw ERC-20 tokens and deposits into Bento first.

How it was found

  1. Call getZetaFromToken with an input token and amount.
  2. The function transfers the input token from the caller and approves the Trident router.
  3. It then calls tridentRouter.exactInputSingle with swap parameters.
  4. The router tries to transfer Bento shares for the input token, but the contract has no Bento balance or approval, so the transaction reverts.

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 bug where a function tries to swap tokens using the wrong internal method. The method it calls expects a different kind of token balance (Bento shares) that the contract never set up, so the swap always fails and the transaction reverts.

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 oakcobalt

View all

50 more disclosed reports, best first.

More from ZetaChain

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.