Skip to content

Commit

Permalink
sync upstream v0.5.10 (ba46d7b)
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Jan 10, 2024
2 parents 84d0cf8 + ba46d7b commit d3ae256
Show file tree
Hide file tree
Showing 323 changed files with 7,896 additions and 4,295 deletions.
6 changes: 0 additions & 6 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@

* @ceyonur @darioush @aaronbuchwald

# Specific directories:

peer/ @anusha-ctrl @ceyonur @darioush @aaronbuchwald
contracts/ @anusha-ctrl @ceyonur @darioush @aaronbuchwald
scripts/ @anusha-ctrl @ceyonur @darioush @aaronbuchwald

3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
- name: Run E2E Tests
shell: bash
run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego DATA_DIR=/tmp/e2e-test/data ./scripts/run_ginkgo.sh
- name: Run Warp E2E Tests
shell: bash
run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego DATA_DIR=/tmp/e2e-test/data ./scripts/run_ginkgo_warp.sh
- name: Upload Artifact
if: always()
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file configures github.com/golangci/golangci-lint.

run:
timeout: 3m
timeout: 10m
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and
[v0.5.0] AvalancheGo@v1.10.0 (Protocol Version: 25)
[v0.5.1] AvalancheGo@v1.10.1-v1.10.4 (Protocol Version: 26)
[v0.5.2] AvalancheGo@v1.10.1-v1.10.4 (Protocol Version: 26)
[v0.5.3] AvalancheGo@v1.10.5-v1.10.6 (Protocol Version: 27)
[v0.5.3] AvalancheGo@v1.10.5-v1.10.8 (Protocol Version: 27)
[v0.5.4] AvalancheGo@v1.10.9-v1.10.12 (Protocol Version: 28)
[v0.5.5] AvalancheGo@v1.10.9-v1.10.12 (Protocol Version: 28)
[v0.5.6] AvalancheGo@v1.10.9-v1.10.12 (Protocol Version: 28)
[v0.5.7] AvalancheGo@v1.10.13-v1.10.14 (Protocol Version: 29)
[v0.5.8] AvalancheGo@v1.10.13-v1.10.14 (Protocol Version: 29)
[v0.5.9] AvalancheGo@v1.10.15-v1.10.17 (Protocol Version: 30)
[v0.5.10] AvalancheGo@v1.10.15-v1.10.17 (Protocol Version: 30)
```

## API
Expand Down
19 changes: 19 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Security Policy

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
responsible disclosures. Valid reports will be eligible for a reward (terms and conditions apply).

## Reporting a Vulnerability

**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).

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
social engineering vulnerabilities.

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.

Please refer to the [Bug Bounty Page](https://hackenproof.com/avalanche) for the most up-to-date program rules and scope.

## Supported Versions

Please use the [most recently released version](https://github.com/ava-labs/subnet-evm/releases/latest) to perform testing and to validate security issues.
11 changes: 11 additions & 0 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
}

// ErrorByID looks up an error by the 4-byte id,
// returns nil if none found.
func (abi *ABI) ErrorByID(sigdata [4]byte) (*Error, error) {
for _, errABI := range abi.Errors {
if bytes.Equal(errABI.ID[:4], sigdata[:]) {
return &errABI, nil
}
}
return nil, fmt.Errorf("no error with id: %#x", sigdata[:])
}

// HasFallback returns an indicator whether a fallback function is included.
func (abi *ABI) HasFallback() bool {
return abi.Fallback.Type == Fallback
Expand Down
28 changes: 28 additions & 0 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,34 @@ func TestABI_EventById(t *testing.T) {
}
}

func TestABI_ErrorByID(t *testing.T) {
abi, err := JSON(strings.NewReader(`[
{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"MyError1","type":"error"},
{"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"},
{"inputs":[{"internalType":"uint256[]","name":"x","type":"uint256[]"}],"name":"MyError3","type":"error"}
]`))
if err != nil {
t.Fatal(err)
}
for name, m := range abi.Errors {
a := fmt.Sprintf("%v", &m)
var id [4]byte
copy(id[:], m.ID[:4])
m2, err := abi.ErrorByID(id)
if err != nil {
t.Fatalf("Failed to look up ABI error: %v", err)
}
b := fmt.Sprintf("%v", m2)
if a != b {
t.Errorf("Error %v (id %x) not 'findable' by id in ABI", name, id)
}
}
// test unsuccessful lookups
if _, err = abi.ErrorByID([4]byte{}); err == nil {
t.Error("Expected error: no error with this id")
}
}

// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
// conflict and that the second transfer method will be renamed transfer1.
func TestDoubleDuplicateMethodNames(t *testing.T) {
Expand Down
8 changes: 6 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
return errors.New("could not fetch parent")
}
// Check transaction validity
signer := types.NewLondonSigner(b.blockchain.Config().ChainID)
signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time())
sender, err := types.Sender(signer, tx)
if err != nil {
return fmt.Errorf("invalid transaction: %v", err)
Expand Down Expand Up @@ -940,7 +940,11 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
if number == nil {
return nil, nil
}
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
header := rawdb.ReadHeader(fb.db, hash, *number)
if header == nil {
return nil, nil
}
return rawdb.ReadReceipts(fb.db, hash, *number, header.Time, fb.bc.Config()), nil
}

func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) {
Expand Down
3 changes: 1 addition & 2 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func TestSimulatedBackend(t *testing.T) {
code := `6060604052600a8060106000396000f360606040526008565b00`
var gas uint64 = 3000000
tx := types.NewContractCreation(0, big.NewInt(0), gas, gasPrice, common.FromHex(code))
signer := types.NewLondonSigner(big.NewInt(1337))
tx, _ = types.SignTx(tx, signer, key)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, key)

err = sim.SendTransaction(context.Background(), tx)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]inter

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

// UnpackLogIntoMap unpacks a retrieved log into the provided map.
func (c *BoundContract) UnpackLogIntoMap(out map[string]interface{}, event string, log types.Log) error {
// Anonymous events are not supported.
if len(log.Topics) == 0 {
return errNoEventSignature
}
Expand Down
17 changes: 17 additions & 0 deletions accounts/abi/bind/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ func TestUnpackIndexedStringTyLogIntoMap(t *testing.T) {
unpackAndCheck(t, bc, expectedReceivedMap, mockLog)
}

func TestUnpackAnonymousLogIntoMap(t *testing.T) {
mockLog := newMockLog(nil, common.HexToHash("0x0"))

abiString := `[{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"received","type":"event"}]`
parsedAbi, _ := abi.JSON(strings.NewReader(abiString))
bc := bind.NewBoundContract(common.HexToAddress("0x0"), parsedAbi, nil, nil, nil)

var received map[string]interface{}
err := bc.UnpackLogIntoMap(received, "received", mockLog)
if err == nil {
t.Error("unpacking anonymous event is not supported")
}
if err.Error() != "no event signature" {
t.Errorf("expected error 'no event signature', got '%s'", err)
}
}

func TestUnpackIndexedSliceTyLogIntoMap(t *testing.T) {
sliceBytes, err := rlp.EncodeToBytes([]string{"name1", "name2", "name3", "name4"})
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
// Normalize the method for capital cases and non-anonymous inputs/outputs
normalized := original
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))

// Ensure there is no duplicated identifier
identifiers := callIdentifiers
if !original.IsConstant() {
identifiers = transactIdentifiers
}
// Name shouldn't start with a digit. It will make the generated code invalid.
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
normalizedName = fmt.Sprintf("M%s", normalizedName)
normalizedName = abi.ResolveNameConflict(normalizedName, func(name string) bool {
_, ok := identifiers[name]
return ok
})
}
if identifiers[normalizedName] {
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
}
Expand Down Expand Up @@ -199,6 +206,14 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s

// Ensure there is no duplicated identifier
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
// Name shouldn't start with a digit. It will make the generated code invalid.
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
normalizedName = fmt.Sprintf("E%s", normalizedName)
normalizedName = abi.ResolveNameConflict(normalizedName, func(name string) bool {
_, ok := eventIdentifiers[name]
return ok
})
}
if eventIdentifiers[normalizedName] {
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
}
Expand Down
23 changes: 23 additions & 0 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,29 @@ var bindTests = []struct {
t.Errorf("error deploying the contract: %v", err)
}
`,
}, {
name: "NumericMethodName",
contract: `
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
contract NumericMethodName {
event _1TestEvent(address _param);
function _1test() public pure {}
function __1test() public pure {}
function __2test() public pure {}
}
`,
bytecode: []string{"0x6080604052348015600f57600080fd5b5060958061001e6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80639d993132146041578063d02767c7146049578063ffa02795146051575b600080fd5b60476059565b005b604f605b565b005b6057605d565b005b565b565b56fea26469706673582212200382ca602dff96a7e2ba54657985e2b4ac423a56abe4a1f0667bc635c4d4371f64736f6c63430008110033"},
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"}]`},
imports: `
"github.com/ethereum/go-ethereum/common"
`,
tester: `
if b, err := NewNumericMethodName(common.Address{}, nil); b == nil || err != nil {
t.Fatalf("combined binding (%v) nil or error (%v) not nil", b, nil)
}
`,
},
}

Expand Down
18 changes: 9 additions & 9 deletions accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ var (
if err != nil {
return *outstruct, err
}
{{range $i, $t := .Normalized.Outputs}}
{{range $i, $t := .Normalized.Outputs}}
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return *outstruct, err
Expand All @@ -345,7 +345,7 @@ var (
}
{{range $i, $t := .Normalized.Outputs}}
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
{{end}}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ var (
}
{{end}}
{{if .Fallback}}
{{if .Fallback}}
// Fallback is a paid mutator transaction binding the contract fallback function.
//
// Solidity: {{.Fallback.Original.String}}
Expand All @@ -402,16 +402,16 @@ var (
func (_{{$contract.Type}} *{{$contract.Type}}Session) Fallback(calldata []byte) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
}
// Fallback is a paid mutator transaction binding the contract fallback function.
//
//
// Solidity: {{.Fallback.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Fallback(calldata []byte) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
}
{{end}}
{{if .Receive}}
{{if .Receive}}
// Receive is a paid mutator transaction binding the contract receive function.
//
// Solidity: {{.Receive.Original.String}}
Expand All @@ -425,9 +425,9 @@ var (
func (_{{$contract.Type}} *{{$contract.Type}}Session) Receive() (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
}
// Receive is a paid mutator transaction binding the contract receive function.
//
//
// Solidity: {{.Receive.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Receive() (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
Expand Down Expand Up @@ -576,6 +576,6 @@ var (
return event, nil
}
{{end}}
{{end}}
{{end}}
`
4 changes: 2 additions & 2 deletions accounts/abi/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Error struct {
str string

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

Expand Down Expand Up @@ -88,7 +88,7 @@ func NewError(name string, inputs Arguments) Error {
}
}

func (e *Error) String() string {
func (e Error) String() string {
return e.str
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/simulator/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Key struct {
Address common.Address
}

func createKey(pk *ecdsa.PrivateKey) *Key {
func CreateKey(pk *ecdsa.PrivateKey) *Key {
return &Key{pk, ethcrypto.PubkeyToAddress(pk.PublicKey)}
}

Expand All @@ -29,7 +29,7 @@ func Load(file string) (*Key, error) {
if err != nil {
return nil, fmt.Errorf("problem loading private key from %s: %w", file, err)
}
return createKey(pk), nil
return CreateKey(pk), nil
}

// LoadAll loads all keys in [dir].
Expand Down Expand Up @@ -81,5 +81,5 @@ func Generate() (*Key, error) {
if err != nil {
return nil, fmt.Errorf("%w: cannot generate key", err)
}
return createKey(pk), nil
return CreateKey(pk), nil
}
2 changes: 1 addition & 1 deletion cmd/simulator/load/funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func DistributeFunds(ctx context.Context, client ethclient.Client, keys []*key.K
}

numTxs := uint64(len(needFundsAddrs))
txSequence, err := txs.GenerateTxSequence(ctx, txGenerator, client, maxFundsKey.PrivKey, numTxs)
txSequence, err := txs.GenerateTxSequence(ctx, txGenerator, client, maxFundsKey.PrivKey, numTxs, false)
if err != nil {
return nil, fmt.Errorf("failed to generate fund distribution sequence from %s of length %d", maxFundsKey.Address, len(needFundsAddrs))
}
Expand Down
Loading

0 comments on commit d3ae256

Please sign in to comment.