Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crosschain): add support to perform withdraws in ZetaChain onRevert call #3348

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Unreleased

### Fixes

* [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
71 changes: 40 additions & 31 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
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])
lumtis marked this conversation as resolved.
Show resolved Hide resolved

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)
}
Loading
Loading