xrpld
Loading...
Searching...
No Matches
include/xrpl/protocol/ConfidentialTransfer.h
1#pragma once
2
3#include <xrpl/basics/Slice.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/protocol/Indexes.h>
6#include <xrpl/protocol/MPTIssue.h>
7#include <xrpl/protocol/Protocol.h>
8#include <xrpl/protocol/Rate.h>
9#include <xrpl/protocol/STLedgerEntry.h>
10#include <xrpl/protocol/STObject.h>
11#include <xrpl/protocol/Serializer.h>
12#include <xrpl/protocol/TER.h>
13#include <xrpl/protocol/TxFormats.h>
14#include <xrpl/protocol/detail/secp256k1.h>
15
16#include <secp256k1_mpt.h>
17
18#include <cstdint>
19#include <limits>
20
21namespace xrpl {
22
41
46struct EcPair
47{
49 secp256k1_pubkey c1;
50
52 secp256k1_pubkey c2;
53};
54
64inline void
66{
67 // Retrieve current version and increment, wrapping back to 0 at UINT32_MAX.
68 // The wrap is computed explicitly rather than relying on unsigned overflow
69 // of `+ 1u`, as it trips the unsigned-integer-overflow sanitizer in the UBSan CI build.
70 auto const current = mptoken[~sfConfidentialBalanceVersion].valueOr(0u);
71 mptoken[sfConfidentialBalanceVersion] =
72 current == std::numeric_limits<std::uint32_t>::max() ? 0u : current + 1u;
73}
74
90 AccountID const& account,
91 uint192 const& issuanceID,
92 std::uint32_t sequence,
93 AccountID const& destination,
94 std::uint32_t version);
95
110 AccountID const& account,
111 uint192 const& issuanceID,
112 std::uint32_t sequence,
113 AccountID const& holder);
114
127getConvertContextHash(AccountID const& account, uint192 const& issuanceID, std::uint32_t sequence);
128
143 AccountID const& account,
144 uint192 const& issuanceID,
145 std::uint32_t sequence,
146 std::uint32_t version);
147
160makeEcPair(Slice const& buffer);
161
174serializeEcPair(EcPair const& pair);
175
182bool
183isValidCiphertext(Slice const& buffer);
184
195bool
196isValidCompressedECPoint(Slice const& buffer);
197
209homomorphicAdd(Slice const& a, Slice const& b);
210
222homomorphicSubtract(Slice const& a, Slice const& b);
223
239rerandomizeCiphertext(Slice const& ciphertext, Slice const& pubKeySlice, Slice const& randomness);
240
254encryptAmount(uint64_t const amt, Slice const& pubKeySlice, Slice const& blindingFactor);
255
269encryptCanonicalZeroAmount(Slice const& pubKeySlice, AccountID const& account, MPTID const& mptId);
270
282TER
283verifySchnorrProof(Slice const& pubKeySlice, Slice const& proofSlice, uint256 const& contextHash);
284
296NotTEC
297checkEncryptedAmountFormat(STObject const& object);
298
313TER
315 uint64_t const amount,
316 Slice const& blindingFactor,
317 ConfidentialRecipient const& holder,
318 ConfidentialRecipient const& issuer,
320
330constexpr uint8_t
332{
333 return hasAuditor ? 4 : 3;
334}
335
351TER
353 uint64_t const amount,
354 Slice const& proof,
355 Slice const& pubKeySlice,
356 Slice const& ciphertext,
357 uint256 const& contextHash);
358
369Buffer
371
394TER
396 Slice const& proof,
397 ConfidentialRecipient const& sender,
398 ConfidentialRecipient const& destination,
399 ConfidentialRecipient const& issuer,
401 Slice const& spendingBalance,
402 Slice const& amountCommitment,
403 Slice const& balanceCommitment,
404 uint256 const& contextHash);
405
422TER
424 Slice const& proof,
425 Slice const& pubKeySlice,
426 Slice const& spendingBalance,
427 Slice const& balanceCommitment,
428 uint64_t amount,
429 uint256 const& contextHash);
430
431} // namespace xrpl
An immutable linear range of bytes.
Definition Slice.h:26
T max(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 192 > uint192
Definition base_uint.h:563
NotTEC checkEncryptedAmountFormat(STObject const &object)
Validates the format of encrypted amount fields in a transaction.
std::optional< Buffer > rerandomizeCiphertext(Slice const &ciphertext, Slice const &pubKeySlice, Slice const &randomness)
Re-randomizes an ElGamal ciphertext without changing its plaintext.
TER verifySchnorrProof(Slice const &pubKeySlice, Slice const &proofSlice, uint256 const &contextHash)
Verifies a Schnorr proof of knowledge of an ElGamal private key.
std::optional< Buffer > encryptCanonicalZeroAmount(Slice const &pubKeySlice, AccountID const &account, MPTID const &mptId)
Generates the canonical zero encryption for a specific MPToken.
std::optional< Buffer > encryptAmount(uint64_t const amt, Slice const &pubKeySlice, Slice const &blindingFactor)
Encrypts an amount using ElGamal encryption.
bool isValidCompressedECPoint(Slice const &buffer)
Verifies that a buffer contains a valid, parsable compressed EC point.
constexpr uint8_t getConfidentialRecipientCount(bool hasAuditor)
Returns the number of recipients in a confidential transfer.
std::optional< EcPair > makeEcPair(Slice const &buffer)
Parses an ElGamal ciphertext into two secp256k1 public key components.
std::optional< Buffer > serializeEcPair(EcPair const &pair)
Serializes an EcPair into compressed form.
TER verifyRevealedAmount(uint64_t const amount, Slice const &blindingFactor, ConfidentialRecipient const &holder, ConfidentialRecipient const &issuer, std::optional< ConfidentialRecipient > const &auditor)
Verifies revealed amount encryptions for all recipients.
uint256 getConvertBackContextHash(AccountID const &account, uint192 const &issuanceID, std::uint32_t sequence, std::uint32_t version)
Generates the context hash for ConfidentialMPTConvertBack transactions.
bool isValidCiphertext(Slice const &buffer)
Verifies that a buffer contains two valid, parsable EC public keys.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
std::optional< Buffer > homomorphicSubtract(Slice const &a, Slice const &b)
Homomorphically subtracts two ElGamal ciphertexts.
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:44
uint256 getConvertContextHash(AccountID const &account, uint192 const &issuanceID, std::uint32_t sequence)
Generates the context hash for ConfidentialMPTConvert transactions.
uint256 getClawbackContextHash(AccountID const &account, uint192 const &issuanceID, std::uint32_t sequence, AccountID const &holder)
Generates the context hash for ConfidentialMPTClawback transactions.
Buffer generateBlindingFactor()
Generates a cryptographically secure blinding factor (size=xrpl::kEcBlindingFactorLength).
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
TER verifyConvertBackProof(Slice const &proof, Slice const &pubKeySlice, Slice const &spendingBalance, Slice const &balanceCommitment, uint64_t amount, uint256 const &contextHash)
Verifies all zero-knowledge proofs for a ConfidentialMPTConvertBack transaction.
uint256 getSendContextHash(AccountID const &account, uint192 const &issuanceID, std::uint32_t sequence, AccountID const &destination, std::uint32_t version)
Generates the context hash for ConfidentialMPTSend transactions.
TERSubset< CanCvtToTER > TER
Definition TER.h:634
void incrementConfidentialVersion(STObject &mptoken)
Increments the confidential balance version counter on an MPToken.
BaseUInt< 256 > uint256
Definition base_uint.h:562
std::optional< Buffer > homomorphicAdd(Slice const &a, Slice const &b)
Homomorphically adds two ElGamal ciphertexts.
TER verifySendProof(Slice const &proof, ConfidentialRecipient const &sender, ConfidentialRecipient const &destination, ConfidentialRecipient const &issuer, std::optional< ConfidentialRecipient > const &auditor, Slice const &spendingBalance, Slice const &amountCommitment, Slice const &balanceCommitment, uint256 const &contextHash)
Verifies all zero-knowledge proofs for a ConfidentialMPTSend transaction.
TER verifyClawbackProof(uint64_t const amount, Slice const &proof, Slice const &pubKeySlice, Slice const &ciphertext, uint256 const &contextHash)
Verifies a compact sigma clawback proof.
Bundles an ElGamal public key with its associated encrypted amount.
Slice encryptedAmount
The encrypted amount ciphertext (size=xrpl::kEcGamalEncryptedTotalLength).
Slice publicKey
The recipient's ElGamal public key (size=xrpl::kEcPubKeyLength).
Holds two secp256k1 public key components representing an ElGamal ciphertext (C1, C2).
secp256k1_pubkey c2
Second ElGamal ciphertext component.
secp256k1_pubkey c1
First ElGamal ciphertext component.