Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/ISSUE_TEMPLATE.md → .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Hi there,

Please note that this is an issue tracker reserved for bug reports and feature requests.

For general questions please use [discord](https://discord.gg/nthXNEv) or the Ethereum stack exchange at https://ethereum.stackexchange.com.
---
name: Report a bug
about: Something with go-ethereum is not working as expected
title: ''
labels: 'type:bug'
assignees: ''
---

#### System information

Expand Down
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Request a feature
about: Report a missing feature - e.g. as a step before submitting a PR
title: ''
labels: 'type:feature'
assignees: ''
---

# Rationale

Why should this feature exist?
What are the use-cases?

# Implementation

Do you have ideas regarding the implementation of this feature?
Are you willing to implement this feature?
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Ask a question
about: Something is unclear
title: ''
labels: 'type:docs'
assignees: ''
---

This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation. For general questions please use [discord](https://discord.gg/nthXNEv) or the Ethereum stack exchange at https://ethereum.stackexchange.com.
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/vulnerability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Report a vulnerability
about: There is a bug in go-ethereum that can be exploited
title: ''
labels: 'type:security'
assignees: ''
---

Please do not submit these in this public issue tracker!

To find out how to disclose a vulnerability in Ethereum visit https://bounty.ethereum.org or email bounty@ethereum.org.

Please read [Reporting a vulnerability](https://github.com/ethereum/go-ethereum/security/policy#reporting-a-vulnerability) for more information.
9 changes: 9 additions & 0 deletions crypto/bls12381/fp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,15 @@ func BenchmarkMultiplication(t *testing.B) {
}
}

func BenchmarkInverse(t *testing.B) {
a, _ := new(fe).rand(rand.Reader)
b, _ := new(fe).rand(rand.Reader)
t.ResetTimer()
for i := 0; i < t.N; i++ {
inverse(a, b)
}
}

func padBytes(in []byte, size int) []byte {
out := make([]byte, size)
if len(in) > size {
Expand Down
66 changes: 45 additions & 21 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package graphql
import (
"context"
"errors"
"fmt"
"strconv"
"time"

"github.com/ethereum/go-ethereum"
Expand All @@ -39,6 +41,27 @@ var (
errBlockInvariant = errors.New("block objects must be instantiated with at least one of num or hash")
)

type Long uint64

// ImplementsGraphQLType returns true if Long implements the provided GraphQL type.
func (b Long) ImplementsGraphQLType(name string) bool { return name == "Long" }

// UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (b *Long) UnmarshalGraphQL(input interface{}) error {
var err error
switch input := input.(type) {
case string:
value, err := strconv.ParseUint(input, 10, 64)
*b = Long(value)
return err
case int32:
*b = Long(input)
default:
err = fmt.Errorf("unexpected type %T for Long", input)
}
return err
}

// Account represents an Ethereum account at a particular block.
type Account struct {
backend ethapi.Backend
Expand Down Expand Up @@ -268,21 +291,21 @@ func (t *Transaction) Status(ctx context.Context) (*hexutil.Uint64, error) {
return &ret, nil
}

func (t *Transaction) GasUsed(ctx context.Context) (*hexutil.Uint64, error) {
func (t *Transaction) GasUsed(ctx context.Context) (*Long, error) {
receipt, err := t.getReceipt(ctx)
if err != nil || receipt == nil {
return nil, err
}
ret := hexutil.Uint64(receipt.GasUsed)
ret := Long(receipt.GasUsed)
return &ret, nil
}

func (t *Transaction) CumulativeGasUsed(ctx context.Context) (*hexutil.Uint64, error) {
func (t *Transaction) CumulativeGasUsed(ctx context.Context) (*Long, error) {
receipt, err := t.getReceipt(ctx)
if err != nil || receipt == nil {
return nil, err
}
ret := hexutil.Uint64(receipt.CumulativeGasUsed)
ret := Long(receipt.CumulativeGasUsed)
return &ret, nil
}

Expand Down Expand Up @@ -415,13 +438,13 @@ func (b *Block) resolveReceipts(ctx context.Context) ([]*types.Receipt, error) {
return b.receipts, nil
}

func (b *Block) Number(ctx context.Context) (hexutil.Uint64, error) {
func (b *Block) Number(ctx context.Context) (Long, error) {
header, err := b.resolveHeader(ctx)
if err != nil {
return 0, err
return Long(0), err
}

return hexutil.Uint64(header.Number.Uint64()), nil
return Long(header.Number.Uint64()), nil
}

func (b *Block) Hash(ctx context.Context) (common.Hash, error) {
Expand All @@ -435,20 +458,20 @@ func (b *Block) Hash(ctx context.Context) (common.Hash, error) {
return b.hash, nil
}

func (b *Block) GasLimit(ctx context.Context) (hexutil.Uint64, error) {
func (b *Block) GasLimit(ctx context.Context) (Long, error) {
header, err := b.resolveHeader(ctx)
if err != nil {
return 0, err
}
return hexutil.Uint64(header.GasLimit), nil
return Long(header.GasLimit), nil
}

func (b *Block) GasUsed(ctx context.Context) (hexutil.Uint64, error) {
func (b *Block) GasUsed(ctx context.Context) (Long, error) {
header, err := b.resolveHeader(ctx)
if err != nil {
return 0, err
}
return hexutil.Uint64(header.GasUsed), nil
return Long(header.GasUsed), nil
}

func (b *Block) Parent(ctx context.Context) (*Block, error) {
Expand Down Expand Up @@ -778,16 +801,16 @@ type CallData struct {
// CallResult encapsulates the result of an invocation of the `call` accessor.
type CallResult struct {
data hexutil.Bytes // The return data from the call
gasUsed hexutil.Uint64 // The amount of gas used
gasUsed Long // The amount of gas used
status hexutil.Uint64 // The return status of the call - 0 for failure or 1 for success.
}

func (c *CallResult) Data() hexutil.Bytes {
return c.data
}

func (c *CallResult) GasUsed() hexutil.Uint64 {
return c.gasUsed
func (c *CallResult) GasUsed() Long {
return Long(c.gasUsed)
}

func (c *CallResult) Status() hexutil.Uint64 {
Expand All @@ -814,22 +837,22 @@ func (b *Block) Call(ctx context.Context, args struct {

return &CallResult{
data: result.ReturnData,
gasUsed: hexutil.Uint64(result.UsedGas),
gasUsed: Long(result.UsedGas),
status: status,
}, nil
}

func (b *Block) EstimateGas(ctx context.Context, args struct {
Data ethapi.CallArgs
}) (hexutil.Uint64, error) {
}) (Long, error) {
if b.numberOrHash == nil {
_, err := b.resolveHeader(ctx)
if err != nil {
return hexutil.Uint64(0), err
return Long(0), err
}
}
gas, err := ethapi.DoEstimateGas(ctx, b.backend, args.Data, *b.numberOrHash, b.backend.RPCGasCap())
return gas, err
return Long(gas), err
}

type Pending struct {
Expand Down Expand Up @@ -884,16 +907,17 @@ func (p *Pending) Call(ctx context.Context, args struct {

return &CallResult{
data: result.ReturnData,
gasUsed: hexutil.Uint64(result.UsedGas),
gasUsed: Long(result.UsedGas),
status: status,
}, nil
}

func (p *Pending) EstimateGas(ctx context.Context, args struct {
Data ethapi.CallArgs
}) (hexutil.Uint64, error) {
}) (Long, error) {
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
return ethapi.DoEstimateGas(ctx, p.backend, args.Data, pendingBlockNr, p.backend.RPCGasCap())
long, err := ethapi.DoEstimateGas(ctx, p.backend, args.Data, pendingBlockNr, p.backend.RPCGasCap())
return Long(long), err
}

// Resolver is the top-level object in the GraphQL hierarchy.
Expand Down
27 changes: 26 additions & 1 deletion graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,32 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Successful(t *testing.T) {
if err != nil {
t.Fatalf("could not read from response body: %v", err)
}
expected := "{\"data\":{\"block\":{\"number\":\"0x0\"}}}"
expected := "{\"data\":{\"block\":{\"number\":0}}}"
assert.Equal(t, expected, string(bodyBytes))
}

// 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)
defer stack.Close()
// start node
if err := stack.Start(); err != nil {
t.Fatalf("could not start node: %v", err)
}
// create http request
body := strings.NewReader("{\"query\": \"{block{number,gasUsed,gasLimit}}\",\"variables\": null}")
gqlReq, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s/graphql", "127.0.0.1:9393"), body)
if err != nil {
t.Error("could not issue new http request ", err)
}
gqlReq.Header.Set("Content-Type", "application/json")
// read from response
resp := doHTTPRequest(t, gqlReq)
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("could not read from response body: %v", err)
}
expected := "{\"data\":{\"block\":{\"number\":0,\"gasUsed\":0,\"gasLimit\":5000}}}"
assert.Equal(t, expected, string(bodyBytes))
}

Expand Down
4 changes: 4 additions & 0 deletions les/flowcontrol/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package flowcontrol

import (
"fmt"
"math"
"sync"
"time"

Expand Down Expand Up @@ -316,6 +317,9 @@ func (node *ServerNode) CanSend(maxCost uint64) (time.Duration, float64) {
node.lock.RLock()
defer node.lock.RUnlock()

if node.params.BufLimit == 0 {
return time.Duration(math.MaxInt64), 0
}
now := node.clock.Now()
node.recalcBLE(now)
maxCost += uint64(safetyMargin) * node.params.MinRecharge / uint64(fcTimeConst)
Expand Down
11 changes: 11 additions & 0 deletions les/utils/weighted_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package utils

import (
"math"
"math/rand"

"github.com/ethereum/go-ethereum/log"
)

type (
Expand Down Expand Up @@ -54,6 +57,14 @@ func (w *WeightedRandomSelect) IsEmpty() bool {

// setWeight sets an item's weight to a specific value (removes it if zero)
func (w *WeightedRandomSelect) setWeight(item WrsItem, weight uint64) {
if weight > math.MaxInt64-w.root.sumWeight {
// old weight is still included in sumWeight, remove and check again
w.setWeight(item, 0)
if weight > math.MaxInt64-w.root.sumWeight {
log.Error("WeightedRandomSelect overflow", "sumWeight", w.root.sumWeight, "new weight", weight)
weight = math.MaxInt64 - w.root.sumWeight
}
}
idx, ok := w.idx[item]
if ok {
w.root.setWeight(idx, weight)
Expand Down
19 changes: 18 additions & 1 deletion oss-fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ function compile_fuzzer {
path=$SRC/go-ethereum/$1
func=$2
fuzzer=$3
echo "Building $fuzzer"
corpusfile="${path}/testdata/${fuzzer}_seed_corpus.zip"
echo "Building $fuzzer (expecting corpus at $corpusfile)"
(cd $path && \
go-fuzz -func $func -o $WORK/$fuzzer.a . && \
echo "First stage built OK" && \
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $WORK/$fuzzer.a -o $OUT/$fuzzer && \
echo "Second stage built ok" )

## Check if there exists a seed corpus file
if [ -f $corpusfile ]
then
cp $corpusfile $OUT/
echo "Found seed corpus: $corpusfile"
fi
}

compile_fuzzer common/bitutil Fuzz fuzzBitutilCompress
Expand All @@ -51,6 +58,16 @@ compile_fuzzer tests/fuzzers/rlp Fuzz fuzzRlp
compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie
compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie

compile_fuzzer tests/fuzzers/bls12381 FuzzG1Add fuzz_g1_add
compile_fuzzer tests/fuzzers/bls12381 FuzzG1Mul fuzz_g1_mul
compile_fuzzer tests/fuzzers/bls12381 FuzzG1MultiExp fuzz_g1_multiexp
compile_fuzzer tests/fuzzers/bls12381 FuzzG2Add fuzz_g2_add
compile_fuzzer tests/fuzzers/bls12381 FuzzG2Mul fuzz_g2_mul
compile_fuzzer tests/fuzzers/bls12381 FuzzG2MultiExp fuzz_g2_multiexp
compile_fuzzer tests/fuzzers/bls12381 FuzzPairing fuzz_pairing
compile_fuzzer tests/fuzzers/bls12381 FuzzMapG1 fuzz_map_g1
compile_fuzzer tests/fuzzers/bls12381 FuzzMapG2 fuzz_map_g2

# This doesn't work very well @TODO
#compile_fuzzertests/fuzzers/abi Fuzz fuzzAbi

Loading