Skip to content

Commit

Permalink
feat: zevm message passing (#2034)
Browse files Browse the repository at this point in the history
* add evm unit tests

* add unit tests for ZevmOnReceive and ZevmOnRevert

* add unit tests for reverts

* changes to evm deposti

* refactor call to use connector for deposit to contract

* fix unit tests for ZEVMdeposit

* add unit tests for revert

* add todo for message encoding and decoding

* add base54 encoding and decoding

* add e2e test for revert

* add e2e test for revert

* add e2e test for revert

* add debugging for issue

* add logs

* add refund for gas meter

* increase gas limit to 400000 for msg passing

* add zEVM to EVM messages

* add tests for onRevert

* fix unit tests

* fix unit tests

* add comments

* add changelog

* Fix the error in execution

Replace error code duplicated to fix the execution error

* Update testutil/contracts/Dapp.sol

Co-authored-by: Lucas Bertrand <[email protected]>

* fixed logs and resolved comments 1

* move end to end tests to zeta advanced tests

* move end to end tests to zeta advanced tests

* revert a cctx instead of aborting when message decode fails

* separate processing for ZEVM orginating and non ZEVM originating txs into separate functions

* fix lint issues

---------

Co-authored-by: Lucas Bertrand <[email protected]>
  • Loading branch information
kingpinXD and lumtis authored Apr 19, 2024
1 parent 1051a31 commit fe916e2
Show file tree
Hide file tree
Showing 69 changed files with 2,693 additions and 198 deletions.
10 changes: 5 additions & 5 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmlog "github.com/tendermint/tendermint/libs/log"
cctxtypes "github.com/zeta-chain/zetacore/x/crosschain/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

Expand Down Expand Up @@ -168,10 +168,10 @@ func IsSystemTx(tx sdk.Tx, isAuthorizedSigner func(string) bool) bool {
}
}
switch innerMsg.(type) {
case *cctxtypes.MsgVoteGasPrice,
*cctxtypes.MsgVoteOnObservedInboundTx,
*cctxtypes.MsgVoteOnObservedOutboundTx,
*cctxtypes.MsgAddToOutTxTracker,
case *crosschaintypes.MsgVoteGasPrice,
*crosschaintypes.MsgVoteOnObservedInboundTx,
*crosschaintypes.MsgVoteOnObservedOutboundTx,
*crosschaintypes.MsgAddToOutTxTracker,
*observertypes.MsgVoteBlockHeader,
*observertypes.MsgVoteTSS,
*observertypes.MsgAddBlameVote:
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* [1954](https://github.com/zeta-chain/node/pull/1954) - add metric for concurrent keysigns
* [2006](https://github.com/zeta-chain/node/pull/2006) - add Amoy testnet static chain information
* [2046](https://github.com/zeta-chain/node/pull/2046) - add state variable in crosschain for rate limiter flags
* [2034](https://github.com/zeta-chain/node/pull/2034) - add support for zEVM message passing

### Tests

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.C
conf.Contracts.ZEVM.WZetaAddr = r.WZetaAddr.Hex()
conf.Contracts.ZEVM.ZEVMSwapAppAddr = r.ZEVMSwapAppAddr.Hex()
conf.Contracts.ZEVM.ContextAppAddr = r.ContextAppAddr.Hex()
conf.Contracts.ZEVM.TestDappAddr = r.TestDAppAddr.Hex()
conf.Contracts.ZEVM.TestDappAddr = r.EvmTestDAppAddr.Hex()

return conf
}
4 changes: 2 additions & 2 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
zetaeth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zeta.eth.sol"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/connectorzevm.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/wzeta.sol"
connectorzevm "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zetaconnectorzevm.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol"
"github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol"
uniswapv2router "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol"
Expand Down Expand Up @@ -181,7 +181,7 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid TestDappAddr: %s", c)
}
r.TestDAppAddr = ethcommon.HexToAddress(c)
r.EvmTestDAppAddr = ethcommon.HexToAddress(c)
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}
zetaAdvancedTests := []string{
e2etests.TestZetaDepositRestrictedName,
e2etests.TestMessagePassingZEVMToEVMName,
e2etests.TestMessagePassingEVMtoZEVMName,
e2etests.TestMessagePassingEVMtoZEVMRevertName,
e2etests.TestMessagePassingZEVMtoEVMRevertName,
}
bitcoinTests := []string{
e2etests.TestBitcoinWithdrawSegWitName,
Expand Down
37 changes: 37 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const (
TestCrosschainSwapName = "crosschain_swap"
TestMessagePassingRevertFailName = "message_passing_revert_fail"
TestMessagePassingRevertSuccessName = "message_passing_revert_success"
TestMessagePassingEVMtoZEVMName = "message_passing_zevm"
TestMessagePassingZEVMToEVMName = "message_passing_zevm_to_evm"

TestMessagePassingZEVMtoEVMRevertName = "message_passing_zevm_to_evm_revert"
TestMessagePassingEVMtoZEVMRevertName = "message_passing_revert_zevm"
TestERC20DepositAndCallRefundName = "erc20_deposit_and_call_refund"
TestEtherDepositAndCallName = "eth_deposit_and_call"
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
Expand Down Expand Up @@ -372,4 +377,36 @@ var AllE2ETests = []runner.E2ETest{
[]runner.ArgDefinition{},
TestUpdateBytecodeConnector,
),
runner.NewE2ETest(
TestMessagePassingZEVMToEVMName,
"zevm -> evm message passing contract call",
[]runner.ArgDefinition{
runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000007"},
},
TestMessagePassingZEVMtoEVM,
),
runner.NewE2ETest(
TestMessagePassingZEVMtoEVMRevertName,
"zevm -> evm message passing contract call reverts",
[]runner.ArgDefinition{
runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000006"},
},
TestMessagePassingZEVMtoEVMRevert,
),
runner.NewE2ETest(
TestMessagePassingEVMtoZEVMName,
"evm -> zevm message passing contract call ",
[]runner.ArgDefinition{
runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000009"},
},
TestMessagePassingEVMtoZEVM,
),
runner.NewE2ETest(
TestMessagePassingEVMtoZEVMRevertName,
"evm -> zevm message passing and revert back to evm",
[]runner.ArgDefinition{
runner.ArgDefinition{Description: "amount in azeta", DefaultValue: "10000000000000000008"},
},
TestMessagePassingEVMtoZEVMRevert,
),
}
1 change: 1 addition & 0 deletions e2e/e2etests/test_eth_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) {
if receipt.Status == 0 {
panic("tx failed")
}

cctx = utils.WaitCctxMinedByInTxHash(r.Ctx, signedTx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
if cctx.CctxStatus.Status != types.CctxStatus_Reverted {
panic(fmt.Sprintf("expected cctx status to be reverted; got %s", cctx.CctxStatus.Status))
Expand Down
8 changes: 4 additions & 4 deletions e2e/e2etests/test_message_passing.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestMessagePassingRevertSuccess(r *runner.E2ERunner, args []string) {

auth := r.EVMAuth

tx, err := r.ZetaEth.Approve(auth, r.TestDAppAddr, amount)
tx, err := r.ZetaEth.Approve(auth, r.EvmTestDAppAddr, amount)
if err != nil {
panic(err)
}
Expand All @@ -202,8 +202,8 @@ func TestMessagePassingRevertSuccess(r *runner.E2ERunner, args []string) {
}
r.Logger.Info("Approve tx receipt: %d", receipt.Status)

r.Logger.Info("Calling TestDApp.SendHello on contract address %s", r.TestDAppAddr.Hex())
testDApp, err := testdapp.NewTestDApp(r.TestDAppAddr, r.EVMClient)
r.Logger.Info("Calling TestDApp.SendHello on contract address %s", r.EvmTestDAppAddr.Hex())
testDApp, err := testdapp.NewTestDApp(r.EvmTestDAppAddr, r.EVMClient)
if err != nil {
panic(err)
}
Expand All @@ -216,7 +216,7 @@ func TestMessagePassingRevertSuccess(r *runner.E2ERunner, args []string) {
}
r.Logger.Info("$$$ Before: SUPPLY OF AZETA: %d", res2.Amount.Amount)

tx, err = testDApp.SendHelloWorld(auth, r.TestDAppAddr, chainID, amount, true)
tx, err = testDApp.SendHelloWorld(auth, r.EvmTestDAppAddr, chainID, amount, true)
if err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit fe916e2

Please sign in to comment.