Skip to content

Commit

Permalink
Problem: new evm tx format not integrated (crypto-org-chain#1414)
Browse files Browse the repository at this point in the history
* Problem: new evm tx format not integrated

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

* update deps

* update go

* use rly

* less users

* fix

* update deps

---------

Signed-off-by: yihuang <[email protected]>
Co-authored-by: mmsqe <[email protected]>
  • Loading branch information
2 people authored and alienc0der committed Jun 8, 2024
1 parent a6e8a06 commit ebad89c
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 4 additions & 4 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)


Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
6 changes: 3 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
4 changes: 2 additions & 2 deletions x/cronos/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/cronos/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions x/cronos/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
receipt := &ethtypes.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)
},
},
Expand All @@ -64,7 +63,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
receipt := &ethtypes.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)
},
},
Expand Down Expand Up @@ -94,7 +93,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
receipt := &ethtypes.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)
Expand Down Expand Up @@ -144,7 +143,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
receipt := &ethtypes.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)
},
Expand Down
7 changes: 1 addition & 6 deletions x/cronos/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
26 changes: 9 additions & 17 deletions x/cronos/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
Expand All @@ -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),

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/cronos/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebad89c

Please sign in to comment.