Submitted by oakcobalt, also found by MevSec, deliriusz, QiuhaoLi, and p0wd3r
https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/x/crosschain/keeper/gas_payment.go#L321 https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/x/crosschain/keeper/gas_payment.go#L292
UniswapV2 swap on zetaChain is used in multiple flows where the protocol will swap either zeta or ERC20 token to gas erc20 token to pay for outbound tx gas. However, there is no slippage protection for the swapping transaction which makes the process of charging gas fees slippage-prone, easily causing the sender to overpay the revert gas and lose returned funds.
When an outbound tx is initiated whether as a revert tx or diverted outbound tx, PayGasAndUpdateCctx() on gas_payment.go will be called. Based on CointType, PayGasAndUpdateCctx() divert the flow into different process that swaps either zeta token or ERC20 token into gas token of the external chain to pay for revert or outbound gas.
For example, CointType is zeta coin. PayGasInZetaAndUpdateCctx() will be called, which will first calculate gas token amount needed based on the external chainId. Then it first calls QueryUniswapV2RouterGetZetaAmountsIn() which query wzeta/gasZRC20 uniswapv2 pool for zeta token amount (outTxGasFeeInZeta) needed to swap out outTxGasFee.BigInt() amount of gasZRC20 token. Then it will call CallUniswapV2RouterSwapExactETHForToken() with exact input outTxGasFeeInZeta amount.
The above is problematic because after QueryUniswapV2RouterGetZetaAmountsIn(), there is no check to ensure the quoted input token amount outTxGasFeeInZeta is acceptable within a certain slippage parameter. When there is significant slippage in the uniswapV2 pool before protocols PayGasInZetaAndUpdateCctx() call, gasZRC20 token price in zeta amount will be inflated,causing gas overcharged.
When gas is overcharged, (1) this either cause feeInZeta.GT(zetaBurnt) == true which means sender doesnt have enough zeta token to burn, which directly return an error, which might cause a revert cctx to be aborted and sender will lose all refunds. (2) Or if feeInZeta.GT(zetaBurnt) == false, senders zeta balance will be substracted by inflated gas payment, and the sender is overcharged.
(https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/x/crosschain/keeper/gas_payment.go#L292)
As seen above, any price of gasZRC20 will be accepted during gas payment, will directly result in either user losing the entire refund or user overpaying for gas. I consider this medium severity.
Check and handle slippage case. For example, when QueryUniswapV2RouterGetZetaAmountsIn() returns an overinflated value due to slippage, return gas payment flow with a slippage error, and handle slippage error in the corresponding vote inbound/outbound tx flow to allow for pending cctx instead of direct abort.
lumtis (ZetaChain) confirmed
0xean (Judge) commented:
