Skip to content

Conversation

hodlinator
Copy link
Contributor

@hodlinator hodlinator commented Jul 31, 2024

Motivation:

  • Validates and converts the hex string at compile time instead of at runtime into the resulting bytes.
  • Makes it possible to derive other compile time constants from uint256.
  • Potentially eliminates runtime dependencies (SetHexDeprecated() is called in less places).
  • Has stricter requirements than the deprecated uint256S() (requiring 64 chars exactly, disallows garbage at the end) and replaces it in a bunch of places.
  • Makes the binary smaller (tested Guix-built x86_64-linux-gnu bitcoind binary).
  • Minor: should shave off a few cycles of start-up time.

Extracted from #30377 which diverged into exploring consteval ParseHex() solutions.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 31, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK paplorinc, maflcko, stickies-v
Stale ACK TheCharlatan

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30526 (doc: Correct uint256 hex string endianness by hodlinator)
  • #30377 (refactor: Add consteval uint256{"str"} by hodlinator)
  • #29656 (chainparams: Change nChainTx type to uint64_t by fjahr)
  • #29553 (assumeutxo: Add dumptxoutset height param, remove shell scripts by fjahr)
  • #27433 (getblocktemplate improvements for segwit and sigops by Sjors)
  • #27427 (validation: Replace MinBIP9WarningHeight with MinBIP9WarningStartTime by dimitaracev)
  • #26966 (index: blockfilter initial sync speedup, parallelize process by furszy)
  • #26201 (Remove Taproot activation height by Sjors)
  • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko
Copy link
Member

maflcko commented Jul 31, 2024

Eliminates runtime dependencies.

Is this true? IIRC it was true for ParseHex, because that returns a std::vector<std::byte> (and the module that was used to create the bytes could be dropped before linking. However, the uint256 type lives in the same module as the parsing code, so I don't think this is true?

Has stricter requirements than the deprecated uint256S() and replaces it in a bunch of places.

It would be good to mention them: "Requires exactly 64 hex characters" (or so). Also, it could recap the risks of uint256S: "Previously, any invalid string was accepted silently."?

@hodlinator
Copy link
Contributor Author

Eliminates runtime dependencies.

Is this true? IIRC it was true for ParseHex, because that returns a std::vector<std::byte> (and the module that was used to create the bytes could be dropped before linking. However, the uint256 type lives in the same module as the parsing code, so I don't think this is true?

Your memory serves you right: #30377 (comment)
However, this change eliminates some calls to the .cpp SetHexDeprecated() which has potential to decrease runtime dependencies in the future, even if it were not to happen right now. Adjusted summary.

Has stricter requirements than the deprecated uint256S() and replaces it in a bunch of places.

It would be good to mention them: "Requires exactly 64 hex characters" (or so). Also, it could recap the risks of uint256S: "Previously, any invalid string was accepted silently."?

Cheers, adjusted summary somewhat.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Left some nits, feel free to ignore them.

Mazzika1

This comment was marked as spam.

Mazzika1

This comment was marked as spam.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some more nits.

ACK 9315c1f 🕵

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 9315c1f34abaa4cd78185818ed8d2df5f35eb3ce 🕵
GZQfOWL8G0spNKvjqmkS65RYUYIQBpZjUi0j+fcqLs9A5d+ffS+M/zKWMvJBpjmBad5mU4mrr/6AY/sNvV6DBg==

@hodlinator hodlinator force-pushed the 2024-07_uint256_consteval_ctor branch from 9315c1f to ed9823f Compare August 1, 2024 12:28
Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ed9823f

@DrahtBot DrahtBot requested a review from maflcko August 1, 2024 12:45
@hodlinator hodlinator force-pushed the 2024-07_uint256_consteval_ctor branch from ed9823f to c0b259b Compare August 1, 2024 13:00
Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ACK c0b259b

Only changes are dropping the commit changing some strings to string_view.

@hodlinator
Copy link
Contributor Author

@TheCharlatan thanks for the speedy re-ACK! My latest force-push actually dropped a tangential commit: #30560 (comment)

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c0b259b

Very nice PR, more compile-time checks and easy to review. Makes my branch removing uint256S a bunch more compact too. Non-blocking nits.

Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed a part of it, left some questions.
I will have to measure the before/after compilation speeds and the before/after artefact size to be able to approve - will do that in the following days.

@hodlinator hodlinator force-pushed the 2024-07_uint256_consteval_ctor branch from c0b259b to be750dc Compare August 1, 2024 22:11
BOOST_CHECK_EQUAL(one, uint256::ONE);
}

BOOST_AUTO_TEST_CASE(FromHex_vs_uint256)
{
auto runtime_uint{uint256::FromHex("4A5E1E4BAAB89F3A32518A88C31BC87F618f76673e2cc77ab2127b7afdeda33b").value()};
Copy link
Contributor

@l0rinc l0rinc Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure we want to mandate that mixed-case hex strings can be parsed? I consider that an error instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, retouching ACKed PRs becomes an attack on Bitcoin. But this is a good enough question to possibly trigger a re-touch.

Would be happy to hear opinions from others on this. But I understand if they prefer spending time on more significant things.

Supporting both cases could be considered a hangover from SetHexDeprecated, but on the other hand, mixed cases are still supported by FromHex/IsHex/HexDigit.

Checked for occurrences of uppercase hex after "uint256".

$ git grep -E 'uint256.*"[a-fA-F0-9]{64}"' |grep -E 'uint256.{0,32}".{0,63}[A-F]+.{0,63}"'
src/kernel/chainparams.cpp:            uint256{"0000A000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22"}, SCRIPT_VERIFY_NONE);
src/test/pow_tests.cpp:        arith_uint256 targ_max{UintToArith256(uint256{"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"})};
src/test/uint256_tests.cpp:    auto runtime_uint{uint256::FromHex("4A5E1E4BAAB89F3A32518A88C31BC87F618f76673e2cc77ab2127b7afdeda33b").value()};
src/test/uint256_tests.cpp:    constexpr uint256 consteval_uint{  "4a5e1e4baab89f3a32518a88c31bc87f618F76673E2CC77AB2127B7AFDEDA33B"};

src/kernel/chainparams.cpp was my modified local file. So it's only pow_tests.cpp and the current test use uppercase.

Implemented a version of this PR with lowercase enforcement (+ including assert => throw from #30560 (comment)) in 40bd3c1. It uses \L in the scripted-diff regexp to lowercase the hex number (might not be supported on Mac sed I think, but Mac is not officially supported anyways).

$ git range-diff master be750dccb08050bcca48c4236ca6b902dd911c7b 40bd3c1aa766572bf5eb8e14bbc9f9606a69299b
1:  9f4ca1f293 ! 1:  49ff7af46c refactor: Add consteval uint256(hex_str)
    @@ src/test/uint256_tests.cpp: BOOST_AUTO_TEST_CASE( check_ONE )
     +BOOST_AUTO_TEST_CASE(FromHex_vs_uint256)
     +{
     +    auto runtime_uint{uint256::FromHex("4A5E1E4BAAB89F3A32518A88C31BC87F618f76673e2cc77ab2127b7afdeda33b").value()};
    -+    constexpr uint256 consteval_uint{  "4a5e1e4baab89f3a32518a88c31bc87f618F76673E2CC77AB2127B7AFDEDA33B"};
    ++    constexpr uint256 consteval_uint{  "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"};
     +    BOOST_CHECK_EQUAL(consteval_uint, runtime_uint);
     +}
     +
    @@ src/uint256.h: public:
     +    // Non-lookup table version of HexDigit().
     +    auto from_hex = [](const char c) -> int8_t {
     +        if (c >= '0' && c <= '9') return c - '0';
    ++        // Only lowercase letters are supported, for consistency.
     +        if (c >= 'a' && c <= 'f') return c - 'a' + 0xA;
    -+        if (c >= 'A' && c <= 'F') return c - 'A' + 0xA;
     +
    -+        assert(false); // Reached if ctor is called with an invalid hex digit.
    ++        throw "Called ctor with an invalid hex digit";
     +    };
     +
    -+    assert(hex_str.length() == m_data.size() * 2); // 2 hex digits per byte.
    ++    if (hex_str.length() != m_data.size() * 2) throw "Hex string must fit exactly";
     +    auto str_it = hex_str.rbegin();
     +    for (auto& elem : m_data) {
     +        auto lo = from_hex(*(str_it++));
2:  d5e5d7eacc = 2:  5994e659c0 refactor: Hand-replace some uint256S -> uint256
3:  be750dccb0 ! 3:  40bd3c1aa7 scripted-diff: Replace uint256S("str") -> uint256{"str"}
    @@ Commit message
         scripted-diff: Replace uint256S("str") -> uint256{"str"}
     
         -BEGIN VERIFY SCRIPT-
    -    sed -i --regexp-extended -e 's/uint256S\("(0x)?([^"]{64})"\)/uint256{"\2"}/g' $(git grep -l uint256S)
    +    sed -i --regexp-extended -e 's/uint256S\("(0x)?([^"]{64})"\)/uint256{"\L\2"}/g' $(git grep -l uint256S)
         -END VERIFY SCRIPT-
     
      ## src/kernel/chainparams.cpp ##
    @@ src/test/pow_tests.cpp: void sanity_check_chainparams(const ArgsManager& args, C
          // check max target * 4*nPowTargetTimespan doesn't overflow -- see pow.cpp:CalculateNextWorkRequired()
          if (!consensus.fPowNoRetargeting) {
     -        arith_uint256 targ_max{UintToArith256(uint256S("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"))};
    -+        arith_uint256 targ_max{UintToArith256(uint256{"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"})};
    ++        arith_uint256 targ_max{UintToArith256(uint256{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"})};
              targ_max /= consensus.nPowTargetTimespan*4;
              BOOST_CHECK(UintToArith256(consensus.powLimit) < targ_max);
          }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for considering, I'm personally fine with doing it in a different PR as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong view on this but I would prefer getting this PR over the line as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to not spawn yet another PR from this work but will post that as a separate PR then if this one is merged in the current state.

@maflcko
Copy link
Member

maflcko commented Aug 2, 2024

re-ACK be750dc 📩

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: re-ACK be750dccb08050bcca48c4236ca6b902dd911c7b 📩
XKgaX77QrcUqp/QwF4ALbBeRlRY0IPgLGnco+g/GineLXZ8qsKhe6zjomAMVRK99+J/zCiYZfKgLifTLg4SKBA==

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 2, 2024

Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

File commit 9774a95
(master)
commit fc222d0
(master and this pull)
SHA256SUMS.part 57b529722ff8170d... 9cc32e96ee19c7ce...
*-aarch64-linux-gnu-debug.tar.gz 9e133d3761048d87... d731065f25a2067f...
*-aarch64-linux-gnu.tar.gz b51473e78eeb01d9... 4bc1a640bbdce4e6...
*-arm-linux-gnueabihf-debug.tar.gz 7b5b1955f6863a67... ec8dc8be9bd051b0...
*-arm-linux-gnueabihf.tar.gz bafac190444cf1c9... b3aca56136bd925e...
*-arm64-apple-darwin-unsigned.tar.gz 49cd7a29e7b8870d... d944d0ed24bf738b...
*-arm64-apple-darwin-unsigned.zip 3e59d7fdbd306ba9... 559ea1aeb9a6bd40...
*-arm64-apple-darwin.tar.gz 1baa8000875e847a... 57bc5fe398d3ff8f...
*-powerpc64-linux-gnu-debug.tar.gz 9d9523154952b3e4... cd06d4a9bde80644...
*-powerpc64-linux-gnu.tar.gz 0a463da65598d2de... a47fd84db9f6fe0c...
*-riscv64-linux-gnu-debug.tar.gz ac4f691dabc2379b... 93e983f0ff97c2e7...
*-riscv64-linux-gnu.tar.gz 62b45e48084b1122... 22d3d90b92261af1...
*-x86_64-apple-darwin-unsigned.tar.gz 754416c2368c0bc2... 5c156fce57a8f679...
*-x86_64-apple-darwin-unsigned.zip 1fc341265dc614fb... 35e716173c704538...
*-x86_64-apple-darwin.tar.gz 4570c83abed42575... d1b73111d170624a...
*-x86_64-linux-gnu-debug.tar.gz a3749460e54f3799... 4358edf1c01d6d59...
*-x86_64-linux-gnu.tar.gz 1ed77103dbec7f67... 9c2c3a637b594eb5...
*.tar.gz 229aab5f94e60c45... f2d306ae36933f32...
guix_build.log 3ad35213427a9854... 8803670ef192f8ac...
guix_build.log.diff 750efac38926403e...

@l0rinc
Copy link
Contributor

l0rinc commented Aug 3, 2024

ACK be750dc

@hodlinator hodlinator force-pushed the 2024-07_uint256_consteval_ctor branch from be750dc to a34ba0e Compare August 5, 2024 07:30
@hodlinator
Copy link
Contributor Author

hodlinator commented Aug 5, 2024

Rebased with minimal changes to fix merge-issues.

sed -i --regexp-extended -e 's/uint256S\("(0x)?([^"]{64})"\)/uint256{"\2"}/g' $(git grep -l uint256S)
->
sed -i --regexp-extended -e 's/\buint256S\("(0x)?([^"]{64})"\)/uint256{"\2"}/g' $(git grep -l uint256S)
to make it avoid matching new instances of arith_uint256S being passed 64 chars for the first time in arith_uint256_tests.cpp.

Edit: I realized too late that this might have been an okay time to incorporate #30560 (comment) but it is probably just as well as it could lead to further discussion and dragging out this PR.

@maflcko
Copy link
Member

maflcko commented Aug 5, 2024

rebase re-ACK a34ba0e 🔺

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: rebase re-ACK a34ba0eed401f2b48e168b857d05eab065d9ab42 🔺
iFR6SWJkjcVURezwm7wcmHE5vJpN52mrZZQxoZ7seS8rcmQLasm5/VYX2GSWvh9sBxcklTxuhbSz+NQ29GbiDw==

@DrahtBot DrahtBot requested review from l0rinc and TheCharlatan August 5, 2024 08:20
@l0rinc
Copy link
Contributor

l0rinc commented Aug 5, 2024

ACK a34ba0e

@maflcko
Copy link
Member

maflcko commented Aug 5, 2024

(needs another rebase)

Complements uint256::FromHex() nicely in that it naturally does all error checking at compile time and so doesn't need to return an std::optional.

Will be used in the following 2 commits to replace many calls to uint256S(). uint256S() calls taking C-string literals are littered throughout the codebase and executed at runtime to perform parsing unless a given optimizer was surprisingly efficient. While this may not be a hot spot, it's better hygiene in C++20 to store the parsed data blob directly in the binary, without any parsing at runtime.
chainparams.cpp - workaround for MSVC bug triggering C7595 - Calling consteval constructors in initializer lists fails, but works on GCC (13.2.0) & Clang (17.0.6).
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/\buint256S\("(0x)?([^"]{64})"\)/uint256{"\2"}/g' $(git grep -l uint256S)
-END VERIFY SCRIPT-
@hodlinator hodlinator force-pushed the 2024-07_uint256_consteval_ctor branch from a34ba0e to 2d9d752 Compare August 5, 2024 12:59
Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2d9d752

@DrahtBot DrahtBot requested a review from maflcko August 5, 2024 13:24
@maflcko
Copy link
Member

maflcko commented Aug 5, 2024

Checked with git range-diff bitcoin-core/master a34ba0eed401f2b48e168b857d05eab065d9ab42 2d9d752e4fc30aabf2ddd36ca7a63432d26d4fea --word-diff -U1

rebase re-cr-ACK 2d9d752 🎐

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: rebase re-cr-ACK 2d9d752e4fc30aabf2ddd36ca7a63432d26d4fea 🎐
bVzdyt2phN87YtMtJ9BYOknRRBRRiX84Qv5+49gXFTHu5Il0aHR0r7rJUIcOTH6e4oMVe06eFh7+BrYY91yqCg==

@stickies-v
Copy link
Contributor

re-ACK 2d9d752

@ryanofsky ryanofsky merged commit 21c2879 into bitcoin:master Aug 5, 2024
16 checks passed
@hodlinator hodlinator deleted the 2024-07_uint256_consteval_ctor branch August 5, 2024 19:05
hodlinator added a commit to hodlinator/bitcoin that referenced this pull request Aug 27, 2024
Ran scripted-diff from 2d9d752.

Follow-up to bitcoin#29775 which overlapped with work on bitcoin#30560 (the latter includes the scripted-diff commit).
hodlinator added a commit to hodlinator/bitcoin that referenced this pull request Aug 27, 2024
Ran scripted-diff from 2d9d752.

Follow-up to bitcoin#29775 which overlapped with work on bitcoin#30560 (the latter includes the scripted-diff commit).
achow101 added a commit that referenced this pull request Aug 27, 2024
18d65d2 test: use uint256::FromUserHex for RANDOM_CTX_SEED (stickies-v)
6819e5a node: use uint256::FromUserHex for -assumevalid parsing (stickies-v)
2e58fdb util: remove unused IsHexNumber (stickies-v)
8a44d7d node: use uint256::FromUserHex for -minimumchainwork parsing (stickies-v)
70e2c87 refactor: add uint256::FromUserHex helper (stickies-v)
85b7cbf test: unittest chainstatemanager_args (stickies-v)

Pull request description:

  Since fad2991, `uint256S` has been [deprecated](fad2991#diff-800776e2dda39116e889839f69409571a5d397de048a141da7e4003bc099e3e2R138) because it is less robust than the `base_blob::FromHex()` introduced in [the same PR](#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-ACK 18d65d2
  l0rinc:
    ACK 18d65d2
  achow101:
    ACK 18d65d2
  ryanofsky:
    Code review ACK 18d65d2. 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
fanquake added a commit that referenced this pull request Aug 28, 2024
…{"str"}

49f9b64 refactor: Testnet4 - Replace uint256S("str") -> uint256{"str"} (Hodlinator)

Pull request description:

  Ran scripted-diff from 2d9d752:
  ```
  sed -i --regexp-extended -e 's/\buint256S\("(0x)?([^"]{64})"\)/uint256{"\2"}/g' $(git grep -l uint256S)
  ```

  Follow-up to Testnet4 introduction #29775 which overlapped with work on `uint256` `consteval` ctor #30560 (the latter includes the scripted-diff commit).

  Going forward `uint256{}` should be used for constants instead of `uint256S()`.

ACKs for top commit:
  maflcko:
    review-ACK 49f9b64 🐮
  fjahr:
    ACK 49f9b64

Tree-SHA512: 94fe5d9f1fb85e9ce5c3c4c5e4c31667e8cbb55ee691a4b5b3ae4172ccac38230281071023663965917f188b4c19bdf67afd4e3cdf69d89e97c65faea88af833
ryanofsky added a commit that referenced this pull request Aug 31, 2024
8756ccd scripted-diff: Replace ParseHex[<std::byte>]("str") -> "str"_hex[_u8] (Hodlinator)
9cb6873 refactor: Prepare for ParseHex -> ""_hex scripted-diff (Hodlinator)
50bc017 refactor: Hand-replace some ParseHex -> ""_hex (Hodlinator)
5b74a84 util: Add consteval ""_hex[_v][_u8] literals (l0rinc)
dc5f6f6 test refactor: util_tests - parse_hex clean up (Hodlinator)
2b5e6ef refactor: Make XOnlyPubKey tolerate constexpr std::arrays (Hodlinator)
403d86f refactor: vector -> span in CCrypter (Hodlinator)
bd0830b refactor: de-Hungarianize CCrypter (Hodlinator)
d99c816 refactor: Improve CCrypter related lines (Hodlinator)
7e1d9a8 refactor: Enforce lowercase hex digits for consteval uint256 (Hodlinator)

Pull request description:

  Motivation:
  * Validates and converts the hex string into bytes at compile time instead of at runtime like `ParseHex()`.
  * Eliminates runtime dependencies: #30377 (comment), #30048 (comment)
  * Has stricter requirements than `ParseHex()` (disallows whitespace and uppercase hex digits) and replaces it in a bunch of places.
  * Makes it possible to derive other compile time constants.
  * Minor: should shave off a few runtime CPU cycles.

  `""_hex` produces `std::array<std::byte>` as the momentum in the codebase is to use `std::byte` over `uint8_t`.

  Also makes `uint256` hex string constructor disallow uppercase hex digits. Discussed: #30560 (comment)

  Surprisingly does not change the size of the Guix **bitcoind** binary (on x86_64-linux-gnu) by 1 single byte.

  Spawned already merged PRs: #30436, #30482, #30532, #30560.

ACKs for top commit:
  l0rinc:
    ACK 8756ccd
  stickies-v:
    Rebase re-ACK 8756ccd, no changes since a096215
  ryanofsky:
    Code review ACK 8756ccd, just rebasing since last review and taking advantage of CScript constructors in #29369, also tweaking a code comment

Tree-SHA512: 9b2011b7c37e0ef004c669f8601270a214b388916316458370f5902c79c2856790b1b2c7c123efa65decad04886ab5eff95644301e0d84358bb265cf1f8ec195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants