8000 feat(jsonrpc): add support for allow-insecure-unlock by timwhite2 · Pull Request #2374 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(jsonrpc): add support for allow-insecure-unlock #2374

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

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 14 additions & 0 deletions rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"

"github.com/evmos/evmos/v16/crypto/ethsecp256k1"
rpctypes "github.com/evmos/evmos/v16/rpc/types"
"github.com/evmos/evmos/v16/server/config"
Expand All @@ -32,6 +33,10 @@ import (
func (b *Backend) Accounts() ([]common.Address, error) {
addresses := make([]common.Address, 0) // return [] instead of nil if empty

if b.cfg.JSONRPC.Enable && !b.cfg.JSONRPC.AllowInsecureUnlock {
b.logger.Error("Account unlock with HTTP access is forbidden")
return addresses, fmt.Errorf("Account unlock with HTTP access is forbidden!")
}
infos, err := b.clientCtx.Keyring.List()
if err != nil {
return addresses, err
Expand Down Expand Up @@ -77,6 +82,11 @@ func (b *Backend) Syncing() (interface{}, error) {

// SetEtherbase sets the etherbase of the miner
func (b *Backend) SetEtherbase(etherbase common.Address) bool {
if b.cfg.JSONRPC.Enable && !b.cfg.JSONRPC.AllowInsecureUnlock {
b.logger.Error("Account unlock with HTTP access is forbidden")
return false
}

delAddr, err := b.GetCoinbase()
if err != nil {
b.logger.Debug("failed to get coinbase address", "error", err.Error())
Expand Down Expand Up @@ -218,6 +228,10 @@ func (b *Backend) ImportRawKey(privkey, password string) (common.Address, error)
func (b *Backend) ListAccounts() ([]common.Address, error) {
addrs := []common.Address{}

if b.cfg.JSONRPC.Enable && !b.cfg.JSONRPC.AllowInsecureUnlock {
b.logger.Error("Account unlock with HTTP access is forbidden")
return addrs, fmt.Errorf("Account unlock with HTTP access is forbidden!")
}
list, err := b.clientCtx.Keyring.List()
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions rpc/backend/sign_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
// SendTransaction sends transaction based on received args using Node's key to sign it
func (b *Backend) SendTransaction(args evmtypes.TransactionArgs) (common.Hash, error) {
// Look up the wallet containing the requested signer
if b.cfg.JSONRPC.Enable && !b.cfg.JSONRPC.AllowInsecureUnlock {
b.logger.Error("Account unlock with HTTP access is forbidden")
return common.Hash{}, fmt.Errorf("Account unlock with HTTP access is forbidden!")
}
_, err := b.clientCtx.Keyring.KeyByAddress(sdk.AccAddress(args.GetFrom().Bytes()))
if err != nil {
b.logger.Error("failed to find key in keyring", "address", args.GetFrom(), "error", err.Error())
Expand Down
6 changes: 6 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const (
// DefaultGasCap is the default cap on gas that can be used in eth_call/estimateGas
DefaultGasCap uint64 = 25000000

// DefaultJSONRPCAllowInsecureUnlock is false
DefaultJSONRPCAllowInsecureUnlock bool = false

// DefaultFilterCap is the default cap for total number of filters that can be created
DefaultFilterCap int32 = 200

Expand Down Expand Up @@ -150,6 +153,8 @@ type JSONRPCConfig struct {
WsAddress string `mapstructure:"ws-address"`
// GasCap is the global gas cap for eth-call variants.
GasCap uint64 `mapstructure:"gas-cap"`
// AllowInsecureUnlock defines account enable when account-related RPCs are exposed by http.
AllowInsecureUnlock bool `mapstructure:"allow-insecure-unlock"`
// EVMTimeout is the global timeout for eth-call.
EVMTimeout time.Duration `mapstructure:"evm-timeout"`
// TxFeeCap is the global tx-fee cap for send transaction
Expand Down Expand Up @@ -276,6 +281,7 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
Address: DefaultJSONRPCAddress,
WsAddress: DefaultJSONRPCWsAddress,
GasCap: DefaultGasCap,
AllowInsecureUnlock: DefaultJSONRPCAllowInsecureUnlock,
EVMTimeout: DefaultEVMTimeout,
TxFeeCap: DefaultTxFeeCap,
FilterCap: DefaultFilterCap,
Expand Down
3 changes: 3 additions & 0 deletions
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ api = "{{range $index, $elmt := .JSONRPC.API}}{{if $index}},{{$elmt}}{{else}}{{$
# GasCap sets a cap on gas that can be used in eth_call/estimateGas (0=infinite). Default: 25,000,000.
gas-cap = {{ .JSONRPC.GasCap }}

# Allow insecure account unlocking when account-related RPCs are exposed by http
allow-insecure-unlock = {{ .JSONRPC.AllowInsecureUnlock }}

# EVMTimeout is the global timeout for eth_call. Default: 5s.
evm-timeout = "{{ .JSONRPC.EVMTimeout }}"

Expand Down
1 change: 1 addition & 0 deletions server/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
JSONRPCAddress = "json-rpc.address"
JSONWsAddress = "json-rpc.ws-address"
JSONRPCGasCap = "json-rpc.gas-cap"
JSONRPCAllowInsecureUnlock = "json-rpc.allow-insecure-unlock"
JSONRPCEVMTimeout = "json-rpc.evm-timeout"
JSONRPCTxFeeCap = "json-rpc.txfee-cap"
JSONRPCFilterCap = "json-rpc.filter-cap"
Expand Down
5 changes: 3 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ which accepts a path for the resulting pprof file.
cmd.Flags().StringSlice(srvflags.JSONRPCAPI, config.GetDefaultAPINamespaces(), "Defines a list of JSON-RPC namespaces that should be enabled")
cmd.Flags().String(srvflags.JSONRPCAddress, config.DefaultJSONRPCAddress, "the JSON-RPC server address to listen on")
cmd.Flags().String(srvflags.JSONWsAddress, config.DefaultJSONRPCWsAddress, "the JSON-RPC WS server address to listen on")
cmd.Flags().Uint64(srvflags.JSONRPCGasCap, config.DefaultGasCap, "Sets a cap on gas that can be used in eth_call/estimateGas unit is aevmos (0=infinite)") //nolint:lll
cmd.Flags().Float64(srvflags.JSONRPCTxFeeCap, config.DefaultTxFeeCap, "Sets a cap on transaction fee that can be sent via the RPC APIs (1 = default 1 evmos)") //nolint:lll
cmd.Flags().Uint64(srvflags.JSONRPCGasCap, config.DefaultGasCap, "Sets a cap on gas that can be used in eth_call/estimateGas unit is aevmos (0=infinite)") //nolint:lll
cmd.Flags().Bool(srvflags.JSONRPCAllowInsecureUnlock, config.DefaultJSONRPCAllowInsecureUnlock, "Allow insecure account unlocking when account-related RPCs are exposed by http") //nolint:lll
cmd.Flags().Float64(srvflags.JSONRPCTxFeeCap, config.DefaultTxFeeCap, "Sets a cap on transaction fee that can be sent via the RPC APIs (1 = default 1 evmos)") //nolint:lll
cmd.Flags().Int32(srvflags.JSONRPCFilterCap, config.DefaultFilterCap, "Sets the global cap for total number of filters that can be created")
cmd.Flags().Duration(srvflags.JSONRPCEVMTimeout, config.DefaultEVMTimeout, "Sets a timeout used for eth_call (0=infinite)")
cmd.Flags().Duration(srvflags.JSONRPCHTTPTimeout, config.DefaultHTTPTimeout, "Sets a read/write timeout for json-rpc http server (0=infinite)")
Expand Down
0