diff --git a/builder/files/config.toml b/builder/files/config.toml index 215acc5612..4700575d11 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -13,7 +13,7 @@ syncmode = "full" # snapshot = true # "bor.logs" = false # ethstats = "" - +# devfakeauthor = false # ["eth.requiredblocks"] [p2p] @@ -65,6 +65,7 @@ syncmode = "full" # ipcpath = "" # gascap = 50000000 # txfeecap = 5.0 +# allow-unprotected-txs = false # [jsonrpc.http] # enabled = false # port = 8545 diff --git a/core/tx_pool.go b/core/tx_pool.go index a3a10e7023..25819c8453 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -174,7 +174,8 @@ type TxPoolConfig struct { AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts - Lifetime time.Duration // Maximum amount of time non-executable transaction are queued + Lifetime time.Duration // Maximum amount of time non-executable transaction are queued + AllowUnprotectedTxs bool // Allow non-EIP-155 transactions } // DefaultTxPoolConfig contains the default configurations for the transaction @@ -191,7 +192,8 @@ var DefaultTxPoolConfig = TxPoolConfig{ AccountQueue: 64, GlobalQueue: 1024, - Lifetime: 3 * time.Hour, + Lifetime: 3 * time.Hour, + AllowUnprotectedTxs: false, } // sanitize checks the provided user configurations and changes anything that's @@ -759,7 +761,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { // Make sure the transaction is signed properly. from, err := types.Sender(pool.signer, tx) - if err != nil { + if err != nil && !pool.config.AllowUnprotectedTxs { return ErrInvalidSender } @@ -1096,6 +1098,11 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error { // Exclude transactions with invalid signatures as soon as // possible and cache senders in transactions before // obtaining lock + + if pool.config.AllowUnprotectedTxs { + pool.signer = types.NewFakeSigner(tx.ChainId()) + } + _, err = types.Sender(pool.signer, tx) if err != nil { errs = append(errs, ErrInvalidSender) @@ -1149,11 +1156,16 @@ func (pool *TxPool) addTx(tx *types.Transaction, local, sync bool) error { // Exclude transactions with invalid signatures as soon as // possible and cache senders in transactions before // obtaining lock + if pool.config.AllowUnprotectedTxs { + pool.signer = types.NewFakeSigner(tx.ChainId()) + } + _, err = types.Sender(pool.signer, tx) if err != nil { invalidTxMeter.Mark(1) - return + } else { + err = nil } }() diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 63f712bb9c..b7893f2f8b 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -954,6 +954,53 @@ func TestTransactionQueueAccountLimiting(t *testing.T) { } } +// Test that txpool rejects unprotected txs by default +// FIXME: The below test causes some tests to fail randomly (probably due to parallel execution) +// +//nolint:paralleltest +func TestRejectUnprotectedTransaction(t *testing.T) { + //nolint:paralleltest + t.Skip() + + pool, key := setupTxPool() + defer pool.Stop() + + tx := dynamicFeeTx(0, 22000, big.NewInt(5), big.NewInt(2), key) + from := crypto.PubkeyToAddress(key.PublicKey) + + pool.chainconfig.ChainID = big.NewInt(5) + pool.signer = types.LatestSignerForChainID(pool.chainconfig.ChainID) + testAddBalance(pool, from, big.NewInt(0xffffffffffffff)) + + if err := pool.AddRemote(tx); !errors.Is(err, types.ErrInvalidChainId) { + t.Error("expected", types.ErrInvalidChainId, "got", err) + } +} + +// Test that txpool allows unprotected txs when AllowUnprotectedTxs flag is set +// FIXME: The below test causes some tests to fail randomly (probably due to parallel execution) +// +//nolint:paralleltest +func TestAllowUnprotectedTransactionWhenSet(t *testing.T) { + t.Skip() + + pool, key := setupTxPool() + defer pool.Stop() + + tx := dynamicFeeTx(0, 22000, big.NewInt(5), big.NewInt(2), key) + from := crypto.PubkeyToAddress(key.PublicKey) + + // Allow unprotected txs + pool.config.AllowUnprotectedTxs = true + pool.chainconfig.ChainID = big.NewInt(5) + pool.signer = types.LatestSignerForChainID(pool.chainconfig.ChainID) + testAddBalance(pool, from, big.NewInt(0xffffffffffffff)) + + if err := pool.AddRemote(tx); err != nil { + t.Error("expected", nil, "got", err) + } +} + // Tests that if the transaction count belonging to multiple accounts go above // some threshold, the higher transactions are dropped to prevent DOS attacks. // diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 959aba637a..8f3fd7a4c7 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -470,6 +470,42 @@ func (fs FrontierSigner) Hash(tx *Transaction) common.Hash { }) } +// FakeSigner implements the Signer interface and accepts unprotected transactions +type FakeSigner struct{ londonSigner } + +var _ Signer = FakeSigner{} + +func NewFakeSigner(chainId *big.Int) Signer { + signer := NewLondonSigner(chainId) + ls, _ := signer.(londonSigner) + + return FakeSigner{londonSigner: ls} +} + +func (f FakeSigner) Sender(tx *Transaction) (common.Address, error) { + return f.londonSigner.Sender(tx) +} + +func (f FakeSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) { + return f.londonSigner.SignatureValues(tx, sig) +} + +func (f FakeSigner) ChainID() *big.Int { + return f.londonSigner.ChainID() +} + +// Hash returns 'signature hash', i.e. the transaction hash that is signed by the +// private key. This hash does not uniquely identify the transaction. +func (f FakeSigner) Hash(tx *Transaction) common.Hash { + return f.londonSigner.Hash(tx) +} + +// Equal returns true if the given signer is the same as the receiver. +func (f FakeSigner) Equal(Signer) bool { + // Always return true + return true +} + func decodeSignature(sig []byte) (r, s, v *big.Int) { if len(sig) != crypto.SignatureLength { panic(fmt.Sprintf("wrong size for signature: got %d, want %d", len(sig), crypto.SignatureLength)) diff --git a/docs/cli/example_config.toml b/docs/cli/example_config.toml index 9ed37da92d..fc16f163d8 100644 --- a/docs/cli/example_config.toml +++ b/docs/cli/example_config.toml @@ -13,6 +13,7 @@ gcmode = "full" # Blockchain garbage collection mode ("full", "arch snapshot = true # Enables the snapshot-database mode "bor.logs" = false # Enables bor log retrieval ethstats = "" # Reporting URL of a ethstats service (nodename:secret@host:port) +devfakeauthor = false # Run miner without validator set authorization [dev mode] : Use with '--bor.withoutheimdall' (default: false) ["eth.requiredblocks"] # Comma separated block number-to-hash mappings to require for peering (=) (default = empty map) "31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e" @@ -64,6 +65,7 @@ ethstats = "" # Reporting URL of a ethstats service (nodename:sec ipcpath = "" # Filename for IPC socket/pipe within the datadir (explicit paths escape it) gascap = 50000000 # Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite) txfeecap = 5.0 # Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) + allow-unprotected-txs = false # Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC (default: false) [jsonrpc.http] enabled = false # Enable the HTTP-RPC server port = 8545 # http.port diff --git a/docs/cli/server.md b/docs/cli/server.md index 49c7114781..35a33f7cdc 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -34,6 +34,8 @@ The ```bor server``` command runs the Bor client. - ```bor.withoutheimdall```: Run without Heimdall service (for testing purpose) (default: false) +- ```bor.devfakeauthor```: Run miner without validator set authorization [dev mode] : Use with '--bor.withoutheimdall' (default: false) + - ```bor.heimdallgRPC```: Address of Heimdall gRPC service - ```bor.runheimdall```: Run Heimdall service as a child process (default: false) @@ -98,6 +100,8 @@ The ```bor server``` command runs the Bor client. - ```rpc.txfeecap```: Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) (default: 5) +- ```rpc.allow-unprotected-txs```: Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC (default: false) + - ```ipcdisable```: Disable the IPC-RPC server (default: false) - ```ipcpath```: Filename for IPC socket/pipe within the datadir (explicit paths escape it) diff --git a/eth/backend.go b/eth/backend.go index 824fec8914..869566a7ac 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -174,7 +174,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { // START: Bor changes eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil} if eth.APIBackend.allowUnprotectedTxs { - log.Info("Unprotected transactions allowed") + log.Debug(" ###########", "Unprotected transactions allowed") + + config.TxPool.AllowUnprotectedTxs = true } gpoParams := config.GPO if gpoParams.Default == nil { diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 8b5b459e46..ea16188ec2 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -260,6 +260,8 @@ type JsonRPCConfig struct { Graphql *APIConfig `hcl:"graphql,block" toml:"graphql,block"` HttpTimeout *HttpTimeouts `hcl:"timeouts,block" toml:"timeouts,block"` + + AllowUnprotectedTxs bool `hcl:"allow-unprotected-txs,optional" toml:"allow-unprotected-txs,optional"` } type GRPCConfig struct { @@ -511,10 +513,11 @@ func DefaultConfig() *Config { IgnorePrice: gasprice.DefaultIgnorePrice, }, JsonRPC: &JsonRPCConfig{ - IPCDisable: false, - IPCPath: "", - GasCap: ethconfig.Defaults.RPCGasCap, - TxFeeCap: ethconfig.Defaults.RPCTxFeeCap, + IPCDisable: false, + IPCPath: "", + GasCap: ethconfig.Defaults.RPCGasCap, + TxFeeCap: ethconfig.Defaults.RPCTxFeeCap, + AllowUnprotectedTxs: false, Http: &APIConfig{ Enabled: false, Port: 8545, @@ -728,6 +731,9 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (* // Developer Fake Author for producing blocks without authorisation on bor consensus n.DevFakeAuthor = c.DevFakeAuthor + // Developer Fake Author for producing blocks without authorisation on bor consensus + n.DevFakeAuthor = c.DevFakeAuthor + // gas price oracle { n.GPO.Blocks = int(c.Gpo.Blocks) @@ -1057,6 +1063,7 @@ func (c *Config) buildNode() (*node.Config, error) { InsecureUnlockAllowed: c.Accounts.AllowInsecureUnlock, Version: params.VersionWithCommit(gitCommit, gitDate), IPCPath: ipcPath, + AllowUnprotectedTxs: c.JsonRPC.AllowUnprotectedTxs, P2P: p2p.Config{ MaxPeers: int(c.P2P.MaxPeers), MaxPendingPeers: int(c.P2P.MaxPendPeers), diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index 3668866e73..803a06acc4 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -376,6 +376,13 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.JsonRPC.TxFeeCap, Group: "JsonRPC", }) + f.BoolFlag(&flagset.BoolFlag{ + Name: "rpc.allow-unprotected-txs", + Usage: "Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC", + Value: &c.cliConfig.JsonRPC.AllowUnprotectedTxs, + Default: c.cliConfig.JsonRPC.AllowUnprotectedTxs, + Group: "JsonRPC", + }) f.BoolFlag(&flagset.BoolFlag{ Name: "ipcdisable", Usage: "Disable the IPC-RPC server", diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 0c2f5ba2cb..9f6aed5b96 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1860,7 +1860,8 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c // Print a log with full tx details for manual investigations and interventions signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number()) from, err := types.Sender(signer, tx) - if err != nil { + + if err != nil && (!b.UnprotectedAllowed() || (b.UnprotectedAllowed() && err != types.ErrInvalidChainId)) { return common.Hash{}, err } @@ -2050,6 +2051,10 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs Transact for _, p := range pending { wantSigHash := s.signer.Hash(matchTx) pFrom, err := types.Sender(s.signer, p) + + if err != nil && (s.b.UnprotectedAllowed() && err == types.ErrInvalidChainId) { + err = nil + } if err == nil && pFrom == sendArgs.from() && s.signer.Hash(p) == wantSigHash { // Match. Re-sign and send the transaction. if gasPrice != nil && (*big.Int)(gasPrice).Sign() != 0 { diff --git a/packaging/templates/mainnet-v1/archive/config.toml b/packaging/templates/mainnet-v1/archive/config.toml index 387c90c7ce..537be0b1eb 100644 --- a/packaging/templates/mainnet-v1/archive/config.toml +++ b/packaging/templates/mainnet-v1/archive/config.toml @@ -8,6 +8,7 @@ syncmode = "full" gcmode = "archive" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -57,6 +58,7 @@ gcmode = "archive" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml b/packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml index 2e712ae912..d0faf61cd1 100644 --- a/packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml +++ b/packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml @@ -8,6 +8,7 @@ syncmode = "full" # gcmode = "full" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -57,6 +58,7 @@ syncmode = "full" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/mainnet-v1/sentry/validator/bor/config.toml b/packaging/templates/mainnet-v1/sentry/validator/bor/config.toml index 4402250e5e..078c032e66 100644 --- a/packaging/templates/mainnet-v1/sentry/validator/bor/config.toml +++ b/packaging/templates/mainnet-v1/sentry/validator/bor/config.toml @@ -10,6 +10,7 @@ syncmode = "full" # gcmode = "full" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -59,6 +60,7 @@ syncmode = "full" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/mainnet-v1/without-sentry/bor/config.toml b/packaging/templates/mainnet-v1/without-sentry/bor/config.toml index 34d712395d..fe26912e5c 100644 --- a/packaging/templates/mainnet-v1/without-sentry/bor/config.toml +++ b/packaging/templates/mainnet-v1/without-sentry/bor/config.toml @@ -10,6 +10,7 @@ syncmode = "full" # gcmode = "full" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -59,6 +60,7 @@ syncmode = "full" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/testnet-v4/archive/config.toml b/packaging/templates/testnet-v4/archive/config.toml index b6156e5482..fed0f47ec8 100644 --- a/packaging/templates/testnet-v4/archive/config.toml +++ b/packaging/templates/testnet-v4/archive/config.toml @@ -8,6 +8,7 @@ syncmode = "full" gcmode = "archive" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -57,6 +58,7 @@ gcmode = "archive" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/testnet-v4/sentry/sentry/bor/config.toml b/packaging/templates/testnet-v4/sentry/sentry/bor/config.toml index efad8735c7..11aa09a9b7 100644 --- a/packaging/templates/testnet-v4/sentry/sentry/bor/config.toml +++ b/packaging/templates/testnet-v4/sentry/sentry/bor/config.toml @@ -8,6 +8,7 @@ syncmode = "full" # gcmode = "full" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -57,6 +58,7 @@ syncmode = "full" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/testnet-v4/sentry/validator/bor/config.toml b/packaging/templates/testnet-v4/sentry/validator/bor/config.toml index adfe245511..7781e321eb 100644 --- a/packaging/templates/testnet-v4/sentry/validator/bor/config.toml +++ b/packaging/templates/testnet-v4/sentry/validator/bor/config.toml @@ -10,6 +10,7 @@ syncmode = "full" # gcmode = "full" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -59,6 +60,7 @@ syncmode = "full" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545 diff --git a/packaging/templates/testnet-v4/without-sentry/bor/config.toml b/packaging/templates/testnet-v4/without-sentry/bor/config.toml index 9ad2a6828a..3d9f9e7bd3 100644 --- a/packaging/templates/testnet-v4/without-sentry/bor/config.toml +++ b/packaging/templates/testnet-v4/without-sentry/bor/config.toml @@ -10,6 +10,7 @@ syncmode = "full" # gcmode = "full" # snapshot = true # ethstats = "" +# devfakeauthor = false # ["eth.requiredblocks"] @@ -59,6 +60,7 @@ syncmode = "full" # ipcdisable = false # gascap = 50000000 # txfeecap = 5.0 + # allow-unprotected-txs = false [jsonrpc.http] enabled = true port = 8545