Skip to content

Consolidate EVM Chain ID #192

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

Merged
merged 13 commits into from
Jun 2, 2025
14 changes: 9 additions & 5 deletions client/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
"github.com/cosmos/evm/ethereum/eip712"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -165,10 +164,10 @@ func RawBytesCmd() *cobra.Command {
// LegacyEIP712Cmd outputs types of legacy EIP712 typed data
func LegacyEIP712Cmd() *cobra.Command {
return &cobra.Command{
Use: "legacy-eip712 [file]",
Use: "legacy-eip712 [file] [evm-chain-id]",
Short: "Output types of legacy eip712 typed data according to the given transaction",
Example: fmt.Sprintf(`$ %s debug legacy-eip712 tx.json --chain-id evmd-1`, version.AppName),
Args: cobra.ExactArgs(1),
Example: fmt.Sprintf(`$ %s debug legacy-eip712 tx.json 4221 --chain-id evmd-1`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -185,7 +184,12 @@ func LegacyEIP712Cmd() *cobra.Command {
return errors.Wrap(err, "encode tx")
}

td, err := eip712.LegacyWrapTxToTypedData(clientCtx.Codec, evmdconfig.EVMChainID, stdTx.GetMsgs()[0], txBytes, nil)
evmChainID, err := strconv.Atoi(args[0])
if err != nil {
return errors.Wrap(err, "parse evm-chain-id")
}

td, err := eip712.LegacyWrapTxToTypedData(clientCtx.Codec, uint64(evmChainID), stdTx.GetMsgs()[0], txBytes, nil) //nolint:gosec // G115 // overflow not a concern
if err != nil {
return errors.Wrap(err, "wrap tx to typed data")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/evmd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewRootCmd() *cobra.Command {
nil,
true,
simtestutil.EmptyAppOptions{},
cosmosevmserverconfig.DefaultEVMChainID,
evmdconfig.EVMChainID,
testutil.NoOpEvmAppOptions,
)

Expand Down Expand Up @@ -149,7 +149,7 @@ func NewRootCmd() *cobra.Command {
}

if initClientCtx.ChainID != "" {
if err := evmd.EvmAppOptions(cosmosevmserverconfig.DefaultEVMChainID); err != nil {
if err := evmd.EvmAppOptions(evmdconfig.EVMChainID); err != nil {
panic(err)
}
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/evmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ var ChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{
DisplayDenom: "test",
Decimals: evmtypes.EighteenDecimals,
},
EVMChainID: {
Denom: "atest",
ExtendedDenom: "atest",
DisplayDenom: "test",
Decimals: evmtypes.EighteenDecimals,
},
}

const (
Expand All @@ -47,7 +53,7 @@ const (
// BaseDenomUnit defines the precision of the base denomination.
BaseDenomUnit = 18
// EVMChainID defines the EIP-155 replay-protection chain id for the current ethereum chain config.
EVMChainID = 262144
EVMChainID = 4221
)

// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
Expand Down
4 changes: 2 additions & 2 deletions rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ func init() {
},
}
},
NetNamespace: func(_ *server.Context, clientCtx client.Context, _ *rpcclient.WSClient, _ bool, _ types.EVMTxIndexer) []rpc.API {
NetNamespace: func(ctx *server.Context, clientCtx client.Context, _ *rpcclient.WSClient, _ bool, _ types.EVMTxIndexer) []rpc.API {
return []rpc.API{
{
Namespace: NetNamespace,
Version: apiVersion,
Service: net.NewPublicAPI(clientCtx),
Service: net.NewPublicAPI(ctx, clientCtx),
Public: true,
},
}
Expand Down
7 changes: 4 additions & 3 deletions rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"

dbm "github.com/cosmos/cosmos-db"
evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
"github.com/cosmos/evm/crypto/hd"
"github.com/cosmos/evm/encoding"
"github.com/cosmos/evm/indexer"
"github.com/cosmos/evm/rpc/backend/mocks"
rpctypes "github.com/cosmos/evm/rpc/types"
"github.com/cosmos/evm/server/config"
"github.com/cosmos/evm/testutil/constants"
testnetwork "github.com/cosmos/evm/testutil/integration/os/network"
utiltx "github.com/cosmos/evm/testutil/tx"
Expand Down Expand Up @@ -50,6 +50,7 @@ var ChainID = constants.ExampleChainID
func (suite *BackendTestSuite) SetupTest() {
ctx := server.NewDefaultContext()
ctx.Viper.Set("telemetry.global-labels", []interface{}{})
ctx.Viper.Set("evm.evm-chain-id", evmdconfig.EVMChainID)

baseDir := suite.T().TempDir()
nodeDirName := "node"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (suite *BackendTestSuite) SetupTest() {
suite.backend.cfg.JSONRPC.GasCap = 0
suite.backend.cfg.JSONRPC.EVMTimeout = 0
suite.backend.cfg.JSONRPC.AllowInsecureUnlock = true
suite.backend.cfg.EVM.EVMChainID = 262144
suite.backend.cfg.EVM.EVMChainID = evmdconfig.EVMChainID
suite.backend.queryClient.QueryClient = mocks.NewEVMQueryClient(suite.T())
suite.backend.queryClient.FeeMarket = mocks.NewFeeMarketQueryClient(suite.T())
suite.backend.ctx = rpctypes.ContextWithHeight(1)
Expand Down Expand Up @@ -194,7 +195,7 @@ func (suite *BackendTestSuite) buildFormattedBlock(

func (suite *BackendTestSuite) generateTestKeyring(clientDir string) (keyring.Keyring, error) {
buf := bufio.NewReader(os.Stdin)
encCfg := encoding.MakeConfig(config.DefaultEVMChainID)
encCfg := encoding.MakeConfig(evmdconfig.EVMChainID)
return keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, clientDir, buf, encCfg.Codec, []keyring.Option{hd.EthSecp256k1Option()}...)
}

Expand Down
3 changes: 2 additions & 1 deletion rpc/backend/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cometbft/cometbft/abci/types"
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"

evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
"github.com/cosmos/evm/rpc/backend/mocks"
rpc "github.com/cosmos/evm/rpc/types"
utiltx "github.com/cosmos/evm/testutil/tx"
Expand Down Expand Up @@ -154,7 +155,7 @@ func (suite *BackendTestSuite) TestBaseFee() {
}

func (suite *BackendTestSuite) TestChainId() {
expChainID := (*hexutil.Big)(big.NewInt(262144))
expChainID := (*hexutil.Big)(big.NewInt(evmdconfig.EVMChainID))
testCases := []struct {
name string
registerMock func()
Expand Down
10 changes: 5 additions & 5 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
"github.com/cosmos/evm/rpc/backend/mocks"
rpc "github.com/cosmos/evm/rpc/types"
"github.com/cosmos/evm/server/config"
utiltx "github.com/cosmos/evm/testutil/tx"
evmtypes "github.com/cosmos/evm/x/vm/types"

Expand All @@ -39,26 +39,26 @@ var _ evmtypes.QueryClient = &mocks.EVMQueryClient{}
func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, predecessors []*evmtypes.MsgEthereumTx) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceTx", rpc.ContextWithHeight(1),
&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: config.DefaultEVMChainID, BlockMaxGas: -1}).
&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: evmdconfig.EVMChainID, BlockMaxGas: -1}).
Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil)
}

func RegisterTraceTransaction(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: config.DefaultEVMChainID, BlockMaxGas: -1}).
queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: evmdconfig.EVMChainID, BlockMaxGas: -1}).
Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil)
}

func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx) {
queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: config.DefaultEVMChainID}).
queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: evmdconfig.EVMChainID}).
Return(nil, errortypes.ErrInvalidRequest)
}

// TraceBlock
func RegisterTraceBlock(queryClient *mocks.EVMQueryClient, txs []*evmtypes.MsgEthereumTx) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceBlock", rpc.ContextWithHeight(1),
&evmtypes.QueryTraceBlockRequest{Txs: txs, BlockNumber: 1, TraceConfig: &evmtypes.TraceConfig{}, ChainId: config.DefaultEVMChainID, BlockMaxGas: -1}).
&evmtypes.QueryTraceBlockRequest{Txs: txs, BlockNumber: 1, TraceConfig: &evmtypes.TraceConfig{}, ChainId: evmdconfig.EVMChainID, BlockMaxGas: -1}).
Return(&evmtypes.QueryTraceBlockResponse{Data: data}, nil)
}

Expand Down
5 changes: 3 additions & 2 deletions rpc/namespaces/ethereum/net/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/evm/server/config"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
)

// PublicAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
Expand All @@ -18,8 +19,8 @@ type PublicAPI struct {
}

// NewPublicAPI creates an instance of the public Net Web3 API.
func NewPublicAPI(clientCtx client.Context) *PublicAPI {
cfg, err := config.GetConfig(clientCtx.Viper)
func NewPublicAPI(ctx *server.Context, clientCtx client.Context) *PublicAPI {
cfg, err := config.GetConfig(ctx.Viper)
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
// DefaultMaxTxGasWanted is the default gas wanted for each eth tx returned in ante handler in check tx mode
DefaultMaxTxGasWanted = 0

// DefaultEVMChainID is the default EVM Chain ID if one is not provided
DefaultEVMChainID = 262144

// DefaultGasCap is the default cap on gas that can be used in eth_call/estimateGas
Expand Down
3 changes: 3 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ max-tx-gas-wanted = {{ .EVM.MaxTxGasWanted }}
# EnablePreimageRecording enables tracking of SHA3 preimages in the VM
cache-preimage = {{ .EVM.EnablePreimageRecording }}

# EVMChainID is the EIP-155 compatible replay protection chain ID. This is separate from the Cosmos chain ID.
evm-chain-id = {{ .EVM.EVMChainID }}

###############################################################################
### JSON RPC Configuration ###
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions server/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
EVMTracer = "evm.tracer"
EVMMaxTxGasWanted = "evm.max-tx-gas-wanted"
EVMEnablePreimageRecording = "evm.cache-preimage"
EVMChainID = "evm.evm-chain-id"
)

// TLS flags
Expand Down
1 change: 1 addition & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ which accepts a path for the resulting pprof file.
cmd.Flags().String(srvflags.EVMTracer, cosmosevmserverconfig.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)") //nolint:lll
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, cosmosevmserverconfig.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll
cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll
cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID")

cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration")
cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration")
Expand Down
2 changes: 1 addition & 1 deletion tests/solidity/suites/precompiles/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
networks: {
cosmos: {
url: "http://127.0.0.1:8545",
chainId: 262144,
chainId: 4221,
accounts: [
"0x88CBEAD91AEE890D27BF06E003ADE3D4E952427E88F88D31D61D3EF5E5D54305",
"0x3B7955D25189C99A7468192FCBC6429205C158834053EBE3F78F4512AB432DB9",
Expand Down
Loading
Loading