diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index 7155c954..d6bb4dcd 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -301,7 +301,6 @@ func createTx(priv *osecp256k1.PrivKey, msgs ...sdk.Msg) (sdk.Tx, error) { context.TODO(), defaultSignMode, signerData, txBuilder, priv, encodingConfig.TxConfig, 0, ) - if err != nil { return nil, err } diff --git a/app/app.go b/app/app.go index 5f5257bb..ed1e734b 100644 --- a/app/app.go +++ b/app/app.go @@ -4,10 +4,12 @@ import ( "fmt" "io" "io/fs" + "maps" "net/http" "os" "path/filepath" + "github.com/ethereum/go-ethereum/common" "github.com/realiotech/realio-network/app/ante" "github.com/realiotech/realio-network/client/docs" "github.com/realiotech/realio-network/crypto/ethsecp256k1" @@ -40,7 +42,11 @@ import ( srvflags "github.com/evmos/os/server/flags" ethermint "github.com/evmos/os/types" + "github.com/evmos/os/precompiles/bech32" + "github.com/evmos/os/precompiles/p256" + stakingprecompile "github.com/evmos/os/precompiles/staking" "github.com/evmos/os/x/evm" + "github.com/evmos/os/x/evm/core/vm" evmkeeper "github.com/evmos/os/x/evm/keeper" evmtypes "github.com/evmos/os/x/evm/types" "github.com/evmos/os/x/feemarket" @@ -159,7 +165,8 @@ import ( ) const ( - Name = "realio-network" + Name = "realio-network" + bech32PrecompileBaseGas = 6_000 ) var ( @@ -553,6 +560,9 @@ func New( ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) app.IBCKeeper.SetRouter(ibcRouter) + app.EvmKeeper.WithStaticPrecompiles( + RealioPrecompile(*app.StakingKeeper, app.AuthzKeeper), + ) /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment @@ -1089,6 +1099,36 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } +func RealioPrecompile( + stakingKeeper stakingkeeper.Keeper, + authzKeeper authzkeeper.Keeper, +) map[common.Address]vm.PrecompiledContract { + // Clone the mapping from the latest EVM fork. + precompiles := maps.Clone(vm.PrecompiledContractsBerlin) + + // secp256r1 precompile as per EIP-7212 + p256Precompile := &p256.Precompile{} + + bech32Precompile, err := bech32.NewPrecompile(bech32PrecompileBaseGas) + if err != nil { + panic(fmt.Errorf("failed to instantiate bech32 precompile: %w", err)) + } + + stakingPrecompile, err := stakingprecompile.NewPrecompile(stakingKeeper, authzKeeper) + if err != nil { + panic(fmt.Errorf("failed to instantiate staking precompile: %w", err)) + } + + // Stateless precompiles + precompiles[bech32Precompile.Address()] = bech32Precompile + precompiles[p256Precompile.Address()] = p256Precompile + + // Stateful precompiles + precompiles[stakingPrecompile.Address()] = stakingPrecompile + + return precompiles +} + func RealioSigVerificationGasConsumer( meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params, ) error { diff --git a/app/upgrades/v2/upgrades.go b/app/upgrades/v2/upgrades.go index 61ab3cc7..160d0177 100644 --- a/app/upgrades/v2/upgrades.go +++ b/app/upgrades/v2/upgrades.go @@ -132,6 +132,14 @@ func CreateUpgradeHandler( return nil, err } + evmParams := evmtypes.DefaultParams() + evmParams.ActiveStaticPrecompiles = []string{ + evmtypes.StakingPrecompileAddress, + } + err = evmKeeper.SetParams(sdkCtx, evmParams) + if err != nil { + return nil, err + } return newVM, nil } } diff --git a/x/asset/client/cli/query_params.go b/x/asset/client/cli/query_params.go index a744084d..abf28d8e 100644 --- a/x/asset/client/cli/query_params.go +++ b/x/asset/client/cli/query_params.go @@ -15,7 +15,7 @@ func CmdQueryParams() *cobra.Command { Use: "params", Short: "shows the parameters of the module", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) diff --git a/x/asset/client/cli/query_tokens.go b/x/asset/client/cli/query_tokens.go index 58092218..c2e36b2a 100644 --- a/x/asset/client/cli/query_tokens.go +++ b/x/asset/client/cli/query_tokens.go @@ -15,7 +15,7 @@ func CmdQueryTokens() *cobra.Command { Use: "tokens", Short: "shows the tokens of the module", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) diff --git a/x/asset/genesis.go b/x/asset/genesis.go index ac4d2e2b..02d51567 100644 --- a/x/asset/genesis.go +++ b/x/asset/genesis.go @@ -31,7 +31,7 @@ func ExportGenesis(ctx context.Context, k keeper.Keeper) *types.GenesisState { } genesis.Params = params tokens := []types.Token{} - err = k.Token.Walk(ctx, nil, func(symbol string, token types.Token) (stop bool, err error) { + err = k.Token.Walk(ctx, nil, func(_ string, token types.Token) (stop bool, err error) { tokens = append(tokens, token) return false, nil }) diff --git a/x/asset/keeper/grpc_query.go b/x/asset/keeper/grpc_query.go index 130fc0ca..e34fbaea 100644 --- a/x/asset/keeper/grpc_query.go +++ b/x/asset/keeper/grpc_query.go @@ -41,7 +41,7 @@ func (q queryServer) Tokens(c context.Context, req *types.QueryTokensRequest) (* } tokens := []types.Token{} - err := q.k.Token.Walk(c, nil, func(symbol string, token types.Token) (stop bool, err error) { + err := q.k.Token.Walk(c, nil, func(_ string, token types.Token) (stop bool, err error) { tokens = append(tokens, token) return false, nil }) diff --git a/x/bridge/client/cli/query.go b/x/bridge/client/cli/query.go index 4d21df24..c4067612 100644 --- a/x/bridge/client/cli/query.go +++ b/x/bridge/client/cli/query.go @@ -35,7 +35,7 @@ func CmdQueryParams() *cobra.Command { Use: "params", Short: "shows the parameters of the module", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) @@ -59,7 +59,7 @@ func CmdQueryRateLimits() *cobra.Command { Use: "ratelimits", Short: "shows the ratelimits of the module", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) @@ -108,7 +108,7 @@ func CmdQueryEpochInfo() *cobra.Command { Use: "epoch-info", Short: "shows the epoch info of the module", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index dbba9f2d..d2e8bd66 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -37,7 +37,7 @@ func GetCmdQueryParams() *cobra.Command { Use: "params", Short: "Query the current minting parameters", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err @@ -66,7 +66,7 @@ func GetCmdQueryInflation() *cobra.Command { Use: "inflation", Short: "Query the current minting inflation value", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err @@ -95,7 +95,7 @@ func GetCmdQueryAnnualProvisions() *cobra.Command { Use: "annual-provisions", Short: "Query the current minting annual provisions value", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err