From fc16fbfffd0b46f09468c448b23da0dcbde70564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 15 Feb 2024 08:02:05 +0100 Subject: [PATCH 01/11] Bump Ethereum tests version --- tests/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests b/tests/tests index 428f218d7d..853b1e03b1 160000 --- a/tests/tests +++ b/tests/tests @@ -1 +1 @@ -Subproject commit 428f218d7d6f4a52544e12684afbfe6e2882ffbf +Subproject commit 853b1e03b1078d370614002851ba1ee9803d9fcf From 17db856a17acfa375306f93635f86212246ad8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 15 Feb 2024 08:13:54 +0100 Subject: [PATCH 02/11] Linter fixes --- crypto/txsigner_london_berlin_test.go | 1 + state/runtime/evm/instructions_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/crypto/txsigner_london_berlin_test.go b/crypto/txsigner_london_berlin_test.go index a8ff06e695..a1c989ce80 100644 --- a/crypto/txsigner_london_berlin_test.go +++ b/crypto/txsigner_london_berlin_test.go @@ -71,6 +71,7 @@ func TestLondonSignerSender(t *testing.T) { require.NoError(t, err, "unable to generate private key") var txn *types.Transaction + switch tc.txType { case types.AccessListTx: txn = types.NewTx(&types.AccessListTxn{ diff --git a/state/runtime/evm/instructions_test.go b/state/runtime/evm/instructions_test.go index 396f67c44e..2312ab6ec3 100644 --- a/state/runtime/evm/instructions_test.go +++ b/state/runtime/evm/instructions_test.go @@ -1624,8 +1624,10 @@ func Test_opSload(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() + s, closeFn := getState(tt.config) defer closeFn() + s.msg = tt.contract s.gas = tt.initState.gas s.sp = tt.initState.sp @@ -1635,6 +1637,7 @@ func Test_opSload(t *testing.T) { s.host = tt.mockHost tt.contract.AccessList = tt.initState.accessList opSload(s) + assert.Equal(t, tt.resultState.gas, s.gas, "gas in state after execution is not correct") assert.Equal(t, tt.resultState.sp, s.sp, "sp in state after execution is not correct") assert.Equal(t, tt.resultState.stack, s.stack, "stack in state after execution is not correct") @@ -2383,6 +2386,7 @@ func Test_opCall(t *testing.T) { test := tt t.Run(test.name, func(t *testing.T) { t.Parallel() + state, closeFn := getState(&test.config) defer closeFn() From d185d027a0dd31c5cc2eb9fd87c0a3b75e41a011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 15 Feb 2024 10:59:05 +0100 Subject: [PATCH 03/11] Skip loopMul and minor refactoring --- tests/state_test.go | 10 +++------- tests/state_test_util.go | 12 ++++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/state_test.go b/tests/state_test.go index fb62258cac..fbe507f356 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -162,7 +162,7 @@ func TestState(t *testing.T) { } skip := []string{ - "RevertPrecompiledTouch", + "loopMul", } // There are two folders in spec tests, one for the current tests for the Istanbul fork @@ -173,18 +173,14 @@ func TestState(t *testing.T) { } for _, folder := range folders { - files, err := listFiles(folder) + files, err := listFiles(folder, ".json") if err != nil { t.Fatal(err) } for _, file := range files { - if !strings.HasSuffix(file, ".json") { - continue - } - if contains(long, file) && testing.Short() { - t.Skipf("Long tests are skipped in short mode") + t.Skip("Long tests are skipped in short mode") continue } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index a1b47aded0..216a6389c0 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -621,7 +621,7 @@ func listFolders(tests ...string) ([]string, error) { return folders, nil } -func listFiles(folder string) ([]string, error) { +func listFiles(folder string, extensions ...string) ([]string, error) { var files []string err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error { @@ -630,7 +630,15 @@ func listFiles(folder string) ([]string, error) { } if !info.IsDir() { - files = append(files, path) + if len(extensions) > 0 { + for _, ext := range extensions { + if strings.HasSuffix(path, ext) { + files = append(files, path) + } + } + } else { + files = append(files, path) + } } return nil From 24bb5103f93f59efa300dcfd1fc8b975b764ff9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 15 Feb 2024 12:09:49 +0100 Subject: [PATCH 04/11] Refactor Ethereum tests files resolution --- tests/state_test.go | 10 +++++----- tests/state_test_util.go | 43 +++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/tests/state_test.go b/tests/state_test.go index fbe507f356..d66e0d7e9d 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -162,12 +162,12 @@ func TestState(t *testing.T) { } skip := []string{ + "RevertPrecompiledTouch", + "RevertPrecompiledTouch_storage", "loopMul", } - // There are two folders in spec tests, one for the current tests for the Istanbul fork - // and one for the legacy tests for the other forks - folders, err := listFolders(stateTests) + folders, err := listFolders([]string{stateTests}, ".json") if err != nil { t.Fatal(err) } @@ -180,13 +180,13 @@ func TestState(t *testing.T) { for _, file := range files { if contains(long, file) && testing.Short() { - t.Skip("Long tests are skipped in short mode") + t.Logf("Long test '%s' is skipped in short mode\n", file) continue } if contains(skip, file) { - t.Skip() + t.Logf("Test '%s' is skipped\n", file) continue } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 216a6389c0..2601539181 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io/fs" "math/big" "os" "path/filepath" @@ -596,25 +597,33 @@ func contains(l []string, name string) bool { return false } -func listFolders(tests ...string) ([]string, error) { +func listFolders(paths []string, extensions ...string) ([]string, error) { var folders []string - for _, t := range tests { - dir, err := os.Open(t) - if err != nil { - return nil, err - } - defer dir.Close() + for _, rootPath := range paths { + err := filepath.WalkDir(rootPath, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } - fileInfos, err := dir.Readdir(-1) - if err != nil { - return nil, err - } + if d.IsDir() { + files, err := os.ReadDir(path) + if err != nil { + return err + } + + if len(files) > 0 { + fmt.Println("Folder", path) - for _, fileInfo := range fileInfos { - if fileInfo.IsDir() && t != "path" { - folders = append(folders, filepath.Join(t, fileInfo.Name())) + folders = append(folders, path) + } } + + return nil + }) + + if err != nil { + return nil, err } } @@ -624,19 +633,21 @@ func listFolders(tests ...string) ([]string, error) { func listFiles(folder string, extensions ...string) ([]string, error) { var files []string - err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error { + err := filepath.WalkDir(folder, func(path string, d fs.DirEntry, err error) error { if err != nil { return err } - if !info.IsDir() { + if !d.IsDir() { if len(extensions) > 0 { + // filter files by extensions for _, ext := range extensions { if strings.HasSuffix(path, ext) { files = append(files, path) } } } else { + // if no extensions filter is provided, add all files files = append(files, path) } } From f69a8ac97a823816911f14133368524652ef952c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 15 Feb 2024 15:08:03 +0100 Subject: [PATCH 05/11] Provide EIP 3607 to each fork config --- tests/state_test_util.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 2601539181..ded5661f6f 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -484,6 +484,7 @@ var Forks = map[string]*chain.Forks{ chain.Constantinople: chain.NewFork(0), }, "ConstantinopleFix": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -491,9 +492,9 @@ 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.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -502,7 +503,6 @@ 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), @@ -552,6 +552,7 @@ var Forks = map[string]*chain.Forks{ chain.Istanbul: chain.NewFork(5), }, "Berlin": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -563,6 +564,7 @@ var Forks = map[string]*chain.Forks{ chain.Berlin: chain.NewFork(0), }, "BerlinToLondonAt5": { + chain.EIP3607: chain.NewFork(0), chain.Homestead: chain.NewFork(0), chain.EIP150: chain.NewFork(0), chain.EIP155: chain.NewFork(0), @@ -613,8 +615,6 @@ func listFolders(paths []string, extensions ...string) ([]string, error) { } if len(files) > 0 { - fmt.Println("Folder", path) - folders = append(folders, path) } } From 66d94a53327a63cb9e9a68e9179655961991b150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 15 Feb 2024 15:08:15 +0100 Subject: [PATCH 06/11] Audit duration of each test --- tests/state_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/state_test.go b/tests/state_test.go index d66e0d7e9d..223ac9ae67 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" "testing" + "time" "github.com/0xPolygon/polygon-edge/chain" "github.com/0xPolygon/polygon-edge/crypto" @@ -216,7 +217,11 @@ func TestState(t *testing.T) { fc := &forkConfig{name: fork, forks: forks} for idx, postStateEntry := range postState { + start := time.Now() err := RunSpecificTest(t, file, tc, fc, idx, postStateEntry) + + t.Logf("'%s' executed. Duration=%v\n", file, time.Since(start)) + require.NoError(t, tc.checkError(fork, idx, err)) } } From d74cbe0deec52bca25e61ff01bd4a67b1bda3bcc Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Fri, 16 Feb 2024 15:06:55 +0100 Subject: [PATCH 07/11] Add detailed logging and skip CREATEBlake2f_MaxRounds test --- tests/state_test.go | 5 +++-- tests/tests | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/state_test.go b/tests/state_test.go index 223ac9ae67..848e79dd31 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -166,6 +166,7 @@ func TestState(t *testing.T) { "RevertPrecompiledTouch", "RevertPrecompiledTouch_storage", "loopMul", + "CALLBlake2f_MaxRounds", } folders, err := listFolders([]string{stateTests}, ".json") @@ -210,7 +211,7 @@ func TestState(t *testing.T) { for fork, postState := range tc.Post { forks, exists := Forks[fork] if !exists { - t.Logf("%s fork is not supported, skipping test case.", fork) + //t.Logf("%s fork is not supported, skipping test case.", fork) continue } @@ -220,7 +221,7 @@ func TestState(t *testing.T) { start := time.Now() err := RunSpecificTest(t, file, tc, fc, idx, postStateEntry) - t.Logf("'%s' executed. Duration=%v\n", file, time.Since(start)) + t.Logf("'%s' executed. Fork: %s. Case: %d, Duration=%v\n", file, fork, idx, time.Since(start)) require.NoError(t, tc.checkError(fork, idx, err)) } diff --git a/tests/tests b/tests/tests index 853b1e03b1..428f218d7d 160000 --- a/tests/tests +++ b/tests/tests @@ -1 +1 @@ -Subproject commit 853b1e03b1078d370614002851ba1ee9803d9fcf +Subproject commit 428f218d7d6f4a52544e12684afbfe6e2882ffbf From 40a26de2c8d3b9c3bf80fb1443a45925bed147d7 Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Fri, 16 Feb 2024 15:46:28 +0100 Subject: [PATCH 08/11] Remove -v flag --- tests/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests b/tests/tests index 428f218d7d..853b1e03b1 160000 --- a/tests/tests +++ b/tests/tests @@ -1 +1 @@ -Subproject commit 428f218d7d6f4a52544e12684afbfe6e2882ffbf +Subproject commit 853b1e03b1078d370614002851ba1ee9803d9fcf From a2307d440ea4342879970b86aef6c4bee714b7af Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Fri, 16 Feb 2024 16:07:22 +0100 Subject: [PATCH 09/11] small fixes --- tests/state_test.go | 4 ++-- tests/state_test_util.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/state_test.go b/tests/state_test.go index 848e79dd31..d35912a349 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -169,7 +169,7 @@ func TestState(t *testing.T) { "CALLBlake2f_MaxRounds", } - folders, err := listFolders([]string{stateTests}, ".json") + folders, err := listFolders([]string{stateTests}) if err != nil { t.Fatal(err) } @@ -211,7 +211,7 @@ func TestState(t *testing.T) { for fork, postState := range tc.Post { forks, exists := Forks[fork] if !exists { - //t.Logf("%s fork is not supported, skipping test case.", fork) + t.Logf("%s fork is not supported, skipping test case.", fork) continue } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index ded5661f6f..62aac545bc 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -599,7 +599,7 @@ func contains(l []string, name string) bool { return false } -func listFolders(paths []string, extensions ...string) ([]string, error) { +func listFolders(paths []string) ([]string, error) { var folders []string for _, rootPath := range paths { From ce96c73a81cdc0fce0014399b01606f464e01f77 Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Fri, 16 Feb 2024 16:27:59 +0100 Subject: [PATCH 10/11] fix --- tests/state_test_util.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 62aac545bc..31ee9e21bd 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -577,6 +577,7 @@ var Forks = map[string]*chain.Forks{ chain.London: chain.NewFork(5), }, // "London": { + // chain.EIP3607: chain.NewFork(0), // chain.Homestead: chain.NewFork(0), // chain.EIP150: chain.NewFork(0), // chain.EIP155: chain.NewFork(0), From 599565dbb8948feae6673a43fa8b11b97cdc621c Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Fri, 16 Feb 2024 16:33:14 +0100 Subject: [PATCH 11/11] Lint fix --- state/executor.go | 1 + state/runtime/evm/instructions.go | 1 + state/runtime/evm/instructions_test.go | 1 + 3 files changed, 3 insertions(+) diff --git a/state/executor.go b/state/executor.go index a494d8f07a..fba376da62 100644 --- a/state/executor.go +++ b/state/executor.go @@ -648,6 +648,7 @@ func (t *Transition) apply(msg *types.Transaction) (*runtime.ExecutionResult, er if err := t.state.IncrNonce(msg.From()); err != nil { return nil, err } + result = t.Call2(msg.From(), *(msg.To()), msg.Input(), value, gasLeft, initialAccessList) } diff --git a/state/runtime/evm/instructions.go b/state/runtime/evm/instructions.go index 0a66d60405..2592e0aabe 100644 --- a/state/runtime/evm/instructions.go +++ b/state/runtime/evm/instructions.go @@ -34,6 +34,7 @@ func (c *state) calculateGasForEIP2929(addr types.Address) uint64 { gas = WarmStorageReadCostEIP2929 } else { gas = ColdAccountAccessCostEIP2929 + c.msg.AddToJournal(&runtime.AccessListAddAccountChange{Address: addr}) c.msg.AccessList.AddAddress(addr) } diff --git a/state/runtime/evm/instructions_test.go b/state/runtime/evm/instructions_test.go index 2312ab6ec3..39c269f0ea 100644 --- a/state/runtime/evm/instructions_test.go +++ b/state/runtime/evm/instructions_test.go @@ -1636,6 +1636,7 @@ func Test_opSload(t *testing.T) { s.config = tt.config s.host = tt.mockHost tt.contract.AccessList = tt.initState.accessList + opSload(s) assert.Equal(t, tt.resultState.gas, s.gas, "gas in state after execution is not correct")