Skip to content

Commit 62cca49

Browse files
antonydenyerholimanfjl
authored
Fix build errors from Bump github.com/holiman/uint256 from 1.1.1 to 1.2.1 (#1523)
* go.mod: upgrade to github.com/holiman/uint256 v1.2.0 (#22745) * eth/protocols/snap: adapt to uint256 API changes (#22851) Co-authored-by: Martin Holst Swende <[email protected]> Co-authored-by: Felix Lange <[email protected]>
1 parent 1fe5b1f commit 62cca49

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

consensus/ethash/difficulty.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ func CalcDifficultyFrontierU256(time uint64, parent *types.Header) *big.Int {
5252
- num = block.number
5353
*/
5454

55-
pDiff := uint256.NewInt()
56-
pDiff.SetFromBig(parent.Difficulty) // pDiff: pdiff
55+
pDiff, _ := uint256.FromBig(parent.Difficulty) // pDiff: pdiff
5756
adjust := pDiff.Clone()
5857
adjust.Rsh(adjust, difficultyBoundDivisor) // adjust: pDiff / 2048
5958

@@ -96,8 +95,7 @@ func CalcDifficultyHomesteadU256(time uint64, parent *types.Header) *big.Int {
9695
- num = block.number
9796
*/
9897

99-
pDiff := uint256.NewInt()
100-
pDiff.SetFromBig(parent.Difficulty) // pDiff: pdiff
98+
pDiff, _ := uint256.FromBig(parent.Difficulty) // pDiff: pdiff
10199
adjust := pDiff.Clone()
102100
adjust.Rsh(adjust, difficultyBoundDivisor) // adjust: pDiff / 2048
103101

core/vm/instructions_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,11 @@ func BenchmarkOpSHA3(bench *testing.B) {
568568
env.interpreter = evmInterpreter
569569
mem.Resize(32)
570570
pc := uint64(0)
571-
start := uint256.NewInt()
571+
start := new(uint256.Int)
572572

573573
bench.ResetTimer()
574574
for i := 0; i < bench.N; i++ {
575-
stack.pushN(*uint256.NewInt().SetUint64(32), *start)
575+
stack.pushN(*uint256.NewInt(32), *start)
576576
opSha3(&pc, evmInterpreter, &ScopeContext{mem, stack, nil})
577577
}
578578
}

core/vm/logger_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func TestStoreCapture(t *testing.T) {
6060
Contract: contract,
6161
}
6262
)
63-
scope.Stack.push(uint256.NewInt().SetUint64(1))
64-
scope.Stack.push(uint256.NewInt())
63+
scope.Stack.push(uint256.NewInt(1))
64+
scope.Stack.push(new(uint256.Int))
6565
var index common.Hash
6666
logger.CaptureState(env, 0, SSTORE, 0, 0, scope, nil, 0, nil)
6767
if len(logger.storage[contract.Address()]) == 0 {

eth/protocols/snap/range.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ func newHashRange(start common.Hash, num uint64) *hashRange {
4242
step256.SetFromBig(step)
4343

4444
return &hashRange{
45-
current: uint256.NewInt().SetBytes32(start[:]),
45+
current: new(uint256.Int).SetBytes32(start[:]),
4646
step: step256,
4747
}
4848
}
4949

5050
// Next pushes the hash range to the next interval.
5151
func (r *hashRange) Next() bool {
52-
next := new(uint256.Int)
53-
if overflow := next.AddOverflow(r.current, r.step); overflow {
52+
next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)
53+
if overflow {
5454
return false
5555
}
5656
r.current = next
@@ -65,16 +65,17 @@ func (r *hashRange) Start() common.Hash {
6565
// End returns the last hash in the current interval.
6666
func (r *hashRange) End() common.Hash {
6767
// If the end overflows (non divisible range), return a shorter interval
68-
next := new(uint256.Int)
69-
if overflow := next.AddOverflow(r.current, r.step); overflow {
68+
next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)
69+
if overflow {
7070
return common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
7171
}
72-
return new(uint256.Int).Sub(next, uint256.NewInt().SetOne()).Bytes32()
72+
return next.SubUint64(next, 1).Bytes32()
7373
}
7474

7575
// incHash returns the next hash, in lexicographical order (a.k.a plus one)
7676
func incHash(h common.Hash) common.Hash {
77-
a := uint256.NewInt().SetBytes32(h[:])
78-
a.Add(a, uint256.NewInt().SetOne())
77+
var a uint256.Int
78+
a.SetBytes32(h[:])
79+
a.AddUint64(&a, 1)
7980
return common.Hash(a.Bytes32())
8081
}

0 commit comments

Comments
 (0)