diff --git a/chain/params.go b/chain/params.go index 5744aa60a4..646c18a56c 100644 --- a/chain/params.go +++ b/chain/params.go @@ -93,6 +93,7 @@ const ( EIP155 = "EIP155" Governance = "governance" EIP3855 = "EIP3855" + EIP3607 = "EIP3607" ) // Forks is map which contains all forks and their starting blocks from genesis @@ -130,6 +131,7 @@ func (f *Forks) At(block uint64) ForksInTime { EIP155: f.IsActive(EIP155, block), Governance: f.IsActive(Governance, block), EIP3855: f.IsActive(EIP3855, block), + EIP3607: f.IsActive(EIP3607, block), } } @@ -181,7 +183,8 @@ type ForksInTime struct { EIP158, EIP155, Governance, - EIP3855 bool + EIP3855, + EIP3607 bool } // AllForksEnabled should contain all supported forks by current edge version @@ -197,4 +200,5 @@ var AllForksEnabled = &Forks{ London: NewFork(0), Governance: NewFork(0), EIP3855: NewFork(0), + EIP3607: NewFork(0), } diff --git a/state/executor.go b/state/executor.go index 5acc7de3f6..aaa31cabdc 100644 --- a/state/executor.go +++ b/state/executor.go @@ -425,8 +425,25 @@ func (t *Transition) Txn() *Txn { return t.state } +// checkSenderAccount rejects transactions from senders with deployed code. +// This check is performed only in case EIP 3607 is enabled. +func (t Transition) checkSenderAccount(msg *types.Transaction) bool { + if !t.config.EIP3607 { + return true + } + + codeHash := t.state.GetCodeHash(msg.From) + + return codeHash == types.ZeroHash || codeHash == types.EmptyCodeHash +} + // Apply applies a new transaction func (t *Transition) Apply(msg *types.Transaction) (*runtime.ExecutionResult, error) { + if !t.checkSenderAccount(msg) { + return nil, fmt.Errorf("%w: address %v, codehash: %v", ErrSenderNoEOA, msg.From.String(), + t.state.GetCodeHash(msg.From).String()) + } + s := t.state.Snapshot() result, err := t.apply(msg) @@ -516,6 +533,7 @@ func (t *Transition) checkDynamicFees(msg *types.Transaction) error { var ( ErrNonceIncorrect = errors.New("incorrect nonce") + ErrSenderNoEOA = errors.New("sender not an eoa") ErrNotEnoughFundsForGas = errors.New("not enough funds to cover gas costs") ErrBlockLimitReached = errors.New("gas limit reached in the pool") ErrIntrinsicGasOverflow = errors.New("overflow in intrinsic gas calculation") diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 0f09383aba..b0bf7d3f72 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -421,21 +421,27 @@ func (t *stTransaction) UnmarshalJSON(input []byte) error { // forks var Forks = map[string]*chain.Forks{ - "Frontier": {}, + "Frontier": { + chain.EIP3607: chain.NewFork(0), + }, "Homestead": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), }, "EIP150": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), }, "EIP158": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), chain.EIP158: chain.NewFork(0), }, "Byzantium": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -443,6 +449,7 @@ var Forks = map[string]*chain.Forks{ chain.Byzantium: chain.NewFork(0), }, "Constantinople": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -458,6 +465,7 @@ var Forks = map[string]*chain.Forks{ chain.Byzantium: chain.NewFork(0), chain.Constantinople: chain.NewFork(0), chain.Petersburg: chain.NewFork(0), + chain.EIP3607: chain.NewFork(0), }, "Istanbul": { chain.Homestead: chain.NewFork(0), @@ -468,18 +476,19 @@ var Forks = map[string]*chain.Forks{ chain.Constantinople: chain.NewFork(0), chain.Petersburg: chain.NewFork(0), chain.Istanbul: chain.NewFork(0), + chain.EIP3607: chain.NewFork(0), }, "FrontierToHomesteadAt5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(5), }, "HomesteadToEIP150At5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(5), }, - "HomesteadToDaoAt5": { - chain.Homestead: chain.NewFork(0), - }, "EIP158ToByzantiumAt5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -487,6 +496,7 @@ var Forks = map[string]*chain.Forks{ chain.Byzantium: chain.NewFork(5), }, "ByzantiumToConstantinopleAt5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -495,6 +505,7 @@ var Forks = map[string]*chain.Forks{ chain.Constantinople: chain.NewFork(5), }, "ByzantiumToConstantinopleFixAt5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -504,6 +515,7 @@ var Forks = map[string]*chain.Forks{ chain.Petersburg: chain.NewFork(5), }, "ConstantinopleFixToIstanbulAt5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0),