Direct WETH swap fails due to incompatibility with ZetaTokenConsumerUniV3 & ZetaTokenConsumerPancakeV3
The swap functions in the Zeta token consumer contracts always route through a WETH/WETH pool when the input or output token is WETH, but such a pool cannot exist, so direct WETH-to-ZETA swaps revert. An attacker could not exploit this; it is a functional bug that prevents users from swapping WETH directly.
Originally disclosed on Code4rena
Submitted by Josephdara_0xTiwa
User use the ZetaTokenConsumerUniV3.sol to get the zeta tokens. Either through ETH or through other ERC20 tokens. One of the most important tokens in Defi today is the WETH token, all swaps in the codebase to/from ZETA are routed through the ZETA/WETH pool. However this contact, as well as the ZetaTokenConsumerPancakeV3 and the ZetaTokenConsumerTrident do not permit users to swap WETH directly to ZETA. This is because of an oversight in the swap function that require the existence of a WETH/WETH pool. As seen below, when the input/output token is WETH, the function will revert:
function getZetaFromToken(
address destinationAddress,
uint256 minAmountOut,
address inputToken,
uint256 inputTokenAmount
) external override returns (uint256) {
if (destinationAddress == address(0) || inputToken == address(0)) revert ZetaCommonErrors.InvalidAddress();
if (inputTokenAmount == 0) revert InputCantBeZero();
IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputTokenAmount);
IERC20(inputToken).safeApprove(address(uniswapV3Router), inputTokenAmount);
ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
deadline: block.timestamp + MAX_DEADLINE,
path: abi.encodePacked(inputToken, tokenPoolFee, WETH9Address, zetaPoolFee, zetaToken),
recipient: destinationAddress,
amountIn: inputTokenAmount,
amountOutMinimum: minAmountOut
});
Proof of Concept
From the Pancake V3 factory and Uni V3 factory contracts, it is evident that pools cannot be created for a token with itself. Therefore users cannot swap WETH to WETH thereby breaking the path needed to swap WETH to Zeta or vice versa. In the code base, the issue is present:
- https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerPancakeV3.strategy.sol#L138-L145
- https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerPancakeV3.strategy.sol#L195-L203
- https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol#L111-L128
- https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerTrident.strategy.sol#L178-L197
- https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerUniV3.strategy.sol#L110-L118
- https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/protocol-contracts/contracts/evm/tools/ZetaTokenConsumerUniV3.strategy.sol#L170-L178
Recommended Mitigation Steps
Implement a check to see if the input/output token is WETH, if so, perform the swap directly between WETH and ZETA without a second swap.
josephdara (Warden) commented:
All references stated in the POC section are lines of code in the codebase within scope that require a WETH/WETH pool.
When the Input token is WETH, it attempts to first swap to WETH, then to ZETA. When the output token is WETH, it first swaps ZETA to WETH, then attempts swapping WETH to WETH.
This was explained above with all the points that this happened listed in the POC section.
More evidence would certainly have been welcomed, but I follow the wardens belief that this would cause an issue when attempting to call
getZetaFromToken()and the input is WETH.
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 swap path construction always includes WETH as an intermediate hop, even when the input or output token is already WETH, requiring a non-existent WETH/WETH pool.
Impact
Users cannot swap WETH directly to ZETA or vice versa through these contracts; the swap reverts, but there is no security impact.
What the attacker needed
None
The fix
The contracts should check if the input or output token is WETH and, if so, perform the swap directly between WETH and ZETA without the extra hop.
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.
These contracts help users swap tokens to get ZETA. They build a path that includes WETH twice when the user already uses WETH, but a trading pool for a token with itself cannot be created, so the swap fails. This is a bug that blocks a normal action, not something an attacker can abuse.
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.