Repository navigation
refactor: Move generateBlindingFactor() from protocol to test utilities - #8644
Open
FawwazLawal wants to merge 4 commits into
Open
FawwazLawal wants to merge 4 commits into
FawwazLawal wants to merge 4 commits into
Conversation
Move the RAND_bytes-based generateBlindingFactor() out of the public protocol library (ConfidentialTransfer.h/.cpp) and into the test JTX helpers (src/test/jtx/). The function is only used by tests, and keeping OpenSSL RAND_bytes in the protocol layer exposes it as public API unnecessarily. Also adds secureErase() on the stack buffer before returning. Fixes XRPLF#7631
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Existing calls in src/test/jtx/impl/mpt.cpp lack the relocated declaration, breaking test-target compilation.
1 open issue
What changed in this PR
Moves generateBlindingFactor() from the public protocol library into the JTX test helpers, keeping test-only randomness generation out of the public API.
Changes:
- Relocates the function’s declaration and implementation to test utilities.
- Moves the OpenSSL random-number include out of the protocol implementation.
- Adds secure erasure of the temporary blinding-factor buffer before returning.
| File | Description |
|---|---|
src/test/jtx/impl/ConfidentialTransfer.cpp |
Adds the relocated implementation and temporary-buffer erasure. |
src/test/jtx/ConfidentialTransfer.h |
Declares the helper for test callers. |
src/libxrpl/protocol/ConfidentialTransfer.cpp |
Removes the helper implementation and OpenSSL random-number include. |
include/xrpl/protocol/ConfidentialTransfer.h |
Removes the helper from the public API. |
Review effort: Balanced
After moving generateBlindingFactor() to the test JTX helpers, mpt.cpp needs the new header to resolve the declaration.
Format the three files whose includes and blank lines drifted after the move of generateBlindingFactor() into test/jtx: a double blank line removed in src/libxrpl/protocol/ConfidentialTransfer.cpp, the <openssl/rand.h> include regrouped in src/test/jtx/impl/ConfidentialTransfer.cpp, and <test/jtx/ConfidentialTransfer.h> moved into its sort position in src/test/jtx/impl/mpt.cpp. No functional change. clang-format 23.1.2 --dry-run --Werror now exits 0 on all five files touched by this PR.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

High Level Overview of Change
Moves
generateBlindingFactor()from the public protocol library (include/xrpl/protocol/ConfidentialTransfer.h/src/libxrpl/protocol/ConfidentialTransfer.cpp) into the test JTX helpers (src/test/jtx/ConfidentialTransfer.h/src/test/jtx/impl/ConfidentialTransfer.cpp).The function is only called from test code (confirmed by grep: all callers are in
src/test/). KeepingRAND_bytesand theopenssl/rand.hinclude in the protocol layer exposes it as public API unnecessarily.Context of Change
generateBlindingFactor()wrapsRAND_bytesto produce a buffer ofkEcBlindingFactorLengthrandom bytes for Pedersen commitment randomness. As noted in the issue, this belongs in the test harness, not in the protocol library that ships to consumers.The relocated version also adds
secureErase()on the stack-allocatedblindingFactorarray before returning, matching the project's pattern for sensitive cryptographic material (seexrpl/crypto/secure_erase.h).Type of Change
API Impact
generateBlindingFactor()fromlibxrplpublic API (header and implementation)Test Plan
The change is a pure relocation (declaration + definition moved, three includes added). All callers remain in
src/test/and continue to include the JTX header. Compilation via CI is the primary verification.Closes #7631