Skip to content

Commit

Permalink
EIP-3607 (check if sender is EOA). Update tests to v10.0 (erigontech#…
Browse files Browse the repository at this point in the history
…2820)

* Update Ethereum tests to v10.0

* Implement EIP-3607
  • Loading branch information
yperbasis authored Oct 13, 2021
1 parent cd1e98d commit 91df893
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
12 changes: 12 additions & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata

0 comments on commit 91df893

Please sign in to comment.