Skip to content

Commit 63f3de0

Browse files
authored
feat: support preinstalls (#728)
* support preinstall * fix proto * fix build * fix lint * fix test * change from error to log * remove unecessary name * register msg * register msg * add dummy log * add dummy log * add log * debug * cleanup * some fixes * somecleanup * move set account * add test * fix logic * add Changelog * update deps * remove dead code * fix comments * add check precompile * add validate basic for MsgRegisterPreinstalls * add more info in error
1 parent f674c51 commit 63f3de0

27 files changed

+1464
-120
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ linters:
6262
- third_party$
6363
- builtin$
6464
- examples$
65+
- x/evm/types/preinstall.go
6566
issues:
6667
max-same-issues: 50
6768
formatters:
@@ -72,4 +73,4 @@ formatters:
7273
paths:
7374
- third_party$
7475
- builtin$
75-
- examples$
76+
- examples$

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040
* (evm) [#725](https://github.com/crypto-org-chain/ethermint/pull/725) feat(RPC): add authorizationList from eth_getTransactionByHash response for EIP-7702 transactions
4141
* (evm) [#740](https://github.com/crypto-org-chain/ethermint/pull/740) fix: missing tx context during vm initialisation
4242
* (evm) [#742](https://github.com/crypto-org-chain/ethermint/pull/742) fix: prevent nil pointer dereference in tracer hooks
43+
* (evm) [#728](https://github.com/crypto-org-chain/ethermint/pull/728) feat: support preinstalls
4344

4445
## [v0.22.0] - 2025-08-12
4546

evmd/app.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ var (
191191
_ evmserver.AppWithPendingTxListener = (*EthermintApp)(nil)
192192
)
193193

194-
type GenesisState map[string]json.RawMessage
195-
196194
// var _ server.Application (*EthermintApp)(nil)
197195

198196
// EthermintApp implements an extended ABCI application. It is an application
@@ -926,7 +924,11 @@ func (app *EthermintApp) InterfaceRegistry() types.InterfaceRegistry {
926924

927925
// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
928926
func (app *EthermintApp) DefaultGenesis() map[string]json.RawMessage {
929-
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
927+
genesis := app.BasicModuleManager.DefaultGenesis(app.appCodec)
928+
evmGenState := NewEVMGenesisState()
929+
genesis[evmtypes.ModuleName] = app.appCodec.MustMarshalJSON(evmGenState)
930+
931+
return genesis
930932
}
931933

932934
func (app *EthermintApp) TxConfig() client.TxConfig {

evmd/genesis.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package evmd
2+
3+
import (
4+
"encoding/json"
5+
6+
evmtypes "github.com/evmos/ethermint/x/evm/types"
7+
)
8+
9+
// GenesisState of the blockchain is represented here as a map of raw json
10+
// messages key'd by an identifier string.
11+
// The identifier is used to determine which module genesis information belongs
12+
// to so it may be appropriately routed during init chain.
13+
// Within this application default genesis information is retrieved from
14+
// the ModuleBasicManager which populates json from each BasicModule
15+
// object provided to it during init.
16+
type GenesisState map[string]json.RawMessage
17+
18+
// NewEVMGenesisState returns the default genesis state for the EVM module.
19+
//
20+
// NOTE: for the example chain implementation we need to set the default EVM denomination,
21+
// enable ALL precompiles, and include default preinstalls.
22+
func NewEVMGenesisState() *evmtypes.GenesisState {
23+
evmGenState := evmtypes.DefaultGenesisState()
24+
evmGenState.Preinstalls = evmtypes.DefaultPreinstalls
25+
26+
return evmGenState
27+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ require (
240240
github.com/tklauser/go-sysconf v0.3.12 // indirect
241241
github.com/tklauser/numcpus v0.6.1 // indirect
242242
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
243-
github.com/ulikunitz/xz v0.5.14 // indirect
243+
github.com/ulikunitz/xz v0.5.15 // indirect
244244
github.com/zeebo/errs v1.4.0 // indirect
245245
github.com/zondax/hid v0.9.2 // indirect
246246
github.com/zondax/ledger-go v0.14.3 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,8 @@ github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3C
17011701
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
17021702
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
17031703
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
1704-
github.com/ulikunitz/xz v0.5.14 h1:uv/0Bq533iFdnMHZdRBTOlaNMdb1+ZxXIlHDZHIHcvg=
1705-
github.com/ulikunitz/xz v0.5.14/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
1704+
github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
1705+
github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
17061706
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
17071707
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
17081708
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=

proto/ethermint/evm/v1/genesis.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
syntax = "proto3";
22
package ethermint.evm.v1;
33

4+
import "amino/amino.proto";
45
import "ethermint/evm/v1/params.proto";
6+
import "ethermint/evm/v1/preinstall.proto";
57
import "ethermint/evm/v1/state.proto";
68
import "gogoproto/gogo.proto";
79

@@ -13,6 +15,9 @@ message GenesisState {
1315
repeated GenesisAccount accounts = 1 [(gogoproto.nullable) = false];
1416
// params defines all the parameters of the module.
1517
Params params = 2 [(gogoproto.nullable) = false];
18+
// preinstalls defines a set of predefined contracts
19+
repeated Preinstall preinstalls = 3
20+
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
1621
}
1722

1823
// GenesisAccount defines an account to be initialized in the genesis state.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
package ethermint.evm.v1;
3+
4+
option go_package = "github.com/evmos/ethermint/x/evm/types";
5+
6+
// Preinstall defines a contract that is preinstalled on-chain with a specific
7+
// contract address and bytecode
8+
message Preinstall {
9+
// name of the preinstall contract
10+
string name = 1;
11+
// address in hex format of the preinstall contract
12+
string address = 2;
13+
// code in hex format for the preinstall contract
14+
string code = 3;
15+
}

proto/ethermint/evm/v1/tx.proto

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
syntax = "proto3";
22
package ethermint.evm.v1;
33

4+
import "amino/amino.proto";
45
import "cosmos/msg/v1/msg.proto";
56
import "cosmos_proto/cosmos.proto";
67
import "gogoproto/gogo.proto";
@@ -9,6 +10,7 @@ import "google/protobuf/any.proto";
910
import "ethermint/evm/v1/access_tuple.proto";
1011
import "ethermint/evm/v1/log.proto";
1112
import "ethermint/evm/v1/params.proto";
13+
import "ethermint/evm/v1/preinstall.proto";
1214
import "ethermint/evm/v1/set_code_authorization.proto";
1315

1416
option go_package = "github.com/evmos/ethermint/x/evm/types";
@@ -23,6 +25,10 @@ service Msg {
2325
// UpdateParams defined a governance operation for updating the x/evm module parameters.
2426
// The authority is hard-coded to the Cosmos SDK x/gov module account
2527
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
28+
29+
// UpdateParams defined a governance operation for updating the x/evm module parameters.
30+
// The authority is hard-coded to the Cosmos SDK x/gov module account
31+
rpc RegisterPreinstalls(MsgRegisterPreinstalls) returns (MsgRegisterPreinstallsResponse);
2632
}
2733

2834
// MsgEthereumTx encapsulates an Ethereum transaction as an SDK message.
@@ -225,3 +231,19 @@ message MsgUpdateParams {
225231
// MsgUpdateParamsResponse defines the response structure for executing a
226232
// MsgUpdateParams message.
227233
message MsgUpdateParamsResponse {}
234+
235+
// MsgRegisterPreinstalls defines a Msg for creating preinstalls in evm state.
236+
message MsgRegisterPreinstalls {
237+
option (cosmos.msg.v1.signer) = "authority";
238+
239+
// authority is the address of the governance account.
240+
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
241+
242+
// preinstalls defines the preinstalls to create.
243+
repeated Preinstall preinstalls = 2
244+
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
245+
}
246+
247+
// MsgRegisterPreinstallsResponse defines the response structure for executing a
248+
// MsgRegisterPreinstalls message.
249+
message MsgRegisterPreinstallsResponse {}

x/evm/genesis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func InitGenesis(
8282
}
8383
}
8484

85+
if err := k.AddPreinstalls(ctx, data.Preinstalls); err != nil {
86+
panic(fmt.Errorf("error adding preinstalls: %s", err))
87+
}
88+
8589
return []abci.ValidatorUpdate{}
8690
}
8791

0 commit comments

Comments
 (0)