Skip to content

Commit 30636db

Browse files
Merge branch 'ripple/confidential-transfer' into ripple/confidential-transfer
2 parents 1601943 + fc8b789 commit 30636db

File tree

9 files changed

+547
-189
lines changed

9 files changed

+547
-189
lines changed

include/xrpl/protocol/ConfidentialTransfer.h

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,49 @@ verifyClawbackEqualityProof(
163163
Buffer
164164
generateBlindingFactor();
165165

166+
/**
167+
* @brief Verifies the cryptographic link between an ElGamal Ciphertext and a
168+
* Pedersen Commitment for a transaction Amount.
169+
*
170+
* It proves that the ElGamal ciphertext `encAmt` encrypts the same value `m`
171+
* as the Pedersen Commitment `pcmSlice`, using the randomness `r`.
172+
* Proves Enc(m) <-> Pcm(m)
173+
*
174+
* @param proof The Zero Knowledge Proof bytes.
175+
* @param encAmt The ElGamal ciphertext of the amount (C1, C2).
176+
* @param pubKeySlice The sender's public key.
177+
* @param pcmSlice The Pedersen Commitment to the amount.
178+
* @param contextHash The unique context hash for this transaction.
179+
* @return tesSUCCESS if the proof is valid, or an error code otherwise.
180+
*/
181+
TER
182+
verifyAmountPcmLinkage(
183+
Slice const& proof,
184+
Slice const& encAmt,
185+
Slice const& pubKeySlice,
186+
Slice const& pcmSlice,
187+
uint256 const& contextHash);
188+
189+
/**
190+
* @brief Verifies the cryptographic link between an ElGamal Ciphertext and a
191+
* Pedersen Commitment for an account Balance.
192+
*
193+
* It proves that the ElGamal ciphertext `encAmt` encrypts the same value `b`
194+
* as the Pedersen Commitment `pcmSlice`, using the secret key `s`.
195+
* Proves Enc(b) <-> Pcm(b)
196+
*
197+
* Note: Swaps arguments (Pk <-> C1) to accommodate the different algebraic
198+
* structure.
199+
*
200+
* @param proof The Zero Knowledge Proof bytes.
201+
* @param encAmt The ElGamal ciphertext of the balance (C1, C2).
202+
* @param pubKeySlice The sender's public key.
203+
* @param pcmSlice The Pedersen Commitment to the balance.
204+
* @param contextHash The unique context hash for this transaction.
205+
* @return tesSUCCESS if the proof is valid, or an error code otherwise.
206+
*/
166207
TER
167-
verifyPedersenLinkage(
208+
verifyBalancePcmLinkage(
168209
Slice const& proof,
169210
Slice const& encAmt,
170211
Slice const& pubKeySlice,

include/xrpl/protocol/detail/sfields.macro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ TYPED_SFIELD(sfAuditorEncryptedBalance, VL, 42)
313313
TYPED_SFIELD(sfAuditorEncryptedAmount, VL, 43)
314314
TYPED_SFIELD(sfAuditorElGamalPublicKey, VL, 44)
315315
TYPED_SFIELD(sfBlindingFactor, VL, 45)
316-
TYPED_SFIELD(sfPedersenCommitment, VL, 46)
316+
TYPED_SFIELD(sfAmountCommitment, VL, 46)
317+
TYPED_SFIELD(sfBalanceCommitment, VL, 47)
317318

318319
// account (common)
319320
TYPED_SFIELD(sfAccount, ACCOUNT, 1)

include/xrpl/protocol/detail/transactions.macro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ TRANSACTION(ttCONFIDENTIAL_CONVERT_BACK, 87, ConfidentialConvertBack,
11071107
{sfAuditorEncryptedAmount, soeOPTIONAL},
11081108
{sfBlindingFactor, soeREQUIRED},
11091109
{sfZKProof, soeREQUIRED},
1110-
{sfPedersenCommitment, soeREQUIRED}
1110+
{sfBalanceCommitment, soeREQUIRED},
11111111
}))
11121112

11131113
#if TRANSACTION_INCLUDE
@@ -1123,9 +1123,11 @@ TRANSACTION(ttCONFIDENTIAL_SEND, 88, ConfidentialSend,
11231123
{sfSenderEncryptedAmount, soeREQUIRED},
11241124
{sfDestinationEncryptedAmount, soeREQUIRED},
11251125
{sfIssuerEncryptedAmount, soeREQUIRED},
1126+
{sfAuditorEncryptedAmount, soeOPTIONAL},
11261127
{sfZKProof, soeREQUIRED},
1128+
{sfAmountCommitment, soeREQUIRED},
1129+
{sfBalanceCommitment, soeREQUIRED},
11271130
{sfCredentialIDs, soeOPTIONAL},
1128-
{sfAuditorEncryptedAmount, soeOPTIONAL},
11291131
}))
11301132

11311133
#if TRANSACTION_INCLUDE

src/libxrpl/protocol/ConfidentialTransfer.cpp

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,48 @@ checkEncryptedAmountFormat(STObject const& object)
479479
}
480480

481481
TER
482-
verifyPedersenLinkage(
482+
verifyAmountPcmLinkage(
483+
Slice const& proof,
484+
Slice const& encAmt,
485+
Slice const& pubKeySlice,
486+
Slice const& pcmSlice,
487+
uint256 const& contextHash)
488+
{
489+
if (proof.length() != ecPedersenProofLength)
490+
return tecINTERNAL;
491+
492+
secp256k1_pubkey c1, c2;
493+
if (!makeEcPair(encAmt, c1, c2))
494+
return tecINTERNAL; // LCOV_EXCL_LINE
495+
496+
secp256k1_pubkey pubKey;
497+
if (pubKeySlice.size() != ecPubKeyLength)
498+
return tecINTERNAL; // LCOV_EXCL_LINE
499+
500+
secp256k1_pubkey pcm;
501+
if (pcmSlice.size() != ecPedersenCommitmentLength)
502+
return tecINTERNAL; // LCOV_EXCL_LINE
503+
504+
std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength);
505+
std::memcpy(pcm.data, pcmSlice.data(), ecPedersenCommitmentLength);
506+
507+
if (secp256k1_elgamal_pedersen_link_verify(
508+
secp256k1Context(),
509+
proof.data(),
510+
&c1,
511+
&c2,
512+
&pubKey,
513+
&pcm,
514+
contextHash.data()) != 1)
515+
{
516+
return tecBAD_PROOF;
517+
}
518+
519+
return tesSUCCESS;
520+
}
521+
522+
TER
523+
verifyBalancePcmLinkage(
483524
Slice const& proof,
484525
Slice const& encAmt,
485526
Slice const& pubKeySlice,
@@ -493,12 +534,17 @@ verifyPedersenLinkage(
493534
secp256k1_pubkey c2;
494535

495536
if (!makeEcPair(encAmt, c1, c2))
496-
return tecINTERNAL;
537+
return tecINTERNAL; // LCOV_EXCL_LINE
497538

498539
secp256k1_pubkey pubKey;
499-
std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength);
540+
if (pubKeySlice.size() != ecPubKeyLength)
541+
return tecINTERNAL; // LCOV_EXCL_LINE
500542

501543
secp256k1_pubkey pcm;
544+
if (pcmSlice.size() != ecPedersenCommitmentLength)
545+
return tecINTERNAL; // LCOV_EXCL_LINE
546+
547+
std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength);
502548
std::memcpy(pcm.data, pcmSlice.data(), ecPubKeyLength);
503549

504550
if (secp256k1_elgamal_pedersen_link_verify(
@@ -509,7 +555,9 @@ verifyPedersenLinkage(
509555
&c1,
510556
&pcm,
511557
contextHash.data()) != 1)
558+
{
512559
return tecBAD_PROOF;
560+
}
513561

514562
return tesSUCCESS;
515563
}

0 commit comments

Comments
 (0)