diff --git a/include/xrpl/protocol/ConfidentialTransfer.h b/include/xrpl/protocol/ConfidentialTransfer.h index 5b1bcbf6061..96fc2923e91 100644 --- a/include/xrpl/protocol/ConfidentialTransfer.h +++ b/include/xrpl/protocol/ConfidentialTransfer.h @@ -356,19 +356,6 @@ verifyClawbackProof( Slice const& ciphertext, uint256 const& contextHash); -/** - * @brief Generates a cryptographically secure blinding factor - * (size=xrpl::kEcBlindingFactorLength). - * - * Produces random bytes suitable for use as an ElGamal blinding factor - * or Pedersen commitment randomness. - * - * @return A buffer containing the random blinding factor - * (size=xrpl::kEcBlindingFactorLength). - */ -Buffer -generateBlindingFactor(); - /** * @brief Verifies all zero-knowledge proofs for a ConfidentialMPTSend transaction. * diff --git a/include/xrpl/protocol/detail/sfields.macro b/include/xrpl/protocol/detail/sfields.macro index 8acf3fe1c58..0d453eea112 100644 --- a/include/xrpl/protocol/detail/sfields.macro +++ b/include/xrpl/protocol/detail/sfields.macro @@ -207,8 +207,8 @@ TYPED_SFIELD(sfParentBatchID, UINT256, 36) TYPED_SFIELD(sfLoanBrokerID, UINT256, 37, SField::kSmdPseudoAccount | SField::kSmdDefault) TYPED_SFIELD(sfLoanID, UINT256, 38) -TYPED_SFIELD(sfBlindingFactor, UINT256, 39) -TYPED_SFIELD(sfReferenceHolding, UINT256, 40) +TYPED_SFIELD(sfReferenceHolding, UINT256, 39) +TYPED_SFIELD(sfBlindingFactor, UINT256, 40) // number (common) TYPED_SFIELD(sfNumber, NUMBER, 1) diff --git a/src/libxrpl/protocol/ConfidentialTransfer.cpp b/src/libxrpl/protocol/ConfidentialTransfer.cpp index 0baff1e33ac..c9cfc551a3f 100644 --- a/src/libxrpl/protocol/ConfidentialTransfer.cpp +++ b/src/libxrpl/protocol/ConfidentialTransfer.cpp @@ -1,9 +1,11 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -197,6 +199,8 @@ homomorphicAdd(Slice const& a, Slice const& b) secp256k1Context(), &sum.c1, &sum.c2, &pairA->c1, &pairA->c2, &pairB->c1, &pairB->c2); res != 1) { + JLOG(debugLog().error()) << "homomorphicAdd: secp256k1_elgamal_add failed" + << " a=" << strHex(a) << " b=" << strHex(b); return std::nullopt; } @@ -220,6 +224,8 @@ homomorphicSubtract(Slice const& a, Slice const& b) secp256k1Context(), &diff.c1, &diff.c2, &pairA->c1, &pairA->c2, &pairB->c1, &pairB->c2); res != 1) { + JLOG(debugLog().error()) << "homomorphicSubtract: secp256k1_elgamal_subtract failed" + << " a=" << strHex(a) << " b=" << strHex(b); return std::nullopt; } @@ -236,18 +242,6 @@ rerandomizeCiphertext(Slice const& ciphertext, Slice const& pubKeySlice, Slice c return homomorphicAdd(ciphertext, *zero); } -Buffer -generateBlindingFactor() -{ - unsigned char blindingFactor[kEcBlindingFactorLength]; - - // todo: might need to be updated using another RNG - if (RAND_bytes(blindingFactor, kEcBlindingFactorLength) != 1) - Throw("Failed to generate random number"); - - return Buffer(blindingFactor, kEcBlindingFactorLength); -} - std::optional encryptAmount(uint64_t const amt, Slice const& pubKeySlice, Slice const& blindingFactor) { diff --git a/src/test/jtx/ConfidentialTransfer.h b/src/test/jtx/ConfidentialTransfer.h index b758683da6e..1fad7fef973 100644 --- a/src/test/jtx/ConfidentialTransfer.h +++ b/src/test/jtx/ConfidentialTransfer.h @@ -239,9 +239,9 @@ class ConfidentialTransferTestBase : public beast::unit_test::Suite : sendAmount(amount) , nRecipients(auditor ? 4 : 3) , version(mpt.getMPTokenVersion(sender)) - , blindingFactor(generateBlindingFactor()) + , blindingFactor(test::jtx::generateBlindingFactor()) , amountBlindingFactor(blindingFactor) - , balanceBlindingFactor(generateBlindingFactor()) + , balanceBlindingFactor(test::jtx::generateBlindingFactor()) , senderAmt(mpt.encryptAmount(sender, amount, blindingFactor)) , destAmt(mpt.encryptAmount(dest, amount, blindingFactor)) , issuerAmt(mpt.encryptAmount(issuer, amount, blindingFactor)) diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index d5fba82e089..882face481a 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -14,12 +14,35 @@ #include #include +#include + #include #include #include namespace xrpl::test::jtx { +/** + * @brief Generates a cryptographically secure blinding factor + * (size=xrpl::kEcBlindingFactorLength). + * + * Produces random bytes suitable for use as an ElGamal blinding factor + * or Pedersen commitment randomness. + * + * @return A buffer containing the random blinding factor + * (size=xrpl::kEcBlindingFactorLength). + */ +inline Buffer +generateBlindingFactor() +{ + unsigned char blindingFactor[kEcBlindingFactorLength]; + + if (RAND_bytes(blindingFactor, kEcBlindingFactorLength) != 1) + Throw("Failed to generate random number"); + + return Buffer(blindingFactor, kEcBlindingFactorLength); +} + class MPTTester; auto const kMptDexFlags = tfMPTCanTrade | tfMPTCanTransfer;