aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2024-07-26 15:01:48 +0100
committerstickies-v <stickies-v@protonmail.com>2024-08-23 13:53:40 +0100
commit8a44d7d3c1e5d5af6779c3e4befe514c9dafb8ff (patch)
tree5fb73a929e81cf3a9b8ac7f5c9300143ae9afdf1 /src
parent70e2c87737e77ee85812cc328c4ddfaea7147533 (diff)
node: use uint256::FromUserHex for -minimumchainwork parsing
Removes dependency on unsafe and deprecated uint256S. This makes parsing more strict, by returning an error when the input contains more than 64 hex digits.
Diffstat (limited to 'src')
-rw-r--r--src/node/chainstatemanager_args.cpp7
-rw-r--r--src/test/validation_chainstatemanager_tests.cpp3
2 files changed, 6 insertions, 4 deletions
diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp
index 39b5f3ad3e..129d51c404 100644
--- a/src/node/chainstatemanager_args.cpp
+++ b/src/node/chainstatemanager_args.cpp
@@ -32,10 +32,11 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
if (auto value{args.GetBoolArg("-checkpoints")}) opts.checkpoints_enabled = *value;
if (auto value{args.GetArg("-minimumchainwork")}) {
- if (!IsHexNumber(*value)) {
- return util::Error{strprintf(Untranslated("Invalid non-hex (%s) minimum chain work value specified"), *value)};
+ if (auto min_work{uint256::FromUserHex(*value)}) {
+ opts.minimum_chain_work = UintToArith256(*min_work);
+ } else {
+ return util::Error{strprintf(Untranslated("Invalid minimum work specified (%s), must be up to %d hex digits"), *value, uint256::size() * 2)};
}
- opts.minimum_chain_work = UintToArith256(uint256S(*value));
}
if (auto value{args.GetArg("-assumevalid")}) opts.assumed_valid_block = uint256S(*value);
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index d6e4c6a340..052f5cd1a7 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -820,7 +820,8 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_args, BasicTestingSetup)
BOOST_CHECK_EQUAL(get_valid_opts({"-nominimumchainwork"}).minimum_chain_work.value().GetCompact(), 0U);
BOOST_CHECK_EQUAL(get_valid_opts({"-minimumchainwork=0x1234"}).minimum_chain_work.value().GetCompact(), 0x02123400U);
- BOOST_CHECK(!get_opts({"-minimumchainwork=xyz"})); // invalid hex characters
+ BOOST_CHECK(!get_opts({"-minimumchainwork=xyz"})); // invalid hex characters
+ BOOST_CHECK(!get_opts({"-minimumchainwork=01234567890123456789012345678901234567890123456789012345678901234"})); // > 64 hex chars
}
BOOST_AUTO_TEST_SUITE_END()