Skip to content

Commit 0814d99

Browse files
authored
common/hexutil: replace customized bit sizer with bit.Uintsize (#32304)
1 parent 2d95ba7 commit 0814d99

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

common/hexutil/hexutil.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ import (
3434
"encoding/hex"
3535
"fmt"
3636
"math/big"
37+
"math/bits"
3738
"strconv"
3839
)
3940

40-
const uintBits = 32 << (uint64(^uint(0)) >> 63)
41-
4241
// Errors
4342
var (
4443
ErrEmptyString = &decError{"empty hex string"}
@@ -48,7 +47,7 @@ var (
4847
ErrEmptyNumber = &decError{"hex string \"0x\""}
4948
ErrLeadingZero = &decError{"hex number with leading zero digits"}
5049
ErrUint64Range = &decError{"hex number > 64 bits"}
51-
ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
50+
ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", bits.UintSize)}
5251
ErrBig256Range = &decError{"hex number > 256 bits"}
5352
)
5453

common/hexutil/json_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"math/big"
25+
"math/bits"
2526
"testing"
2627

2728
"github.com/holiman/uint256"
@@ -384,7 +385,7 @@ func TestUnmarshalUint(t *testing.T) {
384385
for _, test := range unmarshalUintTests {
385386
var v Uint
386387
err := json.Unmarshal([]byte(test.input), &v)
387-
if uintBits == 32 && test.wantErr32bit != nil {
388+
if bits.UintSize == 32 && test.wantErr32bit != nil {
388389
checkError(t, test.input, err, test.wantErr32bit)
389390
continue
390391
}

0 commit comments

Comments
 (0)