Skip to content
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

internal/ethapi: disable sending of non eip155 replay protected tx #22339

Merged
merged 9 commits into from
Feb 23, 2021

Conversation

MariusVanDerWijden
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden commented Feb 17, 2021

This PR prevents users from submitting transactions without EIP-155 enabled.
Replay protection is important so we should gently force our users to use it.

It changes the JSON-RPC API quite significantly, so if you see the "only replay-protected (EIP-155) transactions allowed over RPC" error, you know that you need to update your signer.

To test:

cl, sk := getRealBackend()
fakeTx := types.NewTransaction(0, common.HexToAddress(ADDR), big.NewInt(0), 21000, big.NewInt(1), nil)
noneip, err := types.SignTx(fakeTx, types.HomesteadSigner{}, sk)
if err != nil {
	panic(err)
}
if err := cl.SendTransaction(context.Background(), noneip); err != nil {
	fmt.Println(err) // Prints "only replay-protected (EIP-155) transactions allowed over RPC"
}
eip155, err := types.SignTx(fakeTx, types.NewEIP155Signer(big.NewInt(1337)), sk)
if err != nil {
	panic(err)
}
if err := cl.SendTransaction(context.Background(), eip155); err != nil {
	panic(err)
}

internal/ethapi/api.go Outdated Show resolved Hide resolved
@karalabe
Copy link
Member

Do we want to add a flag to disable this protection?

@holiman
Copy link
Contributor

holiman commented Feb 17, 2021

Do we want to add a flag to disable this protection?

I suggest rpc.allow-unprotected-txs which defaults to false

@karalabe karalabe added this to the 1.10.0 milestone Feb 17, 2021
eth/api_backend.go Outdated Show resolved Hide resolved
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ geth --dev --rpc.allow-unprotected-txs console 2>&1 | tail -n2
   
flag provided but not defined: -rpc.allow-unprotected-txs

You forgot to add it to the enabled flags, I think

@@ -966,6 +970,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(HTTPPathPrefixFlag.Name) {
cfg.HTTPPathPrefix = ctx.GlobalString(HTTPPathPrefixFlag.Name)
}

if ctx.GlobalIsSet(AllowUnprotectedTxs.Name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to check if it's set or not. That's only needed if the default has some special meaning. We only care about the actual value of the flag, so pls just use cfg.UnprotectedAllowed = ctx.GlobalBool(AllowUnprotectedTxs.Name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there is, when we simply override it here, then we will always overwrite the value we read out of the config.
See martins comments below

node/config.go Outdated Show resolved Hide resolved
@MariusVanDerWijden
Copy link
Member Author

@holiman Duh, I enabled it now and tested it

@holiman
Copy link
Contributor

holiman commented Feb 18, 2021

Almost, but not quite :)
With

[user@work go-ethereum]$ git diff 
diff --git a/eth/backend.go b/eth/backend.go
index d20920df0b..0c5e53b171 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -223,6 +223,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
        eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
 
        eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().UnprotectedAllowed, eth, nil}
+       log.Info("unprotected allowed", "value", eth.APIBackend.unprotectedAllowed)
        gpoParams := config.GPO
        if gpoParams.Default == nil {
                gpoParams.Default = config.Miner.GasPrice

And

[user@work go-ethereum]$ geth --rpc.allow-unprotected-txs=true --maxpeers 0 --nodiscover dumpconfig > conf.test
INFO [02-18|11:21:53.931] Maximum peer count                       ETH=0 LES=0 total=0
INFO [02-18|11:21:53.931] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [02-18|11:21:53.932] Set global gas cap                       cap=25000000

Stored to config?

[user@work go-ethereum]$ cat conf.test | grep Unpro
UnprotectedAllowed = true

Yes. However:

[user@work go-ethereum]$ geth --config conf.test --maxpeers 0 --nodiscover 
INFO [02-18|11:22:12.110] Starting Geth on Ethereum mainnet... 
...
INFO [02-18|11:22:12.300] Allocated fast sync bloom                size=1.26GiB
INFO [02-18|11:22:12.305] unprotected allowed                      value=false

@@ -970,8 +970,9 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(HTTPPathPrefixFlag.Name) {
cfg.HTTPPathPrefix = ctx.GlobalString(HTTPPathPrefixFlag.Name)
}

cfg.UnprotectedAllowed = ctx.GlobalBool(AllowUnprotectedTxs.Name)
if ctx.GlobalIsSet(HTTPPathPrefixFlag.Name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this tied to the http flag?

eth/backend.go Outdated
@@ -222,7 +222,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().UnprotectedAllowed, eth, nil}
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
log.Info("Unprotected TXs allowed", "value", eth.APIBackend.allowUnprotectedTxs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please type it out, transactions :P

@holiman
Copy link
Contributor

holiman commented Feb 18, 2021 via email

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@csquan
Copy link

csquan commented May 26, 2022

when I send tx,I still got error:"Cannot submit unprotected transaction".
what should I do?

@MariusVanDerWijden
Copy link
Member Author

Don't use non-eip155 replay protected transactions. They are unsafe as they can be replayed on a different chain.

@csquan
Copy link

csquan commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants