Skip to content

Commit

Permalink
fix: backport for v26 onRevert CCTX and Solana withdraw fixes (#3380)
Browse files Browse the repository at this point in the history
* update contracts

* add revert and withdraw test

* add tx response to revert deposit

* process withdraw

* tests

* add withdraw and revert check in test

* comment lint

* add tests back

* update changelog

* add unit tests

* fix test

* update condition

* remove minimum rent exempt check for SPL tokens

* lower default SPL withdraw amount in E2E to ensure min rent exempt is not checked

* add changelog entry

* add comment to explain why rent exempt check is only applied to Solana gas token

* changelog

* update old version

* add liquidity cap to message

* update messages and tests

* fix e2e tests

* changelog

* fix tests

* proto add new chain types

* add new chains

* changelog

* Revert "fix tests"

This reverts commit 8e37fd0.

* Revert "fix e2e tests"

This reverts commit c27fc1d.

* Revert "update messages and tests"

This reverts commit 159af85.

* Revert "add liquidity cap to message"

This reverts commit 748eec1.

---------

Co-authored-by: Charlie Chen <[email protected]>
  • Loading branch information
lumtis and ws4charlie authored Jan 21, 2025
1 parent 4a04d96 commit 178398a
Show file tree
Hide file tree
Showing 25 changed files with 792 additions and 167 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ ifdef UPGRADE_TEST_FROM_SOURCE
zetanode-upgrade: e2e-images
@echo "Building zetanode-upgrade from source"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source \
--build-arg OLD_VERSION='release/v24' \
--build-arg OLD_VERSION='release/v25' \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg NODE_COMMIT=$(NODE_COMMIT)
.
Expand All @@ -336,7 +336,7 @@ else
zetanode-upgrade: e2e-images
@echo "Building zetanode-upgrade from binaries"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime \
--build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v24.0.0' \
--build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v25.0.0' \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg NODE_COMMIT=$(NODE_COMMIT) \
.
Expand Down
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG

## v26.0.0

### Features

* [3353](https://github.com/zeta-chain/node/pull/3353) - add liquidity cap parameter to ZRC20 creation
* [3379](https://github.com/zeta-chain/node/pull/3379) - add Avalanche, Arbitrum and World Chain in chain info

### Fixes

* [3374](https://github.com/zeta-chain/node/pull/3374) - remove minimum rent exempt check for SPL token withdrawals
* [3348](https://github.com/zeta-chain/node/pull/3348) - add support to perform withdraws in ZetaChain `onRevert` call

## v25.0.0

### Features
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func startEVMTests(eg *errgroup.Group, conf config.Config, deployerRunner *runne
e2etests.TestETHDepositAndCallRevertWithCallName,
e2etests.TestETHWithdrawAndCallRevertName,
e2etests.TestETHWithdrawAndCallRevertWithCallName,
e2etests.TestETHWithdrawAndCallRevertWithWithdrawName,
e2etests.TestDepositAndCallOutOfGasName,
),
)
Expand Down
9 changes: 8 additions & 1 deletion docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57014,8 +57014,12 @@ definitions:
- op_stack
- solana_consensus
- catchain_consensus
- snowman
- arbitrum_nitro
default: ethereum
description: '- catchain_consensus: ton'
description: |-
- catchain_consensus: ton
- snowman: avalanche
title: |-
Consensus represents the consensus algorithm used by the chain
this can represent the consensus of a L1
Expand All @@ -57032,6 +57036,9 @@ definitions:
- base
- solana
- ton
- avalanche
- arbitrum
- worldchain
default: eth
title: |-
Network represents the network of the chain
Expand Down
73 changes: 41 additions & 32 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@ const (
/*
EVM chain tests
*/
TestETHDepositName = "eth_deposit"
TestETHDepositAndCallName = "eth_deposit_and_call"
TestETHDepositAndCallNoMessageName = "eth_deposit_and_call_no_message"
TestETHDepositAndCallRevertName = "eth_deposit_and_call_revert"
TestETHDepositAndCallRevertWithCallName = "eth_deposit_and_call_revert_with_call"
TestETHWithdrawName = "eth_withdraw"
TestETHWithdrawAndArbitraryCallName = "eth_withdraw_and_arbitrary_call"
TestETHWithdrawAndCallName = "eth_withdraw_and_call"
TestETHWithdrawAndCallNoMessageName = "eth_withdraw_and_call_no_message"
TestETHWithdrawAndCallThroughContractName = "eth_withdraw_and_call_through_contract"
TestETHWithdrawAndCallRevertName = "eth_withdraw_and_call_revert"
TestETHWithdrawAndCallRevertWithCallName = "eth_withdraw_and_call_revert_with_call"
TestDepositAndCallOutOfGasName = "deposit_and_call_out_of_gas"
TestERC20DepositName = "erc20_deposit"
TestERC20DepositAndCallName = "erc20_deposit_and_call"
TestERC20DepositAndCallNoMessageName = "erc20_deposit_and_call_no_message"
TestERC20DepositAndCallRevertName = "erc20_deposit_and_call_revert"
TestERC20DepositAndCallRevertWithCallName = "erc20_deposit_and_call_revert_with_call"
TestERC20WithdrawName = "erc20_withdraw"
TestERC20WithdrawAndArbitraryCallName = "erc20_withdraw_and_arbitrary_call"
TestERC20WithdrawAndCallName = "erc20_withdraw_and_call"
TestERC20WithdrawAndCallNoMessageName = "erc20_withdraw_and_call_no_message"
TestERC20WithdrawAndCallRevertName = "erc20_withdraw_and_call_revert"
TestERC20WithdrawAndCallRevertWithCallName = "erc20_withdraw_and_call_revert_with_call"
TestZEVMToEVMArbitraryCallName = "zevm_to_evm_arbitrary_call"
TestZEVMToEVMCallName = "zevm_to_evm_call"
TestZEVMToEVMCallThroughContractName = "zevm_to_evm_call_through_contract"
TestEVMToZEVMCallName = "evm_to_zevm_call"
TestDepositAndCallSwapName = "deposit_and_call_swap"
TestEtherWithdrawRestrictedName = "eth_withdraw_restricted"
TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestETHDepositName = "eth_deposit"
TestETHDepositAndCallName = "eth_deposit_and_call"
TestETHDepositAndCallNoMessageName = "eth_deposit_and_call_no_message"
TestETHDepositAndCallRevertName = "eth_deposit_and_call_revert"
TestETHDepositAndCallRevertWithCallName = "eth_deposit_and_call_revert_with_call"
TestETHWithdrawName = "eth_withdraw"
TestETHWithdrawAndArbitraryCallName = "eth_withdraw_and_arbitrary_call"
TestETHWithdrawAndCallName = "eth_withdraw_and_call"
TestETHWithdrawAndCallNoMessageName = "eth_withdraw_and_call_no_message"
TestETHWithdrawAndCallThroughContractName = "eth_withdraw_and_call_through_contract"
TestETHWithdrawAndCallRevertName = "eth_withdraw_and_call_revert"
TestETHWithdrawAndCallRevertWithCallName = "eth_withdraw_and_call_revert_with_call"
TestETHWithdrawAndCallRevertWithWithdrawName = "eth_withdraw_and_call_revert_with_withdraw"
TestDepositAndCallOutOfGasName = "deposit_and_call_out_of_gas"
TestERC20DepositName = "erc20_deposit"
TestERC20DepositAndCallName = "erc20_deposit_and_call"
TestERC20DepositAndCallNoMessageName = "erc20_deposit_and_call_no_message"
TestERC20DepositAndCallRevertName = "erc20_deposit_and_call_revert"
TestERC20DepositAndCallRevertWithCallName = "erc20_deposit_and_call_revert_with_call"
TestERC20WithdrawName = "erc20_withdraw"
TestERC20WithdrawAndArbitraryCallName = "erc20_withdraw_and_arbitrary_call"
TestERC20WithdrawAndCallName = "erc20_withdraw_and_call"
TestERC20WithdrawAndCallNoMessageName = "erc20_withdraw_and_call_no_message"
TestERC20WithdrawAndCallRevertName = "erc20_withdraw_and_call_revert"
TestERC20WithdrawAndCallRevertWithCallName = "erc20_withdraw_and_call_revert_with_call"
TestZEVMToEVMArbitraryCallName = "zevm_to_evm_arbitrary_call"
TestZEVMToEVMCallName = "zevm_to_evm_call"
TestZEVMToEVMCallThroughContractName = "zevm_to_evm_call_through_contract"
TestEVMToZEVMCallName = "evm_to_zevm_call"
TestDepositAndCallSwapName = "deposit_and_call_swap"
TestEtherWithdrawRestrictedName = "eth_withdraw_restricted"
TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential

/*
* Solana tests
Expand Down Expand Up @@ -295,6 +296,14 @@ var AllE2ETests = []runner.E2ETest{
},
TestETHWithdrawAndCallRevertWithCall,
),
runner.NewE2ETest(
TestETHWithdrawAndCallRevertWithWithdrawName,
"withdraw Ether from ZEVM and call a contract that reverts with a onRevert call that triggers a withdraw",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "10000000000000000"},
},
TestETHWithdrawAndCallRevertWithWithdraw,
),
runner.NewE2ETest(
TestDepositAndCallOutOfGasName,
"deposit Ether into ZEVM and call a contract that runs out of gas",
Expand Down Expand Up @@ -453,7 +462,7 @@ var AllE2ETests = []runner.E2ETest{
TestSPLWithdrawName,
"withdraw SPL from ZEVM",
[]runner.ArgDefinition{
{Description: "amount in spl tokens", DefaultValue: "1000000"},
{Description: "amount in spl tokens", DefaultValue: "100000"},
},
TestSPLWithdraw,
),
Expand Down
49 changes: 49 additions & 0 deletions e2e/e2etests/test_eth_withdraw_and_call_revert_with_withdraw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package e2etests

import (
"math/big"

"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

func TestETHWithdrawAndCallRevertWithWithdraw(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount := utils.ParseBigInt(r, args[0])

r.ApproveETHZRC20(r.GatewayZEVMAddr)

// perform the withdraw
tx := r.ETHWithdrawAndArbitraryCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeGasCall("revert"),
gatewayzevm.RevertOptions{
RevertAddress: r.TestDAppV2ZEVMAddr,
CallOnRevert: true,
RevertMessage: []byte("withdraw"), // call withdraw in the onRevert hook
OnRevertGasLimit: big.NewInt(0),
},
)

// wait for the cctx to be mined
cctxRevert := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctxRevert, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctxRevert.CctxStatus.Status)

cctxWithdrawFromRevert := utils.WaitCctxMinedByInboundHash(
r.Ctx,
cctxRevert.Index,
r.CctxClient,
r.Logger,
r.CctxTimeout,
)

// check the cctx status
utils.RequireCCTXStatus(r, cctxWithdrawFromRevert, crosschaintypes.CctxStatus_OutboundMined)
}
4 changes: 2 additions & 2 deletions pkg/chains/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestChain_Validate(t *testing.T) {
chain: chains.Chain{
ChainId: 42,
Name: "foo",
Network: chains.Network_ton + 1,
Network: chains.Network_worldchain + 1,
NetworkType: chains.NetworkType_testnet,
Vm: chains.Vm_evm,
Consensus: chains.Consensus_op_stack,
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestChain_Validate(t *testing.T) {
Network: chains.Network_base,
NetworkType: chains.NetworkType_devnet,
Vm: chains.Vm_evm,
Consensus: chains.Consensus_catchain_consensus + 1,
Consensus: chains.Consensus_arbitrum_nitro + 1,
IsExternal: true,
},
errStr: "invalid consensus",
Expand Down
78 changes: 78 additions & 0 deletions pkg/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ var (
Name: "base_mainnet",
}

// AvalancheMainnet is the Avalanche mainnet C-Chain
AvalancheMainnet = Chain{
ChainId: 43114,
Network: Network_avalanche,
NetworkType: NetworkType_mainnet,
Vm: Vm_evm,
Consensus: Consensus_snowman,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "avalanche_mainnet",
}

// ArbitrumMainnet is the Arbitrum mainnet
ArbitrumMainnet = Chain{
ChainId: 42161,
Network: Network_arbitrum,
NetworkType: NetworkType_mainnet,
Vm: Vm_evm,
Consensus: Consensus_arbitrum_nitro,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "arbitrum_mainnet",
}

// WorldMainnet is the World Chain mainnet
WorldMainnet = Chain{
ChainId: 480,
Network: Network_worldchain,
NetworkType: NetworkType_mainnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "world_mainnet",
}

// SolanaMainnet is Solana mainnet
// TODO: define final chain ID
// https://github.com/zeta-chain/node/issues/2421
Expand Down Expand Up @@ -244,6 +280,42 @@ var (
Name: "base_sepolia",
}

// AvalancheTestnet is the Avalanche testnet C-Chain
AvalancheTestnet = Chain{
ChainId: 43113,
Network: Network_avalanche,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_snowman,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "avalanche_testnet",
}

// ArbitrumSepolia is the Arbitrum sepolia testnet
ArbitrumSepolia = Chain{
ChainId: 421614,
Network: Network_arbitrum,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_arbitrum_nitro,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "arbitrum_sepolia",
}

// WorldTestnet is the World Chain testnet
WorldTestnet = Chain{
ChainId: 4801,
Network: Network_worldchain,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "world_testnet",
}

// SolanaDevnet is Solana devnet
// NOTE: Solana devnet refers to Solana testnet in our terminology
// Solana uses devnet denomitation for network for development
Expand Down Expand Up @@ -429,6 +501,12 @@ func DefaultChainsList() []Chain {
TONMainnet,
TONTestnet,
TONLocalnet,
AvalancheMainnet,
AvalancheTestnet,
ArbitrumMainnet,
ArbitrumSepolia,
WorldMainnet,
WorldTestnet,
}
}

Expand Down
Loading

0 comments on commit 178398a

Please sign in to comment.