Skip to content

Commit

Permalink
Fix build errors from Bump github.com/holiman/uint256 from 1.1.1 to 1…
Browse files Browse the repository at this point in the history
….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]>
  • Loading branch information
3 people authored Oct 3, 2022
1 parent 1fe5b1f commit 62cca49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
6 changes: 2 additions & 4 deletions consensus/ethash/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ func CalcDifficultyFrontierU256(time uint64, parent *types.Header) *big.Int {
- num = block.number
*/

pDiff := uint256.NewInt()
pDiff.SetFromBig(parent.Difficulty) // pDiff: pdiff
pDiff, _ := uint256.FromBig(parent.Difficulty) // pDiff: pdiff
adjust := pDiff.Clone()
adjust.Rsh(adjust, difficultyBoundDivisor) // adjust: pDiff / 2048

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

pDiff := uint256.NewInt()
pDiff.SetFromBig(parent.Difficulty) // pDiff: pdiff
pDiff, _ := uint256.FromBig(parent.Difficulty) // pDiff: pdiff
adjust := pDiff.Clone()
adjust.Rsh(adjust, difficultyBoundDivisor) // adjust: pDiff / 2048

Expand Down
4 changes: 2 additions & 2 deletions core/vm/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,11 @@ func BenchmarkOpSHA3(bench *testing.B) {
env.interpreter = evmInterpreter
mem.Resize(32)
pc := uint64(0)
start := uint256.NewInt()
start := new(uint256.Int)

bench.ResetTimer()
for i := 0; i < bench.N; i++ {
stack.pushN(*uint256.NewInt().SetUint64(32), *start)
stack.pushN(*uint256.NewInt(32), *start)
opSha3(&pc, evmInterpreter, &ScopeContext{mem, stack, nil})
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/vm/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestStoreCapture(t *testing.T) {
Contract: contract,
}
)
scope.Stack.push(uint256.NewInt().SetUint64(1))
scope.Stack.push(uint256.NewInt())
scope.Stack.push(uint256.NewInt(1))
scope.Stack.push(new(uint256.Int))
var index common.Hash
logger.CaptureState(env, 0, SSTORE, 0, 0, scope, nil, 0, nil)
if len(logger.storage[contract.Address()]) == 0 {
Expand Down
17 changes: 9 additions & 8 deletions eth/protocols/snap/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func newHashRange(start common.Hash, num uint64) *hashRange {
step256.SetFromBig(step)

return &hashRange{
current: uint256.NewInt().SetBytes32(start[:]),
current: new(uint256.Int).SetBytes32(start[:]),
step: step256,
}
}

// Next pushes the hash range to the next interval.
func (r *hashRange) Next() bool {
next := new(uint256.Int)
if overflow := next.AddOverflow(r.current, r.step); overflow {
next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)
if overflow {
return false
}
r.current = next
Expand All @@ -65,16 +65,17 @@ func (r *hashRange) Start() common.Hash {
// End returns the last hash in the current interval.
func (r *hashRange) End() common.Hash {
// If the end overflows (non divisible range), return a shorter interval
next := new(uint256.Int)
if overflow := next.AddOverflow(r.current, r.step); overflow {
next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)
if overflow {
return common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
}
return new(uint256.Int).Sub(next, uint256.NewInt().SetOne()).Bytes32()
return next.SubUint64(next, 1).Bytes32()
}

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

0 comments on commit 62cca49

Please sign in to comment.