Skip to content

Commit 4c7bce2

Browse files
authored
Merge pull request #1917 from 0xPolygon/v2.5.3-beta-candidate
v2.5.3 candidate
2 parents ff906a0 + 9d5e3da commit 4c7bce2

File tree

25 files changed

+590
-92
lines changed

25 files changed

+590
-92
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272

7373
- name: Golang-ci install
7474
if: runner.os == 'Linux'
75-
run: make lintci-deps
75+
run: make lint-deps
7676

7777
- name: Lint
7878
if: runner.os == 'Linux'

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file configures github.com/golangci/golangci-lint.
22
version: '2'
33
run:
4+
go: 1.25.5
45
tests: true
56
linters:
67
default: none
@@ -34,6 +35,9 @@ linters:
3435
# - makezero # false positives
3536
# - nilerr # several intentional
3637
settings:
38+
govet:
39+
disable:
40+
- buildtag
3741
staticcheck:
3842
checks:
3943
# disable Quickfixes

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
os: linux
1010
arch: amd64
1111
dist: focal
12-
go: 1.24.x
12+
go: 1.25.x
1313
env:
1414
- docker
1515
services:
@@ -51,7 +51,7 @@ jobs:
5151
os: linux
5252
dist: focal
5353
sudo: required
54-
go: 1.24.x
54+
go: 1.25.x
5555
env:
5656
- azure-linux
5757
git:
@@ -141,7 +141,7 @@ jobs:
141141
os: linux
142142
arch: amd64
143143
dist: focal
144-
go: 1.24.x
144+
go: 1.25.x
145145
script:
146146
- travis_wait 45 go run build/ci.go test $TEST_PACKAGES
147147

@@ -166,7 +166,7 @@ jobs:
166166
if: type = cron || (type = push && tag ~= /^v[0-9]/)
167167
os: linux
168168
dist: focal
169-
go: 1.24.x
169+
go: 1.25.x
170170
env:
171171
- ubuntu-ppa
172172
git:
@@ -182,7 +182,7 @@ jobs:
182182
if: type = cron
183183
os: linux
184184
dist: focal
185-
go: 1.24.x
185+
go: 1.25.x
186186
env:
187187
- azure-purge
188188
git:
@@ -195,7 +195,7 @@ jobs:
195195
if: type = cron
196196
os: linux
197197
dist: focal
198-
go: 1.24.x
198+
go: 1.25.x
199199
env:
200200
- racetests
201201
script:

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ─── BUILDER STAGE ───────────────────────────────────────────────────────────────
2-
FROM golang:1.24-alpine AS builder
2+
FROM golang:1.25-alpine AS builder
33

44
ARG BOR_DIR=/var/lib/bor/
55
ENV BOR_DIR=$BOR_DIR
@@ -36,4 +36,4 @@ COPY --from=builder ${BOR_DIR}/build/bin/bor /usr/bin/
3636

3737
EXPOSE 8545 8546 8547 30303 30303/udp
3838

39-
ENTRYPOINT ["bor"]
39+
ENTRYPOINT ["bor"]

Dockerfile.alltools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build Geth in a stock Go builder container
2-
FROM golang:1.24-alpine AS builder
2+
FROM golang:1.25-alpine AS builder
33

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

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ escape:
8282
lint:
8383
@./build/bin/golangci-lint run --config ./.golangci.yml
8484

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

8989
.PHONY: vulncheck
9090

accounts/abi/bind/v2/dep_tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func TestContractLinking(t *testing.T) {
329329
map[rune]struct{}{},
330330
},
331331
// two contracts ('a' and 'f') share some dependencies. contract 'a' is marked as an override. expect that any of
332-
// its depdencies that aren't shared with 'f' are not deployed.
332+
// its dependencies that aren't shared with 'f' are not deployed.
333333
linkTestCaseInput{map[rune][]rune{
334334
'a': {'b', 'c', 'd', 'e'},
335335
'f': {'g', 'c', 'd', 'h'}},

accounts/abi/bind/v2/internal/contracts/db/contract.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ contract DB {
2525
if (v == 0) {
2626
return _keys.length;
2727
}
28-
// Check if a key is being overriden
28+
// Check if a key is being overridden
2929
if (_store[k] == 0) {
3030
_keys.push(k);
3131
_stats.inserts++;

consensus/bor/bor.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io"
10+
"math"
1011
"math/big"
1112
"slices"
1213
"sort"
@@ -881,9 +882,27 @@ func (c *Bor) verifySeal(chain consensus.ChainHeaderReader, header *types.Header
881882

882883
// Ensure that the difficulty corresponds to the turn-ness of the signer
883884
if !c.fakeDiff {
884-
difficulty := Difficulty(snap.ValidatorSet, signer)
885-
if header.Difficulty.Uint64() != difficulty {
886-
return &WrongDifficultyError{number, difficulty, header.Difficulty.Uint64(), signer.Bytes()}
885+
expected := Difficulty(snap.ValidatorSet, signer)
886+
// range check: difficulty must fit in uint64 (no high bits allowed).
887+
if header.Difficulty == nil || !header.Difficulty.IsUint64() {
888+
// reject the block.
889+
return &WrongDifficultyError{
890+
Number: header.Number.Uint64(),
891+
Expected: expected,
892+
Actual: math.MaxUint64, // invalid sentinel
893+
Signer: signer.Bytes(),
894+
}
895+
}
896+
897+
// value check, now it's safe to use Uint64().
898+
actual := header.Difficulty.Uint64()
899+
if actual != expected {
900+
return &WrongDifficultyError{
901+
Number: header.Number.Uint64(),
902+
Expected: expected,
903+
Actual: actual,
904+
Signer: signer.Bytes(),
905+
}
887906
}
888907
}
889908

consensus/bor/bor_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package bor
22

33
import (
44
"context"
5+
"errors"
6+
"math"
57
"math/big"
68
"testing"
79
"time"
810

11+
"github.com/ethereum/go-ethereum/crypto"
912
"github.com/holiman/uint256"
1013
"github.com/stretchr/testify/require"
1114

@@ -732,3 +735,88 @@ func TestCustomBlockTimeBackwardCompatibility(t *testing.T) {
732735
require.True(t, header.ActualTime.IsZero(), "ActualTime should not be set when blockTime is 0")
733736
})
734737
}
738+
739+
func TestVerifySealRejectsOversizedDifficulty(t *testing.T) {
740+
t.Parallel()
741+
742+
// real key so ecrecover works
743+
privKey, err := crypto.GenerateKey()
744+
require.NoError(t, err)
745+
746+
signerAddr := crypto.PubkeyToAddress(privKey.PublicKey)
747+
748+
sp := &fakeSpanner{
749+
vals: []*valset.Validator{
750+
{Address: signerAddr, VotingPower: 1},
751+
},
752+
}
753+
754+
borCfg := &params.BorConfig{
755+
Sprint: map[string]uint64{"0": 64},
756+
Period: map[string]uint64{"0": 2},
757+
}
758+
759+
// devFake=false, we need real signatures for the sake of this test
760+
chain, b := newChainAndBorForTest(t, sp, borCfg, false, common.Address{})
761+
762+
parent := chain.HeaderChain().GetHeaderByNumber(0)
763+
require.NotNil(t, parent)
764+
765+
header := &types.Header{
766+
ParentHash: parent.Hash(),
767+
Number: big.NewInt(1),
768+
Time: parent.Time + borCfg.Period["0"],
769+
}
770+
771+
// Build snapshot so we can compute the expected difficulty
772+
snap, err := b.snapshot(chain.HeaderChain(), header, []*types.Header{parent}, true)
773+
require.NoError(t, err)
774+
require.NotNil(t, snap)
775+
776+
expected := Difficulty(snap.ValidatorSet, signerAddr)
777+
778+
// Craft a huge difficulty whose low 64 bits match the expected
779+
hugeDiff := new(big.Int).Add(
780+
new(big.Int).SetUint64(expected),
781+
new(big.Int).Lsh(big.NewInt(1), 64),
782+
)
783+
header.Difficulty = hugeDiff
784+
785+
// 32 bytes vanity + 65 bytes for the signature
786+
header.Extra = make([]byte, 32+65)
787+
788+
// Compute the seal hash over the header
789+
sigHash := SealHash(header, borCfg)
790+
791+
// Sign the seal hash
792+
sig, err := crypto.Sign(sigHash.Bytes(), privKey)
793+
require.NoError(t, err)
794+
require.Len(t, sig, 65)
795+
796+
// Put the signature in the last 65 bytes of Extra
797+
copy(header.Extra[len(header.Extra)-65:], sig)
798+
799+
// verify the seal: we expect the difficulty validation to reject it
800+
err = b.verifySeal(chain.HeaderChain(), header, []*types.Header{parent})
801+
if err == nil {
802+
t.Fatalf("expected verifySeal to reject oversized difficulty, got nil")
803+
}
804+
805+
var diffErr *WrongDifficultyError
806+
ok := errors.As(err, &diffErr)
807+
if !ok {
808+
t.Fatalf("expected WrongDifficultyError, got %T (%v)", err, err)
809+
}
810+
if diffErr.Number != header.Number.Uint64() {
811+
t.Fatalf("unexpected Number in WrongDifficultyError: got %d, want %d",
812+
diffErr.Number, header.Number.Uint64())
813+
}
814+
if diffErr.Expected != expected {
815+
t.Fatalf("unexpected Expected in WrongDifficultyError: got %d, want %d",
816+
diffErr.Expected, expected)
817+
}
818+
if diffErr.Actual != math.MaxUint64 {
819+
t.Fatalf("unexpected Actual in WrongDifficultyError: got %d, want %d",
820+
diffErr.Actual, uint64(math.MaxUint64))
821+
}
822+
}

0 commit comments

Comments
 (0)