Skip to content

Commit 997d122

Browse files
karalabeholiman
authored andcommitted
common/math: delete some further dead code (#30639)
1 parent 1c88e42 commit 997d122

File tree

2 files changed

+0
-117
lines changed

2 files changed

+0
-117
lines changed

common/math/big.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ import (
2424

2525
// Various big integer limit values.
2626
var (
27-
tt255 = BigPow(2, 255)
2827
tt256 = BigPow(2, 256)
2928
tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1))
30-
tt63 = BigPow(2, 63)
3129
MaxBig256 = new(big.Int).Set(tt256m1)
32-
MaxBig63 = new(big.Int).Sub(tt63, big.NewInt(1))
3330
)
3431

3532
const (
@@ -162,16 +159,6 @@ func BigMin(x, y *big.Int) *big.Int {
162159
return x
163160
}
164161

165-
// FirstBitSet returns the index of the first 1 bit in v, counting from LSB.
166-
func FirstBitSet(v *big.Int) int {
167-
for i := 0; i < v.BitLen(); i++ {
168-
if v.Bit(i) > 0 {
169-
return i
170-
}
171-
}
172-
return v.BitLen()
173-
}
174-
175162
// PaddedBigBytes encodes a big integer as a big-endian byte slice. The length
176163
// of the slice is at least n bytes.
177164
func PaddedBigBytes(bigint *big.Int, n int) []byte {
@@ -183,34 +170,6 @@ func PaddedBigBytes(bigint *big.Int, n int) []byte {
183170
return ret
184171
}
185172

186-
// bigEndianByteAt returns the byte at position n,
187-
// in Big-Endian encoding
188-
// So n==0 returns the least significant byte
189-
func bigEndianByteAt(bigint *big.Int, n int) byte {
190-
words := bigint.Bits()
191-
// Check word-bucket the byte will reside in
192-
i := n / wordBytes
193-
if i >= len(words) {
194-
return byte(0)
195-
}
196-
word := words[i]
197-
// Offset of the byte
198-
shift := 8 * uint(n%wordBytes)
199-
200-
return byte(word >> shift)
201-
}
202-
203-
// Byte returns the byte at position n,
204-
// with the supplied padlength in Little-Endian encoding.
205-
// n==0 returns the MSB
206-
// Example: bigint '5', padlength 32, n=31 => 5
207-
func Byte(bigint *big.Int, padlength, n int) byte {
208-
if n >= padlength {
209-
return byte(0)
210-
}
211-
return bigEndianByteAt(bigint, padlength-1-n)
212-
}
213-
214173
// ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure
215174
// that buf has enough space. If buf is too short the result will be incomplete.
216175
func ReadBits(bigint *big.Int, buf []byte) {

common/math/big_test.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"encoding/hex"
2222
"math/big"
2323
"testing"
24-
25-
"github.com/ethereum/go-ethereum/common"
2624
)
2725

2826
func TestHexOrDecimal256(t *testing.T) {
@@ -100,23 +98,6 @@ func TestBigMin(t *testing.T) {
10098
}
10199
}
102100

103-
func TestFirstBigSet(t *testing.T) {
104-
tests := []struct {
105-
num *big.Int
106-
ix int
107-
}{
108-
{big.NewInt(0), 0},
109-
{big.NewInt(1), 0},
110-
{big.NewInt(2), 1},
111-
{big.NewInt(0x100), 8},
112-
}
113-
for _, test := range tests {
114-
if ix := FirstBitSet(test.num); ix != test.ix {
115-
t.Errorf("FirstBitSet(b%b) = %d, want %d", test.num, ix, test.ix)
116-
}
117-
}
118-
}
119-
120101
func TestPaddedBigBytes(t *testing.T) {
121102
tests := []struct {
122103
num *big.Int
@@ -220,60 +201,3 @@ func TestU256Bytes(t *testing.T) {
220201
t.Errorf("expected %x got %x", ubytes, unsigned)
221202
}
222203
}
223-
224-
func TestBigEndianByteAt(t *testing.T) {
225-
tests := []struct {
226-
x string
227-
y int
228-
exp byte
229-
}{
230-
{"00", 0, 0x00},
231-
{"01", 1, 0x00},
232-
{"00", 1, 0x00},
233-
{"01", 0, 0x01},
234-
{"0000000000000000000000000000000000000000000000000000000000102030", 0, 0x30},
235-
{"0000000000000000000000000000000000000000000000000000000000102030", 1, 0x20},
236-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 31, 0xAB},
237-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 32, 0x00},
238-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 500, 0x00},
239-
}
240-
for _, test := range tests {
241-
v := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
242-
actual := bigEndianByteAt(v, test.y)
243-
if actual != test.exp {
244-
t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.x, test.y, test.exp, actual)
245-
}
246-
}
247-
}
248-
func TestLittleEndianByteAt(t *testing.T) {
249-
tests := []struct {
250-
x string
251-
y int
252-
exp byte
253-
}{
254-
{"00", 0, 0x00},
255-
{"01", 1, 0x00},
256-
{"00", 1, 0x00},
257-
{"01", 0, 0x00},
258-
{"0000000000000000000000000000000000000000000000000000000000102030", 0, 0x00},
259-
{"0000000000000000000000000000000000000000000000000000000000102030", 1, 0x00},
260-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 31, 0x00},
261-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 32, 0x00},
262-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, 0xAB},
263-
{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, 0xCD},
264-
{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, 0x00},
265-
{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, 0xCD},
266-
{"0000000000000000000000000000000000000000000000000000000000102030", 31, 0x30},
267-
{"0000000000000000000000000000000000000000000000000000000000102030", 30, 0x20},
268-
{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, 0x0},
269-
{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 31, 0xFF},
270-
{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFF, 0x0},
271-
}
272-
for _, test := range tests {
273-
v := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
274-
actual := Byte(v, 32, test.y)
275-
if actual != test.exp {
276-
t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.x, test.y, test.exp, actual)
277-
}
278-
}
279-
}

0 commit comments

Comments
 (0)