Setting `RevertGasLimit` to a value larger than `uint64` in the Solidity gateway contract will cause a panic that prevents finalizing the inbound CCTX and observers from receiving block rewards
The Solidity gateway contract allows a revert gas limit larger than uint64, which causes a panic in the Go code when converting to uint64. This prevents finalizing the inbound cross-chain transaction and observers do not receive block rewards.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-04-zetachain-cross-chain-judging/issues/310
Found by
berndartmueller
Summary
The RevertGasLimit is a uint256 in Solidity. When calling cctx.RevertOptions.RevertGasLimit.Uint64() in GetRevertGasLimit(), it will panic if the value does not fit into a uint64.
As a result, the finalizing vote that executes the MsgVoteInbound message will fail. The ballet will remain pending, and observers will not receive block rewards for those pending ballots.
Root Cause
In GetRevertGasLimit()#L72, the RevertGasLimit is a cosmossdk_io_math.Uint and possibly set to a value of size uint256 in the Solidity gateway contract.
66: // GetRevertGasLimit returns the gas limit for the revert transaction in a CCTX
67: // It returns 0 if there is no error but the gas limit can't be determined from the CCTX data
68: func (k Keeper) GetRevertGasLimit(ctx sdk.Context, cctx types.CrossChainTx) (uint64, error) {
69: // with V2 protocol, reverts on connected chains can eventually call a onRevert function which can require a higher gas limit
70: if cctx.ProtocolContractVersion == types.ProtocolContractVersion_V2 && cctx.RevertOptions.CallOnRevert &&
71: !cctx.RevertOptions.RevertGasLimit.IsZero() {
72: ❌ return cctx.RevertOptions.RevertGasLimit.Uint64(), nil
73: }
However, Uint64() will panic if the value does not fit into a uint64.
File: cosmossdk.io/[email protected]/uint.go
72: // Uint64 converts Uint to uint64
73: // Panics if the value is out of range
74: func (u Uint) Uint64() uint64 {
75: if !u.i.IsUint64() {
76: panic("Uint64() out of bound")
77: }
78: return u.i.Uint64()
79: }
This panic will cause the whole Cosmos SDK MsgVoteInbound message to fail. As a result, the finalizing vote that will trigger this code path will have the message fail. Previous votes on the same ballot will be processed and stored.
Internal Pre-conditions
None
External Pre-conditions
None
Attack Path
- On Ethereum, call the
GatewayEVM.depositAndCall()function withonRevertGasLimitset to a value larger thanuint64. The target contract on ZEVM should revert for this inbound. - Observers vote on this inbound
- The observer with the final vote will execute the inbound CCTX on ZEVM
- On ZEVM, the target function reverts so that a revert outbound is attempted to be created.
GetRevertGasLimit()panics- The inbound and hence the corresponding ballot remains pending
- Observers who voted on the inbound will not receive block rewards
Impact
Observers will vote on the inbound, and the ballot will track the votes. Finalizing the ballot is not possible. It remains pending. Hence, observers will not receive block rewards for those pending ballots, even though they have voted and thus spent gas.
PoC
Adapt the existing E2E test e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go:
diff --git a/node/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go b/node/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go
index db7fd26ca..2868d4dda 100644
--- a/node/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go
+++ b/node/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go
@@ -3,6 +3,7 @@ package e2etests
import (
"math/big"
+ sdkmath "cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/pkg/gatewayevm.sol"
@@ -29,7 +30,7 @@ func TestETHDepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) {
RevertAddress: r.TestDAppV2EVMAddr,
CallOnRevert: true,
RevertMessage: []byte(payload),
- OnRevertGasLimit: big.NewInt(200000),
+ OnRevertGasLimit: sdkmath.NewUintFromString("184467440737095516160").BigIntMut(),
},
)
Run the test:
zetae2e run eth_deposit_and_call_revert_with_call --config cmd/zetae2e/config/local.yml --verbose
Docker container logs show that the Cosmos SDK message panics! This demonstrates that the inbound CCTX (initiated on Ethereum) cannot be finalized on ZetaChain.
Mitigation
Consider using cctx.RevertOptions.RevertGasLimit.BigInt().Uint64(), which safely truncates the value to 64 bits. However, it would be better to update the Solidity code to use uint64 instead of uint256 for the revert gas limit.
func (k Keeper) GetRevertGasLimit(ctx sdk.Context, cctx types.CrossChainTx) (uint64, error) {
// with V2 protocol, reverts on connected chains can eventually call a onRevert function which can require a higher gas limit
if cctx.ProtocolContractVersion == types.ProtocolContractVersion_V2 && cctx.RevertOptions.CallOnRevert &&
!cctx.RevertOptions.RevertGasLimit.IsZero() {
fmt.Println("cctx.RevertOptions.RevertGasLimit", cctx.RevertOptions.RevertGasLimit)
- return cctx.RevertOptions.RevertGasLimit.Uint64(), nil
+ return cctx.RevertOptions.RevertGasLimit.BigInt().Uint64(), nil
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/zeta-chain/protocol-contracts/pull/510
gjaldon
This PR addresses the issue by setting a MAX_REVERT_GAS_LIMIT of 2M for all calls that support reverts in GatewayEVM and GatewayZEVM.
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
The Solidity contract uses a 256-bit integer for the revert gas limit, but the Go code assumes it fits in 64 bits and panics on conversion.
Impact
Observers who voted on the inbound will not receive block rewards for the pending ballot, even though they spent gas.
What the attacker needed
Ability to call the gateway contract on Ethereum
The fix
The protocol team fixed this by setting a maximum revert gas limit of 2 million in the gateway contracts.
How it was found
- Call the gateway contract on Ethereum with a revert gas limit larger than uint64 and a target contract that will revert.
- Observers vote on the inbound transaction.
- The final observer executes the inbound on ZetaChain, which reverts and tries to create a revert outbound.
- The gas limit conversion panics, so the inbound and its ballot remain pending.
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.
A cross-chain transaction can include a gas limit for a fallback action if something goes wrong. The smart contract lets you set that limit to a very large number, but the node software that processes it can only handle smaller numbers. When it tries to convert the large number, it crashes, so the transaction never finishes and the people who validated it don't get their rewards.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.