Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

- name: Golang-ci install
if: runner.os == 'Linux'
run: make lintci-deps
run: make lint-deps

- name: Lint
if: runner.os == 'Linux'
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file configures github.com/golangci/golangci-lint.
version: '2'
run:
go: 1.25.5
tests: true
linters:
default: none
Expand Down Expand Up @@ -34,6 +35,9 @@ linters:
# - makezero # false positives
# - nilerr # several intentional
settings:
govet:
disable:
- buildtag
staticcheck:
checks:
# disable Quickfixes
Expand Down
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
os: linux
arch: amd64
dist: focal
go: 1.24.x
go: 1.25.x
env:
- docker
services:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
os: linux
dist: focal
sudo: required
go: 1.24.x
go: 1.25.x
env:
- azure-linux
git:
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
os: linux
arch: amd64
dist: focal
go: 1.24.x
go: 1.25.x
script:
- travis_wait 45 go run build/ci.go test $TEST_PACKAGES

Expand All @@ -166,7 +166,7 @@ jobs:
if: type = cron || (type = push && tag ~= /^v[0-9]/)
os: linux
dist: focal
go: 1.24.x
go: 1.25.x
env:
- ubuntu-ppa
git:
Expand All @@ -182,7 +182,7 @@ jobs:
if: type = cron
os: linux
dist: focal
go: 1.24.x
go: 1.25.x
env:
- azure-purge
git:
Expand All @@ -195,7 +195,7 @@ jobs:
if: type = cron
os: linux
dist: focal
go: 1.24.x
go: 1.25.x
env:
- racetests
script:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ─── BUILDER STAGE ───────────────────────────────────────────────────────────────
FROM golang:1.24-alpine AS builder
FROM golang:1.25-alpine AS builder

ARG BOR_DIR=/var/lib/bor/
ENV BOR_DIR=$BOR_DIR
Expand Down Expand Up @@ -36,4 +36,4 @@ COPY --from=builder ${BOR_DIR}/build/bin/bor /usr/bin/

EXPOSE 8545 8546 8547 30303 30303/udp

ENTRYPOINT ["bor"]
ENTRYPOINT ["bor"]
2 changes: 1 addition & 1 deletion Dockerfile.alltools
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build Geth in a stock Go builder container
FROM golang:1.24-alpine AS builder
FROM golang:1.25-alpine AS builder

RUN apk add --no-cache make gcc musl-dev linux-headers git

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ escape:
lint:
@./build/bin/golangci-lint run --config ./.golangci.yml

lintci-deps:
lint-deps:
rm -f ./build/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v2.1.5
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v2.6.2

.PHONY: vulncheck

Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/v2/dep_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestContractLinking(t *testing.T) {
map[rune]struct{}{},
},
// two contracts ('a' and 'f') share some dependencies. contract 'a' is marked as an override. expect that any of
// its depdencies that aren't shared with 'f' are not deployed.
// its dependencies that aren't shared with 'f' are not deployed.
linkTestCaseInput{map[rune][]rune{
'a': {'b', 'c', 'd', 'e'},
'f': {'g', 'c', 'd', 'h'}},
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/v2/internal/contracts/db/contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract DB {
if (v == 0) {
return _keys.length;
}
// Check if a key is being overriden
// Check if a key is being overridden
if (_store[k] == 0) {
_keys.push(k);
_stats.inserts++;
Expand Down
25 changes: 22 additions & 3 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"errors"
"fmt"
"io"
"math"
"math/big"
"slices"
"sort"
Expand Down Expand Up @@ -831,7 +832,7 @@
// consensus protocol requirements. The method accepts an optional list of parent
// headers that aren't yet part of the local blockchain to generate the snapshots
// from.
func (c *Bor) verifySeal(chain consensus.ChainHeaderReader, header *types.Header, parents []*types.Header) error {

Check failure on line 835 in consensus/bor/bor.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=0xPolygon_bor&issues=AZrlIZvxi1-4a2sxts-t&open=AZrlIZvxi1-4a2sxts-t&pullRequest=1917
// Verifying the genesis block is not supported
number := header.Number.Uint64()
if number == 0 {
Expand Down Expand Up @@ -881,9 +882,27 @@

// Ensure that the difficulty corresponds to the turn-ness of the signer
if !c.fakeDiff {
difficulty := Difficulty(snap.ValidatorSet, signer)
if header.Difficulty.Uint64() != difficulty {
return &WrongDifficultyError{number, difficulty, header.Difficulty.Uint64(), signer.Bytes()}
expected := Difficulty(snap.ValidatorSet, signer)
// range check: difficulty must fit in uint64 (no high bits allowed).
if header.Difficulty == nil || !header.Difficulty.IsUint64() {
// reject the block.
return &WrongDifficultyError{
Number: header.Number.Uint64(),
Expected: expected,
Actual: math.MaxUint64, // invalid sentinel
Signer: signer.Bytes(),
}
}

// value check, now it's safe to use Uint64().
actual := header.Difficulty.Uint64()
if actual != expected {
return &WrongDifficultyError{
Number: header.Number.Uint64(),
Expected: expected,
Actual: actual,
Signer: signer.Bytes(),
}
}
}

Expand Down
88 changes: 88 additions & 0 deletions consensus/bor/bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package bor

import (
"context"
"errors"
"math"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -732,3 +735,88 @@ func TestCustomBlockTimeBackwardCompatibility(t *testing.T) {
require.True(t, header.ActualTime.IsZero(), "ActualTime should not be set when blockTime is 0")
})
}

func TestVerifySealRejectsOversizedDifficulty(t *testing.T) {
t.Parallel()

// real key so ecrecover works
privKey, err := crypto.GenerateKey()
require.NoError(t, err)

signerAddr := crypto.PubkeyToAddress(privKey.PublicKey)

sp := &fakeSpanner{
vals: []*valset.Validator{
{Address: signerAddr, VotingPower: 1},
},
}

borCfg := &params.BorConfig{
Sprint: map[string]uint64{"0": 64},
Period: map[string]uint64{"0": 2},
}

// devFake=false, we need real signatures for the sake of this test
chain, b := newChainAndBorForTest(t, sp, borCfg, false, common.Address{})

parent := chain.HeaderChain().GetHeaderByNumber(0)
require.NotNil(t, parent)

header := &types.Header{
ParentHash: parent.Hash(),
Number: big.NewInt(1),
Time: parent.Time + borCfg.Period["0"],
}

// Build snapshot so we can compute the expected difficulty
snap, err := b.snapshot(chain.HeaderChain(), header, []*types.Header{parent}, true)
require.NoError(t, err)
require.NotNil(t, snap)

expected := Difficulty(snap.ValidatorSet, signerAddr)

// Craft a huge difficulty whose low 64 bits match the expected
hugeDiff := new(big.Int).Add(
new(big.Int).SetUint64(expected),
new(big.Int).Lsh(big.NewInt(1), 64),
)
header.Difficulty = hugeDiff

// 32 bytes vanity + 65 bytes for the signature
header.Extra = make([]byte, 32+65)

// Compute the seal hash over the header
sigHash := SealHash(header, borCfg)

// Sign the seal hash
sig, err := crypto.Sign(sigHash.Bytes(), privKey)
require.NoError(t, err)
require.Len(t, sig, 65)

// Put the signature in the last 65 bytes of Extra
copy(header.Extra[len(header.Extra)-65:], sig)

// verify the seal: we expect the difficulty validation to reject it
err = b.verifySeal(chain.HeaderChain(), header, []*types.Header{parent})
if err == nil {
t.Fatalf("expected verifySeal to reject oversized difficulty, got nil")
}

var diffErr *WrongDifficultyError
ok := errors.As(err, &diffErr)
if !ok {
t.Fatalf("expected WrongDifficultyError, got %T (%v)", err, err)
}
if diffErr.Number != header.Number.Uint64() {
t.Fatalf("unexpected Number in WrongDifficultyError: got %d, want %d",
diffErr.Number, header.Number.Uint64())
}
if diffErr.Expected != expected {
t.Fatalf("unexpected Expected in WrongDifficultyError: got %d, want %d",
diffErr.Expected, expected)
}
if diffErr.Actual != math.MaxUint64 {
t.Fatalf("unexpected Actual in WrongDifficultyError: got %d, want %d",
diffErr.Actual, uint64(math.MaxUint64))
}
}
Loading
Loading