Skip to content

Commit c66c683

Browse files
committed
Merge bitcoin/bitcoin#30773: Remove unsafe uint256S() and test-only uint160S()
43cd83b test: move uint256_tests/operator_with_self to arith_uint256_tests (stickies-v) c6c994c test: remove test-only uint160S (stickies-v) 62cc465 test: remove test-only uint256S (stickies-v) adc00ad test: remove test-only arith_uint256S (stickies-v) f51b237 refactor: rpc: use uint256::FromHex for ParseHashV (stickies-v) Pull request description: _Continuation of #30569._ Since bitcoin/bitcoin@fad2991, `uint256S()` has been [deprecated](bitcoin/bitcoin@fad2991#diff-800776e2dda39116e889839f69409571a5d397de048a141da7e4003bc099e3e2R138) because it is less robust than the `base_blob::FromHex()` introduced in bitcoin/bitcoin#30482. Specifically, it tries to recover from length-mismatches, recover from untrimmed whitespace, 0x-prefix and garbage at the end, instead of simply requiring exactly 64 hex-only characters. (see also bitcoin/bitcoin#30532) This PR removes `uint256S()` (and `uint160S()`) completely, with no non-test behaviour change. Specifically, the main changes in this PR are: - the (minimal) last non-test usage of `uint256S()` in `ParseHashV()` is removed without behaviour change, which can partially be verified by cherry-picking and/or modifying [this test commit](stickies-v/bitcoin@1f2b0fa)). - the test usage of `uint{160,256}S()` is removed, largely replacing it with `uint{160,256}::FromHex()` where applicable, potentially modifying the test by removing non-hex characters or dropping the test entirely if removing non-hex characters makes it redundant - the now unused `uint{160,256}S()` functions are removed completely. - unit test coverage on converting `uint256` <-> `arith_uint256` through `UintToArith256()` and `ArithToUint256()` is beefed up, and `arith_uint256` tests are moved to `arith_uint256_tests.cpp`, removing the `uint256_tests.cpp` dependency on `uint256h`, mirroring how the code is structured. _Note: `uint256::FromUserHex()` exists to more leniently construct uint256 from user input, allowing "0x" prefixes and too-short-input, as safer alternative to `uint256S()` where necessary._ ACKs for top commit: l0rinc: reACK 43cd83b hodlinator: re-ACK 43cd83b ryanofsky: Code review ACK 43cd83b. Only code change is a small refactoring which looks good. The rest of the PR is all test changes, which I only lightly reviewed, but seem to be positive and do what's described Tree-SHA512: 48147a4c6af671597df0f72c1b477ae4631cd2cae4645ec54d0e327611ff302c9899e344518c81242cdde82930f6ad23a3a7e6e0b80671816e9f457b9de90a5c
2 parents 2756797 + 43cd83b commit c66c683

File tree

6 files changed

+82
-151
lines changed

6 files changed

+82
-151
lines changed

src/rpc/util.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <script/signingprovider.h>
2020
#include <script/solver.h>
2121
#include <tinyformat.h>
22+
#include <uint256.h>
2223
#include <univalue.h>
2324
#include <util/check.h>
2425
#include <util/result.h>
@@ -102,11 +103,11 @@ CFeeRate ParseFeeRate(const UniValue& json)
102103
uint256 ParseHashV(const UniValue& v, std::string_view name)
103104
{
104105
const std::string& strHex(v.get_str());
105-
if (64 != strHex.length())
106-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d, for '%s')", name, 64, strHex.length(), strHex));
107-
if (!IsHex(strHex)) // Note: IsHex("") is false
108-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be hexadecimal string (not '%s')", name, strHex));
109-
return uint256S(strHex);
106+
if (auto rv{uint256::FromHex(strHex)}) return *rv;
107+
if (auto expected_len{uint256::size() * 2}; strHex.length() != expected_len) {
108+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d, for '%s')", name, expected_len, strHex.length(), strHex));
109+
}
110+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be hexadecimal string (not '%s')", name, strHex));
110111
}
111112
uint256 ParseHashO(const UniValue& o, std::string_view strKey)
112113
{

src/test/arith_uint256_tests.cpp

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ static inline arith_uint256 arith_uint256V(const std::vector<unsigned char>& vch
2323
{
2424
return UintToArith256(uint256(vch));
2525
}
26-
// Takes a number written in hex (with most significant digits first).
27-
static inline arith_uint256 arith_uint256S(std::string_view str) { return UintToArith256(uint256S(str)); }
28-
2926
const unsigned char R1Array[] =
3027
"\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
3128
"\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
@@ -39,8 +36,6 @@ const unsigned char R2Array[] =
3936
"\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
4037
const arith_uint256 R2L = arith_uint256V(std::vector<unsigned char>(R2Array,R2Array+32));
4138

42-
const char R1LplusR2L[] = "549FB09FEA236A1EA3E31D4D58F1B1369288D204211CA751527CFC175767850C";
43-
4439
const unsigned char ZeroArray[] =
4540
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
4641
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
@@ -97,27 +92,25 @@ BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
9792
}
9893
BOOST_CHECK(ZeroL == (OneL << 256));
9994

100-
// String Constructor and Copy Constructor
101-
BOOST_CHECK(arith_uint256S("0x" + R1L.ToString()) == R1L);
102-
BOOST_CHECK(arith_uint256S("0x" + R2L.ToString()) == R2L);
103-
BOOST_CHECK(arith_uint256S("0x" + ZeroL.ToString()) == ZeroL);
104-
BOOST_CHECK(arith_uint256S("0x" + OneL.ToString()) == OneL);
105-
BOOST_CHECK(arith_uint256S("0x" + MaxL.ToString()) == MaxL);
106-
BOOST_CHECK(arith_uint256S(R1L.ToString()) == R1L);
107-
BOOST_CHECK(arith_uint256S(" 0x" + R1L.ToString() + " ") == R1L);
108-
BOOST_CHECK(arith_uint256S("") == ZeroL);
109-
BOOST_CHECK(arith_uint256S("1") == OneL);
110-
BOOST_CHECK(R1L == arith_uint256S(R1ArrayHex));
95+
// Construct from hex string
96+
BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(R1L.ToString()).value()), R1L);
97+
BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(R2L.ToString()).value()), R2L);
98+
BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(ZeroL.ToString()).value()), ZeroL);
99+
BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(OneL.ToString()).value()), OneL);
100+
BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(MaxL.ToString()).value()), MaxL);
101+
BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(R1ArrayHex).value()), R1L);
102+
103+
// Copy constructor
111104
BOOST_CHECK(arith_uint256(R1L) == R1L);
112105
BOOST_CHECK((arith_uint256(R1L^R2L)^R2L) == R1L);
113106
BOOST_CHECK(arith_uint256(ZeroL) == ZeroL);
114107
BOOST_CHECK(arith_uint256(OneL) == OneL);
115108

116109
// uint64_t constructor
117-
BOOST_CHECK((R1L & arith_uint256S("0xffffffffffffffff")) == arith_uint256(R1LLow64));
118-
BOOST_CHECK(ZeroL == arith_uint256(0));
119-
BOOST_CHECK(OneL == arith_uint256(1));
120-
BOOST_CHECK(arith_uint256S("0xffffffffffffffff") == arith_uint256(0xffffffffffffffffULL));
110+
BOOST_CHECK_EQUAL(R1L & arith_uint256{0xffffffffffffffff}, arith_uint256{R1LLow64});
111+
BOOST_CHECK_EQUAL(ZeroL, arith_uint256{0});
112+
BOOST_CHECK_EQUAL(OneL, arith_uint256{1});
113+
BOOST_CHECK_EQUAL(arith_uint256{0xffffffffffffffff}, arith_uint256{0xffffffffffffffffULL});
121114

122115
// Assignment (from base_uint)
123116
arith_uint256 tmpL = ~ZeroL; BOOST_CHECK(tmpL == ~ZeroL);
@@ -284,15 +277,12 @@ BOOST_AUTO_TEST_CASE( comparison ) // <= >= < >
284277

285278
BOOST_CHECK_LT(ZeroL,
286279
OneL);
287-
// Verify hex number representation has the most significant digits first.
288-
BOOST_CHECK_LT(arith_uint256S("0000000000000000000000000000000000000000000000000000000000000001"),
289-
arith_uint256S("1000000000000000000000000000000000000000000000000000000000000000"));
290280
}
291281

292282
BOOST_AUTO_TEST_CASE( plusMinus )
293283
{
294284
arith_uint256 TmpL = 0;
295-
BOOST_CHECK(R1L + R2L == arith_uint256S(R1LplusR2L));
285+
BOOST_CHECK_EQUAL(R1L + R2L, UintToArith256(uint256{"549fb09fea236a1ea3e31d4d58f1b1369288d204211ca751527cfc175767850c"}));
296286
TmpL += R1L;
297287
BOOST_CHECK(TmpL == R1L);
298288
TmpL += R2L;
@@ -356,8 +346,8 @@ BOOST_AUTO_TEST_CASE( multiply )
356346

357347
BOOST_AUTO_TEST_CASE( divide )
358348
{
359-
arith_uint256 D1L{arith_uint256S("AD7133AC1977FA2B7")};
360-
arith_uint256 D2L{arith_uint256S("ECD751716")};
349+
arith_uint256 D1L{UintToArith256(uint256{"00000000000000000000000000000000000000000000000ad7133ac1977fa2b7"})};
350+
arith_uint256 D2L{UintToArith256(uint256{"0000000000000000000000000000000000000000000000000000000ecd751716"})};
361351
BOOST_CHECK((R1L / D1L).ToString() == "00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a");
362352
BOOST_CHECK((R1L / D2L).ToString() == "000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a");
363353
BOOST_CHECK(R1L / OneL == R1L);
@@ -571,4 +561,51 @@ BOOST_AUTO_TEST_CASE( getmaxcoverage ) // some more tests just to get 100% cover
571561
CHECKBITWISEOPERATOR(R1,~R2,&)
572562
}
573563

564+
BOOST_AUTO_TEST_CASE(conversion)
565+
{
566+
for (const arith_uint256& arith : {ZeroL, OneL, R1L, R2L}) {
567+
const auto u256{uint256::FromHex(arith.GetHex()).value()};
568+
BOOST_CHECK_EQUAL(UintToArith256(ArithToUint256(arith)), arith);
569+
BOOST_CHECK_EQUAL(UintToArith256(u256), arith);
570+
BOOST_CHECK_EQUAL(u256, ArithToUint256(arith));
571+
BOOST_CHECK_EQUAL(ArithToUint256(arith).GetHex(), UintToArith256(u256).GetHex());
572+
}
573+
574+
for (uint8_t num : {0, 1, 0xff}) {
575+
BOOST_CHECK_EQUAL(UintToArith256(uint256{num}), arith_uint256{num});
576+
BOOST_CHECK_EQUAL(uint256{num}, ArithToUint256(arith_uint256{num}));
577+
BOOST_CHECK_EQUAL(UintToArith256(uint256{num}), num);
578+
}
579+
}
580+
581+
BOOST_AUTO_TEST_CASE(operator_with_self)
582+
{
583+
/* Clang 16 and earlier detects v -= v and v /= v as self-assignments
584+
to 0 and 1 respectively.
585+
See: https://github.com/llvm/llvm-project/issues/42469
586+
and the fix in commit c5302325b2a62d77cf13dd16cd5c19141862fed0 .
587+
588+
This makes some sense for arithmetic classes, but could be considered a bug
589+
elsewhere. Disable the warning here so that the code can be tested, but the
590+
warning should remain on as there will likely always be a better way to
591+
express this.
592+
*/
593+
#if defined(__clang__)
594+
#pragma clang diagnostic push
595+
#pragma clang diagnostic ignored "-Wself-assign-overloaded"
596+
#endif
597+
arith_uint256 v{2};
598+
v *= v;
599+
BOOST_CHECK_EQUAL(v, arith_uint256{4});
600+
v /= v;
601+
BOOST_CHECK_EQUAL(v, arith_uint256{1});
602+
v += v;
603+
BOOST_CHECK_EQUAL(v, arith_uint256{2});
604+
v -= v;
605+
BOOST_CHECK_EQUAL(v, arith_uint256{0});
606+
#if defined(__clang__)
607+
#pragma clang diagnostic pop
608+
#endif
609+
}
610+
574611
BOOST_AUTO_TEST_SUITE_END()

src/test/fuzz/hex.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ FUZZ_TARGET(hex)
3737
if (const auto result{uint256::FromUserHex(random_hex_string)}) {
3838
assert(uint256::FromHex(result->ToString()));
3939
}
40-
(void)uint256S(random_hex_string);
4140
try {
4241
(void)HexToPubKey(random_hex_string);
4342
} catch (const UniValue&) {

src/test/fuzz/integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ FUZZ_TARGET(integer, .init = initialize_integer)
140140

141141
const arith_uint256 au256 = UintToArith256(u256);
142142
assert(ArithToUint256(au256) == u256);
143-
assert(uint256S(au256.GetHex()) == u256);
143+
assert(uint256::FromHex(au256.GetHex()).value() == u256);
144144
(void)au256.bits();
145145
(void)au256.GetCompact(/* fNegative= */ false);
146146
(void)au256.GetCompact(/* fNegative= */ true);

src/test/uint256_tests.cpp

Lines changed: 12 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <arith_uint256.h>
65
#include <streams.h>
76
#include <test/util/setup_common.h>
87
#include <uint256.h>
@@ -61,14 +60,6 @@ static std::string ArrayToString(const unsigned char A[], unsigned int width)
6160
return Stream.str();
6261
}
6362

64-
// Takes hex string in reverse byte order.
65-
inline uint160 uint160S(std::string_view str)
66-
{
67-
uint160 rv;
68-
rv.SetHexDeprecated(str);
69-
return rv;
70-
}
71-
7263
BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
7364
{
7465
// constructor uint256(vector<char>):
@@ -92,33 +83,22 @@ BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
9283
BOOST_CHECK_NE(MaxL, ZeroL); BOOST_CHECK_NE(MaxS, ZeroS);
9384

9485
// String Constructor and Copy Constructor
95-
BOOST_CHECK_EQUAL(uint256S("0x"+R1L.ToString()), R1L);
96-
BOOST_CHECK_EQUAL(uint256S("0x"+R2L.ToString()), R2L);
97-
BOOST_CHECK_EQUAL(uint256S("0x"+ZeroL.ToString()), ZeroL);
98-
BOOST_CHECK_EQUAL(uint256S("0x"+OneL.ToString()), OneL);
99-
BOOST_CHECK_EQUAL(uint256S("0x"+MaxL.ToString()), MaxL);
100-
BOOST_CHECK_EQUAL(uint256S(R1L.ToString()), R1L);
101-
BOOST_CHECK_EQUAL(uint256S(" 0x"+R1L.ToString()+" "), R1L);
102-
BOOST_CHECK_EQUAL(uint256S(" 0x"+R1L.ToString()+"-trash;%^& "), R1L);
103-
BOOST_CHECK_EQUAL(uint256S("\t \n \n \f\n\r\t\v\t 0x"+R1L.ToString()+" \t \n \n \f\n\r\t\v\t "), R1L);
104-
BOOST_CHECK_EQUAL(uint256S(""), ZeroL);
105-
BOOST_CHECK_EQUAL(uint256S("1"), OneL);
106-
BOOST_CHECK_EQUAL(R1L, uint256S(R1ArrayHex));
86+
BOOST_CHECK_EQUAL(uint256::FromHex(R1L.ToString()).value(), R1L);
87+
BOOST_CHECK_EQUAL(uint256::FromHex(R2L.ToString()).value(), R2L);
88+
BOOST_CHECK_EQUAL(uint256::FromHex(ZeroL.ToString()).value(), ZeroL);
89+
BOOST_CHECK_EQUAL(uint256::FromHex(OneL.ToString()).value(), OneL);
90+
BOOST_CHECK_EQUAL(uint256::FromHex(MaxL.ToString()).value(), MaxL);
91+
BOOST_CHECK_EQUAL(uint256::FromHex(R1ArrayHex).value(), R1L);
10792
BOOST_CHECK_EQUAL(uint256(R1L), R1L);
10893
BOOST_CHECK_EQUAL(uint256(ZeroL), ZeroL);
10994
BOOST_CHECK_EQUAL(uint256(OneL), OneL);
11095

111-
BOOST_CHECK_EQUAL(uint160S("0x"+R1S.ToString()), R1S);
112-
BOOST_CHECK_EQUAL(uint160S("0x"+R2S.ToString()), R2S);
113-
BOOST_CHECK_EQUAL(uint160S("0x"+ZeroS.ToString()), ZeroS);
114-
BOOST_CHECK_EQUAL(uint160S("0x"+OneS.ToString()), OneS);
115-
BOOST_CHECK_EQUAL(uint160S("0x"+MaxS.ToString()), MaxS);
116-
BOOST_CHECK_EQUAL(uint160S(R1S.ToString()), R1S);
117-
BOOST_CHECK_EQUAL(uint160S(" 0x"+R1S.ToString()+" "), R1S);
118-
BOOST_CHECK_EQUAL(uint160S(" 0x"+R1S.ToString()+"-trash;%^& "), R1S);
119-
BOOST_CHECK_EQUAL(uint160S(" \t \n \n \f\n\r\t\v\t 0x"+R1S.ToString()+" \t \n \n \f\n\r\t\v\t"), R1S);
120-
BOOST_CHECK_EQUAL(uint160S(""), ZeroS);
121-
BOOST_CHECK_EQUAL(R1S, uint160S(R1ArrayHex));
96+
BOOST_CHECK_EQUAL(uint160::FromHex(R1S.ToString()).value(), R1S);
97+
BOOST_CHECK_EQUAL(uint160::FromHex(R2S.ToString()).value(), R2S);
98+
BOOST_CHECK_EQUAL(uint160::FromHex(ZeroS.ToString()).value(), ZeroS);
99+
BOOST_CHECK_EQUAL(uint160::FromHex(OneS.ToString()).value(), OneS);
100+
BOOST_CHECK_EQUAL(uint160::FromHex(MaxS.ToString()).value(), MaxS);
101+
BOOST_CHECK_EQUAL(uint160::FromHex(std::string_view{R1ArrayHex + 24, 40}).value(), R1S);
122102

123103
BOOST_CHECK_EQUAL(uint160(R1S), R1S);
124104
BOOST_CHECK_EQUAL(uint160(ZeroS), ZeroS);
@@ -264,82 +244,6 @@ BOOST_AUTO_TEST_CASE(methods) // GetHex SetHexDeprecated FromHex begin() end() s
264244
ss.clear();
265245
}
266246

267-
BOOST_AUTO_TEST_CASE( conversion )
268-
{
269-
BOOST_CHECK_EQUAL(ArithToUint256(UintToArith256(ZeroL)), ZeroL);
270-
BOOST_CHECK_EQUAL(ArithToUint256(UintToArith256(OneL)), OneL);
271-
BOOST_CHECK_EQUAL(ArithToUint256(UintToArith256(R1L)), R1L);
272-
BOOST_CHECK_EQUAL(ArithToUint256(UintToArith256(R2L)), R2L);
273-
BOOST_CHECK_EQUAL(UintToArith256(ZeroL), 0);
274-
BOOST_CHECK_EQUAL(UintToArith256(OneL), 1);
275-
BOOST_CHECK_EQUAL(ArithToUint256(0), ZeroL);
276-
BOOST_CHECK_EQUAL(ArithToUint256(1), OneL);
277-
BOOST_CHECK_EQUAL(arith_uint256(UintToArith256(uint256S(R1L.GetHex()))), UintToArith256(R1L));
278-
BOOST_CHECK_EQUAL(arith_uint256(UintToArith256(uint256S(R2L.GetHex()))), UintToArith256(R2L));
279-
BOOST_CHECK_EQUAL(R1L.GetHex(), UintToArith256(R1L).GetHex());
280-
BOOST_CHECK_EQUAL(R2L.GetHex(), UintToArith256(R2L).GetHex());
281-
}
282-
283-
BOOST_AUTO_TEST_CASE( operator_with_self )
284-
{
285-
286-
/* Clang 16 and earlier detects v -= v and v /= v as self-assignments
287-
to 0 and 1 respectively.
288-
See: https://github.com/llvm/llvm-project/issues/42469
289-
and the fix in commit c5302325b2a62d77cf13dd16cd5c19141862fed0 .
290-
291-
This makes some sense for arithmetic classes, but could be considered a bug
292-
elsewhere. Disable the warning here so that the code can be tested, but the
293-
warning should remain on as there will likely always be a better way to
294-
express this.
295-
*/
296-
297-
#if defined(__clang__)
298-
# pragma clang diagnostic push
299-
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
300-
#endif
301-
arith_uint256 v = UintToArith256(uint256S("02"));
302-
v *= v;
303-
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("04")));
304-
v /= v;
305-
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("01")));
306-
v += v;
307-
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("02")));
308-
v -= v;
309-
BOOST_CHECK_EQUAL(v, UintToArith256(uint256S("0")));
310-
#if defined(__clang__)
311-
# pragma clang diagnostic pop
312-
#endif
313-
}
314-
315-
BOOST_AUTO_TEST_CASE(parse)
316-
{
317-
{
318-
std::string s_12{"0000000000000000000000000000000000000000000000000000000000000012"};
319-
BOOST_CHECK_EQUAL(uint256S("12\0").GetHex(), s_12);
320-
BOOST_CHECK_EQUAL(uint256S(std::string_view{"12\0", 3}).GetHex(), s_12);
321-
BOOST_CHECK_EQUAL(uint256S("0x12").GetHex(), s_12);
322-
BOOST_CHECK_EQUAL(uint256S(" 0x12").GetHex(), s_12);
323-
BOOST_CHECK_EQUAL(uint256S(" 12").GetHex(), s_12);
324-
}
325-
{
326-
std::string s_1{uint256::ONE.GetHex()};
327-
BOOST_CHECK_EQUAL(uint256S("1\0").GetHex(), s_1);
328-
BOOST_CHECK_EQUAL(uint256S(std::string_view{"1\0", 2}).GetHex(), s_1);
329-
BOOST_CHECK_EQUAL(uint256S("0x1").GetHex(), s_1);
330-
BOOST_CHECK_EQUAL(uint256S(" 0x1").GetHex(), s_1);
331-
BOOST_CHECK_EQUAL(uint256S(" 1").GetHex(), s_1);
332-
}
333-
{
334-
std::string s_0{uint256::ZERO.GetHex()};
335-
BOOST_CHECK_EQUAL(uint256S("\0").GetHex(), s_0);
336-
BOOST_CHECK_EQUAL(uint256S(std::string_view{"\0", 1}).GetHex(), s_0);
337-
BOOST_CHECK_EQUAL(uint256S("0x").GetHex(), s_0);
338-
BOOST_CHECK_EQUAL(uint256S(" 0x").GetHex(), s_0);
339-
BOOST_CHECK_EQUAL(uint256S(" ").GetHex(), s_0);
340-
}
341-
}
342-
343247
/**
344248
* Implemented as a templated function so it can be reused by other classes that have a FromHex()
345249
* method that wraps base_blob::FromHex(), such as transaction_identifier::FromHex().

src/uint256.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,4 @@ class uint256 : public base_blob<256> {
199199
static const uint256 ONE;
200200
};
201201

202-
/* uint256 from std::string_view, containing byte-reversed hex encoding.
203-
* DEPRECATED. Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated!
204-
*/
205-
inline uint256 uint256S(std::string_view str)
206-
{
207-
uint256 rv;
208-
rv.SetHexDeprecated(str);
209-
return rv;
210-
}
211-
212202
#endif // BITCOIN_UINT256_H

0 commit comments

Comments
 (0)