Skip to content

Commit

Permalink
Implement EIP-3607 (#120)
Browse files Browse the repository at this point in the history
* Adding hash check for empty hash when configured  (#108)

* Fixing transactionCollidingWithNonEmptyAccount_init and transactionCollidingWithNonEmptyAccount_calls tests by checking validity.

* Update state/executor.go

Co-authored-by: Goran Rojovic <[email protected]>

---------

Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Stefan Negovanović <[email protected]>

* Configurable EIP3607 check

---------

Co-authored-by: cokicm <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent cf25955 commit 599a104
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 5 additions & 1 deletion chain/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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
Expand All @@ -197,4 +200,5 @@ var AllForksEnabled = &Forks{
London: NewFork(0),
Governance: NewFork(0),
EIP3855: NewFork(0),
EIP3607: NewFork(0),
}
18 changes: 18 additions & 0 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
20 changes: 16 additions & 4 deletions tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,28 +421,35 @@ 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),
chain.EIP158: chain.NewFork(0),
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),
Expand All @@ -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),
Expand All @@ -468,25 +476,27 @@ 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),
chain.EIP158: chain.NewFork(0),
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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 599a104

Please sign in to comment.