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: emit events on revert #2466

Merged
merged 9 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 3 additions & 1 deletion cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ contracts:
uniswap_router: "0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe"
connector_zevm: "0x239e96c8f17C85c30100AC26F635Ea15f23E9c67"
wzeta: "0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf"
test_dapp: "0xA8D5060feb6B456e886F023709A2795373691E63"
evm:
zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9"
connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca"
custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
test_dapp: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed"
22 changes: 22 additions & 0 deletions e2e/e2etests/test_message_passing_evm_to_zevm_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ import (
cctxtypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

// fungibleModuleAddress is a constant representing the EVM address of the Fungible module account
const fungibleModuleAddress = "0x735b14BB79463307AAcBED86DAf3322B1e6226aB"

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

fungibleEthAddress := ethcommon.HexToAddress(fungibleModuleAddress)
require.True(r, fungibleEthAddress != ethcommon.Address{}, "invalid fungible module address")

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok)

Expand Down Expand Up @@ -46,6 +52,9 @@ func TestMessagePassingEVMtoZEVMRevert(r *runner.E2ERunner, args []string) {
previousBalanceEVM, err := r.ZetaEth.BalanceOf(&bind.CallOpts{}, r.EvmTestDAppAddr)
require.NoError(r, err)

previousFungibleBalance, err := r.WZeta.BalanceOf(&bind.CallOpts{}, fungibleEthAddress)
require.NoError(r, err)

// Call the SendHelloWorld function on the EVM dapp Contract which would in turn create a new send, to be picked up by the zeta-clients
// set Do revert to true which adds a message to signal the ZEVM zetaReceiver to revert the transaction
tx, err = testDAppEVM.SendHelloWorld(r.EVMAuth, destinationAddress, zEVMChainID, amount, true)
Expand Down Expand Up @@ -105,4 +114,17 @@ func TestMessagePassingEVMtoZEVMRevert(r *runner.E2ERunner, args []string) {
previousBalanceAndAmountEVM.String(),
newBalanceEVM.String(),
)

// Check ZETA balance on Fungible Module and check new balance is previous balance
newFungibleBalance, err := r.WZeta.BalanceOf(&bind.CallOpts{}, fungibleEthAddress)
require.NoError(r, err)

require.Equal(
r,
0,
newFungibleBalance.Cmp(previousFungibleBalance),
"expected new balance to be %s, got %s",
previousFungibleBalance.String(),
newFungibleBalance.String(),
)
}
6 changes: 3 additions & 3 deletions rpc/backend/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ func (suite *BackendTestSuite) TestEthAndSyntheticGetBlockByNumber() {
suite.Require().Equal("0x775b87ef5D82ca211811C1a02CE0fE0CA3a455d7", resSyntheticTx.To.Hex())
suite.Require().Equal("0x58", resSyntheticTx.Type.String())
suite.Require().Equal("0x1", resSyntheticTx.Nonce.String())
suite.Require().Nil(resSyntheticTx.V)
suite.Require().Nil(resSyntheticTx.R)
suite.Require().Nil(resSyntheticTx.S)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), resSyntheticTx.V)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), resSyntheticTx.R)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), resSyntheticTx.S)
}
18 changes: 9 additions & 9 deletions rpc/backend/tx_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (suite *BackendTestSuite) TestGetSyntheticTransactionByHash() {
gas, _ := hexutil.DecodeUint64(res.Gas.String())
suite.Require().Equal(uint64(21000), gas)
suite.Require().Equal("0x1234", res.Input.String())
suite.Require().Nil(res.V)
suite.Require().Nil(res.R)
suite.Require().Nil(res.S)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.V)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.R)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.S)
}

func (suite *BackendTestSuite) TestGetSyntheticTransactionReceiptByHash() {
Expand Down Expand Up @@ -127,9 +127,9 @@ func (suite *BackendTestSuite) TestGetSyntheticTransactionByBlockNumberAndIndex(
suite.Require().Equal(uint64(88), txType)
suite.Require().Equal(int64(7001), res.ChainID.ToInt().Int64())
suite.Require().Equal(int64(1000), res.Value.ToInt().Int64())
suite.Require().Nil(res.V)
suite.Require().Nil(res.R)
suite.Require().Nil(res.S)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.V)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.R)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.S)
}

func (suite *BackendTestSuite) TestGetSyntheticTransactionByBlockNumberAndIndexWithRealTransaction() {
Expand Down Expand Up @@ -160,9 +160,9 @@ func (suite *BackendTestSuite) TestGetSyntheticTransactionByBlockNumberAndIndexW
suite.Require().Equal(uint64(88), txType)
suite.Require().Equal(int64(7001), res.ChainID.ToInt().Int64())
suite.Require().Equal(int64(1000), res.Value.ToInt().Int64())
suite.Require().Nil(res.V)
suite.Require().Nil(res.R)
suite.Require().Nil(res.S)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.V)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.R)
suite.Require().Equal((*hexutil.Big)(big.NewInt(0)), res.S)
}

func (suite *BackendTestSuite) TestGetTransactionByHash() {
Expand Down
6 changes: 3 additions & 3 deletions rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ func NewRPCTransactionFromIncompleteMsg(
Nonce: hexutil.Uint64(txAdditional.Nonce), // TODO: get nonce for "from" from ethermint
To: to,
Value: (*hexutil.Big)(txAdditional.Value),
V: nil,
R: nil,
S: nil,
V: (*hexutil.Big)(big.NewInt(0)),
R: (*hexutil.Big)(big.NewInt(0)),
S: (*hexutil.Big)(big.NewInt(0)),
lumtis marked this conversation as resolved.
Show resolved Hide resolved
ChainID: (*hexutil.Big)(chainID),
}
if blockHash != (common.Hash{}) {
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/cctx_gateway_zevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c CCTXGatewayZEVM) InitiateOutbound(
}

newCCTXStatus = c.crosschainKeeper.ValidateOutboundZEVM(ctx, config.CCTX, err, isContractReverted)
if newCCTXStatus == types.CctxStatus_OutboundMined {
if newCCTXStatus != types.CctxStatus_Aborted {
skosito marked this conversation as resolved.
Show resolved Hide resolved
commit()
}

Expand Down
8 changes: 4 additions & 4 deletions x/fungible/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,6 @@ func (k Keeper) CallEVMWithData(
return nil, err
}

if res.Failed() {
return res, cosmoserrors.Wrap(evmtypes.ErrVMExecution, fmt.Sprintf("%s: ret 0x%x", res.VmError, res.Ret))
}

// Emit events and log for the transaction if it is committed
if commit {
msgBytes, err := json.Marshal(msg)
Expand Down Expand Up @@ -825,5 +821,9 @@ func (k Keeper) CallEVMWithData(
}
}

if res.Failed() {
lumtis marked this conversation as resolved.
Show resolved Hide resolved
return res, cosmoserrors.Wrap(evmtypes.ErrVMExecution, fmt.Sprintf("%s: ret 0x%x", res.VmError, res.Ret))
skosito marked this conversation as resolved.
Show resolved Hide resolved
}

return res, nil
}
Loading