Skip to content

Commit 30007fd

Browse files
committed
Remove now-unused methods from arith_uint256 and base_uint
- Methods that access the guts of arith_uint256 are removed, as these are incompatible between endians. Use uint256 instead - Serialization is no longer needed as arith_uint256's are never read or written - GetHash is never used on arith_uint256
1 parent edc7204 commit 30007fd

File tree

3 files changed

+1
-148
lines changed

3 files changed

+1
-148
lines changed

src/arith_uint256.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -278,68 +278,6 @@ uint32_t arith_uint256::GetCompact(bool fNegative) const
278278
return nCompact;
279279
}
280280

281-
static void inline HashMix(uint32_t& a, uint32_t& b, uint32_t& c)
282-
{
283-
// Taken from lookup3, by Bob Jenkins.
284-
a -= c;
285-
a ^= ((c << 4) | (c >> 28));
286-
c += b;
287-
b -= a;
288-
b ^= ((a << 6) | (a >> 26));
289-
a += c;
290-
c -= b;
291-
c ^= ((b << 8) | (b >> 24));
292-
b += a;
293-
a -= c;
294-
a ^= ((c << 16) | (c >> 16));
295-
c += b;
296-
b -= a;
297-
b ^= ((a << 19) | (a >> 13));
298-
a += c;
299-
c -= b;
300-
c ^= ((b << 4) | (b >> 28));
301-
b += a;
302-
}
303-
304-
static void inline HashFinal(uint32_t& a, uint32_t& b, uint32_t& c)
305-
{
306-
// Taken from lookup3, by Bob Jenkins.
307-
c ^= b;
308-
c -= ((b << 14) | (b >> 18));
309-
a ^= c;
310-
a -= ((c << 11) | (c >> 21));
311-
b ^= a;
312-
b -= ((a << 25) | (a >> 7));
313-
c ^= b;
314-
c -= ((b << 16) | (b >> 16));
315-
a ^= c;
316-
a -= ((c << 4) | (c >> 28));
317-
b ^= a;
318-
b -= ((a << 14) | (a >> 18));
319-
c ^= b;
320-
c -= ((b << 24) | (b >> 8));
321-
}
322-
323-
uint64_t arith_uint256::GetHash(const arith_uint256& salt) const
324-
{
325-
uint32_t a, b, c;
326-
a = b = c = 0xdeadbeef + (WIDTH << 2);
327-
328-
a += pn[0] ^ salt.pn[0];
329-
b += pn[1] ^ salt.pn[1];
330-
c += pn[2] ^ salt.pn[2];
331-
HashMix(a, b, c);
332-
a += pn[3] ^ salt.pn[3];
333-
b += pn[4] ^ salt.pn[4];
334-
c += pn[5] ^ salt.pn[5];
335-
HashMix(a, b, c);
336-
a += pn[6] ^ salt.pn[6];
337-
b += pn[7] ^ salt.pn[7];
338-
HashFinal(a, b, c);
339-
340-
return ((((uint64_t)b) << 32) | c);
341-
}
342-
343281
uint256 ArithToUint256(const arith_uint256 &a)
344282
{
345283
uint256 b;

src/arith_uint256.h

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -232,26 +232,6 @@ class base_uint
232232
void SetHex(const std::string& str);
233233
std::string ToString() const;
234234

235-
unsigned char* begin()
236-
{
237-
return (unsigned char*)&pn[0];
238-
}
239-
240-
unsigned char* end()
241-
{
242-
return (unsigned char*)&pn[WIDTH];
243-
}
244-
245-
const unsigned char* begin() const
246-
{
247-
return (unsigned char*)&pn[0];
248-
}
249-
250-
const unsigned char* end() const
251-
{
252-
return (unsigned char*)&pn[WIDTH];
253-
}
254-
255235
unsigned int size() const
256236
{
257237
return sizeof(pn);
@@ -268,40 +248,6 @@ class base_uint
268248
assert(WIDTH >= 2);
269249
return pn[0] | (uint64_t)pn[1] << 32;
270250
}
271-
272-
unsigned int GetSerializeSize(int nType, int nVersion) const
273-
{
274-
return sizeof(pn);
275-
}
276-
277-
template<typename Stream>
278-
void Serialize(Stream& s, int nType, int nVersion) const
279-
{
280-
s.write((char*)pn, sizeof(pn));
281-
}
282-
283-
template<typename Stream>
284-
void Unserialize(Stream& s, int nType, int nVersion)
285-
{
286-
s.read((char*)pn, sizeof(pn));
287-
}
288-
289-
// Temporary for migration to blob160/256
290-
uint64_t GetCheapHash() const
291-
{
292-
return GetLow64();
293-
}
294-
void SetNull()
295-
{
296-
memset(pn, 0, sizeof(pn));
297-
}
298-
bool IsNull() const
299-
{
300-
for (int i = 0; i < WIDTH; i++)
301-
if (pn[i] != 0)
302-
return false;
303-
return true;
304-
}
305251
};
306252

307253
/** 256-bit unsigned big integer. */
@@ -336,8 +282,6 @@ class arith_uint256 : public base_uint<256> {
336282
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
337283
uint32_t GetCompact(bool fNegative = false) const;
338284

339-
uint64_t GetHash(const arith_uint256& salt) const;
340-
341285
friend uint256 ArithToUint256(const arith_uint256 &);
342286
friend arith_uint256 UintToArith256(const uint256 &);
343287
};

src/test/arith_uint256_tests.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ bool almostEqual(double d1, double d2)
370370
return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
371371
}
372372

373-
BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex begin() end() size() GetLow64 GetSerializeSize, Serialize, Unserialize
373+
BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex size() GetLow64 GetSerializeSize, Serialize, Unserialize
374374
{
375375
BOOST_CHECK(R1L.GetHex() == R1L.ToString());
376376
BOOST_CHECK(R2L.GetHex() == R2L.ToString());
@@ -383,42 +383,13 @@ BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex begin() end() size() GetLow64 G
383383
TmpL.SetHex(HalfL.ToString()); BOOST_CHECK(TmpL == HalfL);
384384

385385
TmpL.SetHex(R1L.ToString());
386-
BOOST_CHECK(memcmp(R1L.begin(), R1Array, 32)==0);
387-
BOOST_CHECK(memcmp(TmpL.begin(), R1Array, 32)==0);
388-
BOOST_CHECK(memcmp(R2L.begin(), R2Array, 32)==0);
389-
BOOST_CHECK(memcmp(ZeroL.begin(), ZeroArray, 32)==0);
390-
BOOST_CHECK(memcmp(OneL.begin(), OneArray, 32)==0);
391386
BOOST_CHECK(R1L.size() == 32);
392387
BOOST_CHECK(R2L.size() == 32);
393388
BOOST_CHECK(ZeroL.size() == 32);
394389
BOOST_CHECK(MaxL.size() == 32);
395-
BOOST_CHECK(R1L.begin() + 32 == R1L.end());
396-
BOOST_CHECK(R2L.begin() + 32 == R2L.end());
397-
BOOST_CHECK(OneL.begin() + 32 == OneL.end());
398-
BOOST_CHECK(MaxL.begin() + 32 == MaxL.end());
399-
BOOST_CHECK(TmpL.begin() + 32 == TmpL.end());
400390
BOOST_CHECK(R1L.GetLow64() == R1LLow64);
401391
BOOST_CHECK(HalfL.GetLow64() ==0x0000000000000000ULL);
402392
BOOST_CHECK(OneL.GetLow64() ==0x0000000000000001ULL);
403-
BOOST_CHECK(R1L.GetSerializeSize(0,PROTOCOL_VERSION) == 32);
404-
BOOST_CHECK(ZeroL.GetSerializeSize(0,PROTOCOL_VERSION) == 32);
405-
406-
std::stringstream ss;
407-
R1L.Serialize(ss,0,PROTOCOL_VERSION);
408-
BOOST_CHECK(ss.str() == std::string(R1Array,R1Array+32));
409-
TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
410-
BOOST_CHECK(R1L == TmpL);
411-
ss.str("");
412-
ZeroL.Serialize(ss,0,PROTOCOL_VERSION);
413-
BOOST_CHECK(ss.str() == std::string(ZeroArray,ZeroArray+32));
414-
TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
415-
BOOST_CHECK(ZeroL == TmpL);
416-
ss.str("");
417-
MaxL.Serialize(ss,0,PROTOCOL_VERSION);
418-
BOOST_CHECK(ss.str() == std::string(MaxArray,MaxArray+32));
419-
TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
420-
BOOST_CHECK(MaxL == TmpL);
421-
ss.str("");
422393

423394
for (unsigned int i = 0; i < 255; ++i)
424395
{

0 commit comments

Comments
 (0)