3#include <test/jtx/AMM.h>
4#include <test/jtx/Account.h>
5#include <test/jtx/Env.h>
6#include <test/jtx/TestHelpers.h>
7#include <test/jtx/amount.h>
8#include <test/jtx/batch.h>
9#include <test/jtx/credentials.h>
10#include <test/jtx/delegate.h>
11#include <test/jtx/deposit.h>
12#include <test/jtx/flags.h>
13#include <test/jtx/mpt.h>
14#include <test/jtx/pay.h>
15#include <test/jtx/ter.h>
16#include <test/jtx/ticket.h>
17#include <test/jtx/vault.h>
19#include <xrpl/basics/Buffer.h>
20#include <xrpl/basics/Slice.h>
21#include <xrpl/basics/base_uint.h>
22#include <xrpl/basics/contract.h>
23#include <xrpl/basics/strHex.h>
24#include <xrpl/beast/unit_test/suite.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/core/ServiceRegistry.h>
27#include <xrpl/json/json_value.h>
28#include <xrpl/ledger/OpenView.h>
29#include <xrpl/protocol/ConfidentialTransfer.h>
30#include <xrpl/protocol/Feature.h>
31#include <xrpl/protocol/Indexes.h>
32#include <xrpl/protocol/LedgerFormats.h>
33#include <xrpl/protocol/Protocol.h>
34#include <xrpl/protocol/SField.h>
35#include <xrpl/protocol/STObject.h>
36#include <xrpl/protocol/Serializer.h>
37#include <xrpl/protocol/TER.h>
38#include <xrpl/protocol/TxFlags.h>
39#include <xrpl/protocol/jss.h>
41#include <utility/mpt_utility.h>
44#include <secp256k1_mpt.h>
67 return std::move(*value);
93 auto*
const ctx = mpt_secp256k1_context();
96 secp256k1_mpt_get_h_generator(ctx, &h);
101 unsigned char blindings[64];
102 std::memcpy(blindings, blindingFactors[0].data(), 32);
103 std::memcpy(blindings + 32, blindingFactors[1].data(), 32);
105 if (secp256k1_bulletproof_prove_agg(
113 contextHash.
data()) == 0)
124 static Buffer const kBadCiphertext = []() {
133 return kBadCiphertext;
142 static Buffer const kTrivialCiphertext = []() {
155 return kTrivialCiphertext;
163 static Buffer const kTrivialCommitment = []() {
174 return kTrivialCommitment;
241 ,
version(mpt.getMPTokenVersion(sender))
258 mpt.getDecryptedBalance(sender,
test::jtx::MPTTester::holderEncryptedSpending),
259 "Missing sender spending balance"))
261 mpt.getEncryptedBalance(sender,
test::jtx::MPTTester::holderEncryptedSpending),
262 "Missing sender encrypted spending balance"))
362 std::uint32_t flags = tfMPTCanLock | tfMPTCanHoldConfidentialBalance | tfMPTCanTransfer,
366 mpt.create({.ownerCount = 1, .flags = flags});
368 for (
auto const& h : holders)
370 mpt.authorize({.account = h.account});
371 if ((flags & tfMPTRequireAuth) != 0)
372 mpt.authorize({.account = issuer, .holder = h.account});
373 mpt.pay(issuer, h.account, h.payAmount);
376 mpt.generateKeyPair(issuer);
377 for (
auto const& h : holders)
378 mpt.generateKeyPair(h.account);
384 .issuerPubKey = mpt.getPubKey(issuer),
385 .auditorPubKey = auditor
387 : std::optional<Buffer>{},
390 for (
auto const& h : holders)
393 .account = h.account,
394 .amt = h.convertAmount,
395 .holderPubKey = mpt.getPubKey(h.account),
397 mpt.mergeInbox({.account = h.account});
402 static std::vector<test::jtx::Account>
407 for (
auto const& h : holders)
430 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
437 mpt.
pay(alice, bob, bobAmt);
439 mpt.
pay(alice, carol, carolAmt);
Like std::vector<char> but better.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
static Buffer const & getTrivialCiphertext()
static Buffer const & getTrivialCommitment()
static std::string getTrivialSendProofHex()
static constexpr size_t kBulletproofOffset
static T requireOptional(std::optional< T > value, char const *message)
static Buffer const & getBadCiphertext()
static T const & requireOptionalRef(std::optional< T > const &value, char const *message)
static void setupBatchEnv(test::jtx::MPTTester &mpt, test::jtx::Account const &alice, test::jtx::Account const &bob, test::jtx::Account const &carol, test::jtx::Account const &dave, std::uint64_t bobAmt, std::uint64_t carolAmt)
static Buffer getForgedBulletproof(std::array< uint64_t, 2 > const &values, std::array< Buffer, 2 > const &blindingFactors, uint256 const &contextHash)
An immutable linear range of bytes.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
void set(MPTSet const &set={})
void pay(Account const &src, Account const &dest, std::int64_t amount, std::optional< TER > err=std::nullopt, std::optional< std::vector< std::string > > credentials=std::nullopt)
void create(MPTCreate const &arg=MPTCreate{})
void authorize(MPTAuthorize const &arg=MPTAuthorize{})
MPTID const & issuanceID() const
std::optional< Buffer > getConfidentialSendProof(Account const &sender, std::uint64_t const amount, std::vector< ConfidentialRecipient > const &recipients, Slice const &blindingFactor, uint256 const &contextHash, PedersenProofParams const &amountParams, PedersenProofParams const &balanceParams) const
void generateKeyPair(Account const &account)
void mergeInbox(MPTMergeInbox const &arg=MPTMergeInbox{})
void convert(MPTConvert const &arg=MPTConvert{})
std::optional< Buffer > getPubKey(Account const &account) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint8_t kEcCompressedPrefixEvenY
Compressed EC point prefix for even y-coordinate.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::string strHex(FwdIt begin, FwdIt end)
std::optional< Buffer > encryptAmount(uint64_t const amt, Slice const &pubKeySlice, Slice const &blindingFactor)
Encrypts an amount using ElGamal encryption.
constexpr std::size_t kEcGamalEncryptedTotalLength
EC ElGamal ciphertext length: two compressed EC points concatenated.
constexpr std::size_t kEcPedersenCommitmentLength
Length of Pedersen Commitment (compressed).
constexpr std::size_t kEcCiphertextComponentLength
Length of one compressed EC point component in an EC ElGamal ciphertext.
constexpr std::size_t kEcDoubleBulletproofLength
Length of double bulletproof (range proof for 2 commitments) in bytes.
Buffer generateBlindingFactor()
Generates a cryptographically secure blinding factor (size=xrpl::kEcBlindingFactorLength).
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.
constexpr std::size_t kEcSendProofLength
192 bytes compact sigma proof + 754 bytes double bulletproof.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
std::uint64_t convertAmount
test::jtx::Account account
static std::vector< test::jtx::Account > extractAccounts(std::vector< HolderInit > const &holders)
ConfidentialEnv(test::jtx::Env &env, test::jtx::Account const &issuer, std::vector< HolderInit > const &holders, std::uint32_t flags=tfMPTCanLock|tfMPTCanHoldConfidentialBalance|tfMPTCanTransfer, std::optional< test::jtx::Account > auditor=std::nullopt)
Buffer amountBlindingFactor
std::optional< Buffer > generateProof(test::jtx::MPTTester &mpt, test::jtx::Env &env, test::jtx::Account const &sender, test::jtx::Account const &dest) const
std::optional< Buffer > auditorPubKey
std::vector< ConfidentialRecipient > recipients
test::jtx::MPTConfidentialSend sendArgs(test::jtx::Account const &sender, test::jtx::Account const &dest, Buffer const &proof, std::optional< TER > err=std::nullopt) const
Buffer prevEncryptedSpending
ConfidentialSendSetup(test::jtx::MPTTester &mpt, test::jtx::Account const &sender, test::jtx::Account const &dest, test::jtx::Account const &issuer, uint64_t amount, std::optional< std::reference_wrapper< test::jtx::Account const > > auditor=std::nullopt)
std::optional< Buffer > auditorAmt
Buffer balanceBlindingFactor
Arguments for building a ConfidentialMPTSend test transaction.