From 45fd38c30f6f27d67d80f1169f8f0cb4d349faaa Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Wed, 13 Oct 2021 03:30:09 +0200 Subject: [PATCH] EIP-3607 (check if sender is EOA). Update tests to v10.0 (#2820) * Update Ethereum tests to v10.0 * Implement EIP-3607 --- core/error.go | 4 ++++ core/state_transition.go | 12 ++++++++++++ tests/testdata | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/error.go b/core/error.go index 753f20015..317f1ea8d 100644 --- a/core/error.go +++ b/core/error.go @@ -83,4 +83,8 @@ var ( // ErrFeeCapTooLow is returned if the transaction fee cap is less than the // the base fee of the block. ErrFeeCapTooLow = errors.New("fee cap less than block base fee") + + // ErrSenderNoEOA is returned if the sender of a transaction is a contract. + // See EIP-3607: Reject transactions from senders with deployed code. + ErrSenderNoEOA = errors.New("sender not an eoa") ) diff --git a/core/state_transition.go b/core/state_transition.go index 4bb553c73..307e70d6d 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -26,9 +26,12 @@ import ( cmath "github.com/ledgerwatch/erigon/common/math" "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/core/vm" + "github.com/ledgerwatch/erigon/crypto" "github.com/ledgerwatch/erigon/params" ) +var emptyCodeHash = crypto.Keccak256Hash(nil) + /* The State Transitioning Model @@ -239,6 +242,15 @@ func (st *StateTransition) preCheck(gasBailout bool) error { } } + // Make sure the sender is an EOA (EIP-3607) + if codeHash := st.state.GetCodeHash(st.msg.From()); codeHash != emptyCodeHash && codeHash != (common.Hash{}) { + // common.Hash{} means that the sender is not in the state. + // Historically there were transactions with 0 gas price and non-existing sender, + // so we have to allow that. + return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA, + st.msg.From().Hex(), codeHash) + } + // Make sure the transaction gasFeeCap is greater than the block's baseFee. if st.evm.ChainRules.IsLondon { // Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call) diff --git a/tests/testdata b/tests/testdata index 5d651381d..52cb3b3e7 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit 5d651381daf9d12cc663a7326b3b16d7bb4c1aa0 +Subproject commit 52cb3b3e724d13943bd8a457ed70929f98b9b8bf