Skip to content
Merged
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: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ test-system: build-v04 build
cd tests/systemtests/Counter && forge build
$(MAKE) -C tests/systemtests test

# V04_REF is the fork's v0.4.0 release state (last commit before the v0.5.0
# upgrade work began). This fork has no upstream-style v0.4.x git tag, so the
# legacy binary for the v0.4.0-to-v0.5.0 upgrade test is built from this commit.
V04_REF ?= b5053b7e
build-v04:
mkdir -p ./tests/systemtests/binaries/v0.4
git checkout v0.4.1
git checkout $(V04_REF)
make build
cp $(BUILDDIR)/evmd ./tests/systemtests/binaries/v0.4
git checkout -
Expand Down
1 change: 1 addition & 0 deletions encoding/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func MakeConfig(evmChainID uint64) Config {
codec := amino.NewProtoCodec(interfaceRegistry)
enccodec.RegisterLegacyAminoCodec(cdc)
enccodec.RegisterInterfaces(interfaceRegistry)
evmtypes.RegisterInterfaces(interfaceRegistry)
eip712.SetEncodingConfig(cdc, interfaceRegistry, evmChainID)

// This is needed for the EIP712 txs because currently is using
Expand Down
4 changes: 2 additions & 2 deletions evmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ require (
github.com/desertbit/timer v1.0.1 // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/ristretto v0.2.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/dop251/goja v0.0.0-20260311135729-065cd970411c // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
github.com/emicklei/dot v1.6.2 // indirect
Expand Down
19 changes: 6 additions & 13 deletions evmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapp
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.50.0/go.mod h1:otE2jQekW/PqXk1Awf5lmfokJx4uwuqcj1ab5SpGeW0=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
Expand Down Expand Up @@ -785,15 +787,12 @@ github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXH
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
Expand Down Expand Up @@ -917,19 +916,15 @@ github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3 h1:+3HCtB74++ClLy8GgjUQYeC8R4ILzVcIe8+5edAJJnE=
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/dop251/goja v0.0.0-20260311135729-065cd970411c h1:OcLmPfx1T1RmZVHHFwWMPaZDdRf0DBMZOFMVWJa7Pdk=
github.com/dop251/goja v0.0.0-20260311135729-065cd970411c/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down Expand Up @@ -1170,7 +1165,6 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8=
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
Expand Down Expand Up @@ -1300,7 +1294,6 @@ github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSAS
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
github.com/improbable-eng/grpc-web v0.15.0/go.mod h1:1sy9HKV4Jt9aEs9JSnkWlRJPuPtwNr0l57L4f878wP8=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
4 changes: 2 additions & 2 deletions indexer/kv_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (kv *KVIndexer) IndexBlock(block *cmttypes.Block, txResults []*abci.ExecTxR
if !isEthTx(tx) {
// Derived txs (internal EVM executions emitted only as events, not as an
// embedded MsgEthereumTx) still occupy slots in the block's eth-tx index
// sequence (#18). Index them by hash and by (height, ethTxIndex), advancing
// sequence. Index them by hash and by (height, ethTxIndex), advancing
// the shared ethTxIndex so it stays aligned with the emitted txIndex for any
// standard eth txs that follow in the same block.
ethTxIndex, err = kv.indexDerivedTxs(batch, height, uint32(txIndex), result, ethTxIndex) //#nosec G115 -- int overflow is not a concern here
ethTxIndex, err = kv.indexDerivedTxs(batch, height, uint32(txIndex), result, ethTxIndex) //#nosec G115
if err != nil {
kv.logger.Error("Fail to index derived txs", "err", err, "block", height, "txIndex", txIndex)
}
Expand Down
148 changes: 148 additions & 0 deletions rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package backend

import (
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/suite"

dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/evm/indexer"
"github.com/cosmos/evm/rpc/backend/mocks"
"github.com/cosmos/evm/testutil/constants"
utiltx "github.com/cosmos/evm/testutil/tx"
evmtypes "github.com/cosmos/evm/x/vm/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"

"cosmossdk.io/log"
)

// TestMain initializes the global EVM chain config required by NewBackend.
// Without this, GetEthChainConfig() panics on a nil dereference.
func TestMain(m *testing.M) {
configurator := evmtypes.NewEVMConfigurator()
configurator.ResetTestConfig()
ethCfg := evmtypes.DefaultChainConfig(constants.ExampleChainID.EVMChainID)
if err := evmtypes.SetChainConfig(ethCfg); err != nil {
panic(err)
}
coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID]
if err := evmtypes.NewEVMConfigurator().
WithEVMCoinInfo(coinInfo).
Configure(); err != nil {
panic(err)
}
os.Exit(m.Run())
}

// BackendTestSuite wraps setupMockBackend and adds helpers used by TraceTransaction tests.
type BackendTestSuite struct {
suite.Suite
backend *Backend
signer keyring.Signer
}

func TestBackendTestSuite(t *testing.T) {
suite.Run(t, new(BackendTestSuite))
}

func (suite *BackendTestSuite) SetupTest() {
suite.backend = setupMockBackend(suite.T())
_, priv := utiltx.NewAddrKey()
suite.signer = utiltx.NewSigner(priv)
}

// buildEthereumTx returns an unsigned legacy EVM tx and its pre-encoded bytes.
// From is left empty; call signAndEncodeEthTx for a fully signed single-msg tx.
func (suite *BackendTestSuite) buildEthereumTx() (*evmtypes.MsgEthereumTx, []byte) {
ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.backend.EvmChainID,
Nonce: 0,
To: &common.Address{},
Amount: big.NewInt(0),
GasLimit: 100000,
GasPrice: big.NewInt(1),
}
msg := evmtypes.NewTx(&ethTxParams)

txBuilder := suite.backend.ClientCtx.TxConfig.NewTxBuilder()
suite.Require().NoError(txBuilder.SetMsgs(msg))
bz, err := suite.backend.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
suite.Require().NoError(err)
return msg, bz
}

// signAndEncodeEthTx signs msg with a fresh ephemeral key and encodes it as a
// single-message Cosmos tx. The msg.From field is updated in-place; hashes
// computed via msg.AsTransaction().Hash() are valid after this returns.
func (suite *BackendTestSuite) signAndEncodeEthTx(msg *evmtypes.MsgEthereumTx) []byte {
from, priv := utiltx.NewAddrKey()
signer := utiltx.NewSigner(priv)
ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig())
msg.From = from.Bytes()
suite.Require().NoError(msg.Sign(ethSigner, signer))

evmDenom := evmtypes.GetEVMCoinDenom()
tx, err := msg.BuildTx(suite.backend.ClientCtx.TxConfig.NewTxBuilder(), evmDenom)
suite.Require().NoError(err)
txBz, err := suite.backend.ClientCtx.TxConfig.TxEncoder()(tx)
suite.Require().NoError(err)
return txBz
}

// buildAndEncodeMultiMsgEthTx builds a single EVM Cosmos tx containing multiple
// MsgEthereumTx messages. Each message is signed with a fresh ephemeral key so
// their hashes are unique even when underlying tx params are identical.
func (suite *BackendTestSuite) buildAndEncodeMultiMsgEthTx(msgs ...*evmtypes.MsgEthereumTx) []byte {
ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig())
for _, msg := range msgs {
from, priv := utiltx.NewAddrKey()
signer := utiltx.NewSigner(priv)
msg.From = from.Bytes()
suite.Require().NoError(msg.Sign(ethSigner, signer))
msg.From = nil // BuildTx expects empty From for multi-msg txs
}

extBuilder, ok := suite.backend.ClientCtx.TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder)
suite.Require().True(ok)

option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{})
suite.Require().NoError(err)
extBuilder.SetExtensionOptions(option)

sdkMsgs := make([]sdk.Msg, len(msgs))
for i, msg := range msgs {
sdkMsgs[i] = msg
}
suite.Require().NoError(extBuilder.SetMsgs(sdkMsgs...))

bz, err := suite.backend.ClientCtx.TxConfig.TxEncoder()(extBuilder.GetTx())
suite.Require().NoError(err)
return bz
}

// resetIndexer creates a fresh KV indexer and installs it on the backend.
func (suite *BackendTestSuite) resetIndexer() {
suite.backend.Indexer = indexer.NewKVIndexer(
dbm.NewMemDB(),
log.NewNopLogger(),
suite.backend.ClientCtx,
)
}

// mockClient returns the mock CometBFT client used by this backend.
func (suite *BackendTestSuite) mockClient() *mocks.Client {
return suite.backend.ClientCtx.Client.(*mocks.Client)
}

// mockQueryClient returns the mock EVM gRPC query client used by this backend.
func (suite *BackendTestSuite) mockQueryClient() *mocks.EVMQueryClient {
return suite.backend.QueryClient.QueryClient.(*mocks.EVMQueryClient)
}
9 changes: 7 additions & 2 deletions rpc/backend/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ func (b *Backend) GetBlockReceipts(
return nil, fmt.Errorf("block result not found for height %d", resBlock.Block.Height)
}

msgs, _ := b.EthMsgsFromCometBlock(resBlock, blockRes)
msgs, txsAdditional := b.EthMsgsFromCometBlock(resBlock, blockRes)

receipts, err := b.ReceiptsFromCometBlock(resBlock, blockRes, msgs)
receipts, err := b.ReceiptsFromCometBlock(resBlock, blockRes, msgs, txsAdditional)
if err != nil {
return nil, fmt.Errorf("failed to get receipts from comet block: %w, ", err)

Expand All @@ -223,6 +223,11 @@ func (b *Backend) GetBlockReceipts(
if err != nil {
return nil, fmt.Errorf("failed to marshal receipt")
}
// Same override as GetTransactionReceipt: derived txs have an event-emitted
// hash that differs from the reconstructed LegacyTx hash.
if txsAdditional[i] != nil {
result[i]["transactionHash"] = txsAdditional[i].Hash
}
}
return result, nil
}
Expand Down
Loading
Loading