Skip to content

refactor: Move generateBlindingFactor() from protocol to test utilities - #8644

Open
FawwazLawal wants to merge 4 commits into
XRPLF:developfrom
FawwazLawal:fix/7631-confidential-transfer
Open

FawwazLawal wants to merge 4 commits into
XRPLF:developfrom
FawwazLawal:fix/7631-confidential-transfer

Conversation

@FawwazLawal

@FawwazLawal FawwazLawal commented Oct 27, 2026 •

Copy link
Copy Markdown

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/). Keeping RAND_bytes and the openssl/rand.h include in the protocol layer exposes it as public API unnecessarily.

Context of Change

generateBlindingFactor() wraps RAND_bytes to produce a buffer of kEcBlindingFactorLength random 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-allocated blindingFactor array before returning, matching the project's pattern for sensitive cryptographic material (see xrpl/crypto/secure_erase.h).

Type of Change

  • Refactor (no functional change)

API Impact

  • Removes generateBlindingFactor() from libxrpl public API (header and implementation)
  • No peer protocol change
  • No RPC change

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.

5 files changed, 19 insertions(+), 26 deletions(-)

Closes #7631

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread src/test/jtx/ConfidentialTransfer.h Resolved
After moving generateBlindingFactor() to the test JTX helpers,
mpt.cpp needs the new header to resolve the declaration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the relocation of the blinding-factor helper to test utilities.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the helper’s relocation to the JTX test utilities.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move RAND_bytes funciton out of public protocol code and into test/JTX code

2 participants