diff --git a/CHANGELOG.md b/CHANGELOG.md index ef215195c9..ae78f413a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [#1377](https://github.com/crypto-org-chain/cronos/pull/1377) Upgrade sdk to 0.50, and integrate block-stm parallel tx execution. * [#1394](https://github.com/crypto-org-chain/cronos/pull/1394) Add icahost wirings but disable in parameters. * [#1407](https://github.com/crypto-org-chain/cronos/pull/1407) Add end-to-end encryption module. +* [#1414](https://github.com/crypto-org-chain/cronos/pull/1414) Integrate new evm tx format. ### Improvements diff --git a/go.mod b/go.mod index 95c85bcbc7..120d4ce53f 100644 --- a/go.mod +++ b/go.mod @@ -274,9 +274,9 @@ replace ( // dgrijalva/jwt-go is deprecated and doesn't receive security updates. // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 - github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e + github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 // block-stm branch - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240419013511-775ac80b75c7 + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3 // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 1884d9987a..e637cba9b9 100644 --- a/go.sum +++ b/go.sum @@ -429,12 +429,12 @@ github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240415105151-0108877a3201 github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240415105151-0108877a3201/go.mod h1:lfuLI1f4o+0SGtlHQS4x5qsjRcZZfYqG8bp3k8hM0M8= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240415105151-0108877a3201 h1:DbCOM19ywdL5K+bOy4h+0MppzcPgI2guHnYCfDNnAcM= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240415105151-0108877a3201/go.mod h1:CBCU6fsRVz23QGFIQBb1DNX2DztJCf3jWyEkHY2nJQ0= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240419013511-775ac80b75c7 h1:tawNK/e1F1AexRdhxC9o6M70IIrbCuvM6C8F/ujHwTY= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240419013511-775ac80b75c7/go.mod h1:OSFT4cvzHl0g2DizYR9vIy5/xRYAvFJrnRydAmgCqyM= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3 h1:YYmMJowZyiyioNHYnps5hw3XkV1zcXSC3jy/xzqK2Rg= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3/go.mod h1:9MVSajfKloRP8h2chP78LhCKx5u9O2pCMBvxrmx6+0s= github.com/crypto-org-chain/go-block-stm v0.0.0-20240408011717-9f11af197bde h1:sQIHTJfVt5VTrF7po9eZiFkZiPjlHbFvnXtGCOoBjNM= github.com/crypto-org-chain/go-block-stm v0.0.0-20240408011717-9f11af197bde/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= -github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e h1:vnyepPQ/m25+19xcTuBUdRxmltZ/EjVWNqEjhg7Ummk= -github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= +github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 h1:V43F3JFcqG4MUThf9W/DytnPblpR6CcaLBw2Wx6zTgE= +github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/gomod2nix.toml b/gomod2nix.toml index e032605394..493dc9b728 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -258,12 +258,12 @@ schema = 3 version = "v1.6.1" hash = "sha256-zOpoaepCfPLmU9iQji/Ait+SVEHI9eF3rwtW0h/8lho=" [mod."github.com/ethereum/go-ethereum"] - version = "v1.10.20-0.20231207063621-43cf32d91c3e" - hash = "sha256-lDIqRLUrXYCb9mmFBY/+WW+ee69+IkxOgqjHVyo4ij0=" + version = "v1.10.20-0.20240425065928-ebb09502e7a7" + hash = "sha256-lE4G5FaRb3MVi9FFVn+WlwsSTOB4SbjmVboKyQ5yB0A=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20240419013511-775ac80b75c7" - hash = "sha256-94bgC0Z+VD8w9j8+mwW/7PJSZlpKdtdR87C1E8hg3T4=" + version = "v0.6.1-0.20240502052908-179e436703b3" + hash = "sha256-Qc5A89wi+KCKfFdyvZit5MI4yKDhDvvSjkiYL0EIzNA=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/fatih/color"] version = "v1.16.0" diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index e6a3fdfdb4..6895558dc7 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -333,7 +333,8 @@ def get_balances(chain, addr): def ibc_multi_transfer(ibc): chains = [ibc.cronos.cosmos_cli(), ibc.chainmain.cosmos_cli()] - users = [f"user{i}" for i in range(1, 21)] + # FIXME: more users after batch fix + users = [f"user{i}" for i in range(1, 2)] addrs0 = [chains[0].address(user) for user in users] addrs1 = [chains[1].address(user) for user in users] denom0 = "basetcro" diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index 1dbbe16a28..4b35d0f786 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -11,11 +11,11 @@ cronos_transfer_source_tokens, cronos_transfer_source_tokens_with_proxy, get_balance, - hermes_transfer, ibc_denom, ibc_incentivized_transfer, ibc_multi_transfer, prepare_network, + rly_transfer, ) from .utils import ( ADDRS, @@ -54,7 +54,7 @@ def ibc(request, tmp_path_factory): yield from prepare_network( path, name, - relayer=cluster.Relayer.HERMES.value, + relayer=cluster.Relayer.RLY.value, ) @@ -232,7 +232,7 @@ def test_ibc(ibc): w3 = ibc.cronos.w3 wait_for_new_blocks(ibc.cronos.cosmos_cli(), 1) start = w3.eth.get_block_number() - hermes_transfer(ibc) + rly_transfer(ibc) denom = ibc_denom(channel, src_denom) dst_addr = eth_to_bech32(cronos_signer2) old_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom) diff --git a/nix/default.nix b/nix/default.nix index e6c1364dc5..f061a10e59 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -47,11 +47,11 @@ import sources.nixpkgs { cosmovisor = pkgs.callPackage ./cosmovisor.nix { }; }) (_: pkgs: { - rly = pkgs.buildGo120Module rec { + rly = pkgs.buildGo121Module rec { name = "rly"; src = sources.relayer; subPackages = [ "." ]; - vendorHash = "sha256-5s5URiAZk59mOfZdUcqYAB/IvzFuBiQH5jDBuh6huTE="; + vendorHash = "sha256-dwKZZu9wKOo2u1/8AAWFx89iC9pWZbCxAERMMAOFsts="; doCheck = false; GOWORK = "off"; postInstall = '' diff --git a/nix/sources.json b/nix/sources.json index 336932e6c3..960af8a9a1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -126,10 +126,10 @@ "homepage": "https://github.com/crypto-org-chain/relayer", "owner": "crypto-org-chain", "repo": "relayer", - "rev": "bd88a2cba9154450924837ecda915688ff8f9e04", - "sha256": "106mf4mc2ag4a5d21lcqpsq7ixvq70097jglw862jz4g9lbxyv8f", + "rev": "9479327b768a0a0e527c1b34eca353afebac5d15", + "sha256": "0ksxv4al8fjq7p8j3s28h23rr1qzn8fv7gmhcpchwz1536jx2kk4", "type": "tarball", - "url": "https://github.com/crypto-org-chain/relayer/archive/bd88a2cba9154450924837ecda915688ff8f9e04.tar.gz", + "url": "https://github.com/crypto-org-chain/relayer/archive/9479327b768a0a0e527c1b34eca353afebac5d15.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/x/cronos/keeper/evm.go b/x/cronos/keeper/evm.go index dd4a56dd2d..a0eb527622 100644 --- a/x/cronos/keeper/evm.go +++ b/x/cronos/keeper/evm.go @@ -22,7 +22,7 @@ const DefaultGasCap uint64 = 25000000 // CallEVM execute an evm message from native module func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value *big.Int, gasLimit uint64) (*core.Message, *evmtypes.MsgEthereumTxResponse, error) { nonce := k.evmKeeper.GetNonce(ctx, types.EVMModuleAddress) - msg := core.Message{ + msg := &core.Message{ From: types.EVMModuleAddress, To: to, Nonce: nonce, @@ -47,7 +47,7 @@ func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value } } - return &msg, ret, nil + return msg, ret, nil } // CallModuleCRC21 call a method of ModuleCRC21 contract diff --git a/x/cronos/keeper/evm_hooks.go b/x/cronos/keeper/evm_hooks.go index 44dee154aa..f630b719bc 100644 --- a/x/cronos/keeper/evm_hooks.go +++ b/x/cronos/keeper/evm_hooks.go @@ -26,7 +26,7 @@ func NewLogProcessEvmHook(handlers ...types.EvmLogHandler) *LogProcessEvmHook { } // PostTxProcessing implements EvmHook interface -func (h LogProcessEvmHook) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error { +func (h LogProcessEvmHook) PostTxProcessing(ctx sdk.Context, _ *core.Message, receipt *ethtypes.Receipt) error { addLogToReceiptFunc := newFuncAddLogToReceipt(receipt) for _, log := range receipt.Logs { if len(log.Topics) == 0 { diff --git a/x/cronos/keeper/evm_hooks_test.go b/x/cronos/keeper/evm_hooks_test.go index f46a6911d9..4c0428169f 100644 --- a/x/cronos/keeper/evm_hooks_test.go +++ b/x/cronos/keeper/evm_hooks_test.go @@ -6,7 +6,6 @@ import ( sdkmath "cosmossdk.io/math" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err := suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err := suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) suite.Require().NoError(err) }, }, @@ -64,7 +63,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) suite.Require().Error(err) }, }, @@ -94,7 +93,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) suite.Require().NoError(err) balance = suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), denom) @@ -144,7 +143,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) // should fail, because of not ibc denom name suite.Require().Error(err) }, diff --git a/x/cronos/keeper/grpc_query.go b/x/cronos/keeper/grpc_query.go index f8f37aeab1..7bc1568154 100644 --- a/x/cronos/keeper/grpc_query.go +++ b/x/cronos/keeper/grpc_query.go @@ -75,16 +75,11 @@ func (k Keeper) ReplayBlock(goCtx context.Context, req *types.ReplayBlockRequest // we assume the message executions are successful, they are filtered in json-rpc api for _, msg := range req.Msgs { // deduct fee - txData, err := evmtypes.UnpackTxData(msg.Data) - if err != nil { - return nil, err - } - // populate the `From` field if _, err := msg.GetSenderLegacy(ethtypes.LatestSignerForChainID(chainID)); err != nil { return nil, err } - fees, err := evmkeeper.VerifyFee(txData, evmDenom, baseFee, homestead, istanbul, shanghai, ctx.IsCheckTx()) + fees, err := evmkeeper.VerifyFee(msg, evmDenom, baseFee, homestead, istanbul, shanghai, ctx.IsCheckTx()) if err != nil { return nil, errorsmod.Wrapf(err, "failed to verify the fees") } diff --git a/x/cronos/rpc/api.go b/x/cronos/rpc/api.go index e2b6d68358..ebe7076e4d 100644 --- a/x/cronos/rpc/api.go +++ b/x/cronos/rpc/api.go @@ -159,12 +159,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block return nil, fmt.Errorf("invalid tx type: %T", msg) } - txData, err := evmtypes.UnpackTxData(ethMsg.Data) - if err != nil { - api.logger.Error("failed to unpack tx data", "error", err.Error()) - return nil, err - } - + txData := ethMsg.AsTransaction() parsedTx := parsedTxs.GetTxByMsgIndex(msgIndex) // Get the transaction result from the log @@ -179,7 +174,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block return nil, err } - logs, err := evmtypes.DecodeMsgLogsFromEvents(txResult.Data, parsedTx.MsgIndex, uint64(blockRes.Height)) + logs, err := evmtypes.DecodeMsgLogsFromEvents(txResult.Data, txResult.Events, parsedTx.MsgIndex, uint64(blockRes.Height)) if err != nil { api.logger.Debug("failed to parse logs", "block", resBlock.Block.Height, "txIndex", txIndex, "msgIndex", msgIndex, "error", err.Error()) } @@ -197,7 +192,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block // Implementation fields: These fields are added by geth when processing a transaction. // They are stored in the chain database. - "transactionHash": ethMsg.Hash, + "transactionHash": txData.Hash(), "contractAddress": nil, "gasUsed": hexutil.Uint64(parsedTx.GasUsed), @@ -209,21 +204,18 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block // sender and receiver (contract or EOA) addreses "from": from, - "to": txData.GetTo(), - "type": hexutil.Uint(ethMsg.AsTransaction().Type()), + "to": txData.To(), + "type": hexutil.Uint(txData.Type()), } // If the to is empty, assume it is a contract creation - if txData.GetTo() == nil { - receipt["contractAddress"] = crypto.CreateAddress(from, txData.GetNonce()) + if txData.To() == nil { + receipt["contractAddress"] = crypto.CreateAddress(from, txData.Nonce()) } - - if dynamicTx, ok := txData.(*evmtypes.DynamicFeeTx); ok { - receipt["effectiveGasPrice"] = hexutil.Big(*dynamicTx.EffectiveGasPrice(baseFee)) + if txData.Type() == ethtypes.DynamicFeeTxType { + receipt["effectiveGasPrice"] = hexutil.Big(*ethMsg.GetEffectiveGasPrice(baseFee)) } - receipts = append(receipts, receipt) - txIndex++ } cumulativeGasUsed += msgCumulativeGasUsed diff --git a/x/cronos/types/interfaces.go b/x/cronos/types/interfaces.go index 636266bf31..31334abde7 100644 --- a/x/cronos/types/interfaces.go +++ b/x/cronos/types/interfaces.go @@ -62,7 +62,7 @@ type EvmLogHandler interface { // EvmKeeper defines the interface for evm keeper type EvmKeeper interface { GetNonce(ctx sdk.Context, addr common.Address) uint64 - ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*evmtypes.MsgEthereumTxResponse, error) + ApplyMessage(ctx sdk.Context, msg *core.Message, tracer vm.EVMLogger, commit bool) (*evmtypes.MsgEthereumTxResponse, error) GetParams(ctx sdk.Context) evmtypes.Params // to replay the messages