From 21b557fe1f7fcfdee35374577249b0e9fa7dd8b4 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 25 Aug 2022 16:43:35 +0300 Subject: [PATCH 001/103] cmd/geth: fix on darwin, where long test names fail Error is "The ipc endpoint is longer than %d characters." --- cmd/geth/consolecmd_cg_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index f9226f414a..154d0af333 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -1,11 +1,13 @@ package main import ( + "crypto/sha1" "fmt" "os" "path/filepath" "regexp" "strconv" + "strings" "testing" "time" @@ -165,7 +167,10 @@ func TestGethStartupLogs(t *testing.T) { }, } for i, c := range cases { - t.Run(fmt.Sprintf("TestGethStartupLogs/%d: %v", i, c.flags), func(t *testing.T) { + // fix for darwin, where long test names fail with "The ipc endpoint is longer than %d characters." + hashedFlags := fmt.Sprintf("%x", sha1.Sum([]byte(strings.Join(c.flags, " ")))) + + t.Run(fmt.Sprintf("%d:%v", i, hashedFlags[:8]), func(t *testing.T) { geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...) geth.KillTimeout = 10 * time.Second geth.ExpectRegexp("(?ism).*CoreGeth.*") From b62c2b97cdc8424c25b902ec16121e9b5a42253f Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 25 Aug 2022 16:53:39 +0300 Subject: [PATCH 002/103] go.mod,go.sum: update dependency for etclabscore/go-openrpc-reflect@fix-m1-nil-pointer for fixing test issue --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 718014a12e..24002156ef 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/docker/docker v1.6.2 github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf github.com/edsrzf/mmap-go v1.0.0 - github.com/etclabscore/go-openrpc-reflect v0.0.36 + github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006 github.com/ethereum/evmc/v7 v7.5.0 github.com/fatih/color v1.7.0 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c diff --git a/go.sum b/go.sum index 9e89c3db4b..73fcf98ff2 100644 --- a/go.sum +++ b/go.sum @@ -132,6 +132,8 @@ github.com/etclabscore/go-jsonschema-walk v0.0.6 h1:DrNzoKWKd8f8XB5nFGBY00IcjakR github.com/etclabscore/go-jsonschema-walk v0.0.6/go.mod h1:VdfDY72AFAiUhy0ZXEaWSpveGjMT5JcDIm903NGqFwQ= github.com/etclabscore/go-openrpc-reflect v0.0.36 h1:kSqNB2U8RVoW4si+4fsv13NGNkRAQ5j78zTUx1qiehk= github.com/etclabscore/go-openrpc-reflect v0.0.36/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= +github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006 h1:c871GQvxjXH8BIW1GSjuqtGMEDSqSnkob/7X9U+EaOU= +github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= github.com/ethereum/evmc/v7 v7.5.0 h1:vwKcs1DINXqvaymranmlpO64fysJJkirCCJ+kkaPaCs= github.com/ethereum/evmc/v7 v7.5.0/go.mod h1:q2Q0rCSUlIkngd+mZwfCzEUbvB0IIopH1+7hcs9QuDg= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= From f67dd6300a38e756a9e4c8cad19ac21e8148a5e5 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 25 Aug 2022 17:24:13 +0300 Subject: [PATCH 003/103] cmd/geth: fix lint issue (G401: Use of weak cryptographic primitive (gosec)) --- cmd/geth/consolecmd_cg_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index 154d0af333..5e7f52b939 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -1,7 +1,7 @@ package main import ( - "crypto/sha1" + "crypto/sha256" "fmt" "os" "path/filepath" @@ -168,7 +168,7 @@ func TestGethStartupLogs(t *testing.T) { } for i, c := range cases { // fix for darwin, where long test names fail with "The ipc endpoint is longer than %d characters." - hashedFlags := fmt.Sprintf("%x", sha1.Sum([]byte(strings.Join(c.flags, " ")))) + hashedFlags := fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(c.flags, " ")))) t.Run(fmt.Sprintf("%d:%v", i, hashedFlags[:8]), func(t *testing.T) { geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...) From 3d7538059e6f93349abd0f3881ab876ce6bf93c4 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 29 Aug 2022 09:21:05 -0500 Subject: [PATCH 004/103] cmd/geth: fixup subtest names, logging, and datadir paths If IPC paths are too long, Unix systems will complain because there are limits, albeit inconsistent ones. So we try to keep IPC path names short (ie <100 chars). I removed all instances where flags were used in test names because - they cause issues with apple silicon M1, - and they are pointless I also removed the redundant subtest naming scheme which included the test name. Go includes the test name by default anyway. Date: 2022-08-29 09:21:05-05:00 Signed-off-by: meows --- cmd/geth/consolecmd_cg_test.go | 38 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index 5e7f52b939..b203f4ddca 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -1,13 +1,12 @@ package main import ( - "crypto/sha256" "fmt" + "math/rand" "os" "path/filepath" "regexp" "strconv" - "strings" "testing" "time" @@ -51,14 +50,14 @@ func TestConsoleCmdNetworkIdentities(t *testing.T) { // or collisions with an existing geth service. p.flags = append(p.flags, "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none") - t.Run(fmt.Sprintf("%d/%v/networkid", i, p.flags), + t.Run(fmt.Sprintf("%d/networkid", i), consoleCmdStdoutTest(p.flags, "admin.nodeInfo.protocols.eth.network", p.networkId)) - t.Run(fmt.Sprintf("%d/%v/chainid", i, p.flags), + t.Run(fmt.Sprintf("%d/chainid", i), consoleCmdStdoutTest(p.flags, "admin.nodeInfo.protocols.eth.config.chainId", p.chainId)) // The developer mode block has a dynamic genesis, depending on a parameterized address (coinbase) value. if p.genesisHash != "0x0" { - t.Run(fmt.Sprintf("%d/%v/genesis_hash", i, p.flags), + t.Run(fmt.Sprintf("%d/genesis_hash", i), consoleCmdStdoutTest(p.flags, "eth.getBlock(0, false).hash", strconv.Quote(p.genesisHash))) } } @@ -67,6 +66,7 @@ func TestConsoleCmdNetworkIdentities(t *testing.T) { func consoleCmdStdoutTest(flags []string, execCmd string, want interface{}) func(t *testing.T) { return func(t *testing.T) { flags = append(flags, "--ipcpath", filepath.Join(os.TempDir(), "geth.ipc"), "--exec", execCmd, "console") + t.Log("flags:", flags) geth := runGeth(t, flags...) geth.Expect(fmt.Sprintf(`%v `, want)) @@ -88,8 +88,9 @@ func TestGethFailureToLaunch(t *testing.T) { expectErrorReStr: "(?ism)incorrect usage.*", }, } - for _, c := range cases { - t.Run(fmt.Sprintf("TestIncorrectUsage: %v", c.flags), func(t *testing.T) { + for i, c := range cases { + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + t.Log("flags:", c.flags) geth := runGeth(t, c.flags...) geth.ExpectRegexp(c.expectErrorReStr) geth.ExpectExit() @@ -100,11 +101,23 @@ func TestGethFailureToLaunch(t *testing.T) { } } +// randomStr is used in naming the geth tests' temporary datadir. +func randomStr(n int) string { + letterBytes := "abcdefghijklmnopqrstuvwxyz" + b := make([]byte, n) + for i := range b { + b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))] + } + return string(b) +} + // TestGethStartupLogs tests that geth logs certain things (given some set of flags). // In these cases, geth is run with a console command to print its name (and tests that it does). func TestGethStartupLogs(t *testing.T) { // semiPersistentDatadir is used to house an adhoc datadir for co-dependent geth test cases. - semiPersistentDatadir := filepath.Join(os.TempDir(), fmt.Sprintf("geth-startup-logs-test-%d", time.Now().Unix())) + // WATCHOUT: For Unix-based operating systems, you're going to have problems if the IPC endpoint is + // longer than ___ characters. + semiPersistentDatadir := filepath.Join(os.TempDir(), fmt.Sprintf("geth-test-%x", randomStr(4))) defer os.RemoveAll(semiPersistentDatadir) type matching struct { @@ -167,11 +180,10 @@ func TestGethStartupLogs(t *testing.T) { }, } for i, c := range cases { - // fix for darwin, where long test names fail with "The ipc endpoint is longer than %d characters." - hashedFlags := fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(c.flags, " ")))) - - t.Run(fmt.Sprintf("%d:%v", i, hashedFlags[:8]), func(t *testing.T) { - geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...) + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + caseFlags := append(c.flags, "--exec", "admin.nodeInfo.name", "console") + t.Log("flags:", caseFlags) + geth := runGeth(t, caseFlags...) geth.KillTimeout = 10 * time.Second geth.ExpectRegexp("(?ism).*CoreGeth.*") geth.ExpectExit() From 9002f71b5a4b1f97b0fc5b099b37296ecf492e25 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 29 Aug 2022 09:22:26 -0500 Subject: [PATCH 005/103] go.mod,go.sum: bump etclabscore/go-openrpc-reflect to v0.0.37 Bumps dep to a tag version equivalent to the previously referenced, untagged version. Date: 2022-08-29 09:22:26-05:00 Signed-off-by: meows --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 24002156ef..96823835ec 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/docker/docker v1.6.2 github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf github.com/edsrzf/mmap-go v1.0.0 - github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006 + github.com/etclabscore/go-openrpc-reflect v0.0.37 github.com/ethereum/evmc/v7 v7.5.0 github.com/fatih/color v1.7.0 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c diff --git a/go.sum b/go.sum index 73fcf98ff2..89f737ffa6 100644 --- a/go.sum +++ b/go.sum @@ -130,10 +130,8 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/etclabscore/go-jsonschema-walk v0.0.6 h1:DrNzoKWKd8f8XB5nFGBY00IcjakRE22OTI12k+2LkyY= github.com/etclabscore/go-jsonschema-walk v0.0.6/go.mod h1:VdfDY72AFAiUhy0ZXEaWSpveGjMT5JcDIm903NGqFwQ= -github.com/etclabscore/go-openrpc-reflect v0.0.36 h1:kSqNB2U8RVoW4si+4fsv13NGNkRAQ5j78zTUx1qiehk= -github.com/etclabscore/go-openrpc-reflect v0.0.36/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= -github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006 h1:c871GQvxjXH8BIW1GSjuqtGMEDSqSnkob/7X9U+EaOU= -github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= +github.com/etclabscore/go-openrpc-reflect v0.0.37 h1:IH0e7JqIvR9OhbbFWi/BHIkXrqbR3Zyia3RJ733eT6c= +github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= github.com/ethereum/evmc/v7 v7.5.0 h1:vwKcs1DINXqvaymranmlpO64fysJJkirCCJ+kkaPaCs= github.com/ethereum/evmc/v7 v7.5.0/go.mod h1:q2Q0rCSUlIkngd+mZwfCzEUbvB0IIopH1+7hcs9QuDg= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= From 310ca59020c0f7887ef0952ddbefc117e8eab6da Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 31 Aug 2022 19:55:29 -0700 Subject: [PATCH 006/103] consensus/ethash: apply new cache file naming pattern to full datasets too Date: 2022-08-31 19:55:29-07:00 Signed-off-by: meows --- consensus/ethash/ethash.go | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 63e9ae6199..2327f7c990 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -463,7 +463,7 @@ func (d *dataset) generate(dir string, limit int, lock bool, test bool) { if !isLittleEndian() { endian = ".be" } - path := filepath.Join(dir, fmt.Sprintf("full-R%d-%x%s", algorithmRevision, seed[:8], endian)) + path := filepath.Join(dir, fmt.Sprintf("full-R%d-%d-%x%s", algorithmRevision, d.epoch, seed[:8], endian)) logger := log.New("epoch", d.epoch) // We're about to mmap the file, ensure that the mapping is cleaned up when the @@ -499,11 +499,34 @@ func (d *dataset) generate(dir string, limit int, lock bool, test bool) { d.dataset = make([]uint32, dsize/4) generateDataset(d.dataset, d.epoch, d.epochLength, cache) } - // Iterate over all previous instances and delete old ones - for ep := int(d.epoch) - limit; ep >= 0; ep-- { - seed := seedHash(uint64(ep), d.epochLength) - path := filepath.Join(dir, fmt.Sprintf("full-R%d-%x%s", algorithmRevision, seed[:8], endian)) - os.Remove(path) + + // Iterate over all full file instances, deleting any out of bounds (where epoch is below lower limit, or above upper limit). + matches, _ := filepath.Glob(filepath.Join(dir, fmt.Sprintf("full-R%d*", algorithmRevision))) + for _, file := range matches { + var ar int // algorithm revision + var e uint64 // epoch + var s string // seed + if _, err := fmt.Sscanf(filepath.Base(file), "full-R%d-%d-%s"+endian, &ar, &e, &s); err != nil { + // There is an unrecognized file in this directory. + // See if the name matches the expected pattern of the legacy naming scheme. + if _, err := fmt.Sscanf(filepath.Base(file), "full-R%d-%s"+endian, &ar, &s); err == nil { + // This file matches the previous generation naming pattern (sans epoch). + if err := os.Remove(file); err != nil { + logger.Error("Failed to remove legacy ethash full file", "file", file, "err", err) + } else { + logger.Warn("Deleted legacy ethash full file", "path", file) + } + } + // Else the file is unrecognized (unknown name format), leave it alone. + continue + } + if e <= d.epoch-uint64(limit) || e > d.epoch+1 { + if err := os.Remove(file); err == nil { + logger.Debug("Deleted ethash full file", "target.epoch", e, "file", file) + } else { + logger.Error("Failed to delete ethash full file", "target.epoch", e, "file", file, "err", err) + } + } } }) } From d0dc349fd36bd79f94516c866251783641ed12f1 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Wed, 31 Aug 2022 16:14:53 +0200 Subject: [PATCH 007/103] graphql: return correct logs for tx (#25612) * graphql: fix tx logs * minor * Use optimized search for selecting tx logs --- graphql/graphql.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 97b460c205..66c25841db 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "math/big" + "sort" "strconv" "github.com/ethereum/go-ethereum" @@ -478,13 +479,16 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) { if err != nil { return nil, err } - ret := make([]*Log, 0, len(logs)) - for _, log := range logs { + var ret []*Log + // Select tx logs from all block logs + ix := sort.Search(len(logs), func(i int) bool { return uint64(logs[i].TxIndex) == t.index }) + for ix < len(logs) && uint64(logs[ix].TxIndex) == t.index { ret = append(ret, &Log{ r: t.r, transaction: t, - log: log, + log: logs[ix], }) + ix++ } return &ret, nil } From 3b41be695e6e12829abf6e5edec0606ee37f14d9 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Tue, 13 Sep 2022 21:49:52 +0200 Subject: [PATCH 008/103] graphql: fixes missing tx logs (#25745) * graphql: fix tx logs * graphql: refactor test service setup * graphql: add test for tx logs --- graphql/graphql.go | 2 +- graphql/graphql_test.go | 227 +++++++++++++++++++++------------------- graphql/service.go | 9 +- 3 files changed, 124 insertions(+), 114 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 66c25841db..356ff669fb 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -481,7 +481,7 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) { } var ret []*Log // Select tx logs from all block logs - ix := sort.Search(len(logs), func(i int) bool { return uint64(logs[i].TxIndex) == t.index }) + ix := sort.Search(len(logs), func(i int) bool { return uint64(logs[i].TxIndex) >= t.index }) for ix < len(logs) && uint64(logs[ix].TxIndex) == t.index { ret = append(ret, &Log{ r: t.r, diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index d55f4e0634..491c731521 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -17,6 +17,8 @@ package graphql import ( + "context" + "encoding/json" "fmt" "io" "math/big" @@ -51,15 +53,21 @@ func TestBuildSchema(t *testing.T) { } defer stack.Close() // Make sure the schema can be parsed and matched up to the object model. - if err := newHandler(stack, nil, nil, []string{}, []string{}); err != nil { + if _, err := newHandler(stack, nil, nil, []string{}, []string{}); err != nil { t.Errorf("Could not construct GraphQL handler: %v", err) } } // Tests that a graphQL request is successfully handled when graphql is enabled on the specified endpoint func TestGraphQLBlockSerialization(t *testing.T) { - stack := createNode(t, true, false) + stack := createNode(t) defer stack.Close() + genesis := &core.Genesis{ + Config: params.AllEthashProtocolChanges, + GasLimit: 11500000, + Difficulty: big.NewInt(1048576), + } + newGQLService(t, stack, genesis, 10, func(i int, gen *core.BlockGen) {}) // start node if err := stack.Start(); err != nil { t.Fatalf("could not start node: %v", err) @@ -161,8 +169,55 @@ func TestGraphQLBlockSerialization(t *testing.T) { } func TestGraphQLBlockSerializationEIP2718(t *testing.T) { - stack := createNode(t, true, true) + // Account for signing txes + var ( + key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + address = crypto.PubkeyToAddress(key.PublicKey) + funds = big.NewInt(1000000000000000) + dad = common.HexToAddress("0x0000000000000000000000000000000000000dad") + ) + stack := createNode(t) defer stack.Close() + genesis := &core.Genesis{ + Config: params.AllEthashProtocolChanges, + GasLimit: 11500000, + Difficulty: big.NewInt(1048576), + Alloc: core.GenesisAlloc{ + address: {Balance: funds}, + // The address 0xdad sloads 0x00 and 0x01 + dad: { + Code: []byte{byte(vm.PC), byte(vm.PC), byte(vm.SLOAD), byte(vm.SLOAD)}, + Nonce: 0, + Balance: big.NewInt(0), + }, + }, + BaseFee: big.NewInt(params.InitialBaseFee), + } + signer := types.LatestSigner(genesis.Config) + newGQLService(t, stack, genesis, 1, func(i int, gen *core.BlockGen) { + gen.SetCoinbase(common.Address{1}) + tx, _ := types.SignNewTx(key, signer, &types.LegacyTx{ + Nonce: uint64(0), + To: &dad, + Value: big.NewInt(100), + Gas: 50000, + GasPrice: big.NewInt(params.InitialBaseFee), + }) + gen.AddTx(tx) + tx, _ = types.SignNewTx(key, signer, &types.AccessListTx{ + ChainID: genesis.Config.ChainID, + Nonce: uint64(1), + To: &dad, + Gas: 30000, + GasPrice: big.NewInt(params.InitialBaseFee), + Value: big.NewInt(50), + AccessList: types.AccessList{{ + Address: dad, + StorageKeys: []common.Hash{{0}}, + }}, + }) + gen.AddTx(tx) + }) // start node if err := stack.Start(); err != nil { t.Fatalf("could not start node: %v", err) @@ -198,7 +253,7 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) { // Tests that a graphQL request is not handled successfully when graphql is not enabled on the specified endpoint func TestGraphQLHTTPOnSamePort_GQLRequest_Unsuccessful(t *testing.T) { - stack := createNode(t, false, false) + stack := createNode(t) defer stack.Close() if err := stack.Start(); err != nil { t.Fatalf("could not start node: %v", err) @@ -212,7 +267,59 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Unsuccessful(t *testing.T) { assert.Equal(t, http.StatusNotFound, resp.StatusCode) } -func createNode(t *testing.T, gqlEnabled bool, txEnabled bool) *node.Node { +func TestGraphQLTransactionLogs(t *testing.T) { + var ( + key, _ = crypto.GenerateKey() + addr = crypto.PubkeyToAddress(key.PublicKey) + dadStr = "0x0000000000000000000000000000000000000dad" + dad = common.HexToAddress(dadStr) + genesis = &core.Genesis{ + Config: params.AllEthashProtocolChanges, + GasLimit: 11500000, + Difficulty: big.NewInt(1048576), + Alloc: core.GenesisAlloc{ + addr: {Balance: big.NewInt(params.Ether)}, + dad: { + // LOG0(0, 0), LOG0(0, 0), RETURN(0, 0) + Code: common.Hex2Bytes("60006000a060006000a060006000f3"), + Nonce: 0, + Balance: big.NewInt(0), + }, + }, + } + signer = types.LatestSigner(genesis.Config) + stack = createNode(t) + ) + defer stack.Close() + + handler := newGQLService(t, stack, genesis, 1, func(i int, gen *core.BlockGen) { + tx, _ := types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Gas: 100000, GasPrice: big.NewInt(params.InitialBaseFee)}) + gen.AddTx(tx) + tx, _ = types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Nonce: 1, Gas: 100000, GasPrice: big.NewInt(params.InitialBaseFee)}) + gen.AddTx(tx) + tx, _ = types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Nonce: 2, Gas: 100000, GasPrice: big.NewInt(params.InitialBaseFee)}) + gen.AddTx(tx) + }) + // start node + if err := stack.Start(); err != nil { + t.Fatalf("could not start node: %v", err) + } + query := `{block { transactions { logs { account { address } } } } }` + res := handler.Schema.Exec(context.Background(), query, "", map[string]interface{}{}) + if res.Errors != nil { + t.Fatalf("graphql query failed: %v", res.Errors) + } + have, err := json.Marshal(res.Data) + if err != nil { + t.Fatalf("failed to encode graphql response: %s", err) + } + want := fmt.Sprintf(`{"block":{"transactions":[{"logs":[{"account":{"address":"%s"}},{"account":{"address":"%s"}}]},{"logs":[{"account":{"address":"%s"}},{"account":{"address":"%s"}}]},{"logs":[{"account":{"address":"%s"}},{"account":{"address":"%s"}}]}]}}`, dadStr, dadStr, dadStr, dadStr, dadStr, dadStr) + if string(have) != want { + t.Errorf("response unmatch. expected %s, got %s", want, have) + } +} + +func createNode(t *testing.T) *node.Node { stack, err := node.New(&node.Config{ HTTPHost: "127.0.0.1", HTTPPort: 0, @@ -222,83 +329,12 @@ func createNode(t *testing.T, gqlEnabled bool, txEnabled bool) *node.Node { if err != nil { t.Fatalf("could not create node: %v", err) } - if !gqlEnabled { - return stack - } - if !txEnabled { - createGQLService(t, stack) - } else { - createGQLServiceWithTransactions(t, stack) - } return stack } -func createGQLService(t *testing.T, stack *node.Node) { - // create backend - ethConf := ðconfig.Config{ - Genesis: &core.Genesis{ - Config: params.AllEthashProtocolChanges, - GasLimit: 11500000, - Difficulty: big.NewInt(1048576), - }, - Ethash: ethash.Config{ - PowMode: ethash.ModeFake, - }, - NetworkId: 1337, - TrieCleanCache: 5, - TrieCleanCacheJournal: "triecache", - TrieCleanCacheRejournal: 60 * time.Minute, - TrieDirtyCache: 5, - TrieTimeout: 60 * time.Minute, - SnapshotCache: 5, - } - ethBackend, err := eth.New(stack, ethConf) - if err != nil { - t.Fatalf("could not create eth backend: %v", err) - } - // Create some blocks and import them - chain, _ := core.GenerateChain(params.AllEthashProtocolChanges, ethBackend.BlockChain().Genesis(), - ethash.NewFaker(), ethBackend.ChainDb(), 10, func(i int, gen *core.BlockGen) {}) - _, err = ethBackend.BlockChain().InsertChain(chain) - if err != nil { - t.Fatalf("could not create import blocks: %v", err) - } - // create gql service - filterSystem := filters.NewFilterSystem(ethBackend.APIBackend, filters.Config{}) - err = New(stack, ethBackend.APIBackend, filterSystem, []string{}, []string{}) - if err != nil { - t.Fatalf("could not create graphql service: %v", err) - } -} - -func createGQLServiceWithTransactions(t *testing.T, stack *node.Node) { - // create backend - key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") - address := crypto.PubkeyToAddress(key.PublicKey) - funds := big.NewInt(1000000000000000) - dad := common.HexToAddress("0x0000000000000000000000000000000000000dad") - +func newGQLService(t *testing.T, stack *node.Node, gspec *core.Genesis, genBlocks int, genfunc func(i int, gen *core.BlockGen)) *handler { ethConf := ðconfig.Config{ - Genesis: &core.Genesis{ - Config: params.AllEthashProtocolChanges, - GasLimit: 11500000, - Difficulty: big.NewInt(1048576), - Alloc: core.GenesisAlloc{ - address: {Balance: funds}, - // The address 0xdad sloads 0x00 and 0x01 - dad: { - Code: []byte{ - byte(vm.PC), - byte(vm.PC), - byte(vm.SLOAD), - byte(vm.SLOAD), - }, - Nonce: 0, - Balance: big.NewInt(0), - }, - }, - BaseFee: big.NewInt(params.InitialBaseFee), - }, + Genesis: gspec, Ethash: ethash.Config{ PowMode: ethash.ModeFake, }, @@ -310,49 +346,22 @@ func createGQLServiceWithTransactions(t *testing.T, stack *node.Node) { TrieTimeout: 60 * time.Minute, SnapshotCache: 5, } - ethBackend, err := eth.New(stack, ethConf) if err != nil { t.Fatalf("could not create eth backend: %v", err) } - signer := types.LatestSigner(ethConf.Genesis.Config) - - legacyTx, _ := types.SignNewTx(key, signer, &types.LegacyTx{ - Nonce: uint64(0), - To: &dad, - Value: big.NewInt(100), - Gas: 50000, - GasPrice: big.NewInt(params.InitialBaseFee), - }) - envelopTx, _ := types.SignNewTx(key, signer, &types.AccessListTx{ - ChainID: ethConf.Genesis.Config.ChainID, - Nonce: uint64(1), - To: &dad, - Gas: 30000, - GasPrice: big.NewInt(params.InitialBaseFee), - Value: big.NewInt(50), - AccessList: types.AccessList{{ - Address: dad, - StorageKeys: []common.Hash{{0}}, - }}, - }) - // Create some blocks and import them chain, _ := core.GenerateChain(params.AllEthashProtocolChanges, ethBackend.BlockChain().Genesis(), - ethash.NewFaker(), ethBackend.ChainDb(), 1, func(i int, b *core.BlockGen) { - b.SetCoinbase(common.Address{1}) - b.AddTx(legacyTx) - b.AddTx(envelopTx) - }) - + ethash.NewFaker(), ethBackend.ChainDb(), genBlocks, genfunc) _, err = ethBackend.BlockChain().InsertChain(chain) if err != nil { t.Fatalf("could not create import blocks: %v", err) } - // create gql service + // Set up handler filterSystem := filters.NewFilterSystem(ethBackend.APIBackend, filters.Config{}) - err = New(stack, ethBackend.APIBackend, filterSystem, []string{}, []string{}) + handler, err := newHandler(stack, ethBackend.APIBackend, filterSystem, []string{}, []string{}) if err != nil { t.Fatalf("could not create graphql service: %v", err) } + return handler } diff --git a/graphql/service.go b/graphql/service.go index 019026bc7e..6f6e583359 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -57,17 +57,18 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // New constructs a new GraphQL service instance. func New(stack *node.Node, backend ethapi.Backend, filterSystem *filters.FilterSystem, cors, vhosts []string) error { - return newHandler(stack, backend, filterSystem, cors, vhosts) + _, err := newHandler(stack, backend, filterSystem, cors, vhosts) + return err } // newHandler returns a new `http.Handler` that will answer GraphQL queries. // It additionally exports an interactive query browser on the / endpoint. -func newHandler(stack *node.Node, backend ethapi.Backend, filterSystem *filters.FilterSystem, cors, vhosts []string) error { +func newHandler(stack *node.Node, backend ethapi.Backend, filterSystem *filters.FilterSystem, cors, vhosts []string) (*handler, error) { q := Resolver{backend, filterSystem} s, err := graphql.ParseSchema(schema, &q) if err != nil { - return err + return nil, err } h := handler{Schema: s} handler := node.NewHTTPHandlerStack(h, cors, vhosts, nil) @@ -76,5 +77,5 @@ func newHandler(stack *node.Node, backend ethapi.Backend, filterSystem *filters. stack.RegisterHandler("GraphQL", "/graphql", handler) stack.RegisterHandler("GraphQL", "/graphql/", handler) - return nil + return &h, nil } From 972007a517c49ee9e2a359950d81c74467492ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 14 Sep 2022 11:07:10 +0200 Subject: [PATCH 009/103] Release Geth v1.10.24 --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 5f24b41f28..349bdf1c18 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 10 // Minor version component of the current release - VersionPatch = 23 // Patch version component of the current release + VersionPatch = 24 // Patch version component of the current release VersionMeta = "stable" // Version metadata to append to the version string ) From 8f61fc8b73565ff15d27fd9731b945d9d1878ec3 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Thu, 15 Sep 2022 17:50:54 +0200 Subject: [PATCH 010/103] params: set TerminalTotalDifficultyPassed to true (#25769) * params: set TerminalTotalDifficultyPassed to true * Update params/config.go Co-authored-by: Martin Holst Swende --- params/config.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/params/config.go b/params/config.go index 4d6eec8939..80e671f9bf 100644 --- a/params/config.go +++ b/params/config.go @@ -59,25 +59,26 @@ var ( // MainnetChainConfig is the chain parameters to run a node on the main network. MainnetChainConfig = &ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(1_150_000), - DAOForkBlock: big.NewInt(1_920_000), - DAOForkSupport: true, - EIP150Block: big.NewInt(2_463_000), - EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), - EIP155Block: big.NewInt(2_675_000), - EIP158Block: big.NewInt(2_675_000), - ByzantiumBlock: big.NewInt(4_370_000), - ConstantinopleBlock: big.NewInt(7_280_000), - PetersburgBlock: big.NewInt(7_280_000), - IstanbulBlock: big.NewInt(9_069_000), - MuirGlacierBlock: big.NewInt(9_200_000), - BerlinBlock: big.NewInt(12_244_000), - LondonBlock: big.NewInt(12_965_000), - ArrowGlacierBlock: big.NewInt(13_773_000), - GrayGlacierBlock: big.NewInt(15_050_000), - TerminalTotalDifficulty: MainnetTerminalTotalDifficulty, // 58_750_000_000_000_000_000_000 - Ethash: new(EthashConfig), + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(1_150_000), + DAOForkBlock: big.NewInt(1_920_000), + DAOForkSupport: true, + EIP150Block: big.NewInt(2_463_000), + EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), + EIP155Block: big.NewInt(2_675_000), + EIP158Block: big.NewInt(2_675_000), + ByzantiumBlock: big.NewInt(4_370_000), + ConstantinopleBlock: big.NewInt(7_280_000), + PetersburgBlock: big.NewInt(7_280_000), + IstanbulBlock: big.NewInt(9_069_000), + MuirGlacierBlock: big.NewInt(9_200_000), + BerlinBlock: big.NewInt(12_244_000), + LondonBlock: big.NewInt(12_965_000), + ArrowGlacierBlock: big.NewInt(13_773_000), + GrayGlacierBlock: big.NewInt(15_050_000), + TerminalTotalDifficulty: MainnetTerminalTotalDifficulty, // 58_750_000_000_000_000_000_000 + TerminalTotalDifficultyPassed: true, + Ethash: new(EthashConfig), } // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network. From 69568c554880b3567bace64f8848ff1be27d084d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 15 Sep 2022 17:55:58 +0200 Subject: [PATCH 011/103] params: release Geth v1.10.25 --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 349bdf1c18..3b5978e849 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 10 // Minor version component of the current release - VersionPatch = 24 // Patch version component of the current release + VersionPatch = 25 // Patch version component of the current release VersionMeta = "stable" // Version metadata to append to the version string ) From d2be5675a640c38c31dd61956e82eb439eb153b8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Sep 2022 19:21:50 +0000 Subject: [PATCH 012/103] build(deps): bump joblib from 1.0.0 to 1.2.0 Bumps [joblib](https://github.com/joblib/joblib) from 1.0.0 to 1.2.0. - [Release notes](https://github.com/joblib/joblib/releases) - [Changelog](https://github.com/joblib/joblib/blob/master/CHANGES.rst) - [Commits](https://github.com/joblib/joblib/compare/1.0.0...1.2.0) --- updated-dependencies: - dependency-name: joblib dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements-mkdocs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-mkdocs.txt b/requirements-mkdocs.txt index d88161a02e..3d34e20ca6 100644 --- a/requirements-mkdocs.txt +++ b/requirements-mkdocs.txt @@ -5,7 +5,7 @@ gitdb==4.0.5 GitPython==3.1.12 htmlmin==0.1.12 Jinja2==3.0.2 -joblib==1.0.0 +joblib==1.2.0 jsmin==3.0.0 livereload==2.6.3 lunr==0.5.8 From 7497d463f99d18b2b00d73159200284093a96f4e Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 24 Oct 2022 13:09:46 -0700 Subject: [PATCH 013/103] :hammer: Signed-off-by: meows --- core/state/journal.go | 1 + core/state/statedb.go | 2 ++ params/alloc_test.go | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 params/alloc_test.go diff --git a/core/state/journal.go b/core/state/journal.go index 57a692dc7f..14e461660f 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -75,6 +75,7 @@ func (j *journal) revert(statedb *StateDB, snapshot int) { // dirty explicitly sets an address to dirty, even if the change entries would // otherwise suggest it as clean. This method is an ugly hack to handle the RIPEMD // precompile consensus exception. +// meowsbits-ripemd func (j *journal) dirty(addr common.Address) { j.dirties[addr]++ } diff --git a/core/state/statedb.go b/core/state/statedb.go index 6c14b98b89..ec6e357484 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -664,6 +664,7 @@ func (s *StateDB) Copy() *StateDB { // and in the Finalise-method, there is a case where an object is in the journal but not // in the stateObjects: OOG after touch on ripeMD prior to Byzantium. Thus, we need to check for // nil + // meowsbits-ripemd if object, exist := s.stateObjects[addr]; exist { // Even though the original object is dirty, we are not copying the journal, // so we need to make sure that anyside effect the journal would have caused @@ -785,6 +786,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) { // it will persist in the journal even though the journal is reverted. In this special circumstance, // it may exist in `s.journal.dirties` but not in `s.stateObjects`. // Thus, we can safely ignore it here + // meowsbits-ripemd continue } if obj.suicided || (deleteEmptyObjects && obj.empty()) { diff --git a/params/alloc_test.go b/params/alloc_test.go new file mode 100644 index 0000000000..38058cda2f --- /dev/null +++ b/params/alloc_test.go @@ -0,0 +1,20 @@ +package params + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/params/types/genesisT" +) + +func ExampleAllocPrint_Mainnet() { + // Test that the mainnet alloc is parsable. + alloc := MainnetAllocData + ga := genesisT.DecodePreAlloc(alloc) + + fmt.Println(ga[common.Address{0x3}]) + fmt.Println(ga[common.HexToAddress("0x3000000000000000000000000000000000000003")]) + // Output: + // {[] map[] 0 []} + // {[] map[] 0 []} +} From d390462df9df233b60b4cd7a37db5b3043832022 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 25 Oct 2022 12:22:04 -0700 Subject: [PATCH 014/103] tests: change ETC test fork configs to chainid=61 (not =1) Date: 2022-10-25 12:22:04-07:00 Signed-off-by: meows --- tests/init.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/init.go b/tests/init.go index 65d634aa20..d97e391513 100644 --- a/tests/init.go +++ b/tests/init.go @@ -63,7 +63,7 @@ var Forks = map[string]ctypes.ChainConfigurator{ "ETC_Atlantis": &coregeth.CoreGethChainConfig{ NetworkID: 1, Ethash: new(ctypes.EthashConfig), - ChainID: big.NewInt(1), + ChainID: big.NewInt(61), EIP2FBlock: big.NewInt(0), EIP7FBlock: big.NewInt(0), EIP150Block: big.NewInt(0), @@ -115,7 +115,7 @@ var Forks = map[string]ctypes.ChainConfigurator{ "ETC_Agharta": &coregeth.CoreGethChainConfig{ NetworkID: 1, Ethash: new(ctypes.EthashConfig), - ChainID: big.NewInt(1), + ChainID: big.NewInt(61), EIP2FBlock: big.NewInt(0), EIP7FBlock: big.NewInt(0), EIP150Block: big.NewInt(0), @@ -157,7 +157,7 @@ var Forks = map[string]ctypes.ChainConfigurator{ "ETC_Phoenix": &coregeth.CoreGethChainConfig{ NetworkID: 1, Ethash: new(ctypes.EthashConfig), - ChainID: big.NewInt(1), + ChainID: big.NewInt(61), EIP2FBlock: big.NewInt(0), EIP7FBlock: big.NewInt(0), EIP150Block: big.NewInt(0), @@ -361,7 +361,7 @@ var Forks = map[string]ctypes.ChainConfigurator{ "ETC_Magneto": &coregeth.CoreGethChainConfig{ NetworkID: 1, Ethash: new(ctypes.EthashConfig), - ChainID: big.NewInt(1), + ChainID: big.NewInt(61), EIP2FBlock: big.NewInt(0), EIP7FBlock: big.NewInt(0), EIP150Block: big.NewInt(0), @@ -406,7 +406,7 @@ var Forks = map[string]ctypes.ChainConfigurator{ "ETC_Mystique": &coregeth.CoreGethChainConfig{ NetworkID: 1, Ethash: new(ctypes.EthashConfig), - ChainID: big.NewInt(1), + ChainID: big.NewInt(61), EIP2FBlock: big.NewInt(0), EIP7FBlock: big.NewInt(0), EIP150Block: big.NewInt(0), From 701eeb81235340f7c8bb120fbe2cfd048967c044 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 28 Oct 2022 09:22:06 -0700 Subject: [PATCH 015/103] tests: generated state tests Date: 2022-10-28 09:22:06-07:00 Signed-off-by: meows --- tests/testdata-etc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testdata-etc b/tests/testdata-etc index eee0383834..8183e9eebd 160000 --- a/tests/testdata-etc +++ b/tests/testdata-etc @@ -1 +1 @@ -Subproject commit eee0383834a6e32ff17690d6c4763fffd04fcaaa +Subproject commit 8183e9eebd93912cebddbe3e88f66f836a8205dd From 85e469f787be53192fcbcee86ce67635020a4ad5 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 31 Aug 2022 17:58:18 +0200 Subject: [PATCH 016/103] eth/protocols/snap: fix problems due to idle-but-busy peers (#25651) --- eth/protocols/snap/sync.go | 90 +++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index deaa4456e0..1455bacbcb 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -2248,14 +2248,18 @@ func (s *Syncer) OnAccounts(peer SyncPeer, id uint64, hashes []common.Hash, acco // Whether or not the response is valid, we can mark the peer as idle and // notify the scheduler to assign a new task. If the response is invalid, // we'll drop the peer in a bit. + defer func() { + s.lock.Lock() + defer s.lock.Unlock() + if _, ok := s.peers[peer.ID()]; ok { + s.accountIdlers[peer.ID()] = struct{}{} + } + select { + case s.update <- struct{}{}: + default: + } + }() s.lock.Lock() - if _, ok := s.peers[peer.ID()]; ok { - s.accountIdlers[peer.ID()] = struct{}{} - } - select { - case s.update <- struct{}{}: - default: - } // Ensure the response is for a valid request req, ok := s.accountReqs[id] if !ok { @@ -2360,14 +2364,18 @@ func (s *Syncer) onByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) error // Whether or not the response is valid, we can mark the peer as idle and // notify the scheduler to assign a new task. If the response is invalid, // we'll drop the peer in a bit. + defer func() { + s.lock.Lock() + defer s.lock.Unlock() + if _, ok := s.peers[peer.ID()]; ok { + s.bytecodeIdlers[peer.ID()] = struct{}{} + } + select { + case s.update <- struct{}{}: + default: + } + }() s.lock.Lock() - if _, ok := s.peers[peer.ID()]; ok { - s.bytecodeIdlers[peer.ID()] = struct{}{} - } - select { - case s.update <- struct{}{}: - default: - } // Ensure the response is for a valid request req, ok := s.bytecodeReqs[id] if !ok { @@ -2469,14 +2477,18 @@ func (s *Syncer) OnStorage(peer SyncPeer, id uint64, hashes [][]common.Hash, slo // Whether or not the response is valid, we can mark the peer as idle and // notify the scheduler to assign a new task. If the response is invalid, // we'll drop the peer in a bit. + defer func() { + s.lock.Lock() + defer s.lock.Unlock() + if _, ok := s.peers[peer.ID()]; ok { + s.storageIdlers[peer.ID()] = struct{}{} + } + select { + case s.update <- struct{}{}: + default: + } + }() s.lock.Lock() - if _, ok := s.peers[peer.ID()]; ok { - s.storageIdlers[peer.ID()] = struct{}{} - } - select { - case s.update <- struct{}{}: - default: - } // Ensure the response is for a valid request req, ok := s.storageReqs[id] if !ok { @@ -2596,14 +2608,18 @@ func (s *Syncer) OnTrieNodes(peer SyncPeer, id uint64, trienodes [][]byte) error // Whether or not the response is valid, we can mark the peer as idle and // notify the scheduler to assign a new task. If the response is invalid, // we'll drop the peer in a bit. + defer func() { + s.lock.Lock() + defer s.lock.Unlock() + if _, ok := s.peers[peer.ID()]; ok { + s.trienodeHealIdlers[peer.ID()] = struct{}{} + } + select { + case s.update <- struct{}{}: + default: + } + }() s.lock.Lock() - if _, ok := s.peers[peer.ID()]; ok { - s.trienodeHealIdlers[peer.ID()] = struct{}{} - } - select { - case s.update <- struct{}{}: - default: - } // Ensure the response is for a valid request req, ok := s.trienodeHealReqs[id] if !ok { @@ -2691,14 +2707,18 @@ func (s *Syncer) onHealByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) e // Whether or not the response is valid, we can mark the peer as idle and // notify the scheduler to assign a new task. If the response is invalid, // we'll drop the peer in a bit. + defer func() { + s.lock.Lock() + defer s.lock.Unlock() + if _, ok := s.peers[peer.ID()]; ok { + s.bytecodeHealIdlers[peer.ID()] = struct{}{} + } + select { + case s.update <- struct{}{}: + default: + } + }() s.lock.Lock() - if _, ok := s.peers[peer.ID()]; ok { - s.bytecodeHealIdlers[peer.ID()] = struct{}{} - } - select { - case s.update <- struct{}{}: - default: - } // Ensure the response is for a valid request req, ok := s.bytecodeHealReqs[id] if !ok { From 937ea491f95e5676d2ce3e0364ba9f05452bc351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 9 Sep 2022 11:42:57 +0300 Subject: [PATCH 017/103] eth/protocols/snap: throttle trie heal requests when peers DoS us (#25666) * eth/protocols/snap: throttle trie heal requests when peers DoS us * eth/protocols/snap: lower heal throttle log to debug Co-authored-by: Martin Holst Swende * eth/protocols/snap: fix comment Co-authored-by: Martin Holst Swende --- eth/protocols/snap/sync.go | 107 ++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 7 deletions(-) diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index 1455bacbcb..eb8260bf7c 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -21,10 +21,12 @@ import ( "encoding/json" "errors" "fmt" + gomath "math" "math/big" "math/rand" "sort" "sync" + "sync/atomic" "time" "github.com/ethereum/go-ethereum/common" @@ -78,6 +80,29 @@ const ( // and waste round trip times. If it's too high, we're capping responses and // waste bandwidth. maxTrieRequestCount = maxRequestSize / 512 + + // trienodeHealRateMeasurementImpact is the impact a single measurement has on + // the local node's trienode processing capacity. A value closer to 0 reacts + // slower to sudden changes, but it is also more stable against temporary hiccups. + trienodeHealRateMeasurementImpact = 0.005 + + // minTrienodeHealThrottle is the minimum divisor for throttling trie node + // heal requests to avoid overloading the local node and exessively expanding + // the state trie bedth wise. + minTrienodeHealThrottle = 1 + + // maxTrienodeHealThrottle is the maximum divisor for throttling trie node + // heal requests to avoid overloading the local node and exessively expanding + // the state trie bedth wise. + maxTrienodeHealThrottle = maxTrieRequestCount + + // trienodeHealThrottleIncrease is the multiplier for the throttle when the + // rate of arriving data is higher than the rate of processing it. + trienodeHealThrottleIncrease = 1.33 + + // trienodeHealThrottleDecrease is the divisor for the throttle when the + // rate of arriving data is lower than the rate of processing it. + trienodeHealThrottleDecrease = 1.25 ) var ( @@ -431,6 +456,11 @@ type Syncer struct { trienodeHealReqs map[uint64]*trienodeHealRequest // Trie node requests currently running bytecodeHealReqs map[uint64]*bytecodeHealRequest // Bytecode requests currently running + trienodeHealRate float64 // Average heal rate for processing trie node data + trienodeHealPend uint64 // Number of trie nodes currently pending for processing + trienodeHealThrottle float64 // Divisor for throttling the amount of trienode heal data requested + trienodeHealThrottled time.Time // Timestamp the last time the throttle was updated + trienodeHealSynced uint64 // Number of state trie nodes downloaded trienodeHealBytes common.StorageSize // Number of state trie bytes persisted to disk trienodeHealDups uint64 // Number of state trie nodes already processed @@ -476,9 +506,10 @@ func NewSyncer(db ethdb.KeyValueStore) *Syncer { trienodeHealIdlers: make(map[string]struct{}), bytecodeHealIdlers: make(map[string]struct{}), - trienodeHealReqs: make(map[uint64]*trienodeHealRequest), - bytecodeHealReqs: make(map[uint64]*bytecodeHealRequest), - stateWriter: db.NewBatch(), + trienodeHealReqs: make(map[uint64]*trienodeHealRequest), + bytecodeHealReqs: make(map[uint64]*bytecodeHealRequest), + trienodeHealThrottle: maxTrienodeHealThrottle, // Tune downward instead of insta-filling with junk + stateWriter: db.NewBatch(), extProgress: new(SyncProgress), } @@ -1321,6 +1352,10 @@ func (s *Syncer) assignTrienodeHealTasks(success chan *trienodeHealResponse, fai if cap > maxTrieRequestCount { cap = maxTrieRequestCount } + cap = int(float64(cap) / s.trienodeHealThrottle) + if cap <= 0 { + cap = 1 + } var ( hashes = make([]common.Hash, 0, cap) paths = make([]string, 0, cap) @@ -2090,6 +2125,10 @@ func (s *Syncer) processStorageResponse(res *storageResponse) { // processTrienodeHealResponse integrates an already validated trienode response // into the healer tasks. func (s *Syncer) processTrienodeHealResponse(res *trienodeHealResponse) { + var ( + start = time.Now() + fills int + ) for i, hash := range res.hashes { node := res.nodes[i] @@ -2098,6 +2137,8 @@ func (s *Syncer) processTrienodeHealResponse(res *trienodeHealResponse) { res.task.trieTasks[res.paths[i]] = res.hashes[i] continue } + fills++ + // Push the trie node into the state syncer s.trienodeHealSynced++ s.trienodeHealBytes += common.StorageSize(len(node)) @@ -2121,6 +2162,50 @@ func (s *Syncer) processTrienodeHealResponse(res *trienodeHealResponse) { log.Crit("Failed to persist healing data", "err", err) } log.Debug("Persisted set of healing data", "type", "trienodes", "bytes", common.StorageSize(batch.ValueSize())) + + // Calculate the processing rate of one filled trie node + rate := float64(fills) / (float64(time.Since(start)) / float64(time.Second)) + + // Update the currently measured trienode queueing and processing throughput. + // + // The processing rate needs to be updated uniformly independent if we've + // processed 1x100 trie nodes or 100x1 to keep the rate consistent even in + // the face of varying network packets. As such, we cannot just measure the + // time it took to process N trie nodes and update once, we need one update + // per trie node. + // + // Naively, that would be: + // + // for i:=0; i time.Second { + // Periodically adjust the trie node throttler + if float64(pending) > 2*s.trienodeHealRate { + s.trienodeHealThrottle *= trienodeHealThrottleIncrease + } else { + s.trienodeHealThrottle /= trienodeHealThrottleDecrease + } + if s.trienodeHealThrottle > maxTrienodeHealThrottle { + s.trienodeHealThrottle = maxTrienodeHealThrottle + } else if s.trienodeHealThrottle < minTrienodeHealThrottle { + s.trienodeHealThrottle = minTrienodeHealThrottle + } + s.trienodeHealThrottled = time.Now() + + log.Debug("Updated trie node heal throttler", "rate", s.trienodeHealRate, "pending", pending, "throttle", s.trienodeHealThrottle) + } } // processBytecodeHealResponse integrates an already validated bytecode response @@ -2655,10 +2740,12 @@ func (s *Syncer) OnTrieNodes(peer SyncPeer, id uint64, trienodes [][]byte) error // Cross reference the requested trienodes with the response to find gaps // that the serving node is missing - hasher := sha3.NewLegacyKeccak256().(crypto.KeccakState) - hash := make([]byte, 32) - - nodes := make([][]byte, len(req.hashes)) + var ( + hasher = sha3.NewLegacyKeccak256().(crypto.KeccakState) + hash = make([]byte, 32) + nodes = make([][]byte, len(req.hashes)) + fills uint64 + ) for i, j := 0, 0; i < len(trienodes); i++ { // Find the next hash that we've been served, leaving misses with nils hasher.Reset() @@ -2670,16 +2757,22 @@ func (s *Syncer) OnTrieNodes(peer SyncPeer, id uint64, trienodes [][]byte) error } if j < len(req.hashes) { nodes[j] = trienodes[i] + fills++ j++ continue } // We've either ran out of hashes, or got unrequested data logger.Warn("Unexpected healing trienodes", "count", len(trienodes)-i) + // Signal this request as failed, and ready for rescheduling s.scheduleRevertTrienodeHealRequest(req) return errors.New("unexpected healing trienode") } // Response validated, send it to the scheduler for filling + atomic.AddUint64(&s.trienodeHealPend, fills) + defer func() { + atomic.AddUint64(&s.trienodeHealPend, ^(fills - 1)) + }() response := &trienodeHealResponse{ paths: req.paths, task: req.task, From a32e69a28c2abef6a6b96e8d2466f1f27fd693ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 6 Sep 2022 12:57:03 +0300 Subject: [PATCH 018/103] trie: check childrens' existence concurrently for snap heal (#25694) --- trie/sync.go | 57 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/trie/sync.go b/trie/sync.go index 303fcbfa22..862ce7e16e 100644 --- a/trie/sync.go +++ b/trie/sync.go @@ -19,6 +19,7 @@ package trie import ( "errors" "fmt" + "sync" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/prque" @@ -381,11 +382,11 @@ func (s *Sync) scheduleCodeRequest(req *codeRequest) { // retrieval scheduling. func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { // Gather all the children of the node, irrelevant whether known or not - type child struct { + type childNode struct { path []byte node node } - var children []child + var children []childNode switch node := (object).(type) { case *shortNode: @@ -393,14 +394,14 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { if hasTerm(key) { key = key[:len(key)-1] } - children = []child{{ + children = []childNode{{ node: node.Val, path: append(append([]byte(nil), req.path...), key...), }} case *fullNode: for i := 0; i < 17; i++ { if node.Children[i] != nil { - children = append(children, child{ + children = append(children, childNode{ node: node.Children[i], path: append(append([]byte(nil), req.path...), byte(i)), }) @@ -410,7 +411,10 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { panic(fmt.Sprintf("unknown node: %+v", node)) } // Iterate over the children, and request all unknown ones - requests := make([]*nodeRequest, 0, len(children)) + var ( + missing = make(chan *nodeRequest, len(children)) + pending sync.WaitGroup + ) for _, child := range children { // Notify any external watcher of a new key/value node if req.callback != nil { @@ -433,19 +437,36 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { if s.membatch.hasNode(child.path) { continue } - // If database says duplicate, then at least the trie node is present - // and we hold the assumption that it's NOT legacy contract code. - chash := common.BytesToHash(node) - if rawdb.HasTrieNode(s.database, chash) { - continue - } - // Locally unknown node, schedule for retrieval - requests = append(requests, &nodeRequest{ - path: child.path, - hash: chash, - parent: req, - callback: req.callback, - }) + // Check the presence of children concurrently + pending.Add(1) + go func(child childNode) { + defer pending.Done() + + // If database says duplicate, then at least the trie node is present + // and we hold the assumption that it's NOT legacy contract code. + chash := common.BytesToHash(node) + if rawdb.HasTrieNode(s.database, chash) { + return + } + // Locally unknown node, schedule for retrieval + missing <- &nodeRequest{ + path: child.path, + hash: chash, + parent: req, + callback: req.callback, + } + }(child) + } + } + pending.Wait() + + requests := make([]*nodeRequest, 0, len(children)) + for done := false; !done; { + select { + case miss := <-missing: + requests = append(requests, miss) + default: + done = true } } return requests, nil From 99bbb337011ef614fc5d25c130aa1cef92915366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 20 Sep 2022 14:14:24 +0300 Subject: [PATCH 019/103] eth: fix a rare datarace on CHT challenge reply / shutdown (#25831) --- eth/handler.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 4224a9f33a..143147b0c8 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -391,11 +391,16 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error { if h.checkpointHash != (common.Hash{}) { // Request the peer's checkpoint header for chain height/weight validation resCh := make(chan *eth.Response) - if _, err := peer.RequestHeadersByNumber(h.checkpointNumber, 1, 0, false, resCh); err != nil { + + req, err := peer.RequestHeadersByNumber(h.checkpointNumber, 1, 0, false, resCh) + if err != nil { return err } // Start a timer to disconnect if the peer doesn't reply in time go func() { + // Ensure the request gets cancelled in case of error/drop + defer req.Close() + timeout := time.NewTimer(syncChallengeTimeout) defer timeout.Stop() @@ -437,10 +442,15 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error { // If we have any explicit peer required block hashes, request them for number, hash := range h.requiredBlocks { resCh := make(chan *eth.Response) - if _, err := peer.RequestHeadersByNumber(number, 1, 0, false, resCh); err != nil { + + req, err := peer.RequestHeadersByNumber(number, 1, 0, false, resCh) + if err != nil { return err } - go func(number uint64, hash common.Hash) { + go func(number uint64, hash common.Hash, req *eth.Request) { + // Ensure the request gets cancelled in case of error/drop + defer req.Close() + timeout := time.NewTimer(syncChallengeTimeout) defer timeout.Stop() @@ -469,7 +479,7 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error { peer.Log().Warn("Required block challenge timed out, dropping", "addr", peer.RemoteAddr(), "type", peer.Name()) h.removePeer(peer.ID()) } - }(number, hash) + }(number, hash, req) } // Handle incoming messages until the connection is torn down return handler(peer) From 27600a5b8452c39ce9ef5c502c98a0c1ee35859b Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 27 Oct 2022 15:25:01 +0200 Subject: [PATCH 020/103] eth/filters: change filter block to be by-ref (#26054) This PR changes the block field in the filter to be a pointer, to disambiguate between empty hash and no hash --- eth/filters/filter.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 0a70c9ece1..8d80647fc2 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -34,8 +34,8 @@ type Filter struct { addresses []common.Address topics [][]common.Hash - block common.Hash // Block hash if filtering a single block - begin, end int64 // Range interval if filtering multiple blocks + block *common.Hash // Block hash if filtering a single block + begin, end int64 // Range interval if filtering multiple blocks matcher *bloombits.Matcher } @@ -78,7 +78,7 @@ func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Add func (sys *FilterSystem) NewBlockFilter(block common.Hash, addresses []common.Address, topics [][]common.Hash) *Filter { // Create a generic filter and convert it into a block filter filter := newFilter(sys, addresses, topics) - filter.block = block + filter.block = &block return filter } @@ -96,8 +96,8 @@ func newFilter(sys *FilterSystem, addresses []common.Address, topics [][]common. // first block that contains matches, updating the start of the filter accordingly. func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) { // If we're doing singleton block filtering, execute and return - if f.block != (common.Hash{}) { - header, err := f.sys.backend.HeaderByHash(ctx, f.block) + if f.block != nil { + header, err := f.sys.backend.HeaderByHash(ctx, *f.block) if err != nil { return nil, err } From 211dbb719711420358a3cdf718ce476c212adcf5 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 2 Nov 2022 09:29:33 -0500 Subject: [PATCH 021/103] rpc: handle wrong HTTP batch response length (#26064) --- rpc/client.go | 1 + rpc/client_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++ rpc/http.go | 3 +++ 3 files changed, 52 insertions(+) diff --git a/rpc/client.go b/rpc/client.go index d3ce029775..fcd31319a3 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -31,6 +31,7 @@ import ( ) var ( + ErrBadResult = errors.New("bad result in JSON-RPC response") ErrClientQuit = errors.New("client is closed") ErrNoResult = errors.New("no result in JSON-RPC response") ErrSubscriptionQueueOverflow = errors.New("subscription queue overflow") diff --git a/rpc/client_test.go b/rpc/client_test.go index 04c847d0d6..5ae549d865 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -19,6 +19,7 @@ package rpc import ( "context" "encoding/json" + "errors" "fmt" "math/rand" "net" @@ -144,6 +145,53 @@ func TestClientBatchRequest(t *testing.T) { } } +func TestClientBatchRequest_len(t *testing.T) { + b, err := json.Marshal([]jsonrpcMessage{ + {Version: "2.0", ID: json.RawMessage("1"), Method: "foo", Result: json.RawMessage(`"0x1"`)}, + {Version: "2.0", ID: json.RawMessage("2"), Method: "bar", Result: json.RawMessage(`"0x2"`)}, + }) + if err != nil { + t.Fatal("failed to encode jsonrpc message:", err) + } + s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + _, err := rw.Write(b) + if err != nil { + t.Error("failed to write response:", err) + } + })) + t.Cleanup(s.Close) + + client, err := Dial(s.URL) + if err != nil { + t.Fatal("failed to dial test server:", err) + } + defer client.Close() + + t.Run("too-few", func(t *testing.T) { + batch := []BatchElem{ + {Method: "foo"}, + {Method: "bar"}, + {Method: "baz"}, + } + ctx, cancelFn := context.WithTimeout(context.Background(), time.Second) + defer cancelFn() + if err := client.BatchCallContext(ctx, batch); !errors.Is(err, ErrBadResult) { + t.Errorf("expected %q but got: %v", ErrBadResult, err) + } + }) + + t.Run("too-many", func(t *testing.T) { + batch := []BatchElem{ + {Method: "foo"}, + } + ctx, cancelFn := context.WithTimeout(context.Background(), time.Second) + defer cancelFn() + if err := client.BatchCallContext(ctx, batch); !errors.Is(err, ErrBadResult) { + t.Errorf("expected %q but got: %v", ErrBadResult, err) + } + }) +} + func TestClientNotify(t *testing.T) { server := newTestServer() defer server.Stop() diff --git a/rpc/http.go b/rpc/http.go index 858d808586..b82ea2707a 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -173,6 +173,9 @@ func (c *Client) sendBatchHTTP(ctx context.Context, op *requestOp, msgs []*jsonr if err := json.NewDecoder(respBody).Decode(&respmsgs); err != nil { return err } + if len(respmsgs) != len(msgs) { + return fmt.Errorf("batch has %d requests but response has %d: %w", len(msgs), len(respmsgs), ErrBadResult) + } for i := 0; i < len(respmsgs); i++ { op.resp <- &respmsgs[i] } From e5eb32acee19cc9fca6a03b10283b7484246b15a Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 3 Nov 2022 11:59:33 +0100 Subject: [PATCH 022/103] params: release geth v1.10.26 stable --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 3b5978e849..d9a3958512 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 10 // Minor version component of the current release - VersionPatch = 25 // Patch version component of the current release + VersionPatch = 26 // Patch version component of the current release VersionMeta = "stable" // Version metadata to append to the version string ) From bf0a7d73562eb4061a10a2497641913aff81aac3 Mon Sep 17 00:00:00 2001 From: theshoe1029 Date: Sun, 6 Nov 2022 13:10:04 -0800 Subject: [PATCH 023/103] add custom interpreter to t8n evm config --- cmd/evm/internal/t8ntool/transition.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index d5d1ba8939..5331180c19 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -26,6 +26,7 @@ import ( "path" "strings" + "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/state" @@ -178,8 +179,9 @@ func Transition(ctx *cli.Context) error { prestate.Env = *inputData.Env vmConfig := vm.Config{ - Tracer: tracer, - Debug: (tracer != nil), + Tracer: tracer, + Debug: (tracer != nil), + EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), } // Construct the chainconfig var chainConfig ctypes.ChainConfigurator From 7aa2b85432e1cbaeabcb5d9af35dcf8fc5aabc61 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 10:03:55 -0800 Subject: [PATCH 024/103] cmd/evm: use utils.EVMInterpreterFlag for all evm tool apps Date: 2022-11-07 10:03:55-08:00 Signed-off-by: meows --- cmd/evm/main.go | 9 +++------ cmd/evm/runner.go | 2 +- cmd/evm/staterunner.go | 10 ++++++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 5d4fefeb25..8b73343e4b 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -23,6 +23,7 @@ import ( "os" "github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool" + "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/internal/flags" "github.com/urfave/cli/v2" ) @@ -132,11 +133,6 @@ var ( Value: true, Usage: "enable return data output", } - EVMInterpreterFlag = &cli.StringFlag{ - Name: "vm.evm", - Usage: "External EVM configuration (default = built-in interpreter)", - Value: "", - } ) var stateTransitionCommand = &cli.Command{ @@ -162,6 +158,7 @@ var stateTransitionCommand = &cli.Command{ t8ntool.ChainIDFlag, t8ntool.RewardFlag, t8ntool.VerbosityFlag, + utils.EVMInterpreterFlag, }, } @@ -222,7 +219,7 @@ func init() { DisableStackFlag, DisableStorageFlag, DisableReturnDataFlag, - EVMInterpreterFlag, + utils.EVMInterpreterFlag, } app.Commands = []*cli.Command{ compileCommand, diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 1299e7b195..c4186bb550 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -217,7 +217,7 @@ func runCmd(ctx *cli.Context) error { EVMConfig: vm.Config{ Tracer: tracer, Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name), - EVMInterpreter: ctx.String(EVMInterpreterFlag.Name), + EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), }, } diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index ebb19f6e99..5f79bc85c0 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -22,6 +22,7 @@ import ( "fmt" "os" + "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth/tracers/logger" @@ -37,8 +38,11 @@ var stateTestCommand = &cli.Command{ Name: "statetest", Usage: "executes the given state tests", ArgsUsage: "", - Flags: []cli.Flag{stateTestEVMCEWASMFlag}, - Category: flags.DevCategory, + Flags: []cli.Flag{ + stateTestEVMCEWASMFlag, + utils.EVMInterpreterFlag, + }, + Category: flags.DevCategory, } var stateTestEVMCEWASMFlag = &cli.StringFlag{ @@ -107,7 +111,9 @@ func stateTestCmd(ctx *cli.Context) error { Tracer: tracer, Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name), EWASMInterpreter: ctx.String(stateTestEVMCEWASMFlag.Name), + EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), } + results := make([]StatetestResult, 0, len(tests)) for key, test := range tests { for _, st := range test.Subtests(nil) { From 2d0186900e54c6c2144e1a1cd623d7f95e972a79 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 10:04:36 -0800 Subject: [PATCH 025/103] cmd/evm/internal/t8ntool,cmd/evm: make sure the vm inits the external interpreter when set Date: 2022-11-07 10:04:36-08:00 Signed-off-by: meows --- cmd/evm/internal/t8ntool/transition.go | 5 +++++ cmd/evm/staterunner.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 5331180c19..a7d2486877 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -183,6 +183,11 @@ func Transition(ctx *cli.Context) error { Debug: (tracer != nil), EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), } + + if vmConfig.EVMInterpreter != "" { + vm.InitEVMCEVM(vmConfig.EVMInterpreter) + } + // Construct the chainconfig var chainConfig ctypes.ChainConfigurator if cConf, extraEips, err := tests.GetChainConfig(ctx.String(ForknameFlag.Name)); err != nil { diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 5f79bc85c0..3379040fc7 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -114,6 +114,10 @@ func stateTestCmd(ctx *cli.Context) error { EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), } + if cfg.EVMInterpreter != "" { + vm.InitEVMCEVM(cfg.EVMInterpreter) + } + results := make([]StatetestResult, 0, len(tests)) for key, test := range tests { for _, st := range test.Subtests(nil) { From ad2814343764e4d94fa9f667aee81776ea7e5693 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 10:17:54 -0800 Subject: [PATCH 026/103] cmd/utils: initialize external evms if configured for geth Date: 2022-11-07 10:17:54-08:00 Signed-off-by: meows --- cmd/utils/flags.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 7ab4906218..9f09953c35 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2021,10 +2021,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.IsSet(EWASMInterpreterFlag.Name) { cfg.EWASMInterpreter = ctx.String(EWASMInterpreterFlag.Name) + vm.InitEVMCEwasm(cfg.EWASMInterpreter) } if ctx.IsSet(EVMInterpreterFlag.Name) { cfg.EVMInterpreter = ctx.String(EVMInterpreterFlag.Name) + vm.InitEVMCEVM(cfg.EVMInterpreter) } if ctx.IsSet(RPCGlobalGasCapFlag.Name) { cfg.RPCGasCap = ctx.Uint64(RPCGlobalGasCapFlag.Name) From 429275b1ecf7ef7364bee990197d6a8a2017d69d Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 10:43:54 -0800 Subject: [PATCH 027/103] core/vm,go.mod,go.sum: bump ethereum/evmc version: v7.5.0 -> v10.0.0 Date: 2022-11-07 10:43:54-08:00 Signed-off-by: meows --- core/vm/evm.go | 4 ++-- core/vm/evmc.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index c716f4d161..37be74d8e8 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -22,7 +22,7 @@ import ( "sync/atomic" "time" - "github.com/ethereum/evmc/v7/bindings/go/evmc" + "github.com/ethereum/evmc/v10/bindings/go/evmc" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params/types/ctypes" @@ -277,7 +277,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas gas = 0 } // TODO: consider clearing up unused snapshots: - //} else { + // } else { // evm.StateDB.DiscardSnapshot(snapshot) } return ret, gas, err diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 3c44d83b76..ed2d1147b8 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -26,7 +26,7 @@ import ( "strings" "sync" - "github.com/ethereum/evmc/v7/bindings/go/evmc" + "github.com/ethereum/evmc/v10/bindings/go/evmc" "github.com/ethereum/go-ethereum/params/vars" "github.com/ethereum/go-ethereum/common" diff --git a/go.mod b/go.mod index 06b336343b..a0fa720e9c 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf github.com/edsrzf/mmap-go v1.0.0 github.com/etclabscore/go-openrpc-reflect v0.0.37 - github.com/ethereum/evmc/v7 v7.5.0 + github.com/ethereum/evmc/v10 v10.0.0 github.com/fatih/color v1.7.0 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 diff --git a/go.sum b/go.sum index a1339c26ac..d7d76da1c3 100644 --- a/go.sum +++ b/go.sum @@ -135,8 +135,8 @@ github.com/etclabscore/go-jsonschema-walk v0.0.6 h1:DrNzoKWKd8f8XB5nFGBY00IcjakR github.com/etclabscore/go-jsonschema-walk v0.0.6/go.mod h1:VdfDY72AFAiUhy0ZXEaWSpveGjMT5JcDIm903NGqFwQ= github.com/etclabscore/go-openrpc-reflect v0.0.37 h1:IH0e7JqIvR9OhbbFWi/BHIkXrqbR3Zyia3RJ733eT6c= github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= -github.com/ethereum/evmc/v7 v7.5.0 h1:vwKcs1DINXqvaymranmlpO64fysJJkirCCJ+kkaPaCs= -github.com/ethereum/evmc/v7 v7.5.0/go.mod h1:q2Q0rCSUlIkngd+mZwfCzEUbvB0IIopH1+7hcs9QuDg= +github.com/ethereum/evmc/v10 v10.0.0 h1:zuhGmMJIf4hXWph8NPzt5Wlu3Ujsf84KYFordc6mTTk= +github.com/ethereum/evmc/v10 v10.0.0/go.mod h1:A5SnakP7hgfMwjG0cNgpR3st5hQJzXDz2++bvOQqt5c= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq6Q+cGWcGHz0FjGR3QqcInWcW0= From 191325a6324b35ec073a37d9691479eab320865e Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 11:10:34 -0800 Subject: [PATCH 028/103] core/vm: implement hostContext.AccessAccount,.AccessStorage Making sure that EIP2929 is enabled for current context. Date: 2022-11-07 11:10:34-08:00 Signed-off-by: meows --- core/vm/evmc.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index ed2d1147b8..433300807d 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -110,6 +110,28 @@ type hostContext struct { contract *Contract // The reference to the current contract, needed by Call-like methods. } +func (host *hostContext) AccessAccount(addr evmc.Address) evmc.AccessStatus { + if !host.env.chainConfig.IsEnabled(host.env.chainConfig.GetEIP2929Transition, host.env.Context.BlockNumber) { + return evmc.ColdAccess + } + + if host.env.StateDB.AddressInAccessList(common.Address(addr)) { + return evmc.WarmAccess + } + return evmc.ColdAccess +} + +func (host *hostContext) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.AccessStatus { + if !host.env.chainConfig.IsEnabled(host.env.chainConfig.GetEIP2929Transition, host.env.Context.BlockNumber) { + return evmc.ColdAccess + } + + if addrOK, slotOK := host.env.StateDB.SlotInAccessList(common.Address(addr), common.Hash(key)); addrOK && slotOK { + return evmc.WarmAccess + } + return evmc.ColdAccess +} + func (host *hostContext) AccountExists(evmcAddr evmc.Address) bool { addr := common.Address(evmcAddr) if host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP161dTransition, host.env.Context.BlockNumber) { From 1f6cc7526edebf347c5f82f841d597cfc6940436 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 11:46:32 -0800 Subject: [PATCH 029/103] core/vm: update evmc.Storage* vars to new counterparts For reference: https://github.com/ethereum/evmc/commit/35112aed7b4e0fd2f54cf2e3272ba9117a0c6494#diff-d1775ee3911821f864ea729e4ac4a459a522e37a604a5a67e07def298c75fb99R23 Date: 2022-11-07 11:46:32-08:00 Signed-off-by: meows --- core/vm/evmc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 433300807d..b3163ecdce 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -125,7 +125,7 @@ func (host *hostContext) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.Ac if !host.env.chainConfig.IsEnabled(host.env.chainConfig.GetEIP2929Transition, host.env.Context.BlockNumber) { return evmc.ColdAccess } - + if addrOK, slotOK := host.env.StateDB.SlotInAccessList(common.Address(addr), common.Hash(key)); addrOK && slotOK { return evmc.WarmAccess } @@ -158,7 +158,7 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev var oldValue uint256.Int oldValue.SetBytes(host.env.StateDB.GetState(addr, key).Bytes()) if oldValue.Eq(value) { - return evmc.StorageUnchanged + return evmc.StorageAssigned } var current, original uint256.Int @@ -169,7 +169,7 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev // Here's a great example of one of the limits of our (core-geth) current chainconfig interface model. // Should we handle the logic here about historic-featuro logic (which really is nice, because when reading the strange-incantation implemations, it's nice to see why it is), - // or should we handle the question where we handle the rest of the questions like this, since this logic is + // or should we handle the question of where we handle the rest of the questions like this, since this logic is // REALLY logic that belongs to the abstract idea of a chainconfiguration (aka chainconfig), which makes sense // but depends on ECIPs having steadier and more predictable logic. hasEIP2200 := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP2200Transition, host.env.Context.BlockNumber) @@ -221,7 +221,7 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev host.env.StateDB.AddRefund(cleanRefund) } } - return evmc.StorageModifiedAgain + return evmc.StorageAssigned } func (host *hostContext) GetBalance(addr evmc.Address) evmc.Hash { From 57109a9687feb8f531fca146e7b7848d87259e7a Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 11:47:09 -0800 Subject: [PATCH 030/103] core/vm: evmc.TxContext no longer has Difficulty field Date: 2022-11-07 11:47:09-08:00 Signed-off-by: meows --- core/vm/evmc.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index b3163ecdce..0623abaed4 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -257,14 +257,13 @@ func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evm func (host *hostContext) GetTxContext() evmc.TxContext { return evmc.TxContext{ - GasPrice: evmc.Hash(common.BigToHash(host.env.GasPrice)), - Origin: evmc.Address(host.env.TxContext.Origin), - Coinbase: evmc.Address(host.env.Context.Coinbase), - Number: host.env.Context.BlockNumber.Int64(), - Timestamp: host.env.Context.Time.Int64(), - GasLimit: int64(host.env.Context.GasLimit), - Difficulty: evmc.Hash(common.BigToHash(host.env.Context.Difficulty)), - ChainID: evmc.Hash(common.BigToHash(host.env.chainConfig.GetChainID())), + GasPrice: evmc.Hash(common.BigToHash(host.env.GasPrice)), + Origin: evmc.Address(host.env.TxContext.Origin), + Coinbase: evmc.Address(host.env.Context.Coinbase), + Number: host.env.Context.BlockNumber.Int64(), + Timestamp: host.env.Context.Time.Int64(), + GasLimit: int64(host.env.Context.GasLimit), + ChainID: evmc.Hash(common.BigToHash(host.env.chainConfig.GetChainID())), } } From 097e0ef2bc3845d987db95d106e069ce13cb4fc7 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 11:48:10 -0800 Subject: [PATCH 031/103] core/vm: return evmc.Berlin in case EIP2565 (as feature indicator) is enabled Date: 2022-11-07 11:48:10-08:00 Signed-off-by: meows --- core/vm/evmc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 0623abaed4..aa5d3c6317 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -369,7 +369,7 @@ func getRevision(env *EVM) evmc.Revision { // as identifiers for Fork-Feature-Groups. Note that this is very different // than using Feature-complete sets to assert "did Forkage." case conf.IsEnabled(conf.GetEIP2565Transition, n): - panic("berlin is unsupported by EVMCv7") + return evmc.Berlin case conf.IsEnabled(conf.GetEIP1884Transition, n): return evmc.Istanbul case conf.IsEnabled(conf.GetEIP1283DisableTransition, n): From eddf07265be3d0be5a56b9127950151e782252d1 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 11:48:49 -0800 Subject: [PATCH 032/103] core/vm: another syntax improvement for a comment Date: 2022-11-07 11:48:49-08:00 Signed-off-by: meows --- core/vm/evmc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index aa5d3c6317..70c0206e3a 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -367,7 +367,7 @@ func getRevision(env *EVM) evmc.Revision { // This is an example of choosing to use an "abstracted" idea // about chain config, where I'm choosing to prioritize "indicative" features // as identifiers for Fork-Feature-Groups. Note that this is very different - // than using Feature-complete sets to assert "did Forkage." + // from using Feature-complete sets to assert "did Forkage." case conf.IsEnabled(conf.GetEIP2565Transition, n): return evmc.Berlin case conf.IsEnabled(conf.GetEIP1884Transition, n): From ea4f9346d2a40fee1cd144ba4dcfb66d713513c8 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 12:04:07 -0800 Subject: [PATCH 033/103] core/vm: update hostContext.Selfdestruct to return bool Date: 2022-11-07 12:04:07-08:00 Signed-off-by: meows --- core/vm/evmc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 70c0206e3a..22b5ca893d 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -244,7 +244,7 @@ func (host *hostContext) GetCode(addr evmc.Address) []byte { return host.env.StateDB.GetCode(common.Address(addr)) } -func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evmc.Address) { +func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evmc.Address) bool { addr := common.Address(evmcAddr) beneficiary := common.Address(evmcBeneficiary) db := host.env.StateDB @@ -252,7 +252,7 @@ func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evm db.AddRefund(vars.SelfdestructRefundGas) } db.AddBalance(beneficiary, db.GetBalance(addr)) - db.Suicide(addr) + return db.Suicide(addr) } func (host *hostContext) GetTxContext() evmc.TxContext { From 38352695ddbbaf6d75a9244132a80bcfe2aa3eaf Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 12:04:42 -0800 Subject: [PATCH 034/103] core/vm: add gasRefund return value to hostContext.Call signature Date: 2022-11-07 12:04:42-08:00 Signed-off-by: meows --- core/vm/evmc.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 22b5ca893d..f748079f73 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -288,9 +288,14 @@ func (host *hostContext) EmitLog(addr evmc.Address, evmcTopics []evmc.Hash, data }) } +// Call +// need the method: +// Call(kind CallKind, recipient Address, sender Address, value Hash, input []byte, gas int64, depth int, static bool, salt Hash, codeAddress Address) (output []byte, gasLeft int64, gasRefund int64, createAddr Address, err error) +// have the method: +// Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, createAddrEvmc evmc.Address, err error) func (host *hostContext) Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, - static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, createAddrEvmc evmc.Address, err error) { + static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, gasRefund int64, createAddrEvmc evmc.Address, err error) { destination := common.Address(evmcDestination) @@ -356,7 +361,8 @@ func (host *hostContext) Call(kind evmc.CallKind, } gasLeft = int64(gasLeftU) - return output, gasLeft, createAddrEvmc, err + gasRefund = int64(host.env.StateDB.GetRefund()) + return output, gasLeft, gasRefund, createAddrEvmc, err } // getRevision translates ChainConfig's HF block information into EVMC revision. From b2c886bc61ff0bd6f814860e74c57b5a7a6dfcbc Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 12:05:16 -0800 Subject: [PATCH 035/103] core/vm: bump getRevision switch to support London Also fixes wrong number of params argued. Date: 2022-11-07 12:05:16-08:00 Signed-off-by: meows --- core/vm/evmc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index f748079f73..e225e8f264 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -374,6 +374,8 @@ func getRevision(env *EVM) evmc.Revision { // about chain config, where I'm choosing to prioritize "indicative" features // as identifiers for Fork-Feature-Groups. Note that this is very different // from using Feature-complete sets to assert "did Forkage." + case conf.IsEnabled(conf.GetEIP1559Transition, n): + return evmc.London case conf.IsEnabled(conf.GetEIP2565Transition, n): return evmc.Berlin case conf.IsEnabled(conf.GetEIP1884Transition, n): @@ -430,7 +432,7 @@ func (evm *EVMC) Run(contract *Contract, input []byte, readOnly bool) (ret []byt input, evmc.Hash(common.BigToHash(contract.value)), contract.Code, - evmc.Hash{}) + ) contract.Gas = uint64(gasLeft) From d42b9b21aaa9214abb1b9b9b60a20bf619434fba Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 12:12:44 -0800 Subject: [PATCH 036/103] core/vm: implement codeAddress argument for hostContext.Call sig See https://github.com/ethereum/evmc/commit/8314761222c837d41f573b0af1152ce1c9895a32#diff-4c54ef259154e3cd3bd18b1963e027655525f909a887700cc2d1386e075c3628R144-R155 Date: 2022-11-07 12:12:44-08:00 Signed-off-by: meows --- core/vm/evmc.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index e225e8f264..be2ed98527 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -295,9 +295,10 @@ func (host *hostContext) EmitLog(addr evmc.Address, evmcTopics []evmc.Hash, data // Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, createAddrEvmc evmc.Address, err error) func (host *hostContext) Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, - static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, gasRefund int64, createAddrEvmc evmc.Address, err error) { + static bool, saltBytes evmc.Hash, evmcCodeAddress evmc.Address) (output []byte, gasLeft int64, gasRefund int64, createAddrEvmc evmc.Address, err error) { destination := common.Address(evmcDestination) + codeTarget := common.Address(evmcCodeAddress) var createAddr common.Address @@ -318,9 +319,9 @@ func (host *hostContext) Call(kind evmc.CallKind, output, gasLeftU, err = host.env.Call(host.contract, destination, input, gasU, value.ToBig()) } case evmc.DelegateCall: - output, gasLeftU, err = host.env.DelegateCall(host.contract, destination, input, gasU) + output, gasLeftU, err = host.env.DelegateCall(host.contract, codeTarget, input, gasU) case evmc.CallCode: - output, gasLeftU, err = host.env.CallCode(host.contract, destination, input, gasU, value.ToBig()) + output, gasLeftU, err = host.env.CallCode(host.contract, codeTarget, input, gasU, value.ToBig()) case evmc.Create: var createOutput []byte createOutput, createAddr, gasLeftU, err = host.env.Create(host.contract, input, gasU, value.ToBig()) From c051c249eeab992ff3f565a6e920872b1a829660 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 12:52:10 -0800 Subject: [PATCH 037/103] build: bump evmone version: v0.5.0 -> v0.9.1 Date: 2022-11-07 12:52:10-08:00 Signed-off-by: meows --- build/evmone.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/evmone.sh b/build/evmone.sh index 36c379d13d..ba1f3cfac6 100755 --- a/build/evmone.sh +++ b/build/evmone.sh @@ -8,6 +8,6 @@ if [[ "$OSTYPE" != "linux"* ]]; then fi mkdir -p build/_workspace/evmone -[[ -f build/_workspace/evmone/evmone-0.5.0-linux-x86_64.tar.gz ]] && exit 0 -wget -O build/_workspace/evmone/evmone-0.5.0-linux-x86_64.tar.gz https://github.com/ethereum/evmone/releases/download/v0.5.0/evmone-0.5.0-linux-x86_64.tar.gz -tar xzvf build/_workspace/evmone/evmone-0.5.0-linux-x86_64.tar.gz -C build/_workspace/evmone/ +[[ -f build/_workspace/evmone/evmone-0.9.1-linux-x86_64.tar.gz ]] && exit 0 +wget -O build/_workspace/evmone/evmone-0.9.1-linux-x86_64.tar.gz https://github.com/ethereum/evmone/releases/download/v0.9.1/evmone-0.9.1-linux-x86_64.tar.gz +tar xzvf build/_workspace/evmone/evmone-0.9.1-linux-x86_64.tar.gz -C build/_workspace/evmone/ From 2a9508c9afac906bed8c0269d63dc6b0659f4bf9 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 13:15:09 -0800 Subject: [PATCH 038/103] Makefile,build: remove SSVM interpreter; project no longer exists Original https://github.com/second-state/SSVM redirects to https://github.com/WasmEdge/WasmEdge. Date: 2022-11-07 13:15:09-08:00 Signed-off-by: meows --- Makefile | 6 +----- build/ssvm.sh | 13 ------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100755 build/ssvm.sh diff --git a/Makefile b/Makefile index ceda65e98d..1b78185291 100644 --- a/Makefile +++ b/Makefile @@ -48,9 +48,6 @@ test-coregeth: \ hera: ./build/hera.sh -ssvm: - ./build/ssvm.sh - evmone: ./build/evmone.sh @@ -58,9 +55,8 @@ aleth-interpreter: ./build/aleth-interpreter.sh # Test EVMC support against various external interpreters. -test-evmc: hera ssvm evmone aleth-interpreter +test-evmc: hera evmone aleth-interpreter go test -count 1 ./tests -run TestState -evmc.ewasm=$(ROOT_DIR)/build/_workspace/hera/build/src/libhera.so - go test -count 1 ./tests -run TestState -evmc.ewasm=$(ROOT_DIR)/build/_workspace/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so go test -count 1 ./tests -run TestState -evmc.evm=$(ROOT_DIR)/build/_workspace/evmone/lib/libevmone.so go test -count 1 ./tests -run TestState -evmc.evm=$(ROOT_DIR)/build/_workspace/aleth/lib/libaleth-interpreter.so diff --git a/build/ssvm.sh b/build/ssvm.sh deleted file mode 100755 index c6d33c70f1..0000000000 --- a/build/ssvm.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e - -if [[ "$OSTYPE" != "linux"* ]]; then - echo "This script is only currently configured to work on Linux. Please see \"https://github.com/second-state/ssvm-evmc#notice\" documentation for instructions to build in other environments." - exit 1 -fi - -mkdir -p build/_workspace/SSVM/build/tools/ssvm-evmc/ -[[ -f build/_workspace/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so ]] && exit 0 -wget -O build/_workspace/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so \ - https://github.com/second-state/ssvm-evmc/releases/download/evmc7-0.1.1/libssvm-evmc.so From 273a5669a3b6506257ae98a6976b6249486cff96 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 14:05:21 -0800 Subject: [PATCH 039/103] build: bump hera version: v0.3.2 -> v0.6.0 v0.6.0 supports EVMC v10. Date: 2022-11-07 14:05:21-08:00 Signed-off-by: meows --- build/hera.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/hera.sh b/build/hera.sh index e21e6aca2f..09fc3505ea 100755 --- a/build/hera.sh +++ b/build/hera.sh @@ -16,7 +16,7 @@ main() { mkdir -p build/_workspace [ ! -d build/_workspace/hera ] && git clone https://github.com/ewasm/hera build/_workspace/hera || echo "Hera exists." cd build/_workspace/hera - git checkout v0.3.2 + git checkout v0.6.0 git submodule update --init mkdir -p build cd build From 7d9c44413ddd0d7b37925b3696dd11239735d31e Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 7 Nov 2022 14:07:59 -0800 Subject: [PATCH 040/103] Makefile,build: remove aleth interpreter The ethereum/aleth project has been archived and is no longer maintained. This commit also removes an accidental leftover from the ssvm code (call to clean in Makefile). Date: 2022-11-07 14:07:59-08:00 Signed-off-by: meows --- Makefile | 8 ++------ build/aleth-interpreter.sh | 14 -------------- 2 files changed, 2 insertions(+), 20 deletions(-) delete mode 100755 build/aleth-interpreter.sh diff --git a/Makefile b/Makefile index 1b78185291..b1df535d6b 100644 --- a/Makefile +++ b/Makefile @@ -51,17 +51,13 @@ hera: evmone: ./build/evmone.sh -aleth-interpreter: - ./build/aleth-interpreter.sh - # Test EVMC support against various external interpreters. -test-evmc: hera evmone aleth-interpreter +test-evmc: hera evmone go test -count 1 ./tests -run TestState -evmc.ewasm=$(ROOT_DIR)/build/_workspace/hera/build/src/libhera.so go test -count 1 ./tests -run TestState -evmc.evm=$(ROOT_DIR)/build/_workspace/evmone/lib/libevmone.so - go test -count 1 ./tests -run TestState -evmc.evm=$(ROOT_DIR)/build/_workspace/aleth/lib/libaleth-interpreter.so clean-evmc: - rm -rf ./build/_workspace/hera ./build/_workspace/SSVM ./build/_workspace/evmone ./build/_workspace/aleth + rm -rf ./build/_workspace/hera ./build/_workspace/evmone test-coregeth-features: \ test-coregeth-features-coregeth \ diff --git a/build/aleth-interpreter.sh b/build/aleth-interpreter.sh deleted file mode 100755 index 42942cabac..0000000000 --- a/build/aleth-interpreter.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -set -e - - -if [[ "$OSTYPE" != "linux"* ]]; then - echo "This script is only currently configured to work on Linux. Please see \"https://github.com/ethereum/aleth\" documentation for instructions to build in other environments." - exit 1 -fi - -mkdir -p build/_workspace/aleth -[[ -f build/_workspace/aleth/aleth-1.8.0-linux-x86_64.tar.gz ]] && exit 0 -wget -O build/_workspace/aleth/aleth-1.8.0-linux-x86_64.tar.gz https://github.com/ethereum/aleth/releases/download/v1.8.0/aleth-1.8.0-linux-x86_64.tar.gz -tar xzvf build/_workspace/aleth/aleth-1.8.0-linux-x86_64.tar.gz -C build/_workspace/aleth/ From 194f06f09213f5cf52f7217130a7b238c2b36331 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 8 Nov 2022 10:23:14 -0800 Subject: [PATCH 041/103] .github/workflows: fixing c++/cmake issues w/r/t evmone, evmc tests The command 'make test-evmc' complains about a GLIBCXX version incompatibility (missing 3.4.29). This issue has been shown resolved by the Actions CI run here: https://github.com/meowsbits/core-geth/actions/runs/3429882085/jobs/5716103415 The run ultimately fails, but it fails because the tests fail, while the evmone .so is used appropriately. Full context of the error follows. panic: EVMC loading error: /lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.29 not found, required by /home/ia/go/src/github.com/ethereum/go-ethereum/build/_workspace/evmone/lib/libevmone.so goroutine 1 [running]: github.com/ethereum/go-ethereum/core/vm.initEVMC(0x11e4e0?, {0x7ffc235f574c?, 0xc0001361c0?}) /home/ia/go/src/github.com/ethereum/go-ethereum/core/vm/evmc.go:83 +0x605 github.com/ethereum/go-ethereum/core/vm.InitEVMCEVM({0x7ffc235f574c, 0x58}) /home/ia/go/src/github.com/ethereum/go-ethereum/core/vm/evmc.go:60 +0xd0 github.com/ethereum/go-ethereum/tests.TestMain(0xffffffffffffffff?) /home/ia/go/src/github.com/ethereum/go-ethereum/tests/init_test.go:50 +0xec main.main() _testmain.go:77 +0x1d3 FAIL github.com/ethereum/go-ethereum/tests 0.014s FAIL make: *** [Makefile:57: test-evmc] Error 1 See also here: https://github.com/etclabscore/core-geth/actions/runs/3414467176/jobs/5682462570#step:5:482 Date: 2022-11-09 07:44:38-08:00 Signed-off-by: meows --- .github/workflows/evmc.yml | 22 ++++++++++++++++++++++ cmake.sh | 0 2 files changed, 22 insertions(+) create mode 100755 cmake.sh diff --git a/.github/workflows/evmc.yml b/.github/workflows/evmc.yml index 3fe5b3b244..422265a790 100644 --- a/.github/workflows/evmc.yml +++ b/.github/workflows/evmc.yml @@ -22,9 +22,31 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 + - name: Install cmake + run: | + sudo apt-get update -y + sudo apt-get upgrade -y + sudo apt-get install -y cmake + cmake --version + + - name: Install necessary GLIBCXX version + run: | + strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y + sudo apt-get update -y + sudo apt-get install -y gcc-9 g++-9 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 + g++ --version + gcc --version + strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX + - name: Get dependencies run: | go get -v -t -d ./... + git config --global --add safe.directory /home/ia/go/src/github.com/ethereum/go-ethereum/tests/evm-benchmarks + git config --global --add safe.directory /home/ia/go/src/github.com/ethereum/go-ethereum/tests/testdata + git config --global --add safe.directory /home/ia/go/src/github.com/ethereum/go-ethereum/tests/testdata/LegacyTests git submodule update --init --recursive export GOBIN=${HOME}/go/bin mkdir -p "${GOBIN}" diff --git a/cmake.sh b/cmake.sh new file mode 100755 index 0000000000..e69de29bb2 From 9363a2a393da0a0ccbe060ed4ceb0d3cb5f93d5c Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 08:59:00 -0800 Subject: [PATCH 042/103] core/vm: use evmc.Revision values for logical conditions I think this provides better readability, and encourages readers to check and use the getRevision both as a logical nexus, as well as to appreciate its limitations. Date: 2022-11-09 08:59:00-08:00 Signed-off-by: meows --- core/vm/evmc.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index be2ed98527..edcd8d61ec 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -111,7 +111,7 @@ type hostContext struct { } func (host *hostContext) AccessAccount(addr evmc.Address) evmc.AccessStatus { - if !host.env.chainConfig.IsEnabled(host.env.chainConfig.GetEIP2929Transition, host.env.Context.BlockNumber) { + if getRevision(host.env) < evmc.Berlin /* EIP-2929 */ { return evmc.ColdAccess } @@ -122,7 +122,7 @@ func (host *hostContext) AccessAccount(addr evmc.Address) evmc.AccessStatus { } func (host *hostContext) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.AccessStatus { - if !host.env.chainConfig.IsEnabled(host.env.chainConfig.GetEIP2929Transition, host.env.Context.BlockNumber) { + if getRevision(host.env) < evmc.Berlin /* EIP-2929 */ { return evmc.ColdAccess } @@ -134,7 +134,7 @@ func (host *hostContext) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.Ac func (host *hostContext) AccountExists(evmcAddr evmc.Address) bool { addr := common.Address(evmcAddr) - if host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP161dTransition, host.env.Context.BlockNumber) { + if getRevision(host.env) >= evmc.SpuriousDragon /* EIP-161 */ { if !host.env.StateDB.Empty(addr) { return true } @@ -172,13 +172,12 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev // or should we handle the question of where we handle the rest of the questions like this, since this logic is // REALLY logic that belongs to the abstract idea of a chainconfiguration (aka chainconfig), which makes sense // but depends on ECIPs having steadier and more predictable logic. - hasEIP2200 := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP2200Transition, host.env.Context.BlockNumber) - hasEIP1884 := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP1884Transition, host.env.Context.BlockNumber) - // Here's an example where to me, it makes sense to use individual EIPs in the code... - // when they don't specify each other in the spec. - hasNetStorageCostEIP := hasEIP2200 && hasEIP1884 - if !hasNetStorageCostEIP { + // isIstanbul was originally defined as two conditions: EIP1884, EIP2200; + // but now the code expects any configuration to always apply (or have applied) them together at (as) the Istanbul fork. + isIstanbul := getRevision(host.env) >= evmc.Istanbul + + if !isIstanbul { status = evmc.StorageModified if oldValue.IsZero() { return evmc.StorageAdded @@ -192,7 +191,7 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev resetClearRefund := vars.NetSstoreResetClearRefund cleanRefund := vars.NetSstoreResetRefund - if hasEIP2200 { + if isIstanbul { resetClearRefund = vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200 // 19200 cleanRefund = vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200 // 4200 } @@ -326,7 +325,7 @@ func (host *hostContext) Call(kind evmc.CallKind, var createOutput []byte createOutput, createAddr, gasLeftU, err = host.env.Create(host.contract, input, gasU, value.ToBig()) createAddrEvmc = evmc.Address(createAddr) - isHomestead := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP7Transition, host.env.Context.BlockNumber) + isHomestead := getRevision(host.env) >= evmc.Homestead if !isHomestead && err == ErrCodeStoreOutOfGas { err = nil } @@ -379,7 +378,7 @@ func getRevision(env *EVM) evmc.Revision { return evmc.London case conf.IsEnabled(conf.GetEIP2565Transition, n): return evmc.Berlin - case conf.IsEnabled(conf.GetEIP1884Transition, n): + case conf.IsEnabled(conf.GetEIP1884Transition, n) && conf.IsEnabled(conf.GetEIP2200Transition, n): return evmc.Istanbul case conf.IsEnabled(conf.GetEIP1283DisableTransition, n): return evmc.Petersburg From 6e1a0ddebf0991a214265b88000014efbbe6c4dc Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 09:10:19 -0800 Subject: [PATCH 043/103] .github/workflows: rename actions job to reflect not-just-EWASM Date: 2022-11-09 09:10:19-08:00 Signed-off-by: meows --- .github/workflows/evmc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/evmc.yml b/.github/workflows/evmc.yml index 422265a790..473c20b1a2 100644 --- a/.github/workflows/evmc.yml +++ b/.github/workflows/evmc.yml @@ -8,8 +8,8 @@ on: jobs: - build-ewasm: - name: EWASM State Tests + build-evmc: + name: EVMC/EVM+EWASM State Tests runs-on: ubuntu-latest steps: From c67278b3a34c33d7c43caf5d94623a9e4e979d5f Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 11:07:07 -0800 Subject: [PATCH 044/103] core/vm: fixup comment Date: 2022-11-09 11:07:07-08:00 Signed-off-by: meows --- core/vm/evmc.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index edcd8d61ec..cd39a56949 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -287,11 +287,8 @@ func (host *hostContext) EmitLog(addr evmc.Address, evmcTopics []evmc.Hash, data }) } -// Call -// need the method: -// Call(kind CallKind, recipient Address, sender Address, value Hash, input []byte, gas int64, depth int, static bool, salt Hash, codeAddress Address) (output []byte, gasLeft int64, gasRefund int64, createAddr Address, err error) -// have the method: -// Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, createAddrEvmc evmc.Address, err error) +// Call executes a message call transaction. +// - evmcCodeAddress: https://github.com/ethereum/evmc/commit/8314761222c837d41f573b0af1152ce1c9895a32#diff-4c54ef259154e3cd3bd18b1963e027655525f909a887700cc2d1386e075c3628R155 func (host *hostContext) Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, static bool, saltBytes evmc.Hash, evmcCodeAddress evmc.Address) (output []byte, gasLeft int64, gasRefund int64, createAddrEvmc evmc.Address, err error) { From 98e2d49056d6fa9b491f6adb9bb74cff4885fd4b Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 11:17:42 -0800 Subject: [PATCH 045/103] core/vm: remove extra condition EIP2200 for Istanbul revision While true, I'm debugging failing tests (when running with --vm.evm=path/to/evmone.so), and want to remove any possibly spurious logic. Date: 2022-11-09 11:17:42-08:00 Signed-off-by: meows --- core/vm/evmc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index cd39a56949..d8518d8240 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -375,7 +375,7 @@ func getRevision(env *EVM) evmc.Revision { return evmc.London case conf.IsEnabled(conf.GetEIP2565Transition, n): return evmc.Berlin - case conf.IsEnabled(conf.GetEIP1884Transition, n) && conf.IsEnabled(conf.GetEIP2200Transition, n): + case conf.IsEnabled(conf.GetEIP1884Transition, n): return evmc.Istanbul case conf.IsEnabled(conf.GetEIP1283DisableTransition, n): return evmc.Petersburg From c984765a5b427bb2d342a1250bcec693a2b5b52c Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 11:55:44 -0800 Subject: [PATCH 046/103] core/vm: implement tx BaseFee and PrevRandao in case London enabled Date: 2022-11-09 11:55:44-08:00 Signed-off-by: meows --- core/vm/evmc.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index d8518d8240..a445ca9451 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -255,7 +255,7 @@ func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evm } func (host *hostContext) GetTxContext() evmc.TxContext { - return evmc.TxContext{ + txCtx := evmc.TxContext{ GasPrice: evmc.Hash(common.BigToHash(host.env.GasPrice)), Origin: evmc.Address(host.env.TxContext.Origin), Coinbase: evmc.Address(host.env.Context.Coinbase), @@ -264,6 +264,13 @@ func (host *hostContext) GetTxContext() evmc.TxContext { GasLimit: int64(host.env.Context.GasLimit), ChainID: evmc.Hash(common.BigToHash(host.env.chainConfig.GetChainID())), } + if getRevision(host.env) >= evmc.London { + txCtx.BaseFee = evmc.Hash(common.BigToHash(host.env.Context.BaseFee)) + if host.env.Context.Random != nil { + txCtx.PrevRandao = evmc.Hash(*host.env.Context.Random) + } + } + return txCtx } func (host *hostContext) GetBlockHash(number int64) evmc.Hash { From 475e1e4770ec0ab462be0a8538115846d48b7980 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 11:56:23 -0800 Subject: [PATCH 047/103] core/vm: assign the refund value based on London rules... ? Date: 2022-11-09 11:56:23-08:00 Signed-off-by: meows --- core/vm/evmc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index a445ca9451..70acfedb6a 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -365,7 +365,10 @@ func (host *hostContext) Call(kind evmc.CallKind, } gasLeft = int64(gasLeftU) - gasRefund = int64(host.env.StateDB.GetRefund()) + gasRefund = gasLeft + if getRevision(host.env) >= evmc.London { + gasRefund = int64(host.env.StateDB.GetRefund()) + } return output, gasLeft, gasRefund, createAddrEvmc, err } From a66e4cedc0eda5e9b8d7df0b9a47a36382efa804 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 11:57:19 -0800 Subject: [PATCH 048/103] .github/workflows: fix directory path for git safe config for submodules Date: 2022-11-09 11:57:19-08:00 Signed-off-by: meows --- .github/workflows/evmc.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/evmc.yml b/.github/workflows/evmc.yml index 422265a790..998aba8461 100644 --- a/.github/workflows/evmc.yml +++ b/.github/workflows/evmc.yml @@ -44,9 +44,9 @@ jobs: - name: Get dependencies run: | go get -v -t -d ./... - git config --global --add safe.directory /home/ia/go/src/github.com/ethereum/go-ethereum/tests/evm-benchmarks - git config --global --add safe.directory /home/ia/go/src/github.com/ethereum/go-ethereum/tests/testdata - git config --global --add safe.directory /home/ia/go/src/github.com/ethereum/go-ethereum/tests/testdata/LegacyTests + git config --global --add safe.directory $(pwd)/tests/evm-benchmarks + git config --global --add safe.directory $(pwd)/tests/testdata + git config --global --add safe.directory $(pwd)/tests/testdata/LegacyTests git submodule update --init --recursive export GOBIN=${HOME}/go/bin mkdir -p "${GOBIN}" From 1eec2d84aa38c36044085592e41ed98d9c234191 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 9 Nov 2022 11:57:55 -0800 Subject: [PATCH 049/103] cmake.sh: remove anachronstic development cmake.sh installation script, oops Date: 2022-11-09 11:57:55-08:00 Signed-off-by: meows --- cmake.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 cmake.sh diff --git a/cmake.sh b/cmake.sh deleted file mode 100755 index e69de29bb2..0000000000 From 3588f610269c1fe9ec8452525ccb473113cec4be Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 07:10:13 -0800 Subject: [PATCH 050/103] eth/ethconfig: run 'go generate ./...' Its been a while... Date: 2022-11-11 07:10:13-08:00 Signed-off-by: meows --- eth/ethconfig/gen_config.go | 42 +++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 4896204d51..e814e59bef 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -21,6 +21,7 @@ func (c Config) MarshalTOML() (interface{}, error) { type Config struct { Genesis *genesisT.Genesis `toml:",omitempty"` NetworkId uint64 + ProtocolVersions []uint SyncMode downloader.SyncMode EthDiscoveryURLs []string SnapDiscoveryURLs []string @@ -42,6 +43,7 @@ func (c Config) MarshalTOML() (interface{}, error) { DatabaseHandles int `toml:"-"` DatabaseCache int DatabaseFreezer string + DatabaseFreezerRemote string TrieCleanCache int TrieCleanCacheJournal string `toml:",omitempty"` TrieCleanCacheRejournal time.Duration `toml:",omitempty"` @@ -58,17 +60,21 @@ func (c Config) MarshalTOML() (interface{}, error) { DocRoot string `toml:"-"` EWASMInterpreter string EVMInterpreter string - RPCGasCap uint64 `toml:",omitempty"` + RPCGasCap uint64 RPCEVMTimeout time.Duration RPCTxFeeCap float64 Checkpoint *ctypes.TrustedCheckpoint `toml:",omitempty"` CheckpointOracle *ctypes.CheckpointOracleConfig `toml:",omitempty"` - OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` - OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` + ECBP1100 *big.Int + ECBP1100NoDisable *bool `toml:",omitempty"` + OverrideMystique *big.Int `toml:",omitempty"` + OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` + OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` } var enc Config enc.Genesis = c.Genesis enc.NetworkId = c.NetworkId + enc.ProtocolVersions = c.ProtocolVersions enc.SyncMode = c.SyncMode enc.EthDiscoveryURLs = c.EthDiscoveryURLs enc.SnapDiscoveryURLs = c.SnapDiscoveryURLs @@ -90,6 +96,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.DatabaseHandles = c.DatabaseHandles enc.DatabaseCache = c.DatabaseCache enc.DatabaseFreezer = c.DatabaseFreezer + enc.DatabaseFreezerRemote = c.DatabaseFreezerRemote enc.TrieCleanCache = c.TrieCleanCache enc.TrieCleanCacheJournal = c.TrieCleanCacheJournal enc.TrieCleanCacheRejournal = c.TrieCleanCacheRejournal @@ -111,6 +118,9 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCTxFeeCap = c.RPCTxFeeCap enc.Checkpoint = c.Checkpoint enc.CheckpointOracle = c.CheckpointOracle + enc.ECBP1100 = c.ECBP1100 + enc.ECBP1100NoDisable = c.ECBP1100NoDisable + enc.OverrideMystique = c.OverrideMystique enc.OverrideTerminalTotalDifficulty = c.OverrideTerminalTotalDifficulty enc.OverrideTerminalTotalDifficultyPassed = c.OverrideTerminalTotalDifficultyPassed return &enc, nil @@ -121,6 +131,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { type Config struct { Genesis *genesisT.Genesis `toml:",omitempty"` NetworkId *uint64 + ProtocolVersions []uint SyncMode *downloader.SyncMode EthDiscoveryURLs []string SnapDiscoveryURLs []string @@ -142,6 +153,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { DatabaseHandles *int `toml:"-"` DatabaseCache *int DatabaseFreezer *string + DatabaseFreezerRemote *string TrieCleanCache *int TrieCleanCacheJournal *string `toml:",omitempty"` TrieCleanCacheRejournal *time.Duration `toml:",omitempty"` @@ -158,13 +170,16 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { DocRoot *string `toml:"-"` EWASMInterpreter *string EVMInterpreter *string - RPCGasCap *uint64 `toml:",omitempty"` + RPCGasCap *uint64 RPCEVMTimeout *time.Duration RPCTxFeeCap *float64 Checkpoint *ctypes.TrustedCheckpoint `toml:",omitempty"` CheckpointOracle *ctypes.CheckpointOracleConfig `toml:",omitempty"` - OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` - OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` + ECBP1100 *big.Int + ECBP1100NoDisable *bool `toml:",omitempty"` + OverrideMystique *big.Int `toml:",omitempty"` + OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` + OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` } var dec Config if err := unmarshal(&dec); err != nil { @@ -176,6 +191,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.NetworkId != nil { c.NetworkId = *dec.NetworkId } + if dec.ProtocolVersions != nil { + c.ProtocolVersions = dec.ProtocolVersions + } if dec.SyncMode != nil { c.SyncMode = *dec.SyncMode } @@ -239,6 +257,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.DatabaseFreezer != nil { c.DatabaseFreezer = *dec.DatabaseFreezer } + if dec.DatabaseFreezerRemote != nil { + c.DatabaseFreezerRemote = *dec.DatabaseFreezerRemote + } if dec.TrieCleanCache != nil { c.TrieCleanCache = *dec.TrieCleanCache } @@ -302,6 +323,15 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.CheckpointOracle != nil { c.CheckpointOracle = dec.CheckpointOracle } + if dec.ECBP1100 != nil { + c.ECBP1100 = dec.ECBP1100 + } + if dec.ECBP1100NoDisable != nil { + c.ECBP1100NoDisable = dec.ECBP1100NoDisable + } + if dec.OverrideMystique != nil { + c.OverrideMystique = dec.OverrideMystique + } if dec.OverrideTerminalTotalDifficulty != nil { c.OverrideTerminalTotalDifficulty = dec.OverrideTerminalTotalDifficulty } From 098e8f067e9f77bba9c84d5b211dce7ec18afc36 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 07:14:37 -0800 Subject: [PATCH 051/103] core,params/types/genesisT: move 'go generate' decl to appropriate package Date: 2022-11-11 07:14:37-08:00 Signed-off-by: meows --- core/genesis.go | 3 --- params/types/genesisT/genesis.go | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 6ec35eecfe..3dcbcfc9fb 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -36,9 +36,6 @@ import ( "github.com/ethereum/go-ethereum/trie" ) -//go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go -//go:generate go run github.com/fjl/gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go - // SetupGenesisBlock wraps SetupGenesisBlockWithOverride, always using a nil value for the override. func SetupGenesisBlock(db ethdb.Database, genesis *genesisT.Genesis) (ctypes.ChainConfigurator, common.Hash, error) { return SetupGenesisBlockWithOverride(db, genesis, nil, nil) diff --git a/params/types/genesisT/genesis.go b/params/types/genesisT/genesis.go index 3d3feac180..0a293d2969 100644 --- a/params/types/genesisT/genesis.go +++ b/params/types/genesisT/genesis.go @@ -32,6 +32,9 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +//go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go +//go:generate go run github.com/fjl/gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go + var ErrGenesisNoConfig = errors.New("genesis has no chain configuration") // Genesis specifies the header fields, state of a genesis block. It also defines hard From 237327974e8c07050d7031e980dc2b63530c68f1 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 07:28:57 -0800 Subject: [PATCH 052/103] params/types/genesisT: go generate, change is inoperative except deps tweaks Date: 2022-11-11 07:28:57-08:00 Signed-off-by: meows --- params/types/genesisT/gen_genesis.go | 25 ++++---------------- params/types/genesisT/gen_genesis_account.go | 16 ------------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/params/types/genesisT/gen_genesis.go b/params/types/genesisT/gen_genesis.go index 5d592f151f..7598de6051 100644 --- a/params/types/genesisT/gen_genesis.go +++ b/params/types/genesisT/gen_genesis.go @@ -1,19 +1,3 @@ -// Copyright 2019 The multi-geth Authors -// This file is part of the multi-geth library. -// -// The multi-geth library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The multi-geth library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the multi-geth library. If not, see . - // Code generated by github.com/fjl/gencodec. DO NOT EDIT. package genesisT @@ -27,9 +11,9 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/params/confp/generic" - common0 "github.com/ethereum/go-ethereum/params/types/ctypes" - "github.com/ethereum/go-ethereum/params/types/goethereum" "github.com/ethereum/go-ethereum/params/types/coregeth" + "github.com/ethereum/go-ethereum/params/types/ctypes" + "github.com/ethereum/go-ethereum/params/types/goethereum" "github.com/ethereum/go-ethereum/params/types/multigeth" ) @@ -38,7 +22,7 @@ var _ = (*genesisSpecMarshaling)(nil) // MarshalJSON marshals as JSON. func (g Genesis) MarshalJSON() ([]byte, error) { type Genesis struct { - Config common0.ChainConfigurator `json:"config"` + Config ctypes.ChainConfigurator `json:"config"` Nonce math.HexOrDecimal64 `json:"nonce"` Timestamp math.HexOrDecimal64 `json:"timestamp"` ExtraData hexutil.Bytes `json:"extraData"` @@ -77,7 +61,7 @@ func (g Genesis) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (g *Genesis) UnmarshalJSON(input []byte) error { type Genesis struct { - Config common0.ChainConfigurator `json:"config"` + Config ctypes.ChainConfigurator `json:"config"` Nonce *math.HexOrDecimal64 `json:"nonce"` Timestamp *math.HexOrDecimal64 `json:"timestamp"` ExtraData *hexutil.Bytes `json:"extraData"` @@ -114,7 +98,6 @@ func (g *Genesis) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &dec); err != nil { return err } - if dec.Config != nil { g.Config = dec.Config } diff --git a/params/types/genesisT/gen_genesis_account.go b/params/types/genesisT/gen_genesis_account.go index 65e23b0fb6..77bba09883 100644 --- a/params/types/genesisT/gen_genesis_account.go +++ b/params/types/genesisT/gen_genesis_account.go @@ -1,19 +1,3 @@ -// Copyright 2019 The multi-geth Authors -// This file is part of the multi-geth library. -// -// The multi-geth library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The multi-geth library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the multi-geth library. If not, see . - // Code generated by github.com/fjl/gencodec. DO NOT EDIT. package genesisT From 03efbe99dd18df41fefd85517e4bfd26b1e51d9a Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 08:02:47 -0800 Subject: [PATCH 053/103] cmd/evm/internal/t8ntool: add missing BaseFee field to ExecutionResult struct And carry this through to assignment at the Apply method This solves what felt like a big issue using core-geth's evm with retesteth, which kept complaining as: WARNING: tool vs retesteth basefee disagree: 0 vs 10 makeRPCError Invalid block: base fee not correct! Expected: '10', got: '0' Finishing retesteth run *** Total Tests Run: 0 Error: Invalid block: base fee not correct! Expected: '10', got: '0' (stRandom/randomStatetest153, fork: London, TrInfo: d: 0, g: 0, v: 0, TrData: ) -------- TestOutputHelper detected 1 errors during test execution! /home/ia/dev/ethereum/retesteth/retesteth/TestOutputHelper.cpp(222): error: in 'GeneralStateTests/stRandom' Date: 2022-11-11 08:02:47-08:00 Signed-off-by: meows --- cmd/evm/internal/t8ntool/execution.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 13d9eee8cd..d36eb1bffc 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -58,6 +58,7 @@ type ExecutionResult struct { Rejected []*rejectedTx `json:"rejected,omitempty"` Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` GasUsed math.HexOrDecimal64 `json:"gasUsed"` + BaseFee *math.HexOrDecimal256 `json:"currentBaseFee,omitempty"` } type ommer struct { @@ -273,6 +274,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig ctypes.ChainConfigura Rejected: rejectedTxs, Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty), GasUsed: (math.HexOrDecimal64)(gasUsed), + BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee), } return statedb, execRs, nil } From 1306be87464d726e2a149b9a20c4b7e422fa46b5 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 08:04:57 -0800 Subject: [PATCH 054/103] cmd/evm/internal/t8ntool,cmd/evm: add missing EWASM interpreter flag to 'evm t8n' command Date: 2022-11-11 08:04:57-08:00 Signed-off-by: meows --- cmd/evm/internal/t8ntool/transition.go | 11 ++++++++--- cmd/evm/main.go | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index a7d2486877..3ad12890c4 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -179,15 +179,20 @@ func Transition(ctx *cli.Context) error { prestate.Env = *inputData.Env vmConfig := vm.Config{ - Tracer: tracer, - Debug: (tracer != nil), - EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), + Tracer: tracer, + Debug: (tracer != nil), + EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), + EWASMInterpreter: ctx.String(utils.EWASMInterpreterFlag.Name), } if vmConfig.EVMInterpreter != "" { vm.InitEVMCEVM(vmConfig.EVMInterpreter) } + if vmConfig.EWASMInterpreter != "" { + vm.InitEVMCEwasm(vmConfig.EWASMInterpreter) + } + // Construct the chainconfig var chainConfig ctypes.ChainConfigurator if cConf, extraEips, err := tests.GetChainConfig(ctx.String(ForknameFlag.Name)); err != nil { diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 8b73343e4b..92131edc5e 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -159,6 +159,7 @@ var stateTransitionCommand = &cli.Command{ t8ntool.RewardFlag, t8ntool.VerbosityFlag, utils.EVMInterpreterFlag, + utils.EWASMInterpreterFlag, }, } From 51fc880a283cd630f7938bc5557b72374e0aa31c Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 08:02:47 -0800 Subject: [PATCH 055/103] cmd/evm/internal/t8ntool: add missing BaseFee field to ExecutionResult struct And carry this through to assignment at the Apply method This solves what felt like a big issue using core-geth's evm with retesteth, which kept complaining as: WARNING: tool vs retesteth basefee disagree: 0 vs 10 makeRPCError Invalid block: base fee not correct! Expected: '10', got: '0' Finishing retesteth run *** Total Tests Run: 0 Error: Invalid block: base fee not correct! Expected: '10', got: '0' (stRandom/randomStatetest153, fork: London, TrInfo: d: 0, g: 0, v: 0, TrData: ) -------- TestOutputHelper detected 1 errors during test execution! /home/ia/dev/ethereum/retesteth/retesteth/TestOutputHelper.cpp(222): error: in 'GeneralStateTests/stRandom' Date: 2022-11-11 08:02:47-08:00 Signed-off-by: meows --- cmd/evm/internal/t8ntool/execution.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 2fd3139840..014d61a1a8 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -58,6 +58,7 @@ type ExecutionResult struct { Rejected []*rejectedTx `json:"rejected,omitempty"` Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` GasUsed math.HexOrDecimal64 `json:"gasUsed"` + BaseFee *math.HexOrDecimal256 `json:"currentBaseFee,omitempty"` } type ommer struct { @@ -273,6 +274,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig ctypes.ChainConfigura Rejected: rejectedTxs, Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty), GasUsed: (math.HexOrDecimal64)(gasUsed), + BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee), } return statedb, execRs, nil } From f686f2f83d7825b38761b0e537c0b46ddac15e6f Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 08:04:57 -0800 Subject: [PATCH 056/103] cmd/evm/internal/t8ntool,cmd/evm: add missing EWASM interpreter flag to 'evm t8n' command Date: 2022-11-11 08:04:57-08:00 Signed-off-by: meows --- cmd/evm/internal/t8ntool/transition.go | 11 ++++++++--- cmd/evm/main.go | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index a7d2486877..3ad12890c4 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -179,15 +179,20 @@ func Transition(ctx *cli.Context) error { prestate.Env = *inputData.Env vmConfig := vm.Config{ - Tracer: tracer, - Debug: (tracer != nil), - EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), + Tracer: tracer, + Debug: (tracer != nil), + EVMInterpreter: ctx.String(utils.EVMInterpreterFlag.Name), + EWASMInterpreter: ctx.String(utils.EWASMInterpreterFlag.Name), } if vmConfig.EVMInterpreter != "" { vm.InitEVMCEVM(vmConfig.EVMInterpreter) } + if vmConfig.EWASMInterpreter != "" { + vm.InitEVMCEwasm(vmConfig.EWASMInterpreter) + } + // Construct the chainconfig var chainConfig ctypes.ChainConfigurator if cConf, extraEips, err := tests.GetChainConfig(ctx.String(ForknameFlag.Name)); err != nil { diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 8b73343e4b..92131edc5e 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -159,6 +159,7 @@ var stateTransitionCommand = &cli.Command{ t8ntool.RewardFlag, t8ntool.VerbosityFlag, utils.EVMInterpreterFlag, + utils.EWASMInterpreterFlag, }, } From 4a4a3073c3219f95b9dd7316f29059517bcb0aad Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 09:39:12 -0800 Subject: [PATCH 057/103] tests: DO NOT SKIP tests for Berlin,London when using -evmc.vm/wasm Date: 2022-11-11 09:39:12-08:00 Signed-off-by: meows --- tests/state_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/state_test.go b/tests/state_test.go index 1592abd5c7..6a5e07227a 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -72,10 +72,10 @@ func TestState(t *testing.T) { if *testEVM != "" || *testEWASM != "" { // Berlin tests are not expected to pass for external EVMs, yet. // - st.skipFork("^Berlin$") // ETH - st.skipFork("Magneto") // ETC - st.skipFork("London") // ETH - st.skipFork("Mystique") // ETC + // st.skipFork("Berlin") // ETH + // st.skipFork("Magneto") // ETC + // st.skipFork("London") // ETH + // st.skipFork("Mystique") // ETC } // The multigeth data type (like the Ethereum Foundation data type) doesn't support // the ETC_Mystique fork/feature configuration, which omits EIP1559 and the associated BASEFEE From 75da3cab2bb7bbe6d9ef4c4f2fe2708658be7760 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 09:39:56 -0800 Subject: [PATCH 058/103] core/vm: reimplement evmc.Storage* assignment matrix Reference taken from https://github.com/ethereum/evmc/blob/35112aed7b4e0fd2f54cf2e3272ba9117a0c6494/include/evmc/evmc.h Date: 2022-11-11 09:39:56-08:00 Signed-off-by: meows --- core/vm/evmc.go | 189 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 172 insertions(+), 17 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 70acfedb6a..bd3f913a27 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -188,39 +188,194 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev return evmc.StorageModified } - resetClearRefund := vars.NetSstoreResetClearRefund - cleanRefund := vars.NetSstoreResetRefund + // /** + // * The effect of an attempt to modify a contract storage item. + // * + // * See @ref storagestatus for additional information about design of this enum + // * and analysis of the specification. + // * + // * For the purpose of explaining the meaning of each element, the following + // * notation is used: + // * - 0 is zero value, + // * - X != 0 (X is any value other than 0), + // * - Y != 0, Y != X, (Y is any value other than X and 0), + // * - Z != 0, Z != X, Z != X (Z is any value other than Y and X and 0), + // * - the "o -> c -> v" triple describes the change status in the context of: + // * - o: original value (cold value before a transaction started), + // * - c: current storage value, + // * - v: new storage value to be set. + // * + // * The order of elements follows EIPs introducing net storage gas costs: + // * - EIP-2200: https://eips.ethereum.org/EIPS/eip-2200, + // * - EIP-1283: https://eips.ethereum.org/EIPS/eip-1283. + // */ + // enum evmc_storage_status + // { + // /** + // * The new/same value is assigned to the storage item without affecting the cost structure. + // * + // * The storage value item is either: + // * - left unchanged (c == v) or + // * - the dirty value (o != c) is modified again (c != v). + // * This is the group of cases related to minimal gas cost of only accessing warm storage. + // * 0|X -> 0 -> 0 (current value unchanged) + // * 0|X|Y -> Y -> Y (current value unchanged) + // * 0|X -> Y -> Z (modified previously added/modified value) + // * + // * This is "catch all remaining" status. I.e. if all other statuses are correctly matched + // * this status should be assigned to all remaining cases. + // */ + // EVMC_STORAGE_ASSIGNED = 0, + status = evmc.StorageAssigned + // + // /** + // * A new storage item is added by changing + // * the current clean zero to a nonzero value. + // * 0 -> 0 -> Z + // */ + // EVMC_STORAGE_ADDED = 1, + // + if original.IsZero() && current.IsZero() && !value.IsZero() { + status = evmc.StorageAdded + } + // /** + // * A storage item is deleted by changing + // * the current clean nonzero to the zero value. + // * X -> X -> 0 + // */ + // EVMC_STORAGE_DELETED = 2, + // + if !original.IsZero() && !current.IsZero() && value.IsZero() { + status = evmc.StorageDeleted + } + // /** + // * A storage item is modified by changing + // * the current clean nonzero to other nonzero value. + // * X -> X -> Z + // */ + // EVMC_STORAGE_MODIFIED = 3, + // + if !original.IsZero() && !current.IsZero() && !value.IsZero() { + if original == current { + status = evmc.StorageModified + } + } + // /** + // * A storage item is added by changing + // * the current dirty zero to a nonzero value other than the original value. + // * X -> 0 -> Z + // */ + // EVMC_STORAGE_DELETED_ADDED = 4, + // + if !original.IsZero() && current.IsZero() && !value.IsZero() { + if !original.Eq(value) { + status = evmc.StorageDeletedAdded + } + } + // /** + // * A storage item is deleted by changing + // * the current dirty nonzero to the zero value and the original value is not zero. + // * X -> Y -> 0 + // */ + // EVMC_STORAGE_MODIFIED_DELETED = 5, + // + if !original.IsZero() && !current.IsZero() && value.IsZero() { + if original != current { + status = evmc.StorageModifiedDeleted + } + } + // /** + // * A storage item is added by changing + // * the current dirty zero to the original value. + // * X -> 0 -> X + // */ + // EVMC_STORAGE_DELETED_RESTORED = 6, + // + if !original.IsZero() && current.IsZero() && !value.IsZero() { + if original.Eq(value) { + status = evmc.StorageDeletedRestored + } + } + // /** + // * A storage item is deleted by changing + // * the current dirty nonzero to the original zero value. + // * 0 -> Y -> 0 + // */ + // EVMC_STORAGE_ADDED_DELETED = 7, + // + if original.IsZero() && !current.IsZero() && value.IsZero() { + status = evmc.StorageAddedDeleted + } + // /** + // * A storage item is modified by changing + // * the current dirty nonzero to the original nonzero value other than the current value. + // * X -> Y -> X + // */ + // EVMC_STORAGE_MODIFIED_RESTORED = 8 + // }; + // + if !original.IsZero() && !current.IsZero() && !value.IsZero() { + if original != current && original.Eq(value) { + status = evmc.StorageModifiedRestored + } + } - if isIstanbul { - resetClearRefund = vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200 // 19200 - cleanRefund = vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200 // 4200 + // if original == current { + // // 0 -> 0 -> Z + // if original.IsZero() { // create slot (2.1.1) + // return evmc.StorageAdded + // } + // + // if value.IsZero() { // delete slot (2.1.2b) + // host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + // return evmc.StorageDeleted + // } + // return evmc.StorageModified + // } + // + // if !original.IsZero() { + // if current.IsZero() { // recreate slot (2.2.1.1) + // host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) + // } else if value.IsZero() { // delete slot (2.2.1.2) + // host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + // } + // } + // if original.Eq(value) { + // if original.IsZero() { // reset to original inexistent slot (2.2.2.1) + // host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) + // } else { // reset to original existing slot (2.2.2.2) + // host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) + // } + // } + + if current.Eq(value) { + return } if original == current { - if original.IsZero() { // create slot (2.1.1) - return evmc.StorageAdded + if original.IsZero() { + return } - if value.IsZero() { // delete slot (2.1.2b) + if value.IsZero() { host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - return evmc.StorageDeleted } - return evmc.StorageModified + return } if !original.IsZero() { - if current.IsZero() { // recreate slot (2.2.1.1) + if current.IsZero() { host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) - } else if value.IsZero() { // delete slot (2.2.1.2) + } else if value.IsZero() { host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) } } if original.Eq(value) { - if original.IsZero() { // reset to original inexistent slot (2.2.2.1) - host.env.StateDB.AddRefund(resetClearRefund) - } else { // reset to original existing slot (2.2.2.2) - host.env.StateDB.AddRefund(cleanRefund) + if original.IsZero() { + host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) + } else { + host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) } } - return evmc.StorageAssigned + return status } func (host *hostContext) GetBalance(addr evmc.Address) evmc.Hash { From fbef1fb6ff7941c9a920d02767ea12fc0eb231ed Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 10:12:15 -0800 Subject: [PATCH 059/103] core/vm: still-failing attempt to install EVMC with revisions Date: 2022-11-11 10:12:15-08:00 Signed-off-by: meows --- core/vm/evmc.go | 122 +++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index bd3f913a27..a5af0a1f15 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -167,27 +167,6 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev host.env.StateDB.SetState(addr, key, common.BytesToHash(value.Bytes())) - // Here's a great example of one of the limits of our (core-geth) current chainconfig interface model. - // Should we handle the logic here about historic-featuro logic (which really is nice, because when reading the strange-incantation implemations, it's nice to see why it is), - // or should we handle the question of where we handle the rest of the questions like this, since this logic is - // REALLY logic that belongs to the abstract idea of a chainconfiguration (aka chainconfig), which makes sense - // but depends on ECIPs having steadier and more predictable logic. - - // isIstanbul was originally defined as two conditions: EIP1884, EIP2200; - // but now the code expects any configuration to always apply (or have applied) them together at (as) the Istanbul fork. - isIstanbul := getRevision(host.env) >= evmc.Istanbul - - if !isIstanbul { - status = evmc.StorageModified - if oldValue.IsZero() { - return evmc.StorageAdded - } else if value.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreRefundGas) - return evmc.StorageDeleted - } - return evmc.StorageModified - } - // /** // * The effect of an attempt to modify a contract storage item. // * @@ -246,7 +225,9 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev // EVMC_STORAGE_DELETED = 2, // if !original.IsZero() && !current.IsZero() && value.IsZero() { - status = evmc.StorageDeleted + if original == current { + status = evmc.StorageDeleted + } } // /** // * A storage item is modified by changing @@ -320,6 +301,72 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev } } + revision := getRevision(host.env) + + if revision >= evmc.Istanbul /* EIP-1884, EIP-2200 */ { + if current.Eq(value) { + return + } + if original == current { + if value.IsZero() { + host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) + } + return + } + if !original.IsZero() { + if current.IsZero() { + host.env.StateDB.SubRefund(vars.SstoreClearsScheduleRefundEIP2200) + } else if value.IsZero() { + host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) + } + } + if original.Eq(value) { + if original.IsZero() { + host.env.StateDB.AddRefund(vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200) + } else { + host.env.StateDB.AddRefund(vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200) + } + } + return + + } else if revision == evmc.Constantinople { + if current.Eq(value) { + return + } + + if original == current { + if original.IsZero() { + return + } + if value.IsZero() { + host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + } + return + } + if !original.IsZero() { + if current.IsZero() { + host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) + } else if value.IsZero() { + host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + } + } + if original.Eq(value) { + if original.IsZero() { + host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) + } else { + host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) + } + } + return + } + + // else (default, homestead on) + if !current.IsZero() && value.IsZero() { + host.env.StateDB.AddRefund(vars.SstoreRefundGas) + } + + return status + // if original == current { // // 0 -> 0 -> Z // if original.IsZero() { // create slot (2.1.1) @@ -347,35 +394,6 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev // host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) // } // } - - if current.Eq(value) { - return - } - - if original == current { - if original.IsZero() { - return - } - if value.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - } - return - } - if !original.IsZero() { - if current.IsZero() { - host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) - } else if value.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - } - } - if original.Eq(value) { - if original.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) - } else { - host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) - } - } - return status } func (host *hostContext) GetBalance(addr evmc.Address) evmc.Hash { @@ -540,7 +558,7 @@ func getRevision(env *EVM) evmc.Revision { return evmc.London case conf.IsEnabled(conf.GetEIP2565Transition, n): return evmc.Berlin - case conf.IsEnabled(conf.GetEIP1884Transition, n): + case conf.IsEnabled(conf.GetEIP2200Transition, n): return evmc.Istanbul case conf.IsEnabled(conf.GetEIP1283DisableTransition, n): return evmc.Petersburg From e11ae45ef766b566d33aca178dd3b03fcf330f4e Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 13:32:09 -0800 Subject: [PATCH 060/103] core/vm: refactor/rewrite sstore handler for evmc host This is still a WIP. - native: all tests passing - hera: all tests passing go test -v ./tests -run State -evmc.ewasm=/home/ia/go/src/github.com/ethereum/go-ethereum/build/_workspace/hera/build/src/libhera.so |& tee state.out - evmone: many tests failing go test -v ./tests -run State -evmc.evm=/home/ia/go/src/github.com/ethereum/go-ethereum/build/_workspace/evmone/lib/libevmone.so |& tee state.out Is this an evmone problem? An EVMC host-binding implementation problem? Date: 2022-11-11 13:32:09-08:00 Signed-off-by: meows --- core/vm/evmc.go | 196 +++++++++++++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 76 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index a5af0a1f15..98e43102f7 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -134,14 +134,10 @@ func (host *hostContext) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.Ac func (host *hostContext) AccountExists(evmcAddr evmc.Address) bool { addr := common.Address(evmcAddr) - if getRevision(host.env) >= evmc.SpuriousDragon /* EIP-161 */ { - if !host.env.StateDB.Empty(addr) { - return true - } - } else if host.env.StateDB.Exist(addr) { - return true + if host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP161dTransition, host.env.Context.BlockNumber) /* EIP-161 */ { + return !host.env.StateDB.Empty(addr) } - return false + return host.env.StateDB.Exist(addr) } func (host *hostContext) GetStorage(addr evmc.Address, evmcKey evmc.Hash) evmc.Hash { @@ -151,22 +147,7 @@ func (host *hostContext) GetStorage(addr evmc.Address, evmcKey evmc.Hash) evmc.H return evmc.Hash(value.Bytes32()) } -func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, evmcValue evmc.Hash) (status evmc.StorageStatus) { - addr := common.Address(evmcAddr) - key := common.Hash(evmcKey) - value := new(uint256.Int).SetBytes(evmcValue[:]) - var oldValue uint256.Int - oldValue.SetBytes(host.env.StateDB.GetState(addr, key).Bytes()) - if oldValue.Eq(value) { - return evmc.StorageAssigned - } - - var current, original uint256.Int - current.SetBytes(host.env.StateDB.GetState(addr, key).Bytes()) - original.SetBytes(host.env.StateDB.GetCommittedState(addr, key).Bytes()) - - host.env.StateDB.SetState(addr, key, common.BytesToHash(value.Bytes())) - +func (host *hostContext) storageStatus(original, current, value *uint256.Int) (status evmc.StorageStatus) { // /** // * The effect of an attempt to modify a contract storage item. // * @@ -300,38 +281,135 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev status = evmc.StorageModifiedRestored } } + return status +} + +func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, evmcValue evmc.Hash) (status evmc.StorageStatus) { + addr := common.Address(evmcAddr) + key := common.Hash(evmcKey) + value := new(uint256.Int).SetBytes(evmcValue[:]) + + var current, original = new(uint256.Int), new(uint256.Int) + current.SetBytes(host.env.StateDB.GetState(addr, key).Bytes()) + original.SetBytes(host.env.StateDB.GetCommittedState(addr, key).Bytes()) + + host.env.StateDB.SetState(addr, key, common.BytesToHash(value.Bytes())) - revision := getRevision(host.env) + // defer func() { + status = host.storageStatus(original, current, value) + // }() - if revision >= evmc.Istanbul /* EIP-1884, EIP-2200 */ { + if getRevision(host.env) == evmc.Constantinople /* EIP-1283 */ { if current.Eq(value) { - return + return evmc.StorageAssigned } - if original == current { + + // (X -> X) -> Y + if original.Eq(current) { + // 0 -> 0 -> Y + if original.IsZero() { + return evmc.StorageAdded + } + // X -> X -> 0 if value.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) + host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + return evmc.StorageDeleted } - return + return evmc.StorageModified } if !original.IsZero() { + // X -> 0 -> Z if current.IsZero() { - host.env.StateDB.SubRefund(vars.SstoreClearsScheduleRefundEIP2200) + host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) + // X -> 0 -> 0 } else if value.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) + host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) } } if original.Eq(value) { if original.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200) + host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) } else { - host.env.StateDB.AddRefund(vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200) + host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) } } - return + return evmc.StorageAssigned + } - } else if revision == evmc.Constantinople { + if getRevision(host.env) < evmc.Istanbul { if current.Eq(value) { - return + return evmc.StorageAssigned + } + + if current.IsZero() && !value.IsZero() { + return evmc.StorageAdded + } + if !current.IsZero() && value.IsZero() { + host.env.StateDB.AddRefund(vars.SstoreRefundGas) + return evmc.StorageDeleted + } + return evmc.StorageAssigned + + } else /* Istanbul: EIP-2200 */ { + + /* + Replace SSTORE opcode gas cost calculation (including refunds) with the following logic: + + If gasleft is less than or equal to gas stipend, fail the current call frame with ‘out of gas’ exception. + + If current value equals new value (this is a no-op), SLOAD_GAS is deducted. + + If current value does not equal new value + If original value equals current value (this storage slot has not been changed by the current execution context) + If original value is 0, SSTORE_SET_GAS is deducted. + Otherwise, SSTORE_RESET_GAS gas is deducted. If new value is 0, add SSTORE_CLEARS_SCHEDULE gas to refund counter. + If original value does not equal current value (this storage slot is dirty), SLOAD_GAS gas is deducted. Apply both of the following clauses. + If original value is not 0 + If current value is 0 (also means that new value is not 0), remove SSTORE_CLEARS_SCHEDULE gas from refund counter. + If new value is 0 (also means that current value is not 0), add SSTORE_CLEARS_SCHEDULE gas to refund counter. + If original value equals new value (this storage slot is reset) + If original value is 0, add SSTORE_SET_GAS - SLOAD_GAS to refund counter. + Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS gas to refund counter. + + --- + + If gasleft is less than or equal to gas stipend, fail the current call frame with ‘out of gas’ exception. + :: NO IMPLEMENTATION + + If current value equals new value (this is a no-op), SLOAD_GAS is deducted. + :: SHORT-CIRCUIT near top of function + + If current value does not equal new value + + If original value equals current value (this storage slot has not been changed by the current execution context) + + + If original value is 0, SSTORE_SET_GAS is deducted. + :: 0 -> 0 -> Z: evmc.StorageAdded + + Otherwise, SSTORE_RESET_GAS gas is deducted. + :: X -> X -> Z: evmc.StorageModified + + If new value is 0, add SSTORE_CLEARS_SCHEDULE gas to refund counter. + :: X -> X -> 0: evmc.StorageDeleted + + If original value does not equal current value (this storage slot is dirty), SLOAD_GAS gas is deducted. + Apply both of the following clauses. + + If original value is not 0 + If current value is 0 (also means that new value is not 0), remove SSTORE_CLEARS_SCHEDULE gas from refund counter. + :: X -> 0 -> X: evmc.StorageAddedDeleted + + If new value is 0 (also means that current value is not 0), add SSTORE_CLEARS_SCHEDULE gas to refund counter. + :: X -> Z -> 0: evmc.StorageDeleted + + If original value equals new value (this storage slot is reset) + If original value is 0, add SSTORE_SET_GAS - SLOAD_GAS to refund counter. + Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS gas to refund counter. + */ + + if current.Eq(value) { + return evmc.StorageAssigned } if original == current { @@ -339,61 +417,27 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev return } if value.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) } return } if !original.IsZero() { if current.IsZero() { - host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) + host.env.StateDB.SubRefund(vars.SstoreClearsScheduleRefundEIP2200) } else if value.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) } } if original.Eq(value) { if original.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) + host.env.StateDB.AddRefund(vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200) } else { - host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) + host.env.StateDB.AddRefund(vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200) } } - return - } - - // else (default, homestead on) - if !current.IsZero() && value.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreRefundGas) } - return status - - // if original == current { - // // 0 -> 0 -> Z - // if original.IsZero() { // create slot (2.1.1) - // return evmc.StorageAdded - // } - // - // if value.IsZero() { // delete slot (2.1.2b) - // host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - // return evmc.StorageDeleted - // } - // return evmc.StorageModified - // } - // - // if !original.IsZero() { - // if current.IsZero() { // recreate slot (2.2.1.1) - // host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) - // } else if value.IsZero() { // delete slot (2.2.1.2) - // host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - // } - // } - // if original.Eq(value) { - // if original.IsZero() { // reset to original inexistent slot (2.2.2.1) - // host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) - // } else { // reset to original existing slot (2.2.2.2) - // host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) - // } - // } + return } func (host *hostContext) GetBalance(addr evmc.Address) evmc.Hash { From 9d3899a66b5376212a42ba777adc3975b536712a Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 11 Nov 2022 14:08:10 -0800 Subject: [PATCH 061/103] cmd/echainspec,cmd/faucet,cmd/geth,eth/tracers/internal/tracetest,ethclient,integration,node,params/confp/generic,convert_test,params/confp/tconvert,params/types/parity,tests: SA1019: package io/ioutil is deprecated As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) Date: 2022-11-11 14:08:10-08:00 Signed-off-by: meows --- cmd/echainspec/util.go | 6 +++--- cmd/faucet/faucet.go | 5 ++--- cmd/geth/chaincmd.go | 3 +-- .../internal/tracetest/calltrace_parity_test.go | 10 +++++----- ethclient/docsgen_test.go | 3 +-- integration/configurator_test.go | 6 +++--- node/node_test.go | 3 +-- params/confp/generic/generic_test.go | 10 +++++----- params/confp/internal/convert_test.go | 4 ++-- params/confp/tconvert/aleth_test.go | 6 +++--- params/types/parity/parity_configurator_test.go | 4 ++-- params/types/parity/parity_test.go | 3 +-- tests/difficulty_mgen_test.go | 9 ++++----- tests/params.go | 7 +++---- tests/state_mgen_test.go | 7 +++---- 15 files changed, 39 insertions(+), 47 deletions(-) diff --git a/cmd/echainspec/util.go b/cmd/echainspec/util.go index c97da2c8e2..78a2e2771d 100644 --- a/cmd/echainspec/util.go +++ b/cmd/echainspec/util.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -15,9 +15,9 @@ import ( func readInputData(ctx *cli.Context) ([]byte, error) { if !ctx.GlobalIsSet(fileInFlag.Name) { - return ioutil.ReadAll(os.Stdin) + return io.ReadAll(os.Stdin) } - return ioutil.ReadFile(ctx.GlobalString(fileInFlag.Name)) + return os.ReadFile(ctx.GlobalString(fileInFlag.Name)) } func unmarshalChainSpec(format string, data []byte) (conf ctypes.Configurator, err error) { diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index a3d466e662..e50944a5ee 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -27,7 +27,6 @@ import ( "fmt" "html/template" "io" - "io/ioutil" "math" "math/big" "net/http" @@ -184,7 +183,7 @@ func parseChainFlags() (gs *genesisT.Genesis, bs string, netid uint64) { // allow overrides if *genesisFlag != "" { - blob, err := ioutil.ReadFile(*genesisFlag) + blob, err := os.ReadFile(*genesisFlag) if err != nil { log.Crit("Failed to read genesis block contents", "genesis", *genesisFlag, "err", err) } @@ -414,7 +413,7 @@ func main() { keystorePath := filepath.Join(faucetDirFromChainIndicators(chainID, genesisHash), "keys") ks := keystore.NewKeyStore(keystorePath, keystore.StandardScryptN, keystore.StandardScryptP) - if blob, err = ioutil.ReadFile(*accJSONFlag); err != nil { + if blob, err = os.ReadFile(*accJSONFlag); err != nil { log.Crit("Failed to read account key contents", "file", *accJSONFlag, "err", err) } acc, err := ks.Import(blob, pass, pass) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index ec2e27716d..5f90776a92 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -20,7 +20,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "runtime" "strconv" @@ -179,7 +178,7 @@ func initGenesis(ctx *cli.Context) error { } genesis := new(genesisT.Genesis) - bs, err := ioutil.ReadFile(genesisPath) + bs, err := os.ReadFile(genesisPath) if err != nil { utils.Fatalf("Failed to read genesis file: %v", err) } diff --git a/eth/tracers/internal/tracetest/calltrace_parity_test.go b/eth/tracers/internal/tracetest/calltrace_parity_test.go index f3c981468f..0a681f9eee 100644 --- a/eth/tracers/internal/tracetest/calltrace_parity_test.go +++ b/eth/tracers/internal/tracetest/calltrace_parity_test.go @@ -3,8 +3,8 @@ package tracetest import ( "encoding/json" "fmt" - "io/ioutil" "math/big" + "os" "path/filepath" "reflect" "strings" @@ -51,7 +51,7 @@ type callTracerParityTest struct { func callTracerParityTestRunner(tracerName string, filename string, dirPath string, t testing.TB) error { // Call tracer test found, read if from disk - blob, err := ioutil.ReadFile(filepath.Join("testdata", dirPath, filename)) + blob, err := os.ReadFile(filepath.Join("testdata", dirPath, filename)) if err != nil { return fmt.Errorf("failed to read testcase: %v", err) } @@ -134,7 +134,7 @@ func TestCallTracerParityNative(t *testing.T) { } func testCallTracerParity(tracerName string, dirPath string, t *testing.T) { - files, err := ioutil.ReadDir(filepath.Join("testdata", dirPath)) + files, err := os.ReadDir(filepath.Join("testdata", dirPath)) if err != nil { t.Fatalf("failed to retrieve tracer test suite: %v", err) } @@ -208,7 +208,7 @@ type stateDiffTest struct { func stateDiffTracerTestRunner(tracerName string, filename string, dirPath string, t testing.TB) error { // Call tracer test found, read if from disk - blob, err := ioutil.ReadFile(filepath.Join("testdata", dirPath, filename)) + blob, err := os.ReadFile(filepath.Join("testdata", dirPath, filename)) if err != nil { return fmt.Errorf("failed to read testcase: %v", err) } @@ -300,7 +300,7 @@ func TestStateDiffTracerNative(t *testing.T) { // TestStateDiffTracer Iterates over all the input-output datasets in the state diff tracer test harness and // runs the JavaScript tracers against them. func testStateDiffTracer(tracerName string, dirPath string, t *testing.T) { - files, err := ioutil.ReadDir(filepath.Join("testdata", dirPath)) + files, err := os.ReadDir(filepath.Join("testdata", dirPath)) if err != nil { t.Fatalf("failed to retrieve tracer test suite: %v", err) } diff --git a/ethclient/docsgen_test.go b/ethclient/docsgen_test.go index ad3d8b029c..058a8888b9 100644 --- a/ethclient/docsgen_test.go +++ b/ethclient/docsgen_test.go @@ -3,7 +3,6 @@ package ethclient import ( "encoding/json" "fmt" - "io/ioutil" "os" "sort" "strings" @@ -49,7 +48,7 @@ func TestRPCDiscover_BuildStatic(t *testing.T) { if err != nil { t.Fatal(err) } - err = ioutil.WriteFile("../build/static/openrpc.json", data, os.ModePerm) + err = os.WriteFile("../build/static/openrpc.json", data, os.ModePerm) if err != nil { t.Fatal(err) } diff --git a/integration/configurator_test.go b/integration/configurator_test.go index 77c919b409..b85f25af11 100644 --- a/integration/configurator_test.go +++ b/integration/configurator_test.go @@ -18,8 +18,8 @@ package integration import ( "encoding/json" - "io/ioutil" "log" + "os" "path/filepath" "strings" "testing" @@ -176,7 +176,7 @@ func TestEquivalent_ReadParity(t *testing.T) { a := tests.Forks[k] b := &parity.ParityChainSpec{} - bs, err := ioutil.ReadFile(filepath.Join(parityP, v)) + bs, err := os.ReadFile(filepath.Join(parityP, v)) if err != nil { t.Fatal(err) } @@ -225,7 +225,7 @@ func TestParityGeneses(t *testing.T) { for _, tt := range testes { p := filepath.Join("..", "params", "parity.json.d", tt.filename) pspec := &parity.ParityChainSpec{} - b, err := ioutil.ReadFile(p) + b, err := os.ReadFile(p) if err != nil { t.Fatal(err) } diff --git a/node/node_test.go b/node/node_test.go index cec263fb00..d1f89b4c1f 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "os" @@ -328,7 +327,7 @@ func TestOpenRPCMetaSchemaSpecLatest(t *testing.T) { } localJSONFilePath := "./testdata/open-rpc-meta-schema-1.14.0.json" - localJSONFile, err := ioutil.ReadFile(localJSONFilePath) + localJSONFile, err := os.ReadFile(localJSONFilePath) if err != nil { t.Fatalf("failed to load local spec JSON file: %v", err) } diff --git a/params/confp/generic/generic_test.go b/params/confp/generic/generic_test.go index 50f0560867..76204b8793 100644 --- a/params/confp/generic/generic_test.go +++ b/params/confp/generic/generic_test.go @@ -2,8 +2,8 @@ package generic import ( "encoding/json" - "io/ioutil" "math/big" + "os" "path/filepath" "reflect" "testing" @@ -39,7 +39,7 @@ func TestUnmarshalChainConfigurator(t *testing.T) { } for i, c := range cases { - b, err := ioutil.ReadFile(c.file) + b, err := os.ReadFile(c.file) if err != nil { t.Fatal(err) } @@ -250,19 +250,19 @@ func TestUnmarshalChainConfigurator2(t *testing.T) { wantType: reflect.TypeOf(&coregeth.CoreGethChainConfig{}), }, // FIXME - //{ + // { // versionid: "latest", // raw: func() string { // b, _ := json.MarshalIndent(params.ClassicChainConfig, "", " ") // return string(b) // }(), // wantType: reflect.TypeOf(&multigeth.CoreGethChainConfig{}), - //}, + // }, } head := uint64(10_000_000) - //outer: + // outer: for i := 0; i < len(cases); i++ { for j := 0; j < len(cases); j++ { if j >= i { diff --git a/params/confp/internal/convert_test.go b/params/confp/internal/convert_test.go index fff2acaf3c..2ba4b2f9ef 100644 --- a/params/confp/internal/convert_test.go +++ b/params/confp/internal/convert_test.go @@ -19,8 +19,8 @@ package convert_test import ( "encoding/json" "fmt" - "io/ioutil" "math/big" + "os" "path/filepath" "reflect" "testing" @@ -36,7 +36,7 @@ import ( ) func mustOpenF(t *testing.T, fabbrev string, into interface{}) { - b, err := ioutil.ReadFile(filepath.Join("..", "testdata", fmt.Sprintf("stureby_%s.json", fabbrev))) + b, err := os.ReadFile(filepath.Join("..", "testdata", fmt.Sprintf("stureby_%s.json", fabbrev))) if err != nil { t.Fatal(err) } diff --git a/params/confp/tconvert/aleth_test.go b/params/confp/tconvert/aleth_test.go index 8468049211..f73bdc0f02 100644 --- a/params/confp/tconvert/aleth_test.go +++ b/params/confp/tconvert/aleth_test.go @@ -18,7 +18,7 @@ package tconvert import ( "encoding/json" - "io/ioutil" + "os" "path/filepath" "testing" @@ -31,7 +31,7 @@ import ( // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. func TestAlethSturebyConverter(t *testing.T) { // Read GETH genesis type. - blob, err := ioutil.ReadFile(filepath.Join("..", "testdata", "stureby_geth.json")) + blob, err := os.ReadFile(filepath.Join("..", "testdata", "stureby_geth.json")) if err != nil { t.Fatalf("could not read file: %v", err) } @@ -47,7 +47,7 @@ func TestAlethSturebyConverter(t *testing.T) { } // Read the aleth JSON spec. - expBlob, err := ioutil.ReadFile(filepath.Join("..", "testdata", "stureby_aleth.json")) + expBlob, err := os.ReadFile(filepath.Join("..", "testdata", "stureby_aleth.json")) if err != nil { t.Fatalf("could not read file: %v", err) } diff --git a/params/types/parity/parity_configurator_test.go b/params/types/parity/parity_configurator_test.go index 801fbd60ca..962087c45a 100644 --- a/params/types/parity/parity_configurator_test.go +++ b/params/types/parity/parity_configurator_test.go @@ -18,7 +18,7 @@ package parity import ( "encoding/json" - "io/ioutil" + "os" "testing" "github.com/ethereum/go-ethereum/common/math" @@ -62,7 +62,7 @@ func TestParityChainSpec_GetSetUint64(t *testing.T) { func TestParityChainSpec_GetEIP2537(t *testing.T) { specFile := "../../parity.json.d/foundation.json" - b, err := ioutil.ReadFile(specFile) + b, err := os.ReadFile(specFile) if err != nil { t.Fatalf("read file: %v", err) } diff --git a/params/types/parity/parity_test.go b/params/types/parity/parity_test.go index f1a5b29f04..5c5ff39f04 100644 --- a/params/types/parity/parity_test.go +++ b/params/types/parity/parity_test.go @@ -18,7 +18,6 @@ package parity import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -98,7 +97,7 @@ func TestParityChainSpec_UnmarshalJSON(t *testing.T) { return nil } t.Run(info.Name(), func(t *testing.T) { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { t.Fatal(err) } diff --git a/tests/difficulty_mgen_test.go b/tests/difficulty_mgen_test.go index b9bc3a5206..b5e73e45d4 100644 --- a/tests/difficulty_mgen_test.go +++ b/tests/difficulty_mgen_test.go @@ -20,7 +20,6 @@ import ( "bytes" "crypto/sha1" "encoding/json" - "io/ioutil" "math/big" "os" "path/filepath" @@ -103,7 +102,7 @@ func TestDifficultyTestConfigGen(t *testing.T) { if err != nil { t.Fatal(err) } - err = ioutil.WriteFile(specPath, j, os.ModePerm) + err = os.WriteFile(specPath, j, os.ModePerm) if err != nil { t.Fatal(err) } @@ -131,7 +130,7 @@ func TestDifficultyTestConfigGen(t *testing.T) { if err != nil { t.Fatal(err) } - err = ioutil.WriteFile(specPath, j, os.ModePerm) + err = os.WriteFile(specPath, j, os.ModePerm) if err != nil { t.Fatal(err) } @@ -157,7 +156,7 @@ func TestDifficultyGen(t *testing.T) { } // Truncate/touch output file. - err = ioutil.WriteFile(outNDJSONFile, []byte{}, os.ModePerm) + err = os.WriteFile(outNDJSONFile, []byte{}, os.ModePerm) if err != nil { t.Fatal(err) } @@ -197,7 +196,7 @@ func TestDifficultyGen(t *testing.T) { } mustSha1SumForFile := func(filePath string) []byte { - b, err := ioutil.ReadFile(filePath) + b, err := os.ReadFile(filePath) if err != nil { t.Fatal(err) } diff --git a/tests/params.go b/tests/params.go index b438fe0484..772d4fdd0a 100644 --- a/tests/params.go +++ b/tests/params.go @@ -20,7 +20,6 @@ import ( "crypto/sha1" "encoding/json" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -113,7 +112,7 @@ func readJSONFromFile(name string, value interface{}) (sha1sum []byte, err error } else { fi.Close() } - b, err := ioutil.ReadFile(name) + b, err := os.ReadFile(name) if err != nil { panic(fmt.Sprintf("%s err: %s\n%s", name, err, b)) } @@ -160,7 +159,7 @@ func writeDifficultyConfigFileParity(conf ctypes.ChainConfigurator, forkName str return "", [20]byte{}, err } - err = ioutil.WriteFile(filepath.Join("..", "params", "parity.json.d", specFilepath), b, os.ModePerm) + err = os.WriteFile(filepath.Join("..", "params", "parity.json.d", specFilepath), b, os.ModePerm) if err != nil { return "", [20]byte{}, err } @@ -291,7 +290,7 @@ func init() { config = pspec b, _ := json.MarshalIndent(pspec, "", " ") writePath := filepath.Join(paritySpecsDir, v) - err := ioutil.WriteFile(writePath, b, os.ModePerm) + err := os.WriteFile(writePath, b, os.ModePerm) if err != nil { panic(fmt.Sprintf("failed to write chainspec; wd: %s, config: %v/file: %v", wd, k, writePath)) } diff --git a/tests/state_mgen_test.go b/tests/state_mgen_test.go index 1e16c1ab5a..e01c061759 100644 --- a/tests/state_mgen_test.go +++ b/tests/state_mgen_test.go @@ -20,7 +20,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -118,7 +117,7 @@ func TestGenStateAll(t *testing.T) { if err != nil { t.Fatal(err) } - err = ioutil.WriteFile(fmt.Sprintf("%s_configs.json", dir), b, os.ModePerm) + err = os.WriteFile(fmt.Sprintf("%s_configs.json", dir), b, os.ModePerm) if err != nil { t.Fatal(err) } @@ -175,7 +174,7 @@ func (tm *testMatcherGen) testWriteTest(t *testing.T, name string, test *StateTe // Note that parallelism can cause greasy bugs around file during read/write which is why // we use a temporary file instead of immediately overwriting the canonical file in the first place; // for example, I saw regular encoding errors without this pattern. - tmpFile, err := ioutil.TempFile(os.TempDir(), "geth-state-test-generation") + tmpFile, err := os.CreateTemp(os.TempDir(), "geth-state-test-generation") if err != nil { t.Fatal(err) } @@ -404,7 +403,7 @@ func TestGenStateCoreGethConfigs(t *testing.T) { coregethSpecsDir, strcase.ToSnake(subtest.Fork)+"_test.json", ) - err = ioutil.WriteFile(filename, b, os.ModePerm) + err = os.WriteFile(filename, b, os.ModePerm) if err != nil { t.Fatal(err) } From dcc3ef25954c6291c175dec97ba23b75377c38d6 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 07:41:32 -0800 Subject: [PATCH 062/103] tests: [fixup/post-merge] s/ioutil.WriteFile/os.WriteFile/g Date: 2022-12-06 07:41:32-08:00 Signed-off-by: meows --- tests/difficulty_mgen_test.go | 3 +-- tests/state_mgen_test.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/difficulty_mgen_test.go b/tests/difficulty_mgen_test.go index 8b9d23ef2e..1de0b6a746 100644 --- a/tests/difficulty_mgen_test.go +++ b/tests/difficulty_mgen_test.go @@ -19,7 +19,6 @@ package tests import ( "encoding/json" "fmt" - "io/ioutil" "math/big" "math/rand" "os" @@ -183,7 +182,7 @@ func writeDifficultyTestFileJSON(t *testing.T, filePath string, tests map[string if err != nil { t.Fatal(err) } - err = ioutil.WriteFile(filePath, b, os.ModePerm) + err = os.WriteFile(filePath, b, os.ModePerm) if err != nil { t.Fatal(err) } diff --git a/tests/state_mgen_test.go b/tests/state_mgen_test.go index 47a30e1de9..2ca1638f6a 100644 --- a/tests/state_mgen_test.go +++ b/tests/state_mgen_test.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "os" "path/filepath" @@ -215,7 +214,7 @@ func (tm *testMatcherGen) testWriteTest(t *testing.T, name string, test *StateTe configPathTarget := filepath.Join(targetDirCommon, "configs", fmt.Sprintf("%s_config.json", target)) // e.g. "testdata_generated/GeneralStateTests/ETC_Atlantis_config.json" os.MkdirAll(filepath.Dir(configPathTarget), os.ModePerm) if _, statErr := os.Stat(configPathTarget); os.IsNotExist(statErr) { - if err := ioutil.WriteFile(configPathTarget, b, os.ModePerm); err != nil { + if err := os.WriteFile(configPathTarget, b, os.ModePerm); err != nil { t.Fatal(err) } } From 77496f0ebd94f1ef783c46796ff18c0b6971b35d Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 08:27:09 -0800 Subject: [PATCH 063/103] params: ExampleAllocPrint_Mainnet refers to unknown identifier: AllocPrint (govet) Date: 2022-12-06 08:27:09-08:00 Signed-off-by: meows --- params/alloc_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/alloc_test.go b/params/alloc_test.go index 38058cda2f..85abdb5c1c 100644 --- a/params/alloc_test.go +++ b/params/alloc_test.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/params/types/genesisT" ) -func ExampleAllocPrint_Mainnet() { +func ExampleMainnetAllocData() { // Test that the mainnet alloc is parsable. alloc := MainnetAllocData ga := genesisT.DecodePreAlloc(alloc) From 6604b713d66de914068d5408669860934c1e2fb1 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 08:36:09 -0800 Subject: [PATCH 064/103] tests: (was empty-branch) enable skip evmc tests at Berlin,London Date: 2022-12-06 08:36:09-08:00 Signed-off-by: meows --- tests/state_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/state_test.go b/tests/state_test.go index 4f6dffbbe2..d5fe3287b9 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -75,10 +75,10 @@ func TestState(t *testing.T) { if *testEVM != "" || *testEWASM != "" { // Berlin tests are not expected to pass for external EVMs, yet. // - // st.skipFork("Berlin") // ETH - // st.skipFork("Magneto") // ETC - // st.skipFork("London") // ETH - // st.skipFork("Mystique") // ETC + st.skipFork("Berlin") // ETH + st.skipFork("Magneto") // ETC + st.skipFork("London") // ETH + st.skipFork("Mystique") // ETC } // The multigeth data type (like the Ethereum Foundation data type) doesn't support // the ETC_Mystique fork/feature configuration, which omits EIP1559 and the associated BASEFEE From f443631213537b6f19f15639d3fdc1e55332d587 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 08:39:46 -0800 Subject: [PATCH 065/103] tests: [lint/deadcode] test dirs defined but unused Date: 2022-12-06 08:39:46-08:00 Signed-off-by: meows --- tests/init_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/init_test.go b/tests/init_test.go index 6b160e6e98..0d2a11555b 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -65,12 +65,12 @@ var ( legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests") rlpTestDir = filepath.Join(baseDir, "RLPTests") - difficultyTestDir = filepath.Join(baseDir, "DifficultyTests") - benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") + // difficultyTestDir = filepath.Join(baseDir, "DifficultyTests") + benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") - baseDirETC = filepath.Join(".", "testdata-etc") - stateTestDirETC = filepath.Join(baseDirETC, "GeneralStateTests") - legacyTestDirETC = filepath.Join(baseDirETC, "LegacyTests", "Constantinople", "GeneralStateTests") + baseDirETC = filepath.Join(".", "testdata-etc") + stateTestDirETC = filepath.Join(baseDirETC, "GeneralStateTests") + // legacyTestDirETC = filepath.Join(baseDirETC, "LegacyTests", "Constantinople", "GeneralStateTests") difficultyTestDirETC = filepath.Join(baseDirETC, "DifficultyTests") ) From 7ce7c471bad748e0da36d8688b8ea0db2dbc5e5d Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 08:42:11 -0800 Subject: [PATCH 066/103] tests: [lint] achieve perfection Date: 2022-12-06 08:42:11-08:00 Signed-off-by: meows --- tests/init_mgen_test.go | 168 ++++++++++++++++++++-------------------- tests/init_test.go | 23 +++--- 2 files changed, 93 insertions(+), 98 deletions(-) diff --git a/tests/init_mgen_test.go b/tests/init_mgen_test.go index 2aa246c517..10d86f914e 100644 --- a/tests/init_mgen_test.go +++ b/tests/init_mgen_test.go @@ -17,13 +17,9 @@ package tests import ( - "bufio" - "encoding/json" "fmt" "os" "path/filepath" - "reflect" - "strings" "testing" ) @@ -58,86 +54,86 @@ func (tm *testMatcher) walkFullName(t *testing.T, dir string, runTest interface{ } } -// walk invokes its runTest argument for all subtests in the given directory. +// // walk invokes its runTest argument for all subtests in the given directory. +// // +// // runTest should be a function of type func(t *testing.T, name string, x ), +// // where TestType is the type of the test contained in test files. +// func (tm *testMatcher) walkScanNDJSON(t *testing.T, dir string, runTest interface{}) { +// // Walk the directory. +// dirinfo, err := os.Stat(dir) +// if os.IsNotExist(err) || !dirinfo.IsDir() { +// fmt.Fprintf(os.Stderr, "can't find test files in %s, did you clone the tests submodule?\n", dir) +// t.Skip("missing test files") +// } +// err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { +// name := filepath.ToSlash(strings.TrimPrefix(path, dir+string(filepath.Separator))) +// if info.IsDir() { +// if _, skipload := tm.findSkip(name + "/"); skipload { +// return filepath.SkipDir +// } +// return nil +// } +// if filepath.Ext(path) == ".ndjson" { +// t.Run(name, func(t *testing.T) { tm.runTestFileNDJSON(t, path, name, runTest) }) +// } +// return nil +// }) +// if err != nil { +// t.Fatal(err) +// } +// } // -// runTest should be a function of type func(t *testing.T, name string, x ), -// where TestType is the type of the test contained in test files. -func (tm *testMatcher) walkScanNDJSON(t *testing.T, dir string, runTest interface{}) { - // Walk the directory. - dirinfo, err := os.Stat(dir) - if os.IsNotExist(err) || !dirinfo.IsDir() { - fmt.Fprintf(os.Stderr, "can't find test files in %s, did you clone the tests submodule?\n", dir) - t.Skip("missing test files") - } - err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { - name := filepath.ToSlash(strings.TrimPrefix(path, dir+string(filepath.Separator))) - if info.IsDir() { - if _, skipload := tm.findSkip(name + "/"); skipload { - return filepath.SkipDir - } - return nil - } - if filepath.Ext(path) == ".ndjson" { - t.Run(name, func(t *testing.T) { tm.runTestFileNDJSON(t, path, name, runTest) }) - } - return nil - }) - if err != nil { - t.Fatal(err) - } -} - -func (tm *testMatcher) runTestFileNDJSON(t *testing.T, path, name string, runTest interface{}) { - if r, _ := tm.findSkip(name); r != "" { - t.Skip(r) - } - if tm.runonlylistpat != nil { - if !tm.runonlylistpat.MatchString(name) { - t.Skip("Skipped by whitelist") - } - } - t.Parallel() - - file, err := os.Open(path) - if err != nil { - t.Fatal(err) - } - defer file.Close() - - scanner := bufio.NewScanner(file) - - for scanner.Scan() { - m := makeVOfTestFunc(runTest) - ma := m.Addr().Interface() - err = json.Unmarshal(scanner.Bytes(), &ma) - if err != nil { - t.Fatal(err) - } - t.Run(name, func(t *testing.T) { - if r, _ := tm.findSkip(name); r != "" { - t.Skip(r) - } - runTestFuncNotMap(runTest, t, name, m) - }) - } -} - -func makeVOfTestFunc(f interface{}) reflect.Value { - stringT := reflect.TypeOf("") - testingT := reflect.TypeOf((*testing.T)(nil)) - ftyp := reflect.TypeOf(f) - if ftyp.Kind() != reflect.Func || ftyp.NumIn() != 3 || ftyp.NumOut() != 0 || ftyp.In(0) != testingT || ftyp.In(1) != stringT { - panic(fmt.Sprintf("bad test function type: want func(*testing.T, string, ), have %s", ftyp)) - } - testType := ftyp.In(2) - mp := reflect.New(testType) - return mp.Elem() -} - -func runTestFuncNotMap(runTest interface{}, t *testing.T, name string, m reflect.Value) { - reflect.ValueOf(runTest).Call([]reflect.Value{ - reflect.ValueOf(t), - reflect.ValueOf(name), - m, - }) -} +// func (tm *testMatcher) runTestFileNDJSON(t *testing.T, path, name string, runTest interface{}) { +// if r, _ := tm.findSkip(name); r != "" { +// t.Skip(r) +// } +// if tm.runonlylistpat != nil { +// if !tm.runonlylistpat.MatchString(name) { +// t.Skip("Skipped by whitelist") +// } +// } +// t.Parallel() +// +// file, err := os.Open(path) +// if err != nil { +// t.Fatal(err) +// } +// defer file.Close() +// +// scanner := bufio.NewScanner(file) +// +// for scanner.Scan() { +// m := makeVOfTestFunc(runTest) +// ma := m.Addr().Interface() +// err = json.Unmarshal(scanner.Bytes(), &ma) +// if err != nil { +// t.Fatal(err) +// } +// t.Run(name, func(t *testing.T) { +// if r, _ := tm.findSkip(name); r != "" { +// t.Skip(r) +// } +// runTestFuncNotMap(runTest, t, name, m) +// }) +// } +// } +// +// func makeVOfTestFunc(f interface{}) reflect.Value { +// stringT := reflect.TypeOf("") +// testingT := reflect.TypeOf((*testing.T)(nil)) +// ftyp := reflect.TypeOf(f) +// if ftyp.Kind() != reflect.Func || ftyp.NumIn() != 3 || ftyp.NumOut() != 0 || ftyp.In(0) != testingT || ftyp.In(1) != stringT { +// panic(fmt.Sprintf("bad test function type: want func(*testing.T, string, ), have %s", ftyp)) +// } +// testType := ftyp.In(2) +// mp := reflect.New(testType) +// return mp.Elem() +// } +// +// func runTestFuncNotMap(runTest interface{}, t *testing.T, name string, m reflect.Value) { +// reflect.ValueOf(runTest).Call([]reflect.Value{ +// reflect.ValueOf(t), +// reflect.ValueOf(name), +// m, +// }) +// } diff --git a/tests/init_test.go b/tests/init_test.go index 0d2a11555b..1f8c4be705 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -32,7 +32,6 @@ import ( "testing" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/params/types/coregeth" "github.com/ethereum/go-ethereum/params/types/ctypes" ) @@ -192,17 +191,17 @@ func (tm *testMatcher) findSkip(name string) (reason string, skipload bool) { return "", false } -// findConfig returns the chain config matching defined patterns. -func (tm *testMatcher) findConfig(name string) (config ctypes.ChainConfigurator, configRegexKey string) { - // TODO(fjl): name can be derived from testing.T when min Go version is 1.8 - for _, m := range tm.configpat { - if m.p.MatchString(name) { - return m.config, m.p.String() - } - } - log.Println("using empty config", name) - return new(coregeth.CoreGethChainConfig), "" -} +// // findConfig returns the chain config matching defined patterns. +// func (tm *testMatcher) findConfig(name string) (config ctypes.ChainConfigurator, configRegexKey string) { +// // TODO(fjl): name can be derived from testing.T when min Go version is 1.8 +// for _, m := range tm.configpat { +// if m.p.MatchString(name) { +// return m.config, m.p.String() +// } +// } +// log.Println("using empty config", name) +// return new(coregeth.CoreGethChainConfig), "" +// } // checkFailure checks whether a failure is expected. func (tm *testMatcher) checkFailure(t *testing.T, err error) error { From 12f3472ca7dc028e9dbe0ec840a6d8a8c16482f3 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 09:22:44 -0800 Subject: [PATCH 067/103] cmd/evm/testdata/13,cmd/evm/testdata/14,cmd/evm/testdata/19,cmd/evm/testdata/24,cmd/evm/testdata/25: git checkout foundation-master -- ./cmd/evm/testdata These tests were failing because test expectations (defined in json files) did not contain a 'currentBaseFee' annotation that was expected. Date: 2022-12-06 09:22:44-08:00 Signed-off-by: meows --- cmd/evm/testdata/13/exp2.json | 3 +- cmd/evm/testdata/14/exp.json | 3 +- cmd/evm/testdata/14/exp2.json | 3 +- cmd/evm/testdata/14/exp_berlin.json | 3 +- cmd/evm/testdata/19/exp_arrowglacier.json | 3 +- cmd/evm/testdata/19/exp_grayglacier.json | 3 +- cmd/evm/testdata/19/exp_london.json | 3 +- cmd/evm/testdata/24/exp.json | 3 +- cmd/evm/testdata/25/alloc.json | 8 +++++ cmd/evm/testdata/25/env.json | 11 +++++++ cmd/evm/testdata/25/exp.json | 38 +++++++++++++++++++++++ cmd/evm/testdata/25/txs.json | 15 +++++++++ 12 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 cmd/evm/testdata/25/alloc.json create mode 100644 cmd/evm/testdata/25/env.json create mode 100644 cmd/evm/testdata/25/exp.json create mode 100644 cmd/evm/testdata/25/txs.json diff --git a/cmd/evm/testdata/13/exp2.json b/cmd/evm/testdata/13/exp2.json index ba8c9f865b..cbad6552c1 100644 --- a/cmd/evm/testdata/13/exp2.json +++ b/cmd/evm/testdata/13/exp2.json @@ -34,6 +34,7 @@ } ], "currentDifficulty": "0x20000", - "gasUsed": "0x109a0" + "gasUsed": "0x109a0", + "currentBaseFee": "0x36b" } } diff --git a/cmd/evm/testdata/14/exp.json b/cmd/evm/testdata/14/exp.json index 9bf5635f5b..26d49173ce 100644 --- a/cmd/evm/testdata/14/exp.json +++ b/cmd/evm/testdata/14/exp.json @@ -7,6 +7,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "currentDifficulty": "0x2000020000000", "receipts": [], - "gasUsed": "0x0" + "gasUsed": "0x0", + "currentBaseFee": "0x500" } } diff --git a/cmd/evm/testdata/14/exp2.json b/cmd/evm/testdata/14/exp2.json index 9c9025381f..cd75b47d5a 100644 --- a/cmd/evm/testdata/14/exp2.json +++ b/cmd/evm/testdata/14/exp2.json @@ -7,6 +7,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "receipts": [], "currentDifficulty": "0x1ff8020000000", - "gasUsed": "0x0" + "gasUsed": "0x0", + "currentBaseFee": "0x500" } } diff --git a/cmd/evm/testdata/14/exp_berlin.json b/cmd/evm/testdata/14/exp_berlin.json index c2bf953119..5c00ef130a 100644 --- a/cmd/evm/testdata/14/exp_berlin.json +++ b/cmd/evm/testdata/14/exp_berlin.json @@ -7,6 +7,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "receipts": [], "currentDifficulty": "0x1ff9000000000", - "gasUsed": "0x0" + "gasUsed": "0x0", + "currentBaseFee": "0x500" } } diff --git a/cmd/evm/testdata/19/exp_arrowglacier.json b/cmd/evm/testdata/19/exp_arrowglacier.json index 9cf56ffafc..dd49f7d02e 100644 --- a/cmd/evm/testdata/19/exp_arrowglacier.json +++ b/cmd/evm/testdata/19/exp_arrowglacier.json @@ -7,6 +7,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "currentDifficulty": "0x2000000200000", "receipts": [], - "gasUsed": "0x0" + "gasUsed": "0x0", + "currentBaseFee": "0x500" } } diff --git a/cmd/evm/testdata/19/exp_grayglacier.json b/cmd/evm/testdata/19/exp_grayglacier.json index 95a3cb1685..86fd8e6c13 100644 --- a/cmd/evm/testdata/19/exp_grayglacier.json +++ b/cmd/evm/testdata/19/exp_grayglacier.json @@ -7,6 +7,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "receipts": [], "currentDifficulty": "0x2000000004000", - "gasUsed": "0x0" + "gasUsed": "0x0", + "currentBaseFee": "0x500" } } \ No newline at end of file diff --git a/cmd/evm/testdata/19/exp_london.json b/cmd/evm/testdata/19/exp_london.json index a06bc8ca69..9e9a17da90 100644 --- a/cmd/evm/testdata/19/exp_london.json +++ b/cmd/evm/testdata/19/exp_london.json @@ -7,6 +7,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "currentDifficulty": "0x2000080000000", "receipts": [], - "gasUsed": "0x0" + "gasUsed": "0x0", + "currentBaseFee": "0x500" } } diff --git a/cmd/evm/testdata/24/exp.json b/cmd/evm/testdata/24/exp.json index 05d8c7a03b..d8cec59d6a 100644 --- a/cmd/evm/testdata/24/exp.json +++ b/cmd/evm/testdata/24/exp.json @@ -48,6 +48,7 @@ } ], "currentDifficulty": null, - "gasUsed": "0x10306" + "gasUsed": "0x10306", + "currentBaseFee": "0x500" } } diff --git a/cmd/evm/testdata/25/alloc.json b/cmd/evm/testdata/25/alloc.json new file mode 100644 index 0000000000..d66366718e --- /dev/null +++ b/cmd/evm/testdata/25/alloc.json @@ -0,0 +1,8 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + } +} diff --git a/cmd/evm/testdata/25/env.json b/cmd/evm/testdata/25/env.json new file mode 100644 index 0000000000..bb2c9e0d7d --- /dev/null +++ b/cmd/evm/testdata/25/env.json @@ -0,0 +1,11 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": null, + "currentRandom": "0xdeadc0de", + "currentGasLimit": "0x750a163df65e8a", + "parentBaseFee": "0x500", + "parentGasUsed": "0x0", + "parentGasLimit": "0x750a163df65e8a", + "currentNumber": "1", + "currentTimestamp": "1000" +} diff --git a/cmd/evm/testdata/25/exp.json b/cmd/evm/testdata/25/exp.json new file mode 100644 index 0000000000..a9c310a1e1 --- /dev/null +++ b/cmd/evm/testdata/25/exp.json @@ -0,0 +1,38 @@ +{ + "alloc": { + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": { + "balance": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878bc29ed73", + "nonce": "0xad" + }, + "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x854d00" + } + }, + "result": { + "stateRoot": "0x5139609e39f4d158a7d1ad1800908eb0349cea9b500a8273a6cf0a7e4392639b", + "txRoot": "0x572690baf4898c2972446e56ecf0aa2a027c08a863927d2dce34472f0c5496fe", + "receiptsRoot": "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x5208", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x92ea4a28224d033afb20e0cc2b290d4c7c2d61f6a4800a680e4e19ac962ee941", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "currentDifficulty": null, + "gasUsed": "0x5208", + "currentBaseFee": "0x460" + } +} diff --git a/cmd/evm/testdata/25/txs.json b/cmd/evm/testdata/25/txs.json new file mode 100644 index 0000000000..acb4035fd1 --- /dev/null +++ b/cmd/evm/testdata/25/txs.json @@ -0,0 +1,15 @@ +[ + { + "gas": "0x186a0", + "gasPrice": "0x600", + "hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "input": "0x", + "nonce": "0xac", + "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192", + "value": "0x1", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] From 86fc9cc23ead97c025670df7eedce5891cd909eb Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 09:30:16 -0800 Subject: [PATCH 068/103] cmd/geth: bump geth console test timeout to 20s These tests were failing because they were timing out and getting killed. I think the --dev mode key creation may account for the problematic time spend. This patch just increases the time the test is willing to wait for its geth instance to start up and print the logs the test is waiting for. Date: 2022-12-06 09:30:16-08:00 Signed-off-by: meows --- cmd/geth/consolecmd_cg_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index 921646bed6..1302250523 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -67,6 +67,7 @@ func consoleCmdStdoutTest(flags []string, execCmd string, want interface{}) func flags = append(flags, "--ipcpath", filepath.Join(os.TempDir(), "geth.ipc"), "--exec", execCmd, "console") t.Log("flags:", flags) geth := runGeth(t, flags...) + geth.KillTimeout = 20 * time.Second geth.Expect(fmt.Sprintf(`%v `, want)) geth.ExpectExit() From 5e3c673a3dd379047a3a55070cd3c0f19d223940 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 6 Dec 2022 11:03:11 -0800 Subject: [PATCH 069/103] tests: re-enable legacyStateTestDir Date: 2022-12-06 11:03:11-08:00 Signed-off-by: meows --- tests/state_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/state_test.go b/tests/state_test.go index d5fe3287b9..13b51388a8 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -102,7 +102,7 @@ func TestState(t *testing.T) { // For Istanbul, older tests were moved into LegacyTests for _, dir := range []string{ stateTestDir, - // legacyStateTestDir, + legacyStateTestDir, benchmarksDir, stateTestDirETC, From 14b5a210e31f09b0bff9cca3551e6bc2bf79102d Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 9 Dec 2022 05:14:30 -0800 Subject: [PATCH 070/103] .gitmodules,tests: move ETC testdata submodule to winsvega's ETC tests Dimitry made us these tests, lets see if we can pass them. Date: 2022-12-09 05:14:30-08:00 Signed-off-by: meows --- .gitmodules | 2 +- tests/testdata-etc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 5d72021167..0a3f15d1dc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,4 +8,4 @@ shallow = true [submodule "tests-etc"] path = tests/testdata-etc - url = https://github.com/etclabscore/tests-etc + url = https://github.com/etclabscore/tests diff --git a/tests/testdata-etc b/tests/testdata-etc index 8183e9eebd..5e0bdda91d 160000 --- a/tests/testdata-etc +++ b/tests/testdata-etc @@ -1 +1 @@ -Subproject commit 8183e9eebd93912cebddbe3e88f66f836a8205dd +Subproject commit 5e0bdda91dba6cc54654f66c77e78b60f4a88438 From 79d4135400814b1336c4f3438b5cd8aa6c1e0748 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 12 Dec 2022 06:55:01 -0800 Subject: [PATCH 071/103] tests: ensure context.Difficulty is assigned context.Difficulty should be assigned by the env in case 1559 is not enabled. This makes sure that that happens. Date: 2022-12-12 06:55:01-08:00 Signed-off-by: meows --- tests/state_test_util.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index e8824535c3..57175db1d8 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -318,6 +318,8 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh rnd := common.BigToHash(t.json.Env.Random) context.Random = &rnd context.Difficulty = big.NewInt(0) + } else { + context.Difficulty = t.json.Env.Difficulty } evm := vm.NewEVM(context, txContext, statedb, config, vmconfig) // Execute the message. From 4f4ab7f09f9bcc2988ef93bb1b4ed65051d66edf Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Mon, 12 Dec 2022 17:11:04 +0200 Subject: [PATCH 072/103] graphql: graphql: s/params.vars for InitialBaseFee --- graphql/graphql_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index 0983fd924b..71d871427e 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -39,6 +39,7 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params/types/genesisT" + "github.com/ethereum/go-ethereum/params/vars" "github.com/stretchr/testify/assert" ) @@ -192,7 +193,7 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) { Balance: big.NewInt(0), }, }, - BaseFee: big.NewInt(params.InitialBaseFee), + BaseFee: big.NewInt(vars.InitialBaseFee), } signer := types.LatestSigner(genesis.Config) newGQLService(t, stack, genesis, 1, func(i int, gen *core.BlockGen) { @@ -202,15 +203,15 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) { To: &dad, Value: big.NewInt(100), Gas: 50000, - GasPrice: big.NewInt(params.InitialBaseFee), + GasPrice: big.NewInt(vars.InitialBaseFee), }) gen.AddTx(tx) tx, _ = types.SignNewTx(key, signer, &types.AccessListTx{ - ChainID: genesis.Config.ChainID, + ChainID: genesis.Config.GetChainID(), Nonce: uint64(1), To: &dad, Gas: 30000, - GasPrice: big.NewInt(params.InitialBaseFee), + GasPrice: big.NewInt(vars.InitialBaseFee), Value: big.NewInt(50), AccessList: types.AccessList{{ Address: dad, @@ -279,7 +280,7 @@ func TestGraphQLTransactionLogs(t *testing.T) { GasLimit: 11500000, Difficulty: big.NewInt(1048576), Alloc: genesisT.GenesisAlloc{ - addr: {Balance: big.NewInt(params.Ether)}, + addr: {Balance: big.NewInt(vars.Ether)}, dad: { // LOG0(0, 0), LOG0(0, 0), RETURN(0, 0) Code: common.Hex2Bytes("60006000a060006000a060006000f3"), @@ -294,11 +295,11 @@ func TestGraphQLTransactionLogs(t *testing.T) { defer stack.Close() handler := newGQLService(t, stack, genesis, 1, func(i int, gen *core.BlockGen) { - tx, _ := types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Gas: 100000, GasPrice: big.NewInt(params.InitialBaseFee)}) + tx, _ := types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Gas: 100000, GasPrice: big.NewInt(vars.InitialBaseFee)}) gen.AddTx(tx) - tx, _ = types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Nonce: 1, Gas: 100000, GasPrice: big.NewInt(params.InitialBaseFee)}) + tx, _ = types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Nonce: 1, Gas: 100000, GasPrice: big.NewInt(vars.InitialBaseFee)}) gen.AddTx(tx) - tx, _ = types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Nonce: 2, Gas: 100000, GasPrice: big.NewInt(params.InitialBaseFee)}) + tx, _ = types.SignNewTx(key, signer, &types.LegacyTx{To: &dad, Nonce: 2, Gas: 100000, GasPrice: big.NewInt(vars.InitialBaseFee)}) gen.AddTx(tx) }) // start node From 44581a0e81277a2ca05578dc5e2d74c2674bd082 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Mon, 12 Dec 2022 18:27:01 +0200 Subject: [PATCH 073/103] cmd/geth: cmd/geth: geth-test ipc was using a too-long (>108 char) path by default --- cmd/geth/consolecmd_cg_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index 073634c813..7b9cc5707e 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -165,7 +165,7 @@ func TestGethStartupLogs(t *testing.T) { } for i, c := range cases { t.Run(fmt.Sprintf("TestGethStartupLogs/%d: %v", i, c.flags), func(t *testing.T) { - geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...) + geth := runGeth(t, append(c.flags, "--ipcpath", filepath.Join(os.TempDir(), "geth.ipc"), "--exec", "admin.nodeInfo.name", "console")...) geth.KillTimeout = 10 * time.Second geth.ExpectRegexp("(?ism).*CoreGeth.*") geth.ExpectExit() From 012aafad6f6b11eb95490df44966a1112eab0bb7 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 12 Dec 2022 09:31:53 -0800 Subject: [PATCH 074/103] tests: update tests (incl. s/Merge/Merged/g fix), skip EOF1 tests This core-geth does not yet have EOF1 implemented, so we add a skipLoad for that pattern. Bump the submodule commit to a tests version that fixes the Merge vs. Merged configuration naming issue. Date: 2022-12-12 09:31:53-08:00 Signed-off-by: meows --- tests/init.go | 31 ++++++++++++++++--------------- tests/state_test.go | 2 ++ tests/testdata-etc | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/init.go b/tests/init.go index d97e391513..6ae5922862 100644 --- a/tests/init.go +++ b/tests/init.go @@ -342,21 +342,22 @@ var Forks = map[string]ctypes.ChainConfigurator{ GrayGlacierBlock: big.NewInt(0), }, "Merged": &goethereum.ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - BerlinBlock: big.NewInt(0), - LondonBlock: big.NewInt(0), - ArrowGlacierBlock: big.NewInt(0), - MergeNetsplitBlock: big.NewInt(0), - TerminalTotalDifficulty: big.NewInt(0), + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + BerlinBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + ArrowGlacierBlock: big.NewInt(0), + MergeNetsplitBlock: big.NewInt(0), + TerminalTotalDifficulty: big.NewInt(0), + TerminalTotalDifficultyPassed: true, }, "ETC_Magneto": &coregeth.CoreGethChainConfig{ NetworkID: 1, diff --git a/tests/state_test.go b/tests/state_test.go index 13b51388a8..98ba85831a 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -58,6 +58,8 @@ func TestState(t *testing.T) { // Uses 1GB RAM per tested fork st.skipLoad(`^stStaticCall/static_Call1MB`) + st.skipLoad(`.*EOF1.*`) + if *testEWASM == "" { st.skipLoad(`^stEWASM`) } diff --git a/tests/testdata-etc b/tests/testdata-etc index 5e0bdda91d..315779c508 160000 --- a/tests/testdata-etc +++ b/tests/testdata-etc @@ -1 +1 @@ -Subproject commit 5e0bdda91dba6cc54654f66c77e78b60f4a88438 +Subproject commit 315779c508f7fa385b57566cf610387f016c3477 From 2e13b8204ae604f85dc4f816918dc0f84b967a79 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 12 Dec 2022 10:17:27 -0800 Subject: [PATCH 075/103] tests: re-enable ETC legacy tests Date: 2022-12-12 10:17:27-08:00 Signed-off-by: meows --- tests/init_test.go | 6 +++--- tests/state_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/init_test.go b/tests/init_test.go index 1f8c4be705..8ec82e32e9 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -67,9 +67,9 @@ var ( // difficultyTestDir = filepath.Join(baseDir, "DifficultyTests") benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") - baseDirETC = filepath.Join(".", "testdata-etc") - stateTestDirETC = filepath.Join(baseDirETC, "GeneralStateTests") - // legacyTestDirETC = filepath.Join(baseDirETC, "LegacyTests", "Constantinople", "GeneralStateTests") + baseDirETC = filepath.Join(".", "testdata-etc") + stateTestDirETC = filepath.Join(baseDirETC, "GeneralStateTests") + legacyTestDirETC = filepath.Join(baseDirETC, "LegacyTests", "Constantinople", "GeneralStateTests") difficultyTestDirETC = filepath.Join(baseDirETC, "DifficultyTests") ) diff --git a/tests/state_test.go b/tests/state_test.go index 98ba85831a..7387a7c112 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -108,7 +108,7 @@ func TestState(t *testing.T) { benchmarksDir, stateTestDirETC, - // legacyTestDirETC, + legacyTestDirETC, } { st.walk(t, dir, func(t *testing.T, name string, test *StateTest) { for _, subtest := range test.Subtests(st.skipforkpat) { From cc2883f45894fe737cf8194e1fa6fe42e13bfb50 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 19 Dec 2022 09:55:55 -0800 Subject: [PATCH 076/103] params/types/coregeth,tests: fix GrayGlacier difficulty test Only the testdata-etc suite has this sub-suite of tests. (Because our tests/testdata submodule may be outdated?) Anyways, the chain config for the GrayGlacier fork was not-existing, and the configurator method (EIP5133) for core-geth was not configuring the difficulty bomb delay table right. ALSO, NOTE the json field name fix s/eip5133FBloc/eip5133FBlock/ Date: 2022-12-19 09:55:55-08:00 Signed-off-by: meows --- params/types/coregeth/chain_config.go | 3 ++- .../coregeth/chain_config_configurator.go | 24 ++++++++++++++++++- tests/difficulty_test.go | 2 +- tests/difficulty_test_util.go | 4 ++++ tests/init_test.go | 4 ++-- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/params/types/coregeth/chain_config.go b/params/types/coregeth/chain_config.go index 71d9d49e48..07ae4f6079 100644 --- a/params/types/coregeth/chain_config.go +++ b/params/types/coregeth/chain_config.go @@ -215,7 +215,8 @@ type CoreGethChainConfig struct { EIP3541FBlock *big.Int `json:"eip3541FBlock,omitempty"` EIP3529FBlock *big.Int `json:"eip3529FBlock,omitempty"` - EIP5133FBlock *big.Int `json:"eip5133FBloc,omitempty"` + EIP5133FBlock *big.Int `json:"eip5133FBlock,omitempty"` + eip5133Inferred bool MergeNetsplitVBlock *big.Int `json:"mergeNetsplitVBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter diff --git a/params/types/coregeth/chain_config_configurator.go b/params/types/coregeth/chain_config_configurator.go index 63b0b16553..2b07ca690e 100644 --- a/params/types/coregeth/chain_config_configurator.go +++ b/params/types/coregeth/chain_config_configurator.go @@ -1011,14 +1011,36 @@ func (c *CoreGethChainConfig) GetEthashEIP5133Transition() *uint64 { if c.GetConsensusEngineType() != ctypes.ConsensusEngineT_Ethash { return nil } - return bigNewU64(c.EIP5133FBlock) + if c.eip5133Inferred { + return bigNewU64(c.EIP5133FBlock) + } + + var diffN *uint64 + defer func() { + c.EIP5133FBlock = setBig(c.EIP5133FBlock, diffN) + c.eip5133Inferred = true + }() + + // Get block number (key) from map where EIP5133 criteria is met. + diffN = ctypes.MapMeetsSpecification(c.DifficultyBombDelaySchedule, nil, vars.EIP5133DifficultyBombDelay, nil) + return diffN } func (c *CoreGethChainConfig) SetEthashEIP5133Transition(n *uint64) error { if c.Ethash == nil { return ctypes.ErrUnsupportedConfigFatal } + c.EIP5133FBlock = setBig(c.EIP5133FBlock, n) + c.eip5133Inferred = true + + if n == nil { + return nil + } + + c.ensureExistingDifficultySchedule() + c.DifficultyBombDelaySchedule.SetValueTotalForHeight(n, vars.EIP5133DifficultyBombDelay) + return nil } diff --git a/tests/difficulty_test.go b/tests/difficulty_test.go index cfb502a582..c0d68ce7c6 100644 --- a/tests/difficulty_test.go +++ b/tests/difficulty_test.go @@ -32,7 +32,7 @@ func TestDifficulty(t *testing.T) { } for _, dir := range []string{ - // difficultyTestDir, + difficultyTestDir, difficultyTestDirETC, } { dt.walk(t, dir, func(t *testing.T, name string, superTest map[string]json.RawMessage) { diff --git a/tests/difficulty_test_util.go b/tests/difficulty_test_util.go index 6882e75c4a..ee11301caa 100644 --- a/tests/difficulty_test_util.go +++ b/tests/difficulty_test_util.go @@ -103,6 +103,10 @@ var difficultyChainConfigurations = map[string]ctypes.ChainConfigurator{ Ethash: new(ctypes.EthashConfig), ByzantiumBlock: big.NewInt(0), }, + "GrayGlacier": &goethereum.ChainConfig{ + Ethash: new(ctypes.EthashConfig), + GrayGlacierBlock: big.NewInt(0), + }, "MainNetwork": mainnetChainConfig, "CustomMainNetwork": mainnetChainConfig, "Constantinople": &goethereum.ChainConfig{ diff --git a/tests/init_test.go b/tests/init_test.go index 8ec82e32e9..7f731d85d6 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -64,8 +64,8 @@ var ( legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests") rlpTestDir = filepath.Join(baseDir, "RLPTests") - // difficultyTestDir = filepath.Join(baseDir, "DifficultyTests") - benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") + difficultyTestDir = filepath.Join(baseDir, "DifficultyTests") + benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") baseDirETC = filepath.Join(".", "testdata-etc") stateTestDirETC = filepath.Join(baseDirETC, "GeneralStateTests") From ca284ebd4c93809affaee8511b16439857750557 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 19 Dec 2022 09:56:57 -0800 Subject: [PATCH 077/103] Makefile: problem: tests are timing out on Github CI See https://github.com/etclabscore/core-geth/actions/runs/3696522572/jobs/6260330266 solution: bump test timeout from default=10m to 20m Date: 2022-12-19 09:56:57-08:00 Signed-off-by: meows --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 259fca15a5..552a9e417a 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ ios: @echo "Import \"$(GOBIN)/Geth.framework\" to use the library." test: - $(GORUN) build/ci.go test + $(GORUN) build/ci.go test -timeout 20m # DEPRECATED. # No attempt will be made after the Istanbul fork to maintain From 2ba4218bbc1617c53900938fbd089191dec48ff2 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 19 Dec 2022 10:05:02 -0800 Subject: [PATCH 078/103] build: problem: lint step timed out on Github CI solution: bump lint timeout option to 5m Date: 2022-12-19 10:05:02-08:00 Signed-off-by: meows --- build/ci.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/ci.go b/build/ci.go index 0d239fc9f0..1c05fc9f19 100644 --- a/build/ci.go +++ b/build/ci.go @@ -138,7 +138,7 @@ var ( "focal": "golang-go", // EOL: 04/2030 "impish": "golang-go", // EOL: 07/2022 "jammy": "golang-go", // EOL: 04/2032 - //"kinetic": "golang-go", // EOL: 07/2023 + // "kinetic": "golang-go", // EOL: 07/2023 } debGoBootPaths = map[string]string{ @@ -349,7 +349,7 @@ func doLint(cmdline []string) { } linter := downloadLinter(*cachedir) - lflags := []string{"run", "--timeout", "3m0s", "--config", ".golangci.yml"} + lflags := []string{"run", "--timeout", "5m0s", "--config", ".golangci.yml"} build.MustRunCommand(linter, append(lflags, packages...)...) fmt.Println("You have achieved perfection.") } From 51505156d5fd9c4efa670b4187f78fe33d4981cc Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 19 Dec 2022 10:13:58 -0800 Subject: [PATCH 079/103] .gitmodules: move ETH xclient tests submodule back to ethereum/tests This had been moved to the etclabscore/tests fork because at the time, ETC xclient tests were living at this repo, too. But now we've moved the ETC xclient tests to their own suite with their own repo (etclabscore/tests@etcversion_filled) and those tests have been generated via retesteth by Dimitry. So I want the original xclient suite (with only ETH) tests to treat ethereum/tests as the upstream origin. Date: 2022-12-19 10:13:58-08:00 Signed-off-by: meows --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 0a3f15d1dc..f31d203880 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "tests"] path = tests/testdata - url = https://github.com/etclabscore/tests + url = https://github.com/ethereum/tests shallow = true [submodule "evm-benchmarks"] path = tests/evm-benchmarks From 460091f7268e2606cab870c43103ac410cda26ec Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 14:26:05 +0200 Subject: [PATCH 080/103] .gitmodules: .gitmodules: set shallow mode for tests-etc submodule --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index f31d203880..90207861e6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,3 +9,4 @@ [submodule "tests-etc"] path = tests/testdata-etc url = https://github.com/etclabscore/tests + shallow = true From ca5dd0498f1ee4c7469f1c5172be50df0108f2c7 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 14:38:41 +0200 Subject: [PATCH 081/103] core/state: core/state: remove comment --- core/state/journal.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/state/journal.go b/core/state/journal.go index 14e461660f..57a692dc7f 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -75,7 +75,6 @@ func (j *journal) revert(statedb *StateDB, snapshot int) { // dirty explicitly sets an address to dirty, even if the change entries would // otherwise suggest it as clean. This method is an ugly hack to handle the RIPEMD // precompile consensus exception. -// meowsbits-ripemd func (j *journal) dirty(addr common.Address) { j.dirties[addr]++ } From 7c9fc18bbe1888cc49464d1d254cce413ecf9d89 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 14:44:31 +0200 Subject: [PATCH 082/103] core/vm: core/vm: remove comment --- core/vm/evmc.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 98e43102f7..961ba69de3 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -295,9 +295,7 @@ func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, ev host.env.StateDB.SetState(addr, key, common.BytesToHash(value.Bytes())) - // defer func() { status = host.storageStatus(original, current, value) - // }() if getRevision(host.env) == evmc.Constantinople /* EIP-1283 */ { if current.Eq(value) { From fda1e5192957580524f3dad02d170ecd472383c9 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 20 Dec 2022 06:28:24 -0800 Subject: [PATCH 083/103] tests: remove dead code (state,diff mgen artifacts) This code was used in earlier version of the test generation logic, which extended some given xclient suite with ETC support by writing the results of a test to a new file. Difficulty tests at the time used NDJSON as an additional encoding, but this is no longer. Now, core-geth uses xclient tests generated by retesteth (which uses core-geth as a filler client; actually the t8ntool command provided by the repo). Resolves - https://github.com/etclabscore/core-geth/pull/510#discussion_r1052683037 - https://github.com/etclabscore/core-geth/pull/510#discussion_r1052683214 Date: 2022-12-20 06:28:24-08:00 Signed-off-by: meows --- tests/init_mgen_test.go | 84 ----------------------------------------- tests/init_test.go | 12 ------ 2 files changed, 96 deletions(-) diff --git a/tests/init_mgen_test.go b/tests/init_mgen_test.go index 10d86f914e..58e4e4b7d7 100644 --- a/tests/init_mgen_test.go +++ b/tests/init_mgen_test.go @@ -53,87 +53,3 @@ func (tm *testMatcher) walkFullName(t *testing.T, dir string, runTest interface{ t.Fatal(err) } } - -// // walk invokes its runTest argument for all subtests in the given directory. -// // -// // runTest should be a function of type func(t *testing.T, name string, x ), -// // where TestType is the type of the test contained in test files. -// func (tm *testMatcher) walkScanNDJSON(t *testing.T, dir string, runTest interface{}) { -// // Walk the directory. -// dirinfo, err := os.Stat(dir) -// if os.IsNotExist(err) || !dirinfo.IsDir() { -// fmt.Fprintf(os.Stderr, "can't find test files in %s, did you clone the tests submodule?\n", dir) -// t.Skip("missing test files") -// } -// err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { -// name := filepath.ToSlash(strings.TrimPrefix(path, dir+string(filepath.Separator))) -// if info.IsDir() { -// if _, skipload := tm.findSkip(name + "/"); skipload { -// return filepath.SkipDir -// } -// return nil -// } -// if filepath.Ext(path) == ".ndjson" { -// t.Run(name, func(t *testing.T) { tm.runTestFileNDJSON(t, path, name, runTest) }) -// } -// return nil -// }) -// if err != nil { -// t.Fatal(err) -// } -// } -// -// func (tm *testMatcher) runTestFileNDJSON(t *testing.T, path, name string, runTest interface{}) { -// if r, _ := tm.findSkip(name); r != "" { -// t.Skip(r) -// } -// if tm.runonlylistpat != nil { -// if !tm.runonlylistpat.MatchString(name) { -// t.Skip("Skipped by whitelist") -// } -// } -// t.Parallel() -// -// file, err := os.Open(path) -// if err != nil { -// t.Fatal(err) -// } -// defer file.Close() -// -// scanner := bufio.NewScanner(file) -// -// for scanner.Scan() { -// m := makeVOfTestFunc(runTest) -// ma := m.Addr().Interface() -// err = json.Unmarshal(scanner.Bytes(), &ma) -// if err != nil { -// t.Fatal(err) -// } -// t.Run(name, func(t *testing.T) { -// if r, _ := tm.findSkip(name); r != "" { -// t.Skip(r) -// } -// runTestFuncNotMap(runTest, t, name, m) -// }) -// } -// } -// -// func makeVOfTestFunc(f interface{}) reflect.Value { -// stringT := reflect.TypeOf("") -// testingT := reflect.TypeOf((*testing.T)(nil)) -// ftyp := reflect.TypeOf(f) -// if ftyp.Kind() != reflect.Func || ftyp.NumIn() != 3 || ftyp.NumOut() != 0 || ftyp.In(0) != testingT || ftyp.In(1) != stringT { -// panic(fmt.Sprintf("bad test function type: want func(*testing.T, string, ), have %s", ftyp)) -// } -// testType := ftyp.In(2) -// mp := reflect.New(testType) -// return mp.Elem() -// } -// -// func runTestFuncNotMap(runTest interface{}, t *testing.T, name string, m reflect.Value) { -// reflect.ValueOf(runTest).Call([]reflect.Value{ -// reflect.ValueOf(t), -// reflect.ValueOf(name), -// m, -// }) -// } diff --git a/tests/init_test.go b/tests/init_test.go index 7f731d85d6..c476a74030 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -191,18 +191,6 @@ func (tm *testMatcher) findSkip(name string) (reason string, skipload bool) { return "", false } -// // findConfig returns the chain config matching defined patterns. -// func (tm *testMatcher) findConfig(name string) (config ctypes.ChainConfigurator, configRegexKey string) { -// // TODO(fjl): name can be derived from testing.T when min Go version is 1.8 -// for _, m := range tm.configpat { -// if m.p.MatchString(name) { -// return m.config, m.p.String() -// } -// } -// log.Println("using empty config", name) -// return new(coregeth.CoreGethChainConfig), "" -// } - // checkFailure checks whether a failure is expected. func (tm *testMatcher) checkFailure(t *testing.T, err error) error { failReason := "" From cc9b4ee1501d3eb323e486a992c1c856b94c0e0f Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 18:58:26 +0200 Subject: [PATCH 084/103] =?UTF-8?q?.github/workflows:=20add=20check=20for?= =?UTF-8?q?=20=E2=80=9Cgo=20generate=E2=80=9D=20diff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Usually devs forget to update Marshalers that has been generated by “go generate”, this Action will just check if a diff exists and let the developers know on a PR basis --- .github/workflows/go-generate-check.yml | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/go-generate-check.yml diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml new file mode 100644 index 0000000000..06bf4bedef --- /dev/null +++ b/.github/workflows/go-generate-check.yml @@ -0,0 +1,26 @@ +name: Developer helper +on: pull_request +jobs: + go-generate-check: + name: Check if "go generate" has been run + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + id: go + uses: actions/setup-go@v2 + with: + go-version: ^1.16 + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: Run go:generate + id: go-generate + run: go generate ./... + - name: Check for modified files + id: git-check + run: + if ! git diff-index --quiet HEAD --; then + core.setFailed('Please run `go generate ./...` to update codebase') + fi \ No newline at end of file From fb25c3077084c4949c0821c34fcef32ca65bded0 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 19:02:31 +0200 Subject: [PATCH 085/103] .github/workflows: .github/workflows: no need for submodules for go:generate --- .github/workflows/go-generate-check.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 06bf4bedef..f54179f6c0 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -13,8 +13,6 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 - with: - submodules: 'recursive' - name: Run go:generate id: go-generate run: go generate ./... From abc814b6b445187b3e790620dcd4f8b2a4547b2c Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 19:06:26 +0200 Subject: [PATCH 086/103] =?UTF-8?q?.github/workflows:=20.github/workflows:?= =?UTF-8?q?=20install=20devtools=20for=20=E2=80=9Cgo:generate=E2=80=9D=20d?= =?UTF-8?q?eps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/go-generate-check.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index f54179f6c0..c4cf51d461 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -13,6 +13,16 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 + - name: Install deps + id: install-deps + run: | + sudo add-apt-repository ppa:ethereum/ethereum + sudo apt-get update + sudo apt-get install solc + sudo apt-get install -y protobuf-compiler + - name: Install devtools + id: install-devtools + run: make devtools - name: Run go:generate id: go-generate run: go generate ./... From 20bbcabc68700a8f2b27c7c69cb541bd8a91c7b3 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 19:25:35 +0200 Subject: [PATCH 087/103] =?UTF-8?q?.github/workflows:=20use=20solc=20versi?= =?UTF-8?q?on=20=E2=80=9C0.6.12=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/go-generate-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index c4cf51d461..b6484cfeb5 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -18,7 +18,7 @@ jobs: run: | sudo add-apt-repository ppa:ethereum/ethereum sudo apt-get update - sudo apt-get install solc + sudo apt-get install solc=0.6.12 sudo apt-get install -y protobuf-compiler - name: Install devtools id: install-devtools From 6e567fa1b232a214f73d46c82646ad7f2456bdd8 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 20:07:36 +0200 Subject: [PATCH 088/103] .github/workflows: use solc version 0.6.12 --- .github/workflows/go-generate-check.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index b6484cfeb5..1685d2d5d6 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -18,8 +18,13 @@ jobs: run: | sudo add-apt-repository ppa:ethereum/ethereum sudo apt-get update - sudo apt-get install solc=0.6.12 sudo apt-get install -y protobuf-compiler + + SOLC_BIN=solc-linux-amd64-v0.6.12+commit.27d51765 + curl -OL https://binaries.soliditylang.org/linux-amd64/$SOLC_BIN + sudo mv $SOLC_BIN /usr/local/bin/solc + rm $SOLC_BIN + - name: Install devtools id: install-devtools run: make devtools From df01b678b5ad0c57449302ecb5fc66af98d77267 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 20 Dec 2022 20:25:46 +0200 Subject: [PATCH 089/103] .github/workflows: remove go-generate-check unneeded rm --- .github/workflows/go-generate-check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 1685d2d5d6..52cc7c215c 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -23,7 +23,6 @@ jobs: SOLC_BIN=solc-linux-amd64-v0.6.12+commit.27d51765 curl -OL https://binaries.soliditylang.org/linux-amd64/$SOLC_BIN sudo mv $SOLC_BIN /usr/local/bin/solc - rm $SOLC_BIN - name: Install devtools id: install-devtools From 5161c8d924803f941c75585b77b43e41bf240f39 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 20 Dec 2022 19:40:04 -0800 Subject: [PATCH 090/103] contracts/checkpointoracle,contracts/checkpointoracle/contract,params/types/genesisT: run 'go generate ./...' with partial success A few things I learned along the way this evening. - solc in path must be 0.6.0 or some mysterious upper bound less than the latest available versions that I also tried. - solcjs is not solc. npm install solc installs solcjs which is like solc but is not solc. All of this partially fixes an error which looked like this. go generate ./... protoc-gen-go: no such flag -import_path --go_out: protoc-gen-go: Plugin failed with status code 1. accounts/usbwallet/trezor/trezor.go:45: running 'protoc': exit status 1 Error: Source file requires different compiler version (current compiler is 0.8.5+commit.a4f2e591.Linux.g++) - note that nightly builds are considered to be strictly less than the released version --> contract/oracle.sol:1:1: | 1 | pragma solidity ^0.6.0; | ^^^^^^^^^^^^^^^^^^^^^^^ contracts/checkpointoracle/oracle.go:20: running 'solc': exit status 1 The error now looks like this go generate ./... protoc-gen-go: no such flag -import_path --go_out: protoc-gen-go: Plugin failed with status code 1. Maybe we don't even want these changes. I don't know. I just want the command to work for the sake of order in the universe. But seriously - maybe we should upgrade the Solidity version pragma too/instead? - maybe proto-gen-go actually wants a different version than 'latest', (which is what 'make devtools' installs). - maybe we report the issue at ethereum. their trezor.go looks same same. Goodnight, to dream of green lights. Date: 2022-12-20 19:40:04-08:00 Signed-off-by: meows --- contracts/checkpointoracle/combined.json | 1 + contracts/checkpointoracle/contract/oracle.go | 34 ++++++++++++++----- params/types/genesisT/gen_genesis.go | 23 ------------- 3 files changed, 26 insertions(+), 32 deletions(-) create mode 100644 contracts/checkpointoracle/combined.json diff --git a/contracts/checkpointoracle/combined.json b/contracts/checkpointoracle/combined.json new file mode 100644 index 0000000000..308ae63e67 --- /dev/null +++ b/contracts/checkpointoracle/combined.json @@ -0,0 +1 @@ +{"contracts":{"contract/oracle.sol:CheckpointOracle":{"abi":"[{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_adminlist\",\"type\":\"address[]\"},{\"internalType\":\"uint256\",\"name\":\"_sectionSize\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_processConfirms\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_threshold\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"checkpointHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"NewCheckpointVote\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"GetAllAdmin\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"GetLatestCheckpoint\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_recentNumber\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"_recentHash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_sectionIndex\",\"type\":\"uint64\"},{\"internalType\":\"uint8[]\",\"name\":\"v\",\"type\":\"uint8[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"r\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"s\",\"type\":\"bytes32[]\"}],\"name\":\"SetCheckpoint\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]","bin":"608060405234801561001057600080fd5b5060405161085a38038061085a8339818101604052608081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825186602082028301116401000000008211171561008557600080fd5b82525081516020918201928201910280838360005b838110156100b257818101518382015260200161009a565b50505050919091016040908152602083015190830151606090930151909450919250600090505b84518110156101855760016000808784815181106100f357fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550600185828151811061014057fe5b60209081029190910181015182546001808201855560009485529290932090920180546001600160a01b0319166001600160a01b0390931692909217909155016100d9565b50600592909255600655600755506106b8806101a26000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806345848dfc146100465780634d6a304c1461009e578063d459fc46146100cf575b600080fd5b61004e6102b0565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561008a578181015183820152602001610072565b505050509050019250505060405180910390f35b6100a661034f565b6040805167ffffffffffffffff9094168452602084019290925282820152519081900360600190f35b61029c600480360360e08110156100e557600080fd5b81359160208101359160408201359167ffffffffffffffff6060820135169181019060a08101608082013564010000000081111561012257600080fd5b82018360208201111561013457600080fd5b8035906020019184602083028401116401000000008311171561015657600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092959493602081019350359150506401000000008111156101a657600080fd5b8201836020820111156101b857600080fd5b803590602001918460208302840111640100000000831117156101da57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929594936020810193503591505064010000000081111561022a57600080fd5b82018360208201111561023c57600080fd5b8035906020019184602083028401116401000000008311171561025e57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061036a945050505050565b604080519115158252519081900360200190f35b6060806001805490506040519080825280602002602001820160405280156102e2578160200160208202803883390190505b50905060005b60015481101561034957600181815481106102ff57fe5b9060005260206000200160009054906101000a90046001600160a01b031682828151811061032957fe5b6001600160a01b03909216602092830291909101909101526001016102e8565b50905090565b60025460045460035467ffffffffffffffff90921691909192565b3360009081526020819052604081205460ff1661038657600080fd5b8688401461039357600080fd5b82518451146103a157600080fd5b81518451146103af57600080fd5b6006546005548660010167ffffffffffffffff1602014310156103d457506000610677565b60025467ffffffffffffffff90811690861610156103f457506000610677565b60025467ffffffffffffffff8681169116148015610426575067ffffffffffffffff8516151580610426575060035415155b1561043357506000610677565b8561044057506000610677565b60408051601960f81b6020808301919091526000602183018190523060601b60228401526001600160c01b031960c08a901b166036840152603e8084018b905284518085039091018152605e909301909352815191012090805b86518110156106715760006001848984815181106104b457fe5b60200260200101518985815181106104c857fe5b60200260200101518986815181106104dc57fe5b602002602001015160405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561053b573d6000803e3d6000fd5b505060408051601f1901516001600160a01b03811660009081526020819052919091205490925060ff16905061057057600080fd5b826001600160a01b0316816001600160a01b03161161058e57600080fd5b8092508867ffffffffffffffff167fce51ffa16246bcaf0899f6504f473cd0114f430f566cef71ab7e03d3dde42a418b8a85815181106105ca57fe5b60200260200101518a86815181106105de57fe5b60200260200101518a87815181106105f257fe5b6020026020010151604051808581526020018460ff1660ff16815260200183815260200182815260200194505050505060405180910390a260075482600101106106685750505060048790555050436003556002805467ffffffffffffffff191667ffffffffffffffff86161790556001610677565b5060010161049a565b50600080fd5b97965050505050505056fea2646970667358221220dfd342cc8c4a864e30ffdf7f01340d7974f346a31969d46bceea09b75d46344764736f6c63430006000033","bin-runtime":"608060405234801561001057600080fd5b50600436106100415760003560e01c806345848dfc146100465780634d6a304c1461009e578063d459fc46146100cf575b600080fd5b61004e6102b0565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561008a578181015183820152602001610072565b505050509050019250505060405180910390f35b6100a661034f565b6040805167ffffffffffffffff9094168452602084019290925282820152519081900360600190f35b61029c600480360360e08110156100e557600080fd5b81359160208101359160408201359167ffffffffffffffff6060820135169181019060a08101608082013564010000000081111561012257600080fd5b82018360208201111561013457600080fd5b8035906020019184602083028401116401000000008311171561015657600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092959493602081019350359150506401000000008111156101a657600080fd5b8201836020820111156101b857600080fd5b803590602001918460208302840111640100000000831117156101da57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929594936020810193503591505064010000000081111561022a57600080fd5b82018360208201111561023c57600080fd5b8035906020019184602083028401116401000000008311171561025e57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061036a945050505050565b604080519115158252519081900360200190f35b6060806001805490506040519080825280602002602001820160405280156102e2578160200160208202803883390190505b50905060005b60015481101561034957600181815481106102ff57fe5b9060005260206000200160009054906101000a90046001600160a01b031682828151811061032957fe5b6001600160a01b03909216602092830291909101909101526001016102e8565b50905090565b60025460045460035467ffffffffffffffff90921691909192565b3360009081526020819052604081205460ff1661038657600080fd5b8688401461039357600080fd5b82518451146103a157600080fd5b81518451146103af57600080fd5b6006546005548660010167ffffffffffffffff1602014310156103d457506000610677565b60025467ffffffffffffffff90811690861610156103f457506000610677565b60025467ffffffffffffffff8681169116148015610426575067ffffffffffffffff8516151580610426575060035415155b1561043357506000610677565b8561044057506000610677565b60408051601960f81b6020808301919091526000602183018190523060601b60228401526001600160c01b031960c08a901b166036840152603e8084018b905284518085039091018152605e909301909352815191012090805b86518110156106715760006001848984815181106104b457fe5b60200260200101518985815181106104c857fe5b60200260200101518986815181106104dc57fe5b602002602001015160405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561053b573d6000803e3d6000fd5b505060408051601f1901516001600160a01b03811660009081526020819052919091205490925060ff16905061057057600080fd5b826001600160a01b0316816001600160a01b03161161058e57600080fd5b8092508867ffffffffffffffff167fce51ffa16246bcaf0899f6504f473cd0114f430f566cef71ab7e03d3dde42a418b8a85815181106105ca57fe5b60200260200101518a86815181106105de57fe5b60200260200101518a87815181106105f257fe5b6020026020010151604051808581526020018460ff1660ff16815260200183815260200182815260200194505050505060405180910390a260075482600101106106685750505060048790555050436003556002805467ffffffffffffffff191667ffffffffffffffff86161790556001610677565b5060010161049a565b50600080fd5b97965050505050505056fea2646970667358221220dfd342cc8c4a864e30ffdf7f01340d7974f346a31969d46bceea09b75d46344764736f6c63430006000033","devdoc":"{\"author\":\"Gary Rong, Martin Swende \",\"details\":\"Implementation of the blockchain checkpoint registrar.\",\"methods\":{\"GetAllAdmin()\":{\"details\":\"Get all admin addresses\",\"returns\":{\"_0\":\"address list\"}},\"GetLatestCheckpoint()\":{\"details\":\"Get latest stable checkpoint information.\",\"returns\":{\"_0\":\"section index\",\"_1\":\"checkpoint hash\",\"_2\":\"block height associated with checkpoint\"}}},\"title\":\"CheckpointOracle\"}","hashes":{"GetAllAdmin()":"45848dfc","GetLatestCheckpoint()":"4d6a304c","SetCheckpoint(uint256,bytes32,bytes32,uint64,uint8[],bytes32[],bytes32[])":"d459fc46"},"metadata":"{\"compiler\":{\"version\":\"0.6.0+commit.26b70077\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_adminlist\",\"type\":\"address[]\"},{\"internalType\":\"uint256\",\"name\":\"_sectionSize\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_processConfirms\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_threshold\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"checkpointHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"NewCheckpointVote\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"GetAllAdmin\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"GetLatestCheckpoint\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_recentNumber\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"_recentHash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_sectionIndex\",\"type\":\"uint64\"},{\"internalType\":\"uint8[]\",\"name\":\"v\",\"type\":\"uint8[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"r\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"s\",\"type\":\"bytes32[]\"}],\"name\":\"SetCheckpoint\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"Gary Rong, Martin Swende \",\"details\":\"Implementation of the blockchain checkpoint registrar.\",\"methods\":{\"GetAllAdmin()\":{\"details\":\"Get all admin addresses\",\"returns\":{\"_0\":\"address list\"}},\"GetLatestCheckpoint()\":{\"details\":\"Get latest stable checkpoint information.\",\"returns\":{\"_0\":\"section index\",\"_1\":\"checkpoint hash\",\"_2\":\"block height associated with checkpoint\"}}},\"title\":\"CheckpointOracle\"},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"contract/oracle.sol\":\"CheckpointOracle\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contract/oracle.sol\":{\"keccak256\":\"0x738c2be3bcb2f7f06946ef3c467852e34a4e65120d2782d89d3fc9d88e6cb2eb\",\"urls\":[\"bzz-raw://f2798b17afac3e0d77555bf8ecae9c1c462d2e5317799dc0a83c7ef23de6a930\",\"dweb:/ipfs/QmYqFrDitrtbGuxu2a8BtPrCYp7gKQvbL9qwk9DUczh6Ct\"]}},\"version\":1}","srcmap":"211:5531:0:-:0;;;503:376;8:9:-1;5:2;;;30:1;27;20:12;5:2;503:376:0;;;;;;;;;;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;503:376:0;;;;;;;;;;;;;19:11:-1;14:3;11:20;8:2;;;44:1;41;34:12;8:2;62:21;;;;123:4;114:14;;138:31;;;135:2;;;182:1;179;172:12;135:2;219:3;213:10;331:9;325:2;311:12;307:21;289:16;285:44;282:59;261:11;247:12;244:29;233:116;230:2;;;362:1;359;352:12;230:2;373:25;;-1:-1;503:376:0;;421:4:-1;412:14;;;;503:376:0;;;;;412:14:-1;503:376:0;23:1:-1;8:100;33:3;30:1;27:10;8:100;;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;;-1:-1;;;;503:376:0;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;503:376:0;;-1:-1:-1;625:6:0;;-1:-1:-1;620:141:0;641:10;:17;637:1;:21;620:141;;;703:4;679:6;:21;686:10;697:1;686:13;;;;;;;;;;;;;;-1:-1:-1;;;;;679:21:0;-1:-1:-1;;;;;679:21:0;;;;;;;;;;;;;:28;;;;;;;;;;;;;;;;;;721:9;736:10;747:1;736:13;;;;;;;;;;;;;;;;;;;27:10:-1;;39:1;23:18;;;45:23;;-1:-1;721:29:0;;;;;;;;;;;;-1:-1:-1;;;;;;721:29:0;-1:-1:-1;;;;;721:29:0;;;;;;;;;;660:3;620:141;;;-1:-1:-1;770:11:0;:26;;;;806:15;:34;850:9;:22;-1:-1:-1;211:5531:0;;;;;;","srcmap-runtime":"211:5531:0:-:0;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;211:5531:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4430:267;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:100:-1;33:3;30:1;27:10;8:100;;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;;12:14;4430:267:0;;;;;;;;;;;;;;;;;1070:138;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1605:2739;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;1605:2739:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;21:11:-1;5:28;;2:2;;;46:1;43;36:12;2:2;1605:2739:0;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;1605:2739:0;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;39:11;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;1605:2739:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;1605:2739:0;;;;;;;;-1:-1:-1;1605:2739:0;;-1:-1:-1;;21:11;5:28;;2:2;;;46:1;43;36:12;2:2;1605:2739:0;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;1605:2739:0;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;39:11;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;1605:2739:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;1605:2739:0;;;;;;;;-1:-1:-1;1605:2739:0;;-1:-1:-1;;21:11;5:28;;2:2;;;46:1;43;36:12;2:2;1605:2739:0;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;1605:2739:0;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;39:11;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;1605:2739:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;1605:2739:0;;-1:-1:-1;1605:2739:0;;-1:-1:-1;;;;;1605:2739:0:i;:::-;;;;;;;;;;;;;;;;;;4430:267;4485:16;4517:20;4554:9;:16;;;;4540:31;;;;;;;;;;;;;;;;;;;;;;29:2:-1;21:6;17:15;117:4;105:10;97:6;88:34;136:17;;-1:-1;4540:31:0;-1:-1:-1;4517:54:0;-1:-1:-1;4586:6:0;4581:90;4602:9;:16;4598:20;;4581:90;;;4648:9;4658:1;4648:12;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;4648:12:0;4639:3;4643:1;4639:6;;;;;;;;-1:-1:-1;;;;;4639:21:0;;;:6;;;;;;;;;;;:21;4620:3;;4581:90;;;-1:-1:-1;4687:3:0;-1:-1:-1;4430:267:0;:::o;1070:138::-;1174:12;;1188:4;;1194:6;;1174:12;;;;;1070:138;;;:::o;1605:2739::-;1932:10;1853:4;1925:18;;;;;;;;;;;;;1917:27;;;;;;2110:11;2092:13;2082:24;:39;2074:48;;;;;;2206:1;:8;2194:1;:8;:20;2186:29;;;;;;2245:1;:8;2233:1;:8;:20;2225:29;;;;;;2357:15;;2345:11;;2328:13;2342:1;2328:15;2327:29;;;:45;2312:12;:60;2308:103;;;-1:-1:-1;2395:5:0;2388:12;;2308:103;2481:12;;;;;;2465:28;;;;2461:71;;;-1:-1:-1;2516:5:0;2509:12;;2461:71;2605:12;;;2588:29;;;2605:12;;2588:29;:68;;;;-1:-1:-1;2622:18:0;;;;;;:33;;-1:-1:-1;2644:6:0;;:11;;2622:33;2584:111;;;-1:-1:-1;2679:5:0;2672:12;;2584:111;2753:11;2749:53;;-1:-1:-1;2786:5:0;2779:12;;2749:53;3325:65;;;-1:-1:-1;;;3325:65:0;;;;;;;;3294:18;3325:65;;;;;;3363:4;3325:65;;;;;;-1:-1:-1;;;;;;3325:65:0;;;;;;;;;;;;;;;;;;26:21:-1;;;22:32;;;6:49;;3325:65:0;;;;;;;3315:76;;;;;;3294:18;3646:606;3671:1;:8;3665:3;:14;3646:606;;;3701:14;3718:45;3728:10;3740:1;3742:3;3740:6;;;;;;;;;;;;;;3748:1;3750:3;3748:6;;;;;;;;;;;;;;3756:1;3758:3;3756:6;;;;;;;;;;;;;;3718:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;3718:45:0;;;-1:-1:-1;;3718:45:0;;-1:-1:-1;;;;;3785:14:0;;:6;:14;;;3718:45;3785:14;;;;;;;;3718:45;;-1:-1:-1;3785:14:0;;;-1:-1:-1;3777:23:0;;;;;;3848:9;-1:-1:-1;;;;;3840:18:0;3830:6;-1:-1:-1;;;;;3822:15:0;:36;3814:45;;;;;;3885:6;3873:18;;3928:13;3910:63;;;3943:5;3950:1;3952:3;3950:6;;;;;;;;;;;;;;3958:1;3960:3;3958:6;;;;;;;;;;;;;;3966:1;3968:3;3966:6;;;;;;;;;;;;;;3910:63;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4073:9;;4064:3;4068:1;4064:5;:18;4060:182;;-1:-1:-1;;;4101:4:0;:12;;;-1:-1:-1;;4140:12:0;4131:6;:21;4170:12;:28;;-1:-1:-1;;4170:28:0;;;;;;;-1:-1:-1;4216:11:0;;4060:182;-1:-1:-1;3681:5:0;;3646:606;;;;4329:8;;;1605:2739;;;;;;;;;;:::o","userdoc":"{\"methods\":{}}"}},"sourceList":["contract/oracle.sol"],"version":"0.6.0+commit.26b70077.Linux.g++"} \ No newline at end of file diff --git a/contracts/checkpointoracle/contract/oracle.go b/contracts/checkpointoracle/contract/oracle.go index a4a308f5c5..5277750ec6 100644 --- a/contracts/checkpointoracle/contract/oracle.go +++ b/contracts/checkpointoracle/contract/oracle.go @@ -4,6 +4,7 @@ package contract import ( + "errors" "math/big" "strings" @@ -17,6 +18,7 @@ import ( // Reference imports to suppress errors if they are not otherwise used. var ( + _ = errors.New _ = big.NewInt _ = strings.NewReader _ = ethereum.NotFound @@ -26,27 +28,40 @@ var ( _ = event.NewSubscription ) +// CheckpointOracleMetaData contains all meta data concerning the CheckpointOracle contract. +var CheckpointOracleMetaData = &bind.MetaData{ + ABI: "[{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_adminlist\",\"type\":\"address[]\"},{\"internalType\":\"uint256\",\"name\":\"_sectionSize\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_processConfirms\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_threshold\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"checkpointHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"NewCheckpointVote\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"GetAllAdmin\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"GetLatestCheckpoint\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_recentNumber\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"_recentHash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_sectionIndex\",\"type\":\"uint64\"},{\"internalType\":\"uint8[]\",\"name\":\"v\",\"type\":\"uint8[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"r\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"s\",\"type\":\"bytes32[]\"}],\"name\":\"SetCheckpoint\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + Sigs: map[string]string{ + "45848dfc": "GetAllAdmin()", + "4d6a304c": "GetLatestCheckpoint()", + "d459fc46": "SetCheckpoint(uint256,bytes32,bytes32,uint64,uint8[],bytes32[],bytes32[])", + }, + Bin: "0x608060405234801561001057600080fd5b5060405161085a38038061085a8339818101604052608081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825186602082028301116401000000008211171561008557600080fd5b82525081516020918201928201910280838360005b838110156100b257818101518382015260200161009a565b50505050919091016040908152602083015190830151606090930151909450919250600090505b84518110156101855760016000808784815181106100f357fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550600185828151811061014057fe5b60209081029190910181015182546001808201855560009485529290932090920180546001600160a01b0319166001600160a01b0390931692909217909155016100d9565b50600592909255600655600755506106b8806101a26000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806345848dfc146100465780634d6a304c1461009e578063d459fc46146100cf575b600080fd5b61004e6102b0565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561008a578181015183820152602001610072565b505050509050019250505060405180910390f35b6100a661034f565b6040805167ffffffffffffffff9094168452602084019290925282820152519081900360600190f35b61029c600480360360e08110156100e557600080fd5b81359160208101359160408201359167ffffffffffffffff6060820135169181019060a08101608082013564010000000081111561012257600080fd5b82018360208201111561013457600080fd5b8035906020019184602083028401116401000000008311171561015657600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092959493602081019350359150506401000000008111156101a657600080fd5b8201836020820111156101b857600080fd5b803590602001918460208302840111640100000000831117156101da57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929594936020810193503591505064010000000081111561022a57600080fd5b82018360208201111561023c57600080fd5b8035906020019184602083028401116401000000008311171561025e57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061036a945050505050565b604080519115158252519081900360200190f35b6060806001805490506040519080825280602002602001820160405280156102e2578160200160208202803883390190505b50905060005b60015481101561034957600181815481106102ff57fe5b9060005260206000200160009054906101000a90046001600160a01b031682828151811061032957fe5b6001600160a01b03909216602092830291909101909101526001016102e8565b50905090565b60025460045460035467ffffffffffffffff90921691909192565b3360009081526020819052604081205460ff1661038657600080fd5b8688401461039357600080fd5b82518451146103a157600080fd5b81518451146103af57600080fd5b6006546005548660010167ffffffffffffffff1602014310156103d457506000610677565b60025467ffffffffffffffff90811690861610156103f457506000610677565b60025467ffffffffffffffff8681169116148015610426575067ffffffffffffffff8516151580610426575060035415155b1561043357506000610677565b8561044057506000610677565b60408051601960f81b6020808301919091526000602183018190523060601b60228401526001600160c01b031960c08a901b166036840152603e8084018b905284518085039091018152605e909301909352815191012090805b86518110156106715760006001848984815181106104b457fe5b60200260200101518985815181106104c857fe5b60200260200101518986815181106104dc57fe5b602002602001015160405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561053b573d6000803e3d6000fd5b505060408051601f1901516001600160a01b03811660009081526020819052919091205490925060ff16905061057057600080fd5b826001600160a01b0316816001600160a01b03161161058e57600080fd5b8092508867ffffffffffffffff167fce51ffa16246bcaf0899f6504f473cd0114f430f566cef71ab7e03d3dde42a418b8a85815181106105ca57fe5b60200260200101518a86815181106105de57fe5b60200260200101518a87815181106105f257fe5b6020026020010151604051808581526020018460ff1660ff16815260200183815260200182815260200194505050505060405180910390a260075482600101106106685750505060048790555050436003556002805467ffffffffffffffff191667ffffffffffffffff86161790556001610677565b5060010161049a565b50600080fd5b97965050505050505056fea2646970667358221220dfd342cc8c4a864e30ffdf7f01340d7974f346a31969d46bceea09b75d46344764736f6c63430006000033", +} + // CheckpointOracleABI is the input ABI used to generate the binding from. -const CheckpointOracleABI = "[{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_adminlist\",\"type\":\"address[]\"},{\"internalType\":\"uint256\",\"name\":\"_sectionSize\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_processConfirms\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_threshold\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint64\",\"name\":\"index\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"checkpointHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"NewCheckpointVote\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"GetAllAdmin\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"GetLatestCheckpoint\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_recentNumber\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"_recentHash\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"_hash\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"_sectionIndex\",\"type\":\"uint64\"},{\"internalType\":\"uint8[]\",\"name\":\"v\",\"type\":\"uint8[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"r\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"s\",\"type\":\"bytes32[]\"}],\"name\":\"SetCheckpoint\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" +// Deprecated: Use CheckpointOracleMetaData.ABI instead. +var CheckpointOracleABI = CheckpointOracleMetaData.ABI +// Deprecated: Use CheckpointOracleMetaData.Sigs instead. // CheckpointOracleFuncSigs maps the 4-byte function signature to its string representation. -var CheckpointOracleFuncSigs = map[string]string{ - "45848dfc": "GetAllAdmin()", - "4d6a304c": "GetLatestCheckpoint()", - "d459fc46": "SetCheckpoint(uint256,bytes32,bytes32,uint64,uint8[],bytes32[],bytes32[])", -} +var CheckpointOracleFuncSigs = CheckpointOracleMetaData.Sigs // CheckpointOracleBin is the compiled bytecode used for deploying new contracts. -var CheckpointOracleBin = "0x608060405234801561001057600080fd5b506040516108703803806108708339818101604052608081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825186602082028301116401000000008211171561008557600080fd5b82525081516020918201928201910280838360005b838110156100b257818101518382015260200161009a565b50505050919091016040908152602083015190830151606090930151909450919250600090505b84518110156101855760016000808784815181106100f357fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550600185828151811061014057fe5b60209081029190910181015182546001808201855560009485529290932090920180546001600160a01b0319166001600160a01b0390931692909217909155016100d9565b50600592909255600655600755506106ce806101a26000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806345848dfc146100465780634d6a304c1461009e578063d459fc46146100cf575b600080fd5b61004e6102b0565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561008a578181015183820152602001610072565b505050509050019250505060405180910390f35b6100a6610365565b6040805167ffffffffffffffff9094168452602084019290925282820152519081900360600190f35b61029c600480360360e08110156100e557600080fd5b81359160208101359160408201359167ffffffffffffffff6060820135169181019060a08101608082013564010000000081111561012257600080fd5b82018360208201111561013457600080fd5b8035906020019184602083028401116401000000008311171561015657600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092959493602081019350359150506401000000008111156101a657600080fd5b8201836020820111156101b857600080fd5b803590602001918460208302840111640100000000831117156101da57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929594936020810193503591505064010000000081111561022a57600080fd5b82018360208201111561023c57600080fd5b8035906020019184602083028401116401000000008311171561025e57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610380945050505050565b604080519115158252519081900360200190f35b600154606090819067ffffffffffffffff811180156102ce57600080fd5b506040519080825280602002602001820160405280156102f8578160200160208202803683370190505b50905060005b60015481101561035f576001818154811061031557fe5b9060005260206000200160009054906101000a90046001600160a01b031682828151811061033f57fe5b6001600160a01b03909216602092830291909101909101526001016102fe565b50905090565b60025460045460035467ffffffffffffffff90921691909192565b3360009081526020819052604081205460ff1661039c57600080fd5b868840146103a957600080fd5b82518451146103b757600080fd5b81518451146103c557600080fd5b6006546005548660010167ffffffffffffffff1602014310156103ea5750600061068d565b60025467ffffffffffffffff908116908616101561040a5750600061068d565b60025467ffffffffffffffff868116911614801561043c575067ffffffffffffffff851615158061043c575060035415155b156104495750600061068d565b856104565750600061068d565b60408051601960f81b6020808301919091526000602183018190523060601b60228401526001600160c01b031960c08a901b166036840152603e8084018b905284518085039091018152605e909301909352815191012090805b86518110156106875760006001848984815181106104ca57fe5b60200260200101518985815181106104de57fe5b60200260200101518986815181106104f257fe5b602002602001015160405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015610551573d6000803e3d6000fd5b505060408051601f1901516001600160a01b03811660009081526020819052919091205490925060ff16905061058657600080fd5b826001600160a01b0316816001600160a01b0316116105a457600080fd5b8092508867ffffffffffffffff167fce51ffa16246bcaf0899f6504f473cd0114f430f566cef71ab7e03d3dde42a418b8a85815181106105e057fe5b60200260200101518a86815181106105f457fe5b60200260200101518a878151811061060857fe5b6020026020010151604051808581526020018460ff1660ff16815260200183815260200182815260200194505050505060405180910390a2600754826001011061067e5750505060048790555050436003556002805467ffffffffffffffff191667ffffffffffffffff8616179055600161068d565b506001016104b0565b50600080fd5b97965050505050505056fea26469706673582212202ddf9eda76bf59c0fc65584c0b22d84ecef2c703765de60439596d6ac34c2b7264736f6c634300060b0033" +// Deprecated: Use CheckpointOracleMetaData.Bin instead. +var CheckpointOracleBin = CheckpointOracleMetaData.Bin // DeployCheckpointOracle deploys a new Ethereum contract, binding an instance of CheckpointOracle to it. func DeployCheckpointOracle(auth *bind.TransactOpts, backend bind.ContractBackend, _adminlist []common.Address, _sectionSize *big.Int, _processConfirms *big.Int, _threshold *big.Int) (common.Address, *types.Transaction, *CheckpointOracle, error) { - parsed, err := abi.JSON(strings.NewReader(CheckpointOracleABI)) + parsed, err := CheckpointOracleMetaData.GetAbi() if err != nil { return common.Address{}, nil, nil, err } + if parsed == nil { + return common.Address{}, nil, nil, errors.New("GetABI returned nil") + } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(CheckpointOracleBin), backend, _adminlist, _sectionSize, _processConfirms, _threshold) + address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex(CheckpointOracleBin), backend, _adminlist, _sectionSize, _processConfirms, _threshold) if err != nil { return common.Address{}, nil, nil, err } @@ -424,5 +439,6 @@ func (_CheckpointOracle *CheckpointOracleFilterer) ParseNewCheckpointVote(log ty if err := _CheckpointOracle.contract.UnpackLog(event, "NewCheckpointVote", log); err != nil { return nil, err } + event.Raw = log return event, nil } diff --git a/params/types/genesisT/gen_genesis.go b/params/types/genesisT/gen_genesis.go index 7598de6051..014becc2ae 100644 --- a/params/types/genesisT/gen_genesis.go +++ b/params/types/genesisT/gen_genesis.go @@ -10,11 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" - "github.com/ethereum/go-ethereum/params/confp/generic" - "github.com/ethereum/go-ethereum/params/types/coregeth" "github.com/ethereum/go-ethereum/params/types/ctypes" - "github.com/ethereum/go-ethereum/params/types/goethereum" - "github.com/ethereum/go-ethereum/params/types/multigeth" ) var _ = (*genesisSpecMarshaling)(nil) @@ -76,25 +72,6 @@ func (g *Genesis) UnmarshalJSON(input []byte) error { BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` } var dec Genesis - - // We have to look at the raw input, decide what kind of configurator schema it's using, - // then assign the decoder struct to use that schema type. - conf, err := generic.UnmarshalChainConfigurator(input) - if err != nil { - return err - } - - switch conf.(type) { - case *coregeth.CoreGethChainConfig: - dec.Config = &coregeth.CoreGethChainConfig{} - case *multigeth.ChainConfig: - dec.Config = &multigeth.ChainConfig{} - case *goethereum.ChainConfig: - dec.Config = &goethereum.ChainConfig{} - default: - panic("unmarshal genesis chain config returned a type not supported by unmarshaling") - } - if err := json.Unmarshal(input, &dec); err != nil { return err } From 4b2cf83737ffe7c46c334a11414d151de049e0b3 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 10 Jan 2023 08:11:37 -0800 Subject: [PATCH 091/103] params/types/genesisT: edit the document which shall not be edited (add config type switch) Date: 2023-01-10 08:11:37-08:00 Signed-off-by: meows --- params/types/genesisT/gen_genesis.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/params/types/genesisT/gen_genesis.go b/params/types/genesisT/gen_genesis.go index 014becc2ae..97f1ca4255 100644 --- a/params/types/genesisT/gen_genesis.go +++ b/params/types/genesisT/gen_genesis.go @@ -10,7 +10,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/params/confp/generic" + "github.com/ethereum/go-ethereum/params/types/coregeth" "github.com/ethereum/go-ethereum/params/types/ctypes" + "github.com/ethereum/go-ethereum/params/types/goethereum" + "github.com/ethereum/go-ethereum/params/types/multigeth" ) var _ = (*genesisSpecMarshaling)(nil) @@ -72,6 +76,24 @@ func (g *Genesis) UnmarshalJSON(input []byte) error { BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` } var dec Genesis + // We have to look at the raw input, decide what kind of configurator schema it's using, + // then assign the decoder struct to use that schema type. + conf, err := generic.UnmarshalChainConfigurator(input) + if err != nil { + return err + } + + switch conf.(type) { + case *coregeth.CoreGethChainConfig: + dec.Config = &coregeth.CoreGethChainConfig{} + case *multigeth.ChainConfig: + dec.Config = &multigeth.ChainConfig{} + case *goethereum.ChainConfig: + dec.Config = &goethereum.ChainConfig{} + default: + panic("unmarshal genesis chain config returned a type not supported by unmarshaling") + } + if err := json.Unmarshal(input, &dec); err != nil { return err } From 8675b2a10d24173ac7a0366fa568e4f925921c23 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 10 Jan 2023 09:48:43 -0800 Subject: [PATCH 092/103] cmd/devp2p/internal/ethtest: these tests fails spuriously; solve with 1s sleep They depend on the output of a geth instance. Geth can take a while to start up, and assertions about geth logs should normally use some kind of a hook to decide when its ok to check the logs (eg startup complete). Date: 2023-01-10 09:48:43-08:00 Signed-off-by: meows --- cmd/devp2p/internal/ethtest/suite_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/devp2p/internal/ethtest/suite_test.go b/cmd/devp2p/internal/ethtest/suite_test.go index 4117ccd269..63421dd716 100644 --- a/cmd/devp2p/internal/ethtest/suite_test.go +++ b/cmd/devp2p/internal/ethtest/suite_test.go @@ -48,6 +48,7 @@ func TestEthSuite(t *testing.T) { } for _, test := range suite.EthTests() { t.Run(test.Name, func(t *testing.T) { + time.Sleep(time.Second) result := utesting.RunTAP([]utesting.Test{{Name: test.Name, Fn: test.Fn}}, os.Stdout) if result[0].Failed { t.Fatal() @@ -69,6 +70,7 @@ func TestSnapSuite(t *testing.T) { } for _, test := range suite.SnapTests() { t.Run(test.Name, func(t *testing.T) { + time.Sleep(time.Second) result := utesting.RunTAP([]utesting.Test{{Name: test.Name, Fn: test.Fn}}, os.Stdout) if result[0].Failed { t.Fatal() @@ -100,6 +102,7 @@ func runGeth() (*node.Node, error) { stack.Close() return nil, err } + return stack, nil } From 3539eb3ac3f8328674832cfa5275b6bbe68fe59c Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 10 Jan 2023 10:36:57 -0800 Subject: [PATCH 093/103] core/vm: checkout master@b909e85 Revering the EVMCv10 upgrade. I can't get all tests to pass with EVM One. Date: 2023-01-10 10:36:57-08:00 Signed-off-by: meows --- core/vm/evmc.go | 405 +++++++++--------------------------------------- 1 file changed, 77 insertions(+), 328 deletions(-) diff --git a/core/vm/evmc.go b/core/vm/evmc.go index 961ba69de3..3c44d83b76 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -26,7 +26,7 @@ import ( "strings" "sync" - "github.com/ethereum/evmc/v10/bindings/go/evmc" + "github.com/ethereum/evmc/v7/bindings/go/evmc" "github.com/ethereum/go-ethereum/params/vars" "github.com/ethereum/go-ethereum/common" @@ -110,34 +110,16 @@ type hostContext struct { contract *Contract // The reference to the current contract, needed by Call-like methods. } -func (host *hostContext) AccessAccount(addr evmc.Address) evmc.AccessStatus { - if getRevision(host.env) < evmc.Berlin /* EIP-2929 */ { - return evmc.ColdAccess - } - - if host.env.StateDB.AddressInAccessList(common.Address(addr)) { - return evmc.WarmAccess - } - return evmc.ColdAccess -} - -func (host *hostContext) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.AccessStatus { - if getRevision(host.env) < evmc.Berlin /* EIP-2929 */ { - return evmc.ColdAccess - } - - if addrOK, slotOK := host.env.StateDB.SlotInAccessList(common.Address(addr), common.Hash(key)); addrOK && slotOK { - return evmc.WarmAccess - } - return evmc.ColdAccess -} - func (host *hostContext) AccountExists(evmcAddr evmc.Address) bool { addr := common.Address(evmcAddr) - if host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP161dTransition, host.env.Context.BlockNumber) /* EIP-161 */ { - return !host.env.StateDB.Empty(addr) + if host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP161dTransition, host.env.Context.BlockNumber) { + if !host.env.StateDB.Empty(addr) { + return true + } + } else if host.env.StateDB.Exist(addr) { + return true } - return host.env.StateDB.Exist(addr) + return false } func (host *hostContext) GetStorage(addr evmc.Address, evmcKey evmc.Hash) evmc.Hash { @@ -147,295 +129,77 @@ func (host *hostContext) GetStorage(addr evmc.Address, evmcKey evmc.Hash) evmc.H return evmc.Hash(value.Bytes32()) } -func (host *hostContext) storageStatus(original, current, value *uint256.Int) (status evmc.StorageStatus) { - // /** - // * The effect of an attempt to modify a contract storage item. - // * - // * See @ref storagestatus for additional information about design of this enum - // * and analysis of the specification. - // * - // * For the purpose of explaining the meaning of each element, the following - // * notation is used: - // * - 0 is zero value, - // * - X != 0 (X is any value other than 0), - // * - Y != 0, Y != X, (Y is any value other than X and 0), - // * - Z != 0, Z != X, Z != X (Z is any value other than Y and X and 0), - // * - the "o -> c -> v" triple describes the change status in the context of: - // * - o: original value (cold value before a transaction started), - // * - c: current storage value, - // * - v: new storage value to be set. - // * - // * The order of elements follows EIPs introducing net storage gas costs: - // * - EIP-2200: https://eips.ethereum.org/EIPS/eip-2200, - // * - EIP-1283: https://eips.ethereum.org/EIPS/eip-1283. - // */ - // enum evmc_storage_status - // { - // /** - // * The new/same value is assigned to the storage item without affecting the cost structure. - // * - // * The storage value item is either: - // * - left unchanged (c == v) or - // * - the dirty value (o != c) is modified again (c != v). - // * This is the group of cases related to minimal gas cost of only accessing warm storage. - // * 0|X -> 0 -> 0 (current value unchanged) - // * 0|X|Y -> Y -> Y (current value unchanged) - // * 0|X -> Y -> Z (modified previously added/modified value) - // * - // * This is "catch all remaining" status. I.e. if all other statuses are correctly matched - // * this status should be assigned to all remaining cases. - // */ - // EVMC_STORAGE_ASSIGNED = 0, - status = evmc.StorageAssigned - // - // /** - // * A new storage item is added by changing - // * the current clean zero to a nonzero value. - // * 0 -> 0 -> Z - // */ - // EVMC_STORAGE_ADDED = 1, - // - if original.IsZero() && current.IsZero() && !value.IsZero() { - status = evmc.StorageAdded - } - // /** - // * A storage item is deleted by changing - // * the current clean nonzero to the zero value. - // * X -> X -> 0 - // */ - // EVMC_STORAGE_DELETED = 2, - // - if !original.IsZero() && !current.IsZero() && value.IsZero() { - if original == current { - status = evmc.StorageDeleted - } - } - // /** - // * A storage item is modified by changing - // * the current clean nonzero to other nonzero value. - // * X -> X -> Z - // */ - // EVMC_STORAGE_MODIFIED = 3, - // - if !original.IsZero() && !current.IsZero() && !value.IsZero() { - if original == current { - status = evmc.StorageModified - } - } - // /** - // * A storage item is added by changing - // * the current dirty zero to a nonzero value other than the original value. - // * X -> 0 -> Z - // */ - // EVMC_STORAGE_DELETED_ADDED = 4, - // - if !original.IsZero() && current.IsZero() && !value.IsZero() { - if !original.Eq(value) { - status = evmc.StorageDeletedAdded - } - } - // /** - // * A storage item is deleted by changing - // * the current dirty nonzero to the zero value and the original value is not zero. - // * X -> Y -> 0 - // */ - // EVMC_STORAGE_MODIFIED_DELETED = 5, - // - if !original.IsZero() && !current.IsZero() && value.IsZero() { - if original != current { - status = evmc.StorageModifiedDeleted - } - } - // /** - // * A storage item is added by changing - // * the current dirty zero to the original value. - // * X -> 0 -> X - // */ - // EVMC_STORAGE_DELETED_RESTORED = 6, - // - if !original.IsZero() && current.IsZero() && !value.IsZero() { - if original.Eq(value) { - status = evmc.StorageDeletedRestored - } - } - // /** - // * A storage item is deleted by changing - // * the current dirty nonzero to the original zero value. - // * 0 -> Y -> 0 - // */ - // EVMC_STORAGE_ADDED_DELETED = 7, - // - if original.IsZero() && !current.IsZero() && value.IsZero() { - status = evmc.StorageAddedDeleted - } - // /** - // * A storage item is modified by changing - // * the current dirty nonzero to the original nonzero value other than the current value. - // * X -> Y -> X - // */ - // EVMC_STORAGE_MODIFIED_RESTORED = 8 - // }; - // - if !original.IsZero() && !current.IsZero() && !value.IsZero() { - if original != current && original.Eq(value) { - status = evmc.StorageModifiedRestored - } - } - return status -} - func (host *hostContext) SetStorage(evmcAddr evmc.Address, evmcKey evmc.Hash, evmcValue evmc.Hash) (status evmc.StorageStatus) { addr := common.Address(evmcAddr) key := common.Hash(evmcKey) value := new(uint256.Int).SetBytes(evmcValue[:]) + var oldValue uint256.Int + oldValue.SetBytes(host.env.StateDB.GetState(addr, key).Bytes()) + if oldValue.Eq(value) { + return evmc.StorageUnchanged + } - var current, original = new(uint256.Int), new(uint256.Int) + var current, original uint256.Int current.SetBytes(host.env.StateDB.GetState(addr, key).Bytes()) original.SetBytes(host.env.StateDB.GetCommittedState(addr, key).Bytes()) host.env.StateDB.SetState(addr, key, common.BytesToHash(value.Bytes())) - status = host.storageStatus(original, current, value) - - if getRevision(host.env) == evmc.Constantinople /* EIP-1283 */ { - if current.Eq(value) { - return evmc.StorageAssigned - } - - // (X -> X) -> Y - if original.Eq(current) { - // 0 -> 0 -> Y - if original.IsZero() { - return evmc.StorageAdded - } - // X -> X -> 0 - if value.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - return evmc.StorageDeleted - } - return evmc.StorageModified - } - if !original.IsZero() { - // X -> 0 -> Z - if current.IsZero() { - host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) - // X -> 0 -> 0 - } else if value.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) - } - } - if original.Eq(value) { - if original.IsZero() { - host.env.StateDB.AddRefund(vars.NetSstoreResetClearRefund) - } else { - host.env.StateDB.AddRefund(vars.NetSstoreResetRefund) - } - } - return evmc.StorageAssigned - } - - if getRevision(host.env) < evmc.Istanbul { - if current.Eq(value) { - return evmc.StorageAssigned - } - - if current.IsZero() && !value.IsZero() { + // Here's a great example of one of the limits of our (core-geth) current chainconfig interface model. + // Should we handle the logic here about historic-featuro logic (which really is nice, because when reading the strange-incantation implemations, it's nice to see why it is), + // or should we handle the question where we handle the rest of the questions like this, since this logic is + // REALLY logic that belongs to the abstract idea of a chainconfiguration (aka chainconfig), which makes sense + // but depends on ECIPs having steadier and more predictable logic. + hasEIP2200 := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP2200Transition, host.env.Context.BlockNumber) + hasEIP1884 := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP1884Transition, host.env.Context.BlockNumber) + + // Here's an example where to me, it makes sense to use individual EIPs in the code... + // when they don't specify each other in the spec. + hasNetStorageCostEIP := hasEIP2200 && hasEIP1884 + if !hasNetStorageCostEIP { + status = evmc.StorageModified + if oldValue.IsZero() { return evmc.StorageAdded - } - if !current.IsZero() && value.IsZero() { + } else if value.IsZero() { host.env.StateDB.AddRefund(vars.SstoreRefundGas) return evmc.StorageDeleted } - return evmc.StorageAssigned - - } else /* Istanbul: EIP-2200 */ { - - /* - Replace SSTORE opcode gas cost calculation (including refunds) with the following logic: - - If gasleft is less than or equal to gas stipend, fail the current call frame with ‘out of gas’ exception. - - If current value equals new value (this is a no-op), SLOAD_GAS is deducted. - - If current value does not equal new value - If original value equals current value (this storage slot has not been changed by the current execution context) - If original value is 0, SSTORE_SET_GAS is deducted. - Otherwise, SSTORE_RESET_GAS gas is deducted. If new value is 0, add SSTORE_CLEARS_SCHEDULE gas to refund counter. - If original value does not equal current value (this storage slot is dirty), SLOAD_GAS gas is deducted. Apply both of the following clauses. - If original value is not 0 - If current value is 0 (also means that new value is not 0), remove SSTORE_CLEARS_SCHEDULE gas from refund counter. - If new value is 0 (also means that current value is not 0), add SSTORE_CLEARS_SCHEDULE gas to refund counter. - If original value equals new value (this storage slot is reset) - If original value is 0, add SSTORE_SET_GAS - SLOAD_GAS to refund counter. - Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS gas to refund counter. - - --- - - If gasleft is less than or equal to gas stipend, fail the current call frame with ‘out of gas’ exception. - :: NO IMPLEMENTATION - - If current value equals new value (this is a no-op), SLOAD_GAS is deducted. - :: SHORT-CIRCUIT near top of function - - If current value does not equal new value - - If original value equals current value (this storage slot has not been changed by the current execution context) - - - If original value is 0, SSTORE_SET_GAS is deducted. - :: 0 -> 0 -> Z: evmc.StorageAdded - - Otherwise, SSTORE_RESET_GAS gas is deducted. - :: X -> X -> Z: evmc.StorageModified - - If new value is 0, add SSTORE_CLEARS_SCHEDULE gas to refund counter. - :: X -> X -> 0: evmc.StorageDeleted - - If original value does not equal current value (this storage slot is dirty), SLOAD_GAS gas is deducted. - Apply both of the following clauses. - - If original value is not 0 - If current value is 0 (also means that new value is not 0), remove SSTORE_CLEARS_SCHEDULE gas from refund counter. - :: X -> 0 -> X: evmc.StorageAddedDeleted + return evmc.StorageModified + } - If new value is 0 (also means that current value is not 0), add SSTORE_CLEARS_SCHEDULE gas to refund counter. - :: X -> Z -> 0: evmc.StorageDeleted + resetClearRefund := vars.NetSstoreResetClearRefund + cleanRefund := vars.NetSstoreResetRefund - If original value equals new value (this storage slot is reset) - If original value is 0, add SSTORE_SET_GAS - SLOAD_GAS to refund counter. - Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS gas to refund counter. - */ + if hasEIP2200 { + resetClearRefund = vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200 // 19200 + cleanRefund = vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200 // 4200 + } - if current.Eq(value) { - return evmc.StorageAssigned + if original == current { + if original.IsZero() { // create slot (2.1.1) + return evmc.StorageAdded } - - if original == current { - if original.IsZero() { - return - } - if value.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) - } - return + if value.IsZero() { // delete slot (2.1.2b) + host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) + return evmc.StorageDeleted } - if !original.IsZero() { - if current.IsZero() { - host.env.StateDB.SubRefund(vars.SstoreClearsScheduleRefundEIP2200) - } else if value.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreClearsScheduleRefundEIP2200) - } + return evmc.StorageModified + } + if !original.IsZero() { + if current.IsZero() { // recreate slot (2.2.1.1) + host.env.StateDB.SubRefund(vars.NetSstoreClearRefund) + } else if value.IsZero() { // delete slot (2.2.1.2) + host.env.StateDB.AddRefund(vars.NetSstoreClearRefund) } - if original.Eq(value) { - if original.IsZero() { - host.env.StateDB.AddRefund(vars.SstoreSetGasEIP2200 - vars.SloadGasEIP2200) - } else { - host.env.StateDB.AddRefund(vars.SstoreResetGasEIP2200 - vars.SloadGasEIP2200) - } + } + if original.Eq(value) { + if original.IsZero() { // reset to original inexistent slot (2.2.2.1) + host.env.StateDB.AddRefund(resetClearRefund) + } else { // reset to original existing slot (2.2.2.2) + host.env.StateDB.AddRefund(cleanRefund) } } - - return + return evmc.StorageModifiedAgain } func (host *hostContext) GetBalance(addr evmc.Address) evmc.Hash { @@ -458,7 +222,7 @@ func (host *hostContext) GetCode(addr evmc.Address) []byte { return host.env.StateDB.GetCode(common.Address(addr)) } -func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evmc.Address) bool { +func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evmc.Address) { addr := common.Address(evmcAddr) beneficiary := common.Address(evmcBeneficiary) db := host.env.StateDB @@ -466,26 +230,20 @@ func (host *hostContext) Selfdestruct(evmcAddr evmc.Address, evmcBeneficiary evm db.AddRefund(vars.SelfdestructRefundGas) } db.AddBalance(beneficiary, db.GetBalance(addr)) - return db.Suicide(addr) + db.Suicide(addr) } func (host *hostContext) GetTxContext() evmc.TxContext { - txCtx := evmc.TxContext{ - GasPrice: evmc.Hash(common.BigToHash(host.env.GasPrice)), - Origin: evmc.Address(host.env.TxContext.Origin), - Coinbase: evmc.Address(host.env.Context.Coinbase), - Number: host.env.Context.BlockNumber.Int64(), - Timestamp: host.env.Context.Time.Int64(), - GasLimit: int64(host.env.Context.GasLimit), - ChainID: evmc.Hash(common.BigToHash(host.env.chainConfig.GetChainID())), - } - if getRevision(host.env) >= evmc.London { - txCtx.BaseFee = evmc.Hash(common.BigToHash(host.env.Context.BaseFee)) - if host.env.Context.Random != nil { - txCtx.PrevRandao = evmc.Hash(*host.env.Context.Random) - } + return evmc.TxContext{ + GasPrice: evmc.Hash(common.BigToHash(host.env.GasPrice)), + Origin: evmc.Address(host.env.TxContext.Origin), + Coinbase: evmc.Address(host.env.Context.Coinbase), + Number: host.env.Context.BlockNumber.Int64(), + Timestamp: host.env.Context.Time.Int64(), + GasLimit: int64(host.env.Context.GasLimit), + Difficulty: evmc.Hash(common.BigToHash(host.env.Context.Difficulty)), + ChainID: evmc.Hash(common.BigToHash(host.env.chainConfig.GetChainID())), } - return txCtx } func (host *hostContext) GetBlockHash(number int64) evmc.Hash { @@ -509,14 +267,11 @@ func (host *hostContext) EmitLog(addr evmc.Address, evmcTopics []evmc.Hash, data }) } -// Call executes a message call transaction. -// - evmcCodeAddress: https://github.com/ethereum/evmc/commit/8314761222c837d41f573b0af1152ce1c9895a32#diff-4c54ef259154e3cd3bd18b1963e027655525f909a887700cc2d1386e075c3628R155 func (host *hostContext) Call(kind evmc.CallKind, evmcDestination evmc.Address, evmcSender evmc.Address, valueBytes evmc.Hash, input []byte, gas int64, depth int, - static bool, saltBytes evmc.Hash, evmcCodeAddress evmc.Address) (output []byte, gasLeft int64, gasRefund int64, createAddrEvmc evmc.Address, err error) { + static bool, saltBytes evmc.Hash) (output []byte, gasLeft int64, createAddrEvmc evmc.Address, err error) { destination := common.Address(evmcDestination) - codeTarget := common.Address(evmcCodeAddress) var createAddr common.Address @@ -537,14 +292,14 @@ func (host *hostContext) Call(kind evmc.CallKind, output, gasLeftU, err = host.env.Call(host.contract, destination, input, gasU, value.ToBig()) } case evmc.DelegateCall: - output, gasLeftU, err = host.env.DelegateCall(host.contract, codeTarget, input, gasU) + output, gasLeftU, err = host.env.DelegateCall(host.contract, destination, input, gasU) case evmc.CallCode: - output, gasLeftU, err = host.env.CallCode(host.contract, codeTarget, input, gasU, value.ToBig()) + output, gasLeftU, err = host.env.CallCode(host.contract, destination, input, gasU, value.ToBig()) case evmc.Create: var createOutput []byte createOutput, createAddr, gasLeftU, err = host.env.Create(host.contract, input, gasU, value.ToBig()) createAddrEvmc = evmc.Address(createAddr) - isHomestead := getRevision(host.env) >= evmc.Homestead + isHomestead := host.env.ChainConfig().IsEnabled(host.env.ChainConfig().GetEIP7Transition, host.env.Context.BlockNumber) if !isHomestead && err == ErrCodeStoreOutOfGas { err = nil } @@ -580,11 +335,7 @@ func (host *hostContext) Call(kind evmc.CallKind, } gasLeft = int64(gasLeftU) - gasRefund = gasLeft - if getRevision(host.env) >= evmc.London { - gasRefund = int64(host.env.StateDB.GetRefund()) - } - return output, gasLeft, gasRefund, createAddrEvmc, err + return output, gasLeft, createAddrEvmc, err } // getRevision translates ChainConfig's HF block information into EVMC revision. @@ -595,12 +346,10 @@ func getRevision(env *EVM) evmc.Revision { // This is an example of choosing to use an "abstracted" idea // about chain config, where I'm choosing to prioritize "indicative" features // as identifiers for Fork-Feature-Groups. Note that this is very different - // from using Feature-complete sets to assert "did Forkage." - case conf.IsEnabled(conf.GetEIP1559Transition, n): - return evmc.London + // than using Feature-complete sets to assert "did Forkage." case conf.IsEnabled(conf.GetEIP2565Transition, n): - return evmc.Berlin - case conf.IsEnabled(conf.GetEIP2200Transition, n): + panic("berlin is unsupported by EVMCv7") + case conf.IsEnabled(conf.GetEIP1884Transition, n): return evmc.Istanbul case conf.IsEnabled(conf.GetEIP1283DisableTransition, n): return evmc.Petersburg @@ -654,7 +403,7 @@ func (evm *EVMC) Run(contract *Contract, input []byte, readOnly bool) (ret []byt input, evmc.Hash(common.BigToHash(contract.value)), contract.Code, - ) + evmc.Hash{}) contract.Gas = uint64(gasLeft) From e8d7f2339087bba5663fd7a7474db24dbf335024 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 10 Jan 2023 10:38:13 -0800 Subject: [PATCH 094/103] tests: skip fork Merged for EVMC test suites Date: 2023-01-10 10:38:13-08:00 Signed-off-by: meows --- tests/state_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/state_test.go b/tests/state_test.go index 7387a7c112..d5ac501e05 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -81,6 +81,7 @@ func TestState(t *testing.T) { st.skipFork("Magneto") // ETC st.skipFork("London") // ETH st.skipFork("Mystique") // ETC + st.skipFork("Merged") // ETH } // The multigeth data type (like the Ethereum Foundation data type) doesn't support // the ETC_Mystique fork/feature configuration, which omits EIP1559 and the associated BASEFEE From be95e711bb7bffecbc3b353c61cea1feb8d54631 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 10 Jan 2023 10:40:11 -0800 Subject: [PATCH 095/103] core/vm,go.mod,go.sum: revert ethereum/evmc v10 -> v7 Date: 2023-01-10 10:40:11-08:00 Signed-off-by: meows --- core/vm/evm.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 37be74d8e8..ed8a8e20ed 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -22,7 +22,7 @@ import ( "sync/atomic" "time" - "github.com/ethereum/evmc/v10/bindings/go/evmc" + "github.com/ethereum/evmc/v7/bindings/go/evmc" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params/types/ctypes" diff --git a/go.mod b/go.mod index a0fa720e9c..06b336343b 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf github.com/edsrzf/mmap-go v1.0.0 github.com/etclabscore/go-openrpc-reflect v0.0.37 - github.com/ethereum/evmc/v10 v10.0.0 + github.com/ethereum/evmc/v7 v7.5.0 github.com/fatih/color v1.7.0 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 diff --git a/go.sum b/go.sum index d7d76da1c3..a1339c26ac 100644 --- a/go.sum +++ b/go.sum @@ -135,8 +135,8 @@ github.com/etclabscore/go-jsonschema-walk v0.0.6 h1:DrNzoKWKd8f8XB5nFGBY00IcjakR github.com/etclabscore/go-jsonschema-walk v0.0.6/go.mod h1:VdfDY72AFAiUhy0ZXEaWSpveGjMT5JcDIm903NGqFwQ= github.com/etclabscore/go-openrpc-reflect v0.0.37 h1:IH0e7JqIvR9OhbbFWi/BHIkXrqbR3Zyia3RJ733eT6c= github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E= -github.com/ethereum/evmc/v10 v10.0.0 h1:zuhGmMJIf4hXWph8NPzt5Wlu3Ujsf84KYFordc6mTTk= -github.com/ethereum/evmc/v10 v10.0.0/go.mod h1:A5SnakP7hgfMwjG0cNgpR3st5hQJzXDz2++bvOQqt5c= +github.com/ethereum/evmc/v7 v7.5.0 h1:vwKcs1DINXqvaymranmlpO64fysJJkirCCJ+kkaPaCs= +github.com/ethereum/evmc/v7 v7.5.0/go.mod h1:q2Q0rCSUlIkngd+mZwfCzEUbvB0IIopH1+7hcs9QuDg= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq6Q+cGWcGHz0FjGR3QqcInWcW0= From 7273876c042c92653898d4c47a6d79e6cc73b096 Mon Sep 17 00:00:00 2001 From: meows Date: Tue, 10 Jan 2023 11:54:56 -0800 Subject: [PATCH 096/103] cmd/devp2p/internal/ethtest: register runGeth fn as a t.Helper These tests keep failing... sometimes. This is a shot in the dark. Date: 2023-01-10 11:54:56-08:00 Signed-off-by: meows --- cmd/devp2p/internal/ethtest/suite_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite_test.go b/cmd/devp2p/internal/ethtest/suite_test.go index 63421dd716..18aabaf305 100644 --- a/cmd/devp2p/internal/ethtest/suite_test.go +++ b/cmd/devp2p/internal/ethtest/suite_test.go @@ -36,7 +36,7 @@ var ( ) func TestEthSuite(t *testing.T) { - geth, err := runGeth() + geth, err := runGeth(t) if err != nil { t.Fatalf("could not run geth: %v", err) } @@ -58,7 +58,7 @@ func TestEthSuite(t *testing.T) { } func TestSnapSuite(t *testing.T) { - geth, err := runGeth() + geth, err := runGeth(t) if err != nil { t.Fatalf("could not run geth: %v", err) } @@ -80,7 +80,8 @@ func TestSnapSuite(t *testing.T) { } // runGeth creates and starts a geth node -func runGeth() (*node.Node, error) { +func runGeth(t *testing.T) (*node.Node, error) { + t.Helper() stack, err := node.New(&node.Config{ P2P: p2p.Config{ ListenAddr: "127.0.0.1:0", From 4d572a8670c48745af03ff78ad2f2542df57cbbd Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 10 Jan 2023 23:19:13 +0200 Subject: [PATCH 097/103] .github/workflows: .github/workflows: add whitelisted generated files in go-generate-check We currently have a modified generated file which will cause this check to always file, until we actually fix the generated code, we decided to whitelist this file. The file is: `params/types/genesisT/gen_genesis.go` --- .github/workflows/go-generate-check.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 52cc7c215c..70d18a81f5 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -30,6 +30,9 @@ jobs: - name: Run go:generate id: go-generate run: go generate ./... + - name: Skip whitelisted generated go files + id: skip-files + run: git checkout params/types/genesisT/gen_genesis.go - name: Check for modified files id: git-check run: From 0e79bc94ae1ec97a6547254c86b34f8002cbf545 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 11 Jan 2023 16:43:52 +0200 Subject: [PATCH 098/103] .github/workflows: .github/workflows: fix go-generate-check issues - skip protobuf installation as trezor code generation requires special handling - whitelist `params/types/genesisT/gen_genesis.go` which is custom modified --- .github/workflows/go-generate-check.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 70d18a81f5..47069da486 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -16,26 +16,31 @@ jobs: - name: Install deps id: install-deps run: | - sudo add-apt-repository ppa:ethereum/ethereum - sudo apt-get update - sudo apt-get install -y protobuf-compiler - SOLC_BIN=solc-linux-amd64-v0.6.12+commit.27d51765 curl -OL https://binaries.soliditylang.org/linux-amd64/$SOLC_BIN - sudo mv $SOLC_BIN /usr/local/bin/solc + sudo mv $SOLC_BIN /usr/bin/solc + sudo chmod +x /usr/bin/solc + shell: bash - name: Install devtools id: install-devtools run: make devtools - name: Run go:generate id: go-generate - run: go generate ./... + run: | + # ignore generating trezor package based on this comment: + # https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/trezor/trezor.go#L21-L43 + go generate `go list ./... | grep -v trezor` - name: Skip whitelisted generated go files id: skip-files - run: git checkout params/types/genesisT/gen_genesis.go + run: | + # ignore `gen_genesis.go` file which has custom modifications for unmarshaling the various genesis formats + git checkout params/types/genesisT/gen_genesis.go - name: Check for modified files id: git-check - run: + run: | if ! git diff-index --quiet HEAD --; then - core.setFailed('Please run `go generate ./...` to update codebase') + git status + + core.setFailed('Please run \"go generate ./...\" to update codebase') fi \ No newline at end of file From c4b75203778499efd1ed9f5e6a0eb9a9ea2ea0b6 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 11 Jan 2023 17:14:27 +0200 Subject: [PATCH 099/103] .github/workflows: .github/workflows: .github/workflows: fix emitting a failure in go-generate-check --- .github/workflows/go-generate-check.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 47069da486..2177bd8371 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -10,7 +10,6 @@ jobs: uses: actions/setup-go@v2 with: go-version: ^1.16 - - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: Install deps @@ -40,7 +39,12 @@ jobs: id: git-check run: | if ! git diff-index --quiet HEAD --; then + echo "changes_exist=true" >> $GITHUB_ENV git status - - core.setFailed('Please run \"go generate ./...\" to update codebase') - fi \ No newline at end of file + fi + - name: Fail if modified files exist + if: env.changes_exist == 'true' + uses: actions/github-script@v3 + with: + script: | + core.setFailed("Please run 'go generate ./...' to update codebase") \ No newline at end of file From 94ee05fea52775c5234bc1eeccd24404f679787b Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 11 Jan 2023 18:32:18 +0200 Subject: [PATCH 100/103] .github/workflows: .github/workflows: use solc@0.6.0 in go-generate-check for making checkpointoracle --- .github/workflows/go-generate-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 2177bd8371..7753af8311 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -15,7 +15,7 @@ jobs: - name: Install deps id: install-deps run: | - SOLC_BIN=solc-linux-amd64-v0.6.12+commit.27d51765 + SOLC_BIN=solc-linux-amd64-v0.6.0+commit.26b70077 curl -OL https://binaries.soliditylang.org/linux-amd64/$SOLC_BIN sudo mv $SOLC_BIN /usr/bin/solc sudo chmod +x /usr/bin/solc From 269749013d834893a09867d3577255a0d25e8e71 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 11 Jan 2023 09:03:55 -0800 Subject: [PATCH 101/103] .github/workflows: refactor exceptions and ignores to env vars I think this helps with readability. Date: 2023-01-11 09:03:55-08:00 Signed-off-by: meows --- .github/workflows/go-generate-check.yml | 27 +++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 2177bd8371..abed309e82 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -1,5 +1,17 @@ name: Developer helper on: pull_request +env: + # GENERATE_EXCEPTIONS are exceptions made to the 'go generate' command. + # These patterns are matched (negatively) against 'go list' output. + # + # - trezor: Ignore generating trezor package based on this comment: + # https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/trezor/trezor.go#L21-L43 + GENERATE_EXCEPTIONS: ("trezor") + # GENERATE_IGNORES are applied after the 'go generate' command. + # These files will be reverted after 'go generate' to their original ref version. + # + # - gen_genesis.go: file which has custom modifications for unmarshaling the various genesis formats + GENERATE_IGNORES: ("params/types/genesisT/gen_genesis.go") jobs: go-generate-check: name: Check if "go generate" has been run @@ -27,14 +39,16 @@ jobs: - name: Run go:generate id: go-generate run: | - # ignore generating trezor package based on this comment: - # https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/trezor/trezor.go#L21-L43 - go generate `go list ./... | grep -v trezor` + list="$(go list ./...)" + for pattern in "${env.GENERATE_EXCEPTIONS[@]}"; do + list="$(grep -v "$pattern" <<< "$list")" + done + go generate "$list" - name: Skip whitelisted generated go files id: skip-files run: | - # ignore `gen_genesis.go` file which has custom modifications for unmarshaling the various genesis formats - git checkout params/types/genesisT/gen_genesis.go + git checkout -- "${env.GENERATE_IGNORES[*]}" + - name: Check for modified files id: git-check run: | @@ -42,9 +56,10 @@ jobs: echo "changes_exist=true" >> $GITHUB_ENV git status fi + - name: Fail if modified files exist if: env.changes_exist == 'true' uses: actions/github-script@v3 with: script: | - core.setFailed("Please run 'go generate ./...' to update codebase") \ No newline at end of file + core.setFailed("Please run 'go generate ./...' to update codebase") From f195f3520f6e85c5f389da47bfed5ed7ce3b986a Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 12 Jan 2023 15:18:26 +0200 Subject: [PATCH 102/103] .github/workflows: .github/workflows: fix env vars list parsing in go-generate-check.yml --- .github/workflows/go-generate-check.yml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index 7b5bcf64b5..d3f1a0d918 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -6,12 +6,14 @@ env: # # - trezor: Ignore generating trezor package based on this comment: # https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/trezor/trezor.go#L21-L43 - GENERATE_EXCEPTIONS: ("trezor") + GENERATE_EXCEPTIONS: | + trezor # GENERATE_IGNORES are applied after the 'go generate' command. # These files will be reverted after 'go generate' to their original ref version. # # - gen_genesis.go: file which has custom modifications for unmarshaling the various genesis formats - GENERATE_IGNORES: ("params/types/genesisT/gen_genesis.go") + GENERATE_IGNORES: | + params/types/genesisT/gen_genesis.go jobs: go-generate-check: name: Check if "go generate" has been run @@ -40,26 +42,20 @@ jobs: id: go-generate run: | list="$(go list ./...)" - for pattern in "${env.GENERATE_EXCEPTIONS[@]}"; do + for pattern in ${GENERATE_EXCEPTIONS[@]}; do list="$(grep -v "$pattern" <<< "$list")" done go generate "$list" - name: Skip whitelisted generated go files id: skip-files run: | - git checkout -- "${env.GENERATE_IGNORES[*]}" + git checkout -- ${GENERATE_IGNORES[@]} - name: Check for modified files id: git-check run: | if ! git diff-index --quiet HEAD --; then - echo "changes_exist=true" >> $GITHUB_ENV + echo "🔴 ERROR: There are modified files after running 'go generate'" git status + exit 1 fi - - - name: Fail if modified files exist - if: env.changes_exist == 'true' - uses: actions/github-script@v3 - with: - script: | - core.setFailed("Please run 'go generate ./...' to update codebase") From 9a48b9c237bc970e94621b0efcf4c29b5b57e355 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Fri, 13 Jan 2023 22:26:11 +0200 Subject: [PATCH 103/103] .github/workflows: .github/workflows: .github/workflows: .github/workflows: go-generate-check changed logic for whitelisting changes in generated files directly The intention of this commit is to not break/change the logic for developers when coding. This script serves as a warning notification if a developer forgets to generate those files using gencodec. On specific cases where generated files are modified, we revert the modifications and compare the files so as they will show up any changes in the original files. The developer then will find out the correct way to resolve generating the new files and keeping the modifications intact if needed. --- .github/workflows/go-generate-check.yml | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/go-generate-check.yml b/.github/workflows/go-generate-check.yml index d3f1a0d918..b36c833661 100644 --- a/.github/workflows/go-generate-check.yml +++ b/.github/workflows/go-generate-check.yml @@ -8,12 +8,6 @@ env: # https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/trezor/trezor.go#L21-L43 GENERATE_EXCEPTIONS: | trezor - # GENERATE_IGNORES are applied after the 'go generate' command. - # These files will be reverted after 'go generate' to their original ref version. - # - # - gen_genesis.go: file which has custom modifications for unmarshaling the various genesis formats - GENERATE_IGNORES: | - params/types/genesisT/gen_genesis.go jobs: go-generate-check: name: Check if "go generate" has been run @@ -25,7 +19,9 @@ jobs: with: go-version: ^1.16 - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install deps id: install-deps run: | @@ -46,10 +42,20 @@ jobs: list="$(grep -v "$pattern" <<< "$list")" done go generate "$list" - - name: Skip whitelisted generated go files - id: skip-files + - name: Revert custom generated files modifications before comparing them + id: revert-custom-generated-modifications run: | - git checkout -- ${GENERATE_IGNORES[@]} + # NOTE to developers checking what triggered this alert. + # This script is meant to alert you if some files have to be regenerated using `go generate`. + # If this happens, you have to run `go generate ./...` and then check the below commits that are being reverted and reapply them, after considering if they are needed. + + git config user.name github-actions + git config user.email github-actions@github.com + + # Intentionally revert this commit which has a custom modification to the genesis unmarshaling, + # with regards reading different genesis formats origniating from different clients + # This way, this script can alert us on any code changes that have to be applied on if file gets changed. + git revert --no-edit 4b2cf83737ffe7c46c334a11414d151de049e0b3 - name: Check for modified files id: git-check