mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-07 03:03:58 +01:00
Merge bitcoin/bitcoin#30569: node: reduce unsafe uint256S usage
18d65d2772test: use uint256::FromUserHex for RANDOM_CTX_SEED (stickies-v)6819e5a329node: use uint256::FromUserHex for -assumevalid parsing (stickies-v)2e58fdb544util: remove unused IsHexNumber (stickies-v)8a44d7d3c1node: use uint256::FromUserHex for -minimumchainwork parsing (stickies-v)70e2c87737refactor: add uint256::FromUserHex helper (stickies-v)85b7cbfcbetest: unittest chainstatemanager_args (stickies-v) Pull request description: Sincefad2991ba0, `uint256S` has been [deprecated](fad2991ba0 (diff-800776e2dda39116e889839f69409571a5d397de048a141da7e4003bc099e3e2R138)) because it is less robust than the `base_blob::FromHex()` introduced in [the same PR](https://github.com/bitcoin/bitcoin/pull/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 #30532)_ This PR carves out the few `uint256S` callsites that may potentially prove a bit more controversial to change because they deal with user input and backwards incompatible behaviour change. The main behaviour change introduced in this PR is: - `-minimumchainwork` will raise an error when input is longer than 64 hex digits - `-assumevalid` will raise an error when input contains invalid hex characters, or when it is longer than 64 hex digits - test: the optional RANDOM_CTX_SEED env var will now cause tests to abort when it contains invalid hex characters, or when it is longer than 64 hex digits After this PR, the remaining work to remove `uint256S` completely is almost entirely mechanical and/or test related. I will open that PR once #30560 is merged because it builds on that. ACKs for top commit: hodlinator: re-ACK18d65d2772l0rinc: ACK18d65d2772achow101: ACK18d65d2772ryanofsky: Code review ACK18d65d2772. Very nice change that cleans up the API, adds checking for invalid values, makes parsing of values more consistent, and adds test coverage. Tree-SHA512: ec118ea3d56e1dfbc4c79acdbfc797f65c4d2107b0ca9577c848b4ab9b7cb8d05db9f3c7fe8441a09291aca41bf671572431f4eddc59be8fb53abbea76bbbf86
This commit is contained in:
@@ -32,13 +32,20 @@ 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);
|
||||
if (auto value{args.GetArg("-assumevalid")}) {
|
||||
if (auto block_hash{uint256::FromUserHex(*value)}) {
|
||||
opts.assumed_valid_block = *block_hash;
|
||||
} else {
|
||||
return util::Error{strprintf(Untranslated("Invalid assumevalid block hash specified (%s), must be up to %d hex digits (or 0 to disable)"), *value, uint256::size() * 2)};
|
||||
}
|
||||
}
|
||||
|
||||
if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user