Skip to content

Commit

Permalink
core: check if sender is EOA (ethereum#23303)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Aug 26, 2024
1 parent fc41558 commit dd22058
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ var (
// ErrFeeCapTooLow is returned if the transaction fee cap is less than the
// the base fee of the block.
ErrFeeCapTooLow = errors.New("max fee per gas less than block base fee")

// ErrSenderNoEOA is returned if the sender of a transaction is a contract.
ErrSenderNoEOA = errors.New("sender not an eoa")
)
8 changes: 8 additions & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import (
cmath "github.com/XinFinOrg/XDPoSChain/common/math"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/core/vm"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/params"
)

var emptyCodeHash = crypto.Keccak256Hash(nil)

var (
errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
)
Expand Down Expand Up @@ -222,6 +225,11 @@ func (st *StateTransition) preCheck() error {
msg.From().Hex(), stNonce)
}
}
// Make sure the sender is an EOA
if codeHash := st.state.GetCodeHash(st.msg.From()); codeHash != emptyCodeHash && codeHash != (common.Hash{}) {
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
st.msg.From().Hex(), codeHash)
}
// Make sure that transaction gasFeeCap is greater than the baseFee (post london)
if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) {
// Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call)
Expand Down
29 changes: 25 additions & 4 deletions tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ func findLine(data []byte, offset int64) (line int) {

// testMatcher controls skipping and chain config assignment to tests.
type testMatcher struct {
configpat []testConfig
failpat []testFailure
skiploadpat []*regexp.Regexp
skipshortpat []*regexp.Regexp
configpat []testConfig
failpat []testFailure
skiploadpat []*regexp.Regexp
skipshortpat []*regexp.Regexp
runonlylistpat *regexp.Regexp
}

type testConfig struct {
Expand Down Expand Up @@ -121,6 +122,10 @@ func (tm *testMatcher) fails(pattern string, reason string) {
tm.failpat = append(tm.failpat, testFailure{regexp.MustCompile(pattern), reason})
}

func (tm *testMatcher) runonly(pattern string) {
tm.runonlylistpat = regexp.MustCompile(pattern)
}

// config defines chain config for tests matching the pattern.
func (tm *testMatcher) config(pattern string, cfg params.ChainConfig) {
tm.configpat = append(tm.configpat, testConfig{regexp.MustCompile(pattern), cfg})
Expand Down Expand Up @@ -209,6 +214,11 @@ func (tm *testMatcher) runTestFile(t *testing.T, path, name string, runTest inte
if r, _ := tm.findSkip(name); r != "" {
t.Skip(r)
}
if tm.runonlylistpat != nil {
if !tm.runonlylistpat.MatchString(name) {
t.Skip("Skipped by runonly")
}
}
t.Parallel()

// Load the file as map[string]<testType>.
Expand Down Expand Up @@ -262,3 +272,14 @@ func runTestFunc(runTest interface{}, t *testing.T, name string, m reflect.Value
m.MapIndex(reflect.ValueOf(key)),
})
}

func TestMatcherRunonlylist(t *testing.T) {
t.Parallel()
tm := new(testMatcher)
tm.runonly("invalid*")
tm.walk(t, rlpTestDir, func(t *testing.T, name string, test *RLPTest) {
if name[:len("invalidRLPTest.json")] != "invalidRLPTest.json" {
t.Fatalf("invalid test found: %s != invalidRLPTest.json", name)
}
})
}
7 changes: 7 additions & 0 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ func TestState(t *testing.T) {
st := new(testMatcher)
// Long tests:
st.skipShortMode(`^stQuadraticComplexityTest/`)

// Broken tests:
st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits
st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet

// Uses 1GB RAM per tested fork
st.skipLoad(`^stStaticCall/static_Call1MB`)
// Un-skip this when https://github.com/ethereum/tests/issues/908 is closed
st.skipLoad(`^stQuadraticComplexityTest/QuadraticComplexitySolidity_CallDataCopy`)

// Expected failures:
st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test")
st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158`, "bug in test")
Expand Down

0 comments on commit dd22058

Please sign in to comment.