Skip to content

Commit 8beb366

Browse files
darioushceyonur
andauthored
coreth sync: 0.12.4-rc.0 -> 0.12.7 (#975)
* coreth sync: 0.12.4-rc.0 -> 0.12.7 * Review coreth 0.12.7 (#980) * Apply suggested changes from https://github.com/ava-labs/coreth/pull/381/files * drop reexec=0 * add txHashes * bump avalanchego * remove manager * fix compat test * bump version for e2e tests --------- Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
1 parent bb9aca9 commit 8beb366

File tree

273 files changed

+5703
-3238
lines changed

Some content is hidden

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

273 files changed

+5703
-3238
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file configures github.com/golangci/golangci-lint.
22

33
run:
4-
timeout: 3m
4+
timeout: 10m
55
tests: true
66
# default is true. Enables skipping of directories:
77
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$

SECURITY.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Security Policy
2+
3+
Avalanche takes the security of the platform and of its users very seriously. We and our community recognize the critical role of external security researchers and developers and welcome
4+
responsible disclosures. Valid reports will be eligible for a reward (terms and conditions apply).
5+
6+
## Reporting a Vulnerability
7+
8+
**Please do not file a public ticket** mentioning the vulnerability. To disclose a vulnerability submit it through our [Bug Bounty Program](https://hackenproof.com/avalanche).
9+
10+
Vulnerabilities must be disclosed to us privately with reasonable time to respond, and avoid compromise of other users and accounts, or loss of funds that are not your own. We do not reward spam or
11+
social engineering vulnerabilities.
12+
13+
Do not test for or validate any security issues in the live Avalanche networks (Mainnet and Fuji testnet), confirm all exploits in a local private testnet.
14+
15+
Please refer to the [Bug Bounty Page](https://hackenproof.com/avalanche) for the most up-to-date program rules and scope.
16+
17+
## Supported Versions
18+
19+
Please use the [most recently released version](https://github.com/ava-labs/subnet-evm/releases/latest) to perform testing and to validate security issues.

accounts/abi/abi.go

+11
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,17 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
341341
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
342342
}
343343

344+
// ErrorByID looks up an error by the 4-byte id,
345+
// returns nil if none found.
346+
func (abi *ABI) ErrorByID(sigdata [4]byte) (*Error, error) {
347+
for _, errABI := range abi.Errors {
348+
if bytes.Equal(errABI.ID[:4], sigdata[:]) {
349+
return &errABI, nil
350+
}
351+
}
352+
return nil, fmt.Errorf("no error with id: %#x", sigdata[:])
353+
}
354+
344355
// HasFallback returns an indicator whether a fallback function is included.
345356
func (abi *ABI) HasFallback() bool {
346357
return abi.Fallback.Type == Fallback

accounts/abi/abi_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,34 @@ func TestABI_EventById(t *testing.T) {
10681068
}
10691069
}
10701070

1071+
func TestABI_ErrorByID(t *testing.T) {
1072+
abi, err := JSON(strings.NewReader(`[
1073+
{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"MyError1","type":"error"},
1074+
{"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"},
1075+
{"inputs":[{"internalType":"uint256[]","name":"x","type":"uint256[]"}],"name":"MyError3","type":"error"}
1076+
]`))
1077+
if err != nil {
1078+
t.Fatal(err)
1079+
}
1080+
for name, m := range abi.Errors {
1081+
a := fmt.Sprintf("%v", &m)
1082+
var id [4]byte
1083+
copy(id[:], m.ID[:4])
1084+
m2, err := abi.ErrorByID(id)
1085+
if err != nil {
1086+
t.Fatalf("Failed to look up ABI error: %v", err)
1087+
}
1088+
b := fmt.Sprintf("%v", m2)
1089+
if a != b {
1090+
t.Errorf("Error %v (id %x) not 'findable' by id in ABI", name, id)
1091+
}
1092+
}
1093+
// test unsuccessful lookups
1094+
if _, err = abi.ErrorByID([4]byte{}); err == nil {
1095+
t.Error("Expected error: no error with this id")
1096+
}
1097+
}
1098+
10711099
// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
10721100
// conflict and that the second transfer method will be renamed transfer1.
10731101
func TestDoubleDuplicateMethodNames(t *testing.T) {

accounts/abi/bind/backends/simulated.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
723723
return errors.New("could not fetch parent")
724724
}
725725
// Check transaction validity
726-
signer := types.NewLondonSigner(b.blockchain.Config().ChainID)
726+
signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time())
727727
sender, err := types.Sender(signer, tx)
728728
if err != nil {
729729
return fmt.Errorf("invalid transaction: %v", err)
@@ -940,7 +940,11 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
940940
if number == nil {
941941
return nil, nil
942942
}
943-
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
943+
header := rawdb.ReadHeader(fb.db, hash, *number)
944+
if header == nil {
945+
return nil, nil
946+
}
947+
return rawdb.ReadReceipts(fb.db, hash, *number, header.Time, fb.bc.Config()), nil
944948
}
945949

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

accounts/abi/bind/backends/simulated_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ func TestSimulatedBackend(t *testing.T) {
7575
code := `6060604052600a8060106000396000f360606040526008565b00`
7676
var gas uint64 = 3000000
7777
tx := types.NewContractCreation(0, big.NewInt(0), gas, gasPrice, common.FromHex(code))
78-
signer := types.NewLondonSigner(big.NewInt(1337))
79-
tx, _ = types.SignTx(tx, signer, key)
78+
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, key)
8079

8180
err = sim.SendTransaction(context.Background(), tx)
8281
if err != nil {

accounts/abi/bind/base.go

+2
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]inter
503503

504504
// UnpackLog unpacks a retrieved log into the provided output structure.
505505
func (c *BoundContract) UnpackLog(out interface{}, event string, log types.Log) error {
506+
// Anonymous events are not supported.
506507
if len(log.Topics) == 0 {
507508
return errNoEventSignature
508509
}
@@ -525,6 +526,7 @@ func (c *BoundContract) UnpackLog(out interface{}, event string, log types.Log)
525526

526527
// UnpackLogIntoMap unpacks a retrieved log into the provided map.
527528
func (c *BoundContract) UnpackLogIntoMap(out map[string]interface{}, event string, log types.Log) error {
529+
// Anonymous events are not supported.
528530
if len(log.Topics) == 0 {
529531
return errNoEventSignature
530532
}

accounts/abi/bind/base_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@ func TestUnpackIndexedStringTyLogIntoMap(t *testing.T) {
195195
unpackAndCheck(t, bc, expectedReceivedMap, mockLog)
196196
}
197197

198+
func TestUnpackAnonymousLogIntoMap(t *testing.T) {
199+
mockLog := newMockLog(nil, common.HexToHash("0x0"))
200+
201+
abiString := `[{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"received","type":"event"}]`
202+
parsedAbi, _ := abi.JSON(strings.NewReader(abiString))
203+
bc := bind.NewBoundContract(common.HexToAddress("0x0"), parsedAbi, nil, nil, nil)
204+
205+
var received map[string]interface{}
206+
err := bc.UnpackLogIntoMap(received, "received", mockLog)
207+
if err == nil {
208+
t.Error("unpacking anonymous event is not supported")
209+
}
210+
if err.Error() != "no event signature" {
211+
t.Errorf("expected error 'no event signature', got '%s'", err)
212+
}
213+
}
214+
198215
func TestUnpackIndexedSliceTyLogIntoMap(t *testing.T) {
199216
sliceBytes, err := rlp.EncodeToBytes([]string{"name1", "name2", "name3", "name4"})
200217
if err != nil {

accounts/abi/bind/bind.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,19 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
150150
// Normalize the method for capital cases and non-anonymous inputs/outputs
151151
normalized := original
152152
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
153-
154153
// Ensure there is no duplicated identifier
155154
identifiers := callIdentifiers
156155
if !original.IsConstant() {
157156
identifiers = transactIdentifiers
158157
}
158+
// Name shouldn't start with a digit. It will make the generated code invalid.
159+
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
160+
normalizedName = fmt.Sprintf("M%s", normalizedName)
161+
normalizedName = abi.ResolveNameConflict(normalizedName, func(name string) bool {
162+
_, ok := identifiers[name]
163+
return ok
164+
})
165+
}
159166
if identifiers[normalizedName] {
160167
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
161168
}
@@ -199,6 +206,14 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
199206

200207
// Ensure there is no duplicated identifier
201208
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
209+
// Name shouldn't start with a digit. It will make the generated code invalid.
210+
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
211+
normalizedName = fmt.Sprintf("E%s", normalizedName)
212+
normalizedName = abi.ResolveNameConflict(normalizedName, func(name string) bool {
213+
_, ok := eventIdentifiers[name]
214+
return ok
215+
})
216+
}
202217
if eventIdentifiers[normalizedName] {
203218
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
204219
}

accounts/abi/bind/bind_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,29 @@ var bindTests = []struct {
20532053
t.Errorf("error deploying the contract: %v", err)
20542054
}
20552055
`,
2056+
}, {
2057+
name: "NumericMethodName",
2058+
contract: `
2059+
// SPDX-License-Identifier: GPL-3.0
2060+
pragma solidity >=0.4.22 <0.9.0;
2061+
2062+
contract NumericMethodName {
2063+
event _1TestEvent(address _param);
2064+
function _1test() public pure {}
2065+
function __1test() public pure {}
2066+
function __2test() public pure {}
2067+
}
2068+
`,
2069+
bytecode: []string{"0x6080604052348015600f57600080fd5b5060958061001e6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80639d993132146041578063d02767c7146049578063ffa02795146051575b600080fd5b60476059565b005b604f605b565b005b6057605d565b005b565b565b56fea26469706673582212200382ca602dff96a7e2ba54657985e2b4ac423a56abe4a1f0667bc635c4d4371f64736f6c63430008110033"},
2070+
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"}]`},
2071+
imports: `
2072+
"github.com/ethereum/go-ethereum/common"
2073+
`,
2074+
tester: `
2075+
if b, err := NewNumericMethodName(common.Address{}, nil); b == nil || err != nil {
2076+
t.Fatalf("combined binding (%v) nil or error (%v) not nil", b, nil)
2077+
}
2078+
`,
20562079
},
20572080
}
20582081

accounts/abi/bind/template.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ var (
335335
if err != nil {
336336
return *outstruct, err
337337
}
338-
{{range $i, $t := .Normalized.Outputs}}
338+
{{range $i, $t := .Normalized.Outputs}}
339339
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
340340
341341
return *outstruct, err
@@ -345,7 +345,7 @@ var (
345345
}
346346
{{range $i, $t := .Normalized.Outputs}}
347347
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
348-
348+
349349
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
350350
{{end}}
351351
}
@@ -388,7 +388,7 @@ var (
388388
}
389389
{{end}}
390390
391-
{{if .Fallback}}
391+
{{if .Fallback}}
392392
// Fallback is a paid mutator transaction binding the contract fallback function.
393393
//
394394
// Solidity: {{.Fallback.Original.String}}
@@ -402,16 +402,16 @@ var (
402402
func (_{{$contract.Type}} *{{$contract.Type}}Session) Fallback(calldata []byte) (*types.Transaction, error) {
403403
return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
404404
}
405-
405+
406406
// Fallback is a paid mutator transaction binding the contract fallback function.
407-
//
407+
//
408408
// Solidity: {{.Fallback.Original.String}}
409409
func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Fallback(calldata []byte) (*types.Transaction, error) {
410410
return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
411411
}
412412
{{end}}
413413
414-
{{if .Receive}}
414+
{{if .Receive}}
415415
// Receive is a paid mutator transaction binding the contract receive function.
416416
//
417417
// Solidity: {{.Receive.Original.String}}
@@ -425,9 +425,9 @@ var (
425425
func (_{{$contract.Type}} *{{$contract.Type}}Session) Receive() (*types.Transaction, error) {
426426
return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
427427
}
428-
428+
429429
// Receive is a paid mutator transaction binding the contract receive function.
430-
//
430+
//
431431
// Solidity: {{.Receive.Original.String}}
432432
func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Receive() (*types.Transaction, error) {
433433
return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
@@ -576,6 +576,6 @@ var (
576576
return event, nil
577577
}
578578
579-
{{end}}
579+
{{end}}
580580
{{end}}
581581
`

accounts/abi/error.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Error struct {
4242
str string
4343

4444
// Sig contains the string signature according to the ABI spec.
45-
// e.g. error foo(uint32 a, int b) = "foo(uint32,int256)"
45+
// e.g. error foo(uint32 a, int b) = "foo(uint32,int256)"
4646
// Please note that "int" is substitute for its canonical representation "int256"
4747
Sig string
4848

@@ -88,7 +88,7 @@ func NewError(name string, inputs Arguments) Error {
8888
}
8989
}
9090

91-
func (e *Error) String() string {
91+
func (e Error) String() string {
9292
return e.str
9393
}
9494

consensus/dummy/consensus.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ func (self *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header
233233
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
234234
return consensus.ErrInvalidNumber
235235
}
236+
// Verify the existence / non-existence of excessDataGas
237+
cancun := chain.Config().IsCancun(header.Time)
238+
if cancun && header.ExcessDataGas == nil {
239+
return errors.New("missing excessDataGas")
240+
}
241+
if !cancun && header.ExcessDataGas != nil {
242+
return fmt.Errorf("invalid excessDataGas: have %d, expected nil", header.ExcessDataGas)
243+
}
236244
return nil
237245
}
238246

@@ -400,7 +408,7 @@ func (self *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader,
400408

401409
// Header seems complete, assemble into a block and return
402410
return types.NewBlock(
403-
header, txs, uncles, receipts, new(trie.Trie),
411+
header, txs, uncles, receipts, trie.NewStackTrie(nil),
404412
), nil
405413
}
406414

consensus/misc/eip4844.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2023 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 misc
18+
19+
import (
20+
"math/big"
21+
22+
"github.com/ava-labs/subnet-evm/params"
23+
)
24+
25+
var (
26+
minDataGasPrice = big.NewInt(params.BlobTxMinDataGasprice)
27+
dataGaspriceUpdateFraction = big.NewInt(params.BlobTxDataGaspriceUpdateFraction)
28+
)
29+
30+
// CalcBlobFee calculates the blobfee from the header's excess data gas field.
31+
func CalcBlobFee(excessDataGas *big.Int) *big.Int {
32+
// If this block does not yet have EIP-4844 enabled, return the starting fee
33+
if excessDataGas == nil {
34+
return big.NewInt(params.BlobTxMinDataGasprice)
35+
}
36+
return fakeExponential(minDataGasPrice, excessDataGas, dataGaspriceUpdateFraction)
37+
}
38+
39+
// fakeExponential approximates factor * e ** (numerator / denominator) using
40+
// Taylor expansion.
41+
func fakeExponential(factor, numerator, denominator *big.Int) *big.Int {
42+
var (
43+
output = new(big.Int)
44+
accum = new(big.Int).Mul(factor, denominator)
45+
)
46+
for i := 1; accum.Sign() > 0; i++ {
47+
output.Add(output, accum)
48+
49+
accum.Mul(accum, numerator)
50+
accum.Div(accum, denominator)
51+
accum.Div(accum, big.NewInt(int64(i)))
52+
}
53+
return output.Div(output, denominator)
54+
}

0 commit comments

Comments
 (0)