Skip to content

Commit b9c6d36

Browse files
authored
Merge pull request ethereum#104 from ethereum-optimism/aj/1.12.0
Merge upstream geth 1.12.0 release
2 parents 39d121a + ce4f8b7 commit b9c6d36

File tree

329 files changed

+15162
-11299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+15162
-11299
lines changed

accounts/abi/abi.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
222222
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
223223
}
224224

225+
// ErrorByID looks up an error by the 4-byte id,
226+
// returns nil if none found.
227+
func (abi *ABI) ErrorByID(sigdata [4]byte) (*Error, error) {
228+
for _, errABI := range abi.Errors {
229+
if bytes.Equal(errABI.ID[:4], sigdata[:]) {
230+
return &errABI, nil
231+
}
232+
}
233+
return nil, fmt.Errorf("no error with id: %#x", sigdata[:])
234+
}
235+
225236
// HasFallback returns an indicator whether a fallback function is included.
226237
func (abi *ABI) HasFallback() bool {
227238
return abi.Fallback.Type == Fallback

accounts/abi/abi_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,34 @@ func TestABI_EventById(t *testing.T) {
10571057
}
10581058
}
10591059

1060+
func TestABI_ErrorByID(t *testing.T) {
1061+
abi, err := JSON(strings.NewReader(`[
1062+
{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"MyError1","type":"error"},
1063+
{"inputs":[{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"x","type":"tuple"},{"internalType":"address","name":"y","type":"address"},{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"z","type":"tuple"}],"name":"MyError2","type":"error"},
1064+
{"inputs":[{"internalType":"uint256[]","name":"x","type":"uint256[]"}],"name":"MyError3","type":"error"}
1065+
]`))
1066+
if err != nil {
1067+
t.Fatal(err)
1068+
}
1069+
for name, m := range abi.Errors {
1070+
a := fmt.Sprintf("%v", &m)
1071+
var id [4]byte
1072+
copy(id[:], m.ID[:4])
1073+
m2, err := abi.ErrorByID(id)
1074+
if err != nil {
1075+
t.Fatalf("Failed to look up ABI error: %v", err)
1076+
}
1077+
b := fmt.Sprintf("%v", m2)
1078+
if a != b {
1079+
t.Errorf("Error %v (id %x) not 'findable' by id in ABI", name, id)
1080+
}
1081+
}
1082+
// test unsuccessful lookups
1083+
if _, err = abi.ErrorByID([4]byte{}); err == nil {
1084+
t.Error("Expected error: no error with this id")
1085+
}
1086+
}
1087+
10601088
// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
10611089
// conflict and that the second transfer method will be renamed transfer1.
10621090
func TestDoubleDuplicateMethodNames(t *testing.T) {

accounts/abi/bind/backends/simulated.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
755755
return fmt.Errorf("could not fetch parent")
756756
}
757757
// Check transaction validity
758-
signer := types.MakeSigner(b.blockchain.Config(), block.Number())
758+
signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time())
759759
sender, err := types.Sender(signer, tx)
760760
if err != nil {
761761
return fmt.Errorf("invalid transaction: %v", err)
@@ -955,7 +955,11 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
955955
if number == nil {
956956
return nil, nil
957957
}
958-
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
958+
header := rawdb.ReadHeader(fb.db, hash, *number)
959+
if header == nil {
960+
return nil, nil
961+
}
962+
return rawdb.ReadReceipts(fb.db, hash, *number, header.Time, fb.bc.Config()), nil
959963
}
960964

961965
func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) {

accounts/abi/bind/bind.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,19 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
133133
// Normalize the method for capital cases and non-anonymous inputs/outputs
134134
normalized := original
135135
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
136-
137136
// Ensure there is no duplicated identifier
138137
var identifiers = callIdentifiers
139138
if !original.IsConstant() {
140139
identifiers = transactIdentifiers
141140
}
141+
// Name shouldn't start with a digit. It will make the generated code invalid.
142+
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
143+
normalizedName = fmt.Sprintf("M%s", normalizedName)
144+
normalizedName = abi.ResolveNameConflict(normalizedName, func(name string) bool {
145+
_, ok := identifiers[name]
146+
return ok
147+
})
148+
}
142149
if identifiers[normalizedName] {
143150
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
144151
}
@@ -182,6 +189,14 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
182189

183190
// Ensure there is no duplicated identifier
184191
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
192+
// Name shouldn't start with a digit. It will make the generated code invalid.
193+
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
194+
normalizedName = fmt.Sprintf("E%s", normalizedName)
195+
normalizedName = abi.ResolveNameConflict(normalizedName, func(name string) bool {
196+
_, ok := eventIdentifiers[name]
197+
return ok
198+
})
199+
}
185200
if eventIdentifiers[normalizedName] {
186201
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
187202
}

accounts/abi/bind/bind_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,29 @@ var bindTests = []struct {
20382038
t.Errorf("error deploying the contract: %v", err)
20392039
}
20402040
`,
2041+
}, {
2042+
name: "NumericMethodName",
2043+
contract: `
2044+
// SPDX-License-Identifier: GPL-3.0
2045+
pragma solidity >=0.4.22 <0.9.0;
2046+
2047+
contract NumericMethodName {
2048+
event _1TestEvent(address _param);
2049+
function _1test() public pure {}
2050+
function __1test() public pure {}
2051+
function __2test() public pure {}
2052+
}
2053+
`,
2054+
bytecode: []string{"0x6080604052348015600f57600080fd5b5060958061001e6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80639d993132146041578063d02767c7146049578063ffa02795146051575b600080fd5b60476059565b005b604f605b565b005b6057605d565b005b565b565b56fea26469706673582212200382ca602dff96a7e2ba54657985e2b4ac423a56abe4a1f0667bc635c4d4371f64736f6c63430008110033"},
2055+
abi: []string{`[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_param","type":"address"}],"name":"_1TestEvent","type":"event"},{"inputs":[],"name":"_1test","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"__1test","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"__2test","outputs":[],"stateMutability":"pure","type":"function"}]`},
2056+
imports: `
2057+
"github.com/ethereum/go-ethereum/common"
2058+
`,
2059+
tester: `
2060+
if b, err := NewNumericMethodName(common.Address{}, nil); b == nil || err != nil {
2061+
t.Fatalf("combined binding (%v) nil or error (%v) not nil", b, nil)
2062+
}
2063+
`,
20412064
},
20422065
}
20432066

accounts/abi/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NewError(name string, inputs Arguments) Error {
7878
}
7979
}
8080

81-
func (e *Error) String() string {
81+
func (e Error) String() string {
8282
return e.str
8383
}
8484

beacon/merkle/merkle.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2022 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// Package merkle implements proof verifications in binary merkle trees.
18+
package merkle
19+
20+
import (
21+
"crypto/sha256"
22+
"errors"
23+
"reflect"
24+
25+
"github.com/ethereum/go-ethereum/common"
26+
"github.com/ethereum/go-ethereum/common/hexutil"
27+
)
28+
29+
// Value represents either a 32 byte leaf value or hash node in a binary merkle tree/partial proof.
30+
type Value [32]byte
31+
32+
// Values represent a series of merkle tree leaves/nodes.
33+
type Values []Value
34+
35+
var valueT = reflect.TypeOf(Value{})
36+
37+
// UnmarshalJSON parses a merkle value in hex syntax.
38+
func (m *Value) UnmarshalJSON(input []byte) error {
39+
return hexutil.UnmarshalFixedJSON(valueT, input, m[:])
40+
}
41+
42+
// VerifyProof verifies a Merkle proof branch for a single value in a
43+
// binary Merkle tree (index is a generalized tree index).
44+
func VerifyProof(root common.Hash, index uint64, branch Values, value Value) error {
45+
hasher := sha256.New()
46+
for _, sibling := range branch {
47+
hasher.Reset()
48+
if index&1 == 0 {
49+
hasher.Write(value[:])
50+
hasher.Write(sibling[:])
51+
} else {
52+
hasher.Write(sibling[:])
53+
hasher.Write(value[:])
54+
}
55+
hasher.Sum(value[:0])
56+
if index >>= 1; index == 0 {
57+
return errors.New("branch has extra items")
58+
}
59+
}
60+
if index != 1 {
61+
return errors.New("branch is missing items")
62+
}
63+
if common.Hash(value) != root {
64+
return errors.New("root mismatch")
65+
}
66+
return nil
67+
}
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 The go-ethereum Authors
1+
// Copyright 2022 The go-ethereum Authors
22
// This file is part of the go-ethereum library.
33
//
44
// The go-ethereum library is free software: you can redistribute it and/or modify
@@ -14,22 +14,31 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//go:build linux
18-
// +build linux
17+
package params
1918

20-
package ethash
19+
const (
20+
EpochLength = 32
21+
SyncPeriodLength = 8192
2122

22-
import (
23-
"os"
23+
BLSSignatureSize = 96
24+
BLSPubkeySize = 48
2425

25-
"golang.org/x/sys/unix"
26+
SyncCommitteeSize = 512
27+
SyncCommitteeBitmaskSize = SyncCommitteeSize / 8
28+
SyncCommitteeSupermajority = (SyncCommitteeSize*2 + 2) / 3
2629
)
2730

28-
// ensureSize expands the file to the given size. This is to prevent runtime
29-
// errors later on, if the underlying file expands beyond the disk capacity,
30-
// even though it ostensibly is already expanded, but due to being sparse
31-
// does not actually occupy the full declared size on disk.
32-
func ensureSize(f *os.File, size int64) error {
33-
// Docs: https://www.man7.org/linux/man-pages/man2/fallocate.2.html
34-
return unix.Fallocate(int(f.Fd()), 0, 0, size)
35-
}
31+
const (
32+
StateIndexGenesisTime = 32
33+
StateIndexGenesisValidators = 33
34+
StateIndexForkVersion = 141
35+
StateIndexLatestHeader = 36
36+
StateIndexBlockRoots = 37
37+
StateIndexStateRoots = 38
38+
StateIndexHistoricRoots = 39
39+
StateIndexFinalBlock = 105
40+
StateIndexSyncCommittee = 54
41+
StateIndexNextSyncCommittee = 55
42+
StateIndexExecPayload = 56
43+
StateIndexExecHead = 908
44+
)

0 commit comments

Comments
 (0)