xrpld
Loading...
Searching...
No Matches
mpt.cpp
1
2#include <test/jtx/mpt.h>
3
4#include <test/jtx/Account.h>
5#include <test/jtx/Env.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/credentials.h>
8#include <test/jtx/owners.h>
9#include <test/jtx/pay.h>
10#include <test/jtx/ter.h>
11#include <test/jtx/trust.h>
12
13#include <xrpl/basics/Slice.h>
14#include <xrpl/basics/StringUtilities.h>
15#include <xrpl/basics/base_uint.h>
16#include <xrpl/basics/contract.h>
17#include <xrpl/basics/strHex.h>
18#include <xrpl/beast/unit_test/suite.h>
19#include <xrpl/json/json_value.h>
20#include <xrpl/ledger/helpers/MPTokenHelpers.h>
21#include <xrpl/protocol/AccountID.h>
22#include <xrpl/protocol/Asset.h>
23#include <xrpl/protocol/ConfidentialTransfer.h>
24#include <xrpl/protocol/Indexes.h>
25#include <xrpl/protocol/LedgerFormats.h>
26#include <xrpl/protocol/Protocol.h>
27#include <xrpl/protocol/Rate.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/TER.h>
30#include <xrpl/protocol/TxFlags.h>
31#include <xrpl/protocol/UintTypes.h>
32#include <xrpl/protocol/jss.h>
33#include <xrpl/tx/transactors/token/MPTokenIssuanceSet.h>
34
35#include <utility/mpt_utility.h>
36
37#include <mpt_protocol.h>
38#include <secp256k1.h>
39#include <secp256k1_mpt.h>
40
41#include <algorithm>
42#include <cstddef>
43#include <cstdint>
44#include <cstring>
45#include <filesystem>
46#include <functional>
47#include <optional>
48#include <source_location>
49#include <stdexcept>
50#include <string>
51#include <unordered_map>
52#include <utility>
53#include <variant>
54#include <vector>
55
56namespace xrpl::test::jtx {
57namespace {
58
59constexpr std::uint64_t kElGamalDecryptRangeLow = 0;
60constexpr std::uint64_t kElGamalDecryptRangeHigh = 3000;
61
72template <class T>
73[[nodiscard]] T const&
74requireValue(
75 std::optional<T> const& opt,
76 char const* what,
77 std::source_location const& loc = std::source_location::current())
78{
79 if (!opt)
80 {
82 std::string(what) + " must be present (called from " +
83 std::string(loc.function_name()) + ")");
84 }
85 return *opt;
86}
87
94mpt_pedersen_proof_params
95makePedersenParams(PedersenProofParams const& params)
96{
97 mpt_pedersen_proof_params res{};
99 res.pedersen_commitment, params.pedersenCommitment.data(), kMPT_PEDERSEN_COMMIT_SIZE);
100 res.amount = params.amt;
101 std::memcpy(res.ciphertext, params.encryptedAmt.data(), kMPT_ELGAMAL_TOTAL_SIZE);
102 std::memcpy(res.blinding_factor, params.blindingFactor.data(), kMPT_BLINDING_FACTOR_SIZE);
103 return res;
104}
105
113Account const&
114setAccountField(json::Value& jv, std::optional<Account> const& account)
115{
116 Account const& act = requireValue(account, "account");
117 jv[sfAccount] = act.human();
118 return act;
119}
120
128Account const&
129setDestinationField(json::Value& jv, std::optional<Account> const& dest)
130{
131 Account const& act = requireValue(dest, "dest");
132 jv[sfDestination] = act.human();
133 return act;
134}
135
144void
145setProofOrDummy(json::Value& jv, std::optional<Buffer> const& proof, std::size_t dummyLen)
146{
147 jv[sfZKProof.jsonName] = strHex(proof ? *proof : gMakeZeroBuffer(dummyLen));
148}
149
158[[nodiscard]] std::optional<Buffer>
159keyAtEpoch(
160 std::unordered_map<AccountID, std::vector<Buffer>> const& keys,
161 AccountID const& account,
162 std::optional<std::uint32_t> epoch)
163{
164 auto const it = keys.find(account);
165 if (it == keys.end() || it->second.empty())
166 return std::nullopt;
167
168 if (!epoch)
169 return it->second.back();
170
171 if (*epoch >= it->second.size())
172 return std::nullopt;
173
174 return it->second[*epoch];
175}
176
177} // namespace
178
179namespace {
180// Renders the check's own construction site (usually in mpt.cpp) so it can be
181// embedded as the "reason" alongside the test call site reported as file/line.
182std::string
183checkSiteReason(std::source_location const& checkLoc)
184{
185 return std::string("check ") + std::filesystem::path{checkLoc.file_name()}.filename().string() +
186 "(" + std::to_string(checkLoc.line()) + ")";
187}
188} // namespace
189
190void
192{
193 env.test.expect(
194 tester_.checkFlags(flags_, holder_),
195 checkSiteReason(checkLoc_),
196 testLoc_.file_name(),
197 testLoc_.line());
198}
199
200void
202{
203 env.test.expect(
204 amount_ == tester_.getBalance(account_),
205 checkSiteReason(checkLoc_),
206 testLoc_.file_name(),
207 testLoc_.line());
208}
209
210void
212{
213 env.test.expect(cb_(), checkSiteReason(checkLoc_), testLoc_.file_name(), testLoc_.line());
214}
215
218{
220 for (auto const& h : holders)
221 {
222 if (accounts.find(h.human()) != accounts.cend())
223 Throw<std::runtime_error>("Duplicate holder");
224 accounts.emplace(h.human(), h);
225 }
226 return accounts;
227}
228
230 : env_(env)
231 , issuer_(std::move(issuer))
232 , holders_(makeHolders(arg.holders))
233 , auditor_(arg.auditor)
234 , close_(arg.close)
235{
236 if (arg.fund)
237 {
238 env_.fund(arg.xrp, issuer_);
239 for (auto const& it : holders_)
240 env_.fund(arg.xrpHolders, it.second);
241
242 if (arg.auditor)
243 env_.fund(arg.xrp, *arg.auditor);
244 }
245 if (close_)
246 env.close();
247 if (arg.fund)
248 {
249 env_.require(Owners(issuer_, 0));
250 for (auto const& it : holders_)
251 {
252 if (issuer_.id() == it.second.id())
253 Throw<std::runtime_error>("Issuer can't be holder");
254 env_.require(Owners(it.second, 0));
255 }
256
257 if (arg.auditor)
258 env_.require(Owners(*arg.auditor, 0));
259 }
260 if (arg.create)
261 create(*arg.create, loc);
262}
263
265 Env& env,
267 MPTID const& id,
268 std::vector<Account> const& holders,
269 bool close)
270 : env_(env), issuer_(std::move(issuer)), holders_(makeHolders(holders)), id_(id), close_(close)
271{
272}
273
274static MPTCreate
276{
277 if (arg.pay)
278 {
279 return {
280 .maxAmt = arg.maxAmt,
281 .transferFee = arg.transferFee,
282 .pay = {{arg.holders, *arg.pay}},
283 .flags = arg.flags,
284 .immutableFlags = arg.immutableFlags,
285 .authHolder = arg.authHolder,
286 };
287 }
288 return {
289 .maxAmt = arg.maxAmt,
290 .transferFee = arg.transferFee,
291 .authorize = arg.holders,
292 .flags = arg.flags,
293 .immutableFlags = arg.immutableFlags,
294 .authHolder = arg.authHolder,
295 };
296}
297
299 : MPTTester{
300 arg.env,
301 arg.issuer,
302 MPTInit{
303 .auditor = arg.auditor,
304 .fund = arg.fund,
305 .close = arg.close,
306 .create = makeMPTCreate(arg),
307 },
308 loc,
309 }
310{
311}
312
313MPTTester::
314operator MPT() const
315{
316 if (!id_)
317 Throw<std::runtime_error>("MPT has not been created");
318 return MPT("", *id_);
319}
320
323{
324 if (!arg.issuer)
325 Throw<std::runtime_error>("MPTTester::createJV: issuer is not set");
326 json::Value jv;
327 jv[sfAccount] = arg.issuer->human();
328 if (arg.assetScale)
329 jv[sfAssetScale] = *arg.assetScale;
330 if (arg.transferFee)
331 jv[sfTransferFee] = *arg.transferFee;
332 if (arg.metadata)
333 jv[sfMPTokenMetadata] = strHex(*arg.metadata);
334 if (arg.maxAmt)
335 jv[sfMaximumAmount] = std::to_string(*arg.maxAmt);
336 if (arg.domainID)
337 jv[sfDomainID] = to_string(*arg.domainID);
338 if (arg.immutableFlags)
339 jv[sfImmutableFlags] = *arg.immutableFlags;
340 jv[sfTransactionType] = jss::MPTokenIssuanceCreate;
341
342 return jv;
343}
344
345void
347{
348 if (id_)
349 Throw<std::runtime_error>("MPT can't be reused");
351 json::Value const jv = createJV({
352 .issuer = issuer_,
353 .maxAmt = arg.maxAmt,
354 .assetScale = arg.assetScale,
355 .transferFee = arg.transferFee,
356 .metadata = arg.metadata,
357 .immutableFlags = arg.immutableFlags,
358 .domainID = arg.domainID,
359 });
360 if (!isTesSuccess(submit(arg, {jv, loc})))
361 {
362 // Verify issuance doesn't exist
363 env_.require(RequireAny(
364 [&] -> bool { return env_.le(keylet::mptokenIssuance(*id_)) == nullptr; }, loc));
365
366 id_.reset();
367 }
368 else
369 {
370 env_.require(MptFlags(*this, arg.flags.value_or(0), std::nullopt, loc));
371 auto const authAndPay = [&](auto const& accts, auto const&& getAcct) {
372 for (auto const& it : accts)
373 {
374 authorize({.account = getAcct(it)}, loc);
375 if ((arg.flags.value_or(0) & tfMPTRequireAuth) && arg.authHolder)
376 authorize({.account = issuer_, .holder = getAcct(it)}, loc);
377 if (arg.pay && arg.pay->first.empty())
378 pay(issuer_, getAcct(it), arg.pay->second, std::nullopt, std::nullopt, loc);
379 }
380 if (arg.pay)
381 {
382 for (auto const& p : arg.pay->first)
383 pay(issuer_, p, arg.pay->second, std::nullopt, std::nullopt, loc);
384 }
385 };
386 if (arg.authorize)
387 {
388 if (arg.authorize->empty())
389 {
390 authAndPay(holders_, [](auto const& it) { return it.second; });
391 }
392 else
393 {
394 authAndPay(*arg.authorize, [](auto const& it) { return it; });
395 }
396 }
397 else if (arg.pay)
398 {
399 if (arg.pay->first.empty())
400 {
401 authAndPay(holders_, [](auto const& it) { return it.second; });
402 }
403 else
404 {
405 authAndPay(arg.pay->first, [](auto const& it) { return it; });
406 }
407 }
408 }
409}
410
413{
414 json::Value jv;
415 if (!arg.issuer || !arg.id)
416 Throw<std::runtime_error>("MPTTester::destroyJV: issuer/id is not set");
417 jv[sfAccount] = arg.issuer->human();
418 jv[sfMPTokenIssuanceID] = to_string(*arg.id);
419 jv[sfTransactionType] = jss::MPTokenIssuanceDestroy;
420
421 return jv;
422}
423
424void
426{
427 if (!arg.id && !id_)
428 Throw<std::runtime_error>("MPT has not been created");
429 json::Value const jv =
430 destroyJV({.issuer = arg.issuer ? arg.issuer : issuer_, .id = arg.id ? arg.id : id_});
431 submit(arg, {jv, loc});
432}
433
434Account const&
436{
437 auto const& it = holders_.find(holder);
438 if (it == holders_.cend())
439 Throw<std::runtime_error>("Holder is not found");
440 return it->second;
441}
442
445{
446 json::Value jv;
447 if (!arg.account || !arg.id)
448 Throw<std::runtime_error>("MPTTester::authorizeJV: account/id is not set");
449 jv[sfAccount] = arg.account->human();
450 jv[sfMPTokenIssuanceID] = to_string(*arg.id);
451 if (arg.holder)
452 jv[sfHolder] = arg.holder->human();
453 jv[sfTransactionType] = jss::MPTokenAuthorize;
454
455 return jv;
456}
457
458void
460{
461 if (!arg.id && !id_)
462 Throw<std::runtime_error>("MPT has not been created");
463 json::Value const jv = authorizeJV({
464 .account = arg.account ? arg.account : issuer_,
465 .holder = arg.holder,
466 .id = arg.id ? arg.id : id_,
467 });
468 if (auto const result = submit(arg, {jv, loc}); isTesSuccess(result))
469 {
470 // Issuer authorizes
471 if (!arg.account || *arg.account == issuer_)
472 {
473 auto const flags = getFlags(arg.holder);
474 // issuer un-authorizes the holder
475 if (arg.flags.value_or(0) == tfMPTUnauthorize)
476 {
477 env_.require(MptFlags(*this, flags, arg.holder, loc));
478 // issuer authorizes the holder
479 }
480 else
481 {
482 env_.require(MptFlags(*this, flags | lsfMPTAuthorized, arg.holder, loc));
483 }
484 }
485 // Holder authorizes
486 else if (arg.flags.value_or(0) != tfMPTUnauthorize)
487 {
488 auto const flags = getFlags(arg.account);
489 // holder creates a token
490 env_.require(MptFlags(*this, flags, arg.account, loc));
491 env_.require(MptBalance(*this, *arg.account, 0, loc));
492 }
493 else
494 {
495 // Verify that the MPToken doesn't exist.
496 forObject(
497 [&](SLEP const& sle) {
498 return env_.test.expect(!sle, "", loc.file_name(), loc.line());
499 },
500 arg.account);
501 }
502 }
503 else if (
504 arg.account && *arg.account != issuer_ && arg.flags.value_or(0) != tfMPTUnauthorize && id_)
505 {
506 if (result == tecDUPLICATE)
507 {
508 // Verify that MPToken already exists
509 env_.require(RequireAny(
510 [&] -> bool {
511 return env_.le(keylet::mptoken(*id_, arg.account->id())) != nullptr;
512 },
513 loc));
514 }
515 else
516 {
517 // Verify MPToken doesn't exist if holder failed authorizing(unless
518 // it already exists)
519 env_.require(RequireAny(
520 [&] -> bool {
521 return env_.le(keylet::mptoken(*id_, arg.account->id())) == nullptr;
522 },
523 loc));
524 }
525 }
526}
527
528void
530{
531 for (auto const& holder : holders)
532 {
533 authorize({.account = holder}, loc);
534 }
535}
536
539{
540 json::Value jv;
541 if (!arg.account || !arg.id)
542 Throw<std::runtime_error>("MPTTester::setJV: account and/or id is not set");
543 jv[sfAccount] = arg.account->human();
544 jv[sfMPTokenIssuanceID] = to_string(*arg.id);
545 if (arg.holder)
546 {
548 [&jv]<typename T>(T const& holder) {
549 if constexpr (std::is_same_v<T, Account>)
550 {
551 jv[sfHolder] = holder.human();
552 }
553 else if constexpr (std::is_same_v<T, AccountID>)
554 {
555 jv[sfHolder] = toBase58(holder);
556 }
557 },
558 *arg.holder);
559 }
560
561 if (arg.delegate)
562 jv[sfDelegate] = arg.delegate->human();
563 if (arg.domainID)
564 jv[sfDomainID] = to_string(*arg.domainID);
565 if (arg.immutableFlags)
566 jv[sfImmutableFlags] = *arg.immutableFlags;
567 if (arg.transferFee)
568 jv[sfTransferFee] = *arg.transferFee;
569 if (arg.metadata)
570 jv[sfMPTokenMetadata] = strHex(*arg.metadata);
571 if (arg.issuerPubKey)
572 jv[sfIssuerEncryptionKey] = strHex(*arg.issuerPubKey);
573 if (arg.auditorPubKey)
574 jv[sfAuditorEncryptionKey] = strHex(*arg.auditorPubKey);
575 jv[sfTransactionType] = jss::MPTokenIssuanceSet;
576
577 return jv;
578}
579
580void
582{
583 if (!arg.id && !id_)
584 Throw<std::runtime_error>("MPT has not been created");
585 json::Value const jv = setJV({
586 .account = arg.account ? arg.account : issuer_,
587 .holder = arg.holder,
588 .id = arg.id ? arg.id : id_,
589 .immutableFlags = arg.immutableFlags,
590 .transferFee = arg.transferFee,
591 .metadata = arg.metadata,
592 .delegate = arg.delegate,
593 .domainID = arg.domainID,
594 .issuerPubKey = arg.issuerPubKey,
595 .auditorPubKey = arg.auditorPubKey,
596 });
597 if (submit(arg, {jv, loc}) == tesSUCCESS && arg.flags.value_or(0) != 0u)
598 {
599 auto const require = [&](std::optional<Account> const& holder, bool unchanged) {
600 auto flags = getFlags(holder);
601 if (!unchanged)
602 {
603 if (arg.flags)
604 {
605 if (*arg.flags & tfMPTLock)
606 {
607 flags |= lsfMPTLocked;
608 }
609 else if (*arg.flags & tfMPTUnlock)
610 {
611 flags &= ~lsfMPTLocked;
612 }
613
614 for (auto const& f : MPTokenIssuanceSet::flagMapping)
615 {
616 if ((*arg.flags & f.setFlag) != 0u)
617 {
618 flags |= f.ledgerFlag;
619 }
620 }
621 }
622 }
623 env_.require(MptFlags(*this, flags, holder, loc));
624 };
625 if (arg.account)
626 require(std::nullopt, arg.holder.has_value());
627 if (auto const account = (arg.holder ? std::get_if<Account>(&(*arg.holder)) : nullptr))
628 require(*account, false);
629
630 if (arg.issuerPubKey)
631 {
632 env_.require(RequireAny(
633 [&] -> bool {
634 return forObject([&](SLEP const& sle) -> bool {
635 if (sle)
636 {
637 auto const issuerPubKey = getPubKey(issuer_);
638 if (!issuerPubKey)
639 {
641 "MPTTester::set: issuer's pubkey is not set");
642 }
643
644 return strHex((*sle)[sfIssuerEncryptionKey]) == strHex(*issuerPubKey);
645 }
646 return false;
647 });
648 },
649 loc));
650 }
651 if (arg.auditorPubKey)
652 {
653 env_.require(RequireAny(
654 [&] -> bool {
655 return forObject([&](SLEP const& sle) -> bool {
656 if (sle)
657 {
658 if (!auditor_.has_value())
659 Throw<std::runtime_error>("MPTTester::set: auditor is not set");
660
661 auto const auditorPubKey = getPubKey(*auditor_);
662 if (!auditorPubKey)
663 {
665 "MPTTester::set: auditor's pubkey is not set");
666 }
667
668 return strHex((*sle)[sfAuditorEncryptionKey]) == strHex(*auditorPubKey);
669 }
670 return false;
671 });
672 },
673 loc));
674 }
675 }
676}
677
678bool
680 std::function<bool(SLEP const& sle)> const& cb,
681 std::optional<Account> const& holder) const
682{
683 if (!id_)
684 Throw<std::runtime_error>("MPT has not been created");
685 auto const key = holder ? keylet::mptoken(*id_, holder->id()) : keylet::mptokenIssuance(*id_);
686 if (auto const sle = env_.le(key))
687 return cb(sle);
688 return false;
689}
690
691[[nodiscard]] bool
693{
694 return forObject([&](SLEP const& sle) -> bool {
695 if (sle->isFieldPresent(sfDomainID))
696 return expected == sle->getFieldH256(sfDomainID);
697 return (!expected.has_value());
698 });
699}
700
701[[nodiscard]] bool
703{
704 return forObject(
705 [&](SLEP const& sle) { return expectedAmount == (*sle)[sfMPTAmount]; }, holder);
706}
707
708[[nodiscard]] bool
710{
711 return forObject(
712 [&](SLEP const& sle) { return expectedAmount == (*sle)[sfOutstandingAmount]; });
713}
714
715[[nodiscard]] bool
717{
718 return forObject([&](SLEP const& sle) {
719 return expectedAmount == (*sle)[~sfConfidentialOutstandingAmount].value_or(0);
720 });
721}
722
723[[nodiscard]] bool
724MPTTester::checkFlags(uint32_t const expectedFlags, std::optional<Account> const& holder) const
725{
726 return expectedFlags == getFlags(holder);
727}
728
729[[nodiscard]] bool
731{
732 return forObject([&](SLEP const& sle) -> bool {
733 if (sle->isFieldPresent(sfMPTokenMetadata))
734 return strHex(sle->getFieldVL(sfMPTokenMetadata)) == strHex(metadata);
735 return false;
736 });
737}
738
739[[nodiscard]] bool
741{
742 return forObject(
743 [&](SLEP const& sle) -> bool { return sle->isFieldPresent(sfMPTokenMetadata); });
744}
745
746[[nodiscard]] bool
748{
749 return forObject([&](SLEP const& sle) -> bool {
750 if (sle->isFieldPresent(sfTransferFee))
751 return sle->getFieldU16(sfTransferFee) == transferFee;
752 return false;
753 });
754}
755
756[[nodiscard]] bool
758{
759 return forObject([&](SLEP const& sle) -> bool { return sle->isFieldPresent(sfTransferFee); });
760}
761
762[[nodiscard]] bool
764{
765 // sfImmutableFlags is soeDEFAULT, defaulting to 0 if not present.
766 return forObject([&](SLEP const& sle) -> bool {
767 return sle->getFieldU32(sfImmutableFlags) == expectedFlags;
768 });
769}
770
771[[nodiscard]] bool
773 std::optional<std::uint32_t> issuerKeyEpoch,
774 std::optional<std::uint32_t> auditorKeyEpoch) const
775{
776 return forObject([&](SLEP const& sle) -> bool {
777 return (*sle)[~sfIssuerKeyEpoch] == issuerKeyEpoch &&
778 (*sle)[~sfAuditorKeyEpoch] == auditorKeyEpoch;
779 });
780}
781
782[[nodiscard]] bool
784 Account const& holder,
785 std::optional<std::uint32_t> issuerKeyMirrorEpoch,
786 std::optional<std::uint32_t> auditorKeyMirrorEpoch) const
787{
788 return forObject(
789 [&](SLEP const& sle) -> bool {
790 return (*sle)[~sfIssuerKeyMirrorEpoch] == issuerKeyMirrorEpoch &&
791 (*sle)[~sfAuditorKeyMirrorEpoch] == auditorKeyMirrorEpoch;
792 },
793 holder);
794}
795
798{
800 forObject(
801 [&](SLEP const& sle) -> bool {
802 epoch = (*sle)[~field];
803 return true;
804 },
805 holder);
806 return epoch;
807}
808
809[[nodiscard]] bool
811 std::optional<Account> const& issuerKeyOwner,
812 std::optional<Account> const& auditorKeyOwner) const
813{
814 auto const matches =
815 [this](SLEP const& sle, SF_VL const& field, std::optional<Account> const& owner) {
816 if (!owner)
817 return !sle->isFieldPresent(field);
818
819 auto const expected = getPubKey(*owner);
820 return expected && sle->isFieldPresent(field) &&
821 strHex((*sle)[field]) == strHex(*expected);
822 };
823
824 return forObject([&](SLEP const& sle) -> bool {
825 return matches(sle, sfIssuerEncryptionKey, issuerKeyOwner) &&
826 matches(sle, sfAuditorEncryptionKey, auditorKeyOwner);
827 });
828}
829
830bool
832 std::optional<Buffer> const& expected,
833 SF_VL const& field,
834 std::optional<Account> const& holder) const
835{
836 return forObject(
837 [&](SLEP const& sle) -> bool {
838 auto const encryptionKey = (*sle)[~field];
839 if (!expected)
840 return !encryptionKey;
841 return encryptionKey && Slice(*encryptionKey) == Slice(*expected);
842 },
843 holder);
844}
845
846bool
848{
849 return checkEncryptionKey(expected, sfInitialIssuerEncryptionKey);
850}
851
852bool
854 std::optional<Buffer> const& expected,
855 Account const& holder) const
856{
857 return checkEncryptionKey(expected, sfIssuerMirrorEncryptionKey, holder);
858}
859
860void
862 Account const& src,
863 Account const& dest,
864 std::int64_t amount,
867 std::source_location const& loc)
868{
869 if (!id_)
870 Throw<std::runtime_error>("MPT has not been created");
871 auto const srcAmt = getBalance(src);
872 auto const destAmt = getBalance(dest);
873 auto const outstandingAmt = getBalance(issuer_);
874
875 if (credentials)
876 {
877 env_(
878 WithSourceLocation<json::Value>{jtx::pay(src, dest, mpt(amount)), loc},
879 Ter(err.value_or(tesSUCCESS)),
881 }
882 else
883 {
884 env_(
885 WithSourceLocation<json::Value>{jtx::pay(src, dest, mpt(amount)), loc},
886 Ter(err.value_or(tesSUCCESS)));
887 }
888
889 if (!isTesSuccess(env_.ter()))
890 amount = 0;
891 if (close_)
892 env_.close();
893 if (src == issuer_)
894 {
895 env_.require(MptBalance(*this, src, srcAmt + amount, loc));
896 env_.require(MptBalance(*this, dest, destAmt + amount, loc));
897 }
898 else if (dest == issuer_)
899 {
900 env_.require(MptBalance(*this, src, srcAmt - amount, loc));
901 env_.require(MptBalance(*this, dest, destAmt - amount, loc));
902 }
903 else
904 {
905 STAmount const saAmount = {*id_, amount};
906 auto const actual = multiply(saAmount, transferRate(*env_.current(), *id_)).mpt().value();
907 // Sender pays the transfer fee if any
908 env_.require(MptBalance(*this, src, srcAmt - actual, loc));
909 env_.require(MptBalance(*this, dest, destAmt + amount, loc));
910 // Outstanding amount is reduced by the transfer fee if any
911 env_.require(MptBalance(*this, issuer_, outstandingAmt - (actual - amount), loc));
912 }
913}
914
915void
917 Account const& issuer,
918 Account const& holder,
919 std::int64_t amount,
921 std::source_location const& loc)
922{
923 if (!id_)
924 Throw<std::runtime_error>("MPT has not been created");
925 auto const issuerAmt = getBalance(issuer);
926 auto const holderAmt = getBalance(holder);
927 env_(
929 Ter(err.value_or(tesSUCCESS)));
930 if (!isTesSuccess(env_.ter()))
931 amount = 0;
932 if (close_)
933 env_.close();
934
935 env_.require(MptBalance(*this, issuer, issuerAmt - std::min(holderAmt, amount), loc));
936 env_.require(MptBalance(*this, holder, holderAmt - std::min(holderAmt, amount), loc));
937}
938
941{
942 if (!id_)
943 Throw<std::runtime_error>("MPT has not been created");
944 return xrpl::test::jtx::MPT(issuer_.name(), *id_)(amount);
945}
946
947MPTTester::
948operator Asset() const
949{
950 if (!id_)
951 Throw<std::runtime_error>("MPT has not been created");
952 return Asset(*id_);
953}
954
956MPTTester::getBalance(Account const& account) const
957{
958 if (!id_)
959 Throw<std::runtime_error>("MPT has not been created");
960 if (account == issuer_)
961 {
962 if (auto const sle = env_.le(keylet::mptokenIssuance(*id_)))
963 return sle->getFieldU64(sfOutstandingAmount);
964 }
965 else
966 {
967 if (auto const sle = env_.le(keylet::mptoken(*id_, account.id())))
968 return sle->getFieldU64(sfMPTAmount);
969 }
970 return 0;
971}
972
975{
976 if (!id_)
977 Throw<std::runtime_error>("MPT has not been created");
978
979 if (auto const sle = env_.le(keylet::mptokenIssuance(*id_)))
980 return (*sle)[~sfConfidentialOutstandingAmount].value_or(0);
981
982 return 0;
983}
984
987 Account const& holder,
988 std::uint64_t amount,
989 Buffer const& privateKey,
990 UInt256 const& contextHash) const
991{
992 if (!id_)
993 Throw<std::runtime_error>("MPT has not been created");
994
995 auto const sleHolder = env_.le(keylet::mptoken(*id_, holder.id()));
996 auto const sleIssuance = env_.le(keylet::mptokenIssuance(*id_));
997
998 if (!sleHolder || !sleIssuance)
999 return std::nullopt;
1000
1001 auto const ciphertextBlob = sleHolder->getFieldVL(sfIssuerEncryptedBalance);
1002 if (ciphertextBlob.size() != kEcGamalEncryptedTotalLength)
1003 return std::nullopt;
1004
1005 auto const pubKeyBlob = sleIssuance->getFieldVL(sfIssuerEncryptionKey);
1006 if (pubKeyBlob.size() != kEcPubKeyLength)
1007 return std::nullopt;
1008
1010
1011 if (mpt_get_clawback_proof(
1012 privateKey.data(),
1013 pubKeyBlob.data(),
1014 contextHash.data(),
1015 amount,
1016 ciphertextBlob.data(),
1017 proof.data()) != 0)
1018 {
1019 return std::nullopt;
1020 }
1021
1022 return proof;
1023}
1024
1026MPTTester::getSchnorrProof(Account const& account, UInt256 const& ctxHash) const
1027{
1028 auto const pubKey = getPubKey(account);
1029 if (!pubKey || pubKey->size() != kEcPubKeyLength)
1030 return std::nullopt;
1031
1032 auto const privKey = getPrivKey(account);
1033 if (requireValue(privKey, "privKey").size() != kEcPrivKeyLength)
1034 return std::nullopt;
1035
1037
1038 if (mpt_get_convert_proof(
1039 requireValue(pubKey, "pubKey").data(),
1040 requireValue(privKey, "privKey").data(),
1041 ctxHash.data(),
1042 proof.data()) != 0)
1043 return std::nullopt;
1044
1045 return proof;
1046}
1047
1050 Account const& sender,
1051 std::uint64_t const amount,
1052 std::vector<ConfidentialRecipient> const& recipients,
1053 Slice const& blindingFactor,
1054 UInt256 const& contextHash,
1055 PedersenProofParams const& amountParams,
1056 PedersenProofParams const& balanceParams) const
1057{
1058 auto const pedersenBalanceParams = makePedersenParams(balanceParams);
1059
1060 if (blindingFactor.size() != kEcBlindingFactorLength)
1061 return std::nullopt;
1062
1063 auto const senderPrivKey = getPrivKey(sender);
1064 if (!senderPrivKey)
1065 return std::nullopt;
1066
1067 auto const senderPubKey = getPubKey(sender);
1068 if (!senderPubKey || senderPubKey->size() != kEcPubKeyLength)
1069 return std::nullopt;
1070
1072 return std::nullopt;
1073
1074 // Build mpt_confidential_participant array
1075 std::vector<mpt_confidential_participant> participants(recipients.size());
1076 for (size_t i = 0; i < recipients.size(); ++i)
1077 {
1078 auto const& r = recipients[i];
1079 if (r.encryptedAmount.size() != kEcGamalEncryptedTotalLength ||
1080 r.publicKey.size() != kEcPubKeyLength)
1081 {
1082 return std::nullopt;
1083 }
1084 std::memcpy(participants[i].pubkey, r.publicKey.data(), kEcPubKeyLength);
1086 participants[i].ciphertext, r.encryptedAmount.data(), kEcGamalEncryptedTotalLength);
1087 }
1088
1089 size_t proofLen = kEcSendProofLength;
1090 Buffer proof(proofLen);
1091
1092 if (mpt_get_confidential_send_proof(
1093 senderPrivKey->data(),
1094 senderPubKey->data(),
1095 amount,
1096 participants.data(),
1097 recipients.size(),
1098 blindingFactor.data(),
1099 contextHash.data(),
1100 amountParams.pedersenCommitment.data(),
1101 &pedersenBalanceParams,
1102 proof.data(),
1103 &proofLen) != 0)
1104 return std::nullopt;
1105
1106 return proof;
1107}
1108
1109Buffer
1110MPTTester::getPedersenCommitment(std::uint64_t const amount, Buffer const& pedersenBlindingFactor)
1111{
1112 // Blinding factor (rho) must be a 32-byte scalar
1113 if (pedersenBlindingFactor.size() != kEcBlindingFactorLength)
1114 Throw<std::runtime_error>("Invalid blinding factor size");
1115
1116 // secp256k1_mpt_pedersen_commit doesn't handle amount 0, return a trivial
1117 // valid commitment for test purposes
1118 if (amount == 0)
1119 {
1122 buf.data()[0] = kEcCompressedPrefixEvenY;
1123 buf.data()[kEcPedersenCommitmentLength - 1] = 0x01;
1124 return buf;
1125 }
1126
1128
1129 if (mpt_get_pedersen_commitment(amount, pedersenBlindingFactor.data(), buf.data()) != 0)
1130 Throw<std::runtime_error>("Pedersen commitment generation failed");
1131
1132 return buf;
1133}
1134
1137 Account const& holder,
1138 std::uint64_t const amount,
1139 UInt256 const& contextHash,
1140 PedersenProofParams const& pcParams) const
1141{
1142 // Expected total proof length: compact sigma proof (128 bytes) + single bulletproof (688 bytes)
1143 std::size_t constexpr kExpectedProofLength = kEcConvertBackProofLength;
1144
1145 auto const sleMptoken = env_.le(keylet::mptoken(issuanceID(), holder.id()));
1146 if (!sleMptoken || !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending))
1147 return std::nullopt;
1148
1149 auto const holderPubKey = getPubKey(holder);
1150 auto const holderPrivKey = getPrivKey(holder);
1151
1152 if (!holderPubKey || !holderPrivKey)
1153 return std::nullopt;
1154
1155 auto const pedersenParams = makePedersenParams(pcParams);
1156 Buffer proof(kExpectedProofLength);
1157
1158 if (mpt_get_convert_back_proof(
1159 holderPrivKey->data(),
1160 holderPubKey->data(),
1161 contextHash.data(),
1162 amount,
1163 &pedersenParams,
1164 proof.data()) != 0)
1165 return std::nullopt;
1166
1167 return proof;
1168}
1169
1172{
1173 if (!id_)
1174 Throw<std::runtime_error>("MPT has not been created");
1175
1176 auto const sle = env_.le(keylet::mptoken(*id_, account.id()));
1177 if (!sle)
1178 return {};
1179
1180 SField const* field = nullptr;
1181 switch (option)
1182 {
1184 field = &sfConfidentialBalanceInbox;
1185 break;
1187 field = &sfConfidentialBalanceSpending;
1188 break;
1190 field = &sfIssuerEncryptedBalance;
1191 break;
1193 field = &sfAuditorEncryptedBalance;
1194 break;
1195 }
1196
1197 if (field == nullptr || !sle->isFieldPresent(*field))
1198 return {};
1199
1200 auto const blob = sle->getFieldVL(*field);
1201 return Buffer(blob.data(), blob.size());
1202}
1203
1206{
1207 std::uint32_t flags = 0;
1208 if (!forObject(
1209 [&](SLEP const& sle) {
1210 flags = sle->getFlags();
1211 return true;
1212 },
1213 holder))
1214 Throw<std::runtime_error>("Failed to get the flags");
1215 return flags;
1216}
1217
1218void
1220{
1221 if (id)
1222 {
1223 jv[sfMPTokenIssuanceID] = to_string(*id);
1224 }
1225 else if (id_)
1226 {
1227 jv[sfMPTokenIssuanceID] = to_string(*id_);
1228 }
1229 else
1230 {
1231 Throw<std::runtime_error>("MPT has not been created");
1232 }
1233}
1234
1237 std::optional<std::uint32_t> const& ticketSeq,
1238 std::optional<Account> const& account) const
1239{
1240 if (ticketSeq)
1241 return *ticketSeq;
1242 return env_.seq(requireValue(account, "account"));
1243}
1244
1245MPT
1247{
1248 return MPT(name, issuanceID());
1249}
1250
1253{
1254 return MPT("", issuanceID())(amount);
1255}
1256
1257template <typename T>
1258void
1260 T const& arg,
1261 json::Value& jv,
1262 Account const& account,
1263 std::uint64_t const amount) const
1264{
1265 Buffer const blindingFactor =
1266 arg.blindingFactor ? *arg.blindingFactor : generateBlindingFactor();
1267 jv[sfBlindingFactor.jsonName] = strHex(blindingFactor);
1268
1269 // Handle Holder
1270 Buffer const holderCiphertext = arg.holderEncryptedAmt
1271 ? *arg.holderEncryptedAmt
1272 : encryptAmount(account, amount, blindingFactor);
1273
1274 jv[sfHolderEncryptedAmount.jsonName] = strHex(holderCiphertext);
1275
1276 // Handle Issuer
1277 Buffer const issuerCiphertext = arg.issuerEncryptedAmt
1278 ? *arg.issuerEncryptedAmt
1279 : encryptAmount(issuer_, amount, blindingFactor);
1280
1281 jv[sfIssuerEncryptedAmount.jsonName] = strHex(issuerCiphertext);
1282
1283 // Handle Auditor
1284 std::optional<Buffer> auditorCiphertext;
1285 if (arg.auditorEncryptedAmt)
1286 {
1287 auditorCiphertext = *arg.auditorEncryptedAmt;
1288 }
1289 else if (auditor_.has_value() && arg.fillAuditorEncryptedAmt.value_or(false))
1290 {
1291 auditorCiphertext =
1292 encryptAmount(requireValue(auditor_, "auditor"), amount, blindingFactor);
1293 }
1294
1295 // Update auditor JSON only if ciphertext exists
1296 if (auditorCiphertext)
1297 jv[sfAuditorEncryptedAmount.jsonName] = strHex(*auditorCiphertext);
1298}
1299
1300void
1302{
1303 json::Value const jv = convertJV(arg, ticketOrSeq(arg.ticketSeq, arg.account));
1304
1305 Account const& account = requireValue(arg.account, "account");
1306 auto const amt = requireValue(arg.amt, "amt");
1307
1308 auto const holderAmt = getBalance(account);
1309 auto const prevConfidentialOutstanding = getIssuanceConfidentialBalance();
1310
1311 auto const prevInboxBalance = getDecryptedBalance(account, holderEncryptedInbox);
1312 auto const prevSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
1313 auto const prevIssuerBalance = getDecryptedBalance(account, issuerEncryptedBalance);
1314
1315 if (!prevInboxBalance || !prevSpendingBalance || !prevIssuerBalance)
1316 Throw<std::runtime_error>("Failed to get Pre-convert balance");
1317
1318 // The auditor mirror is only touched if the transaction carries an auditor
1319 // ciphertext, which mirrors the condition convertJV fills it under.
1320 bool const hasAuditorAmt =
1322
1323 std::optional<uint64_t> prevAuditorBalance;
1324 if (hasAuditorAmt)
1325 {
1326 prevAuditorBalance = getDecryptedBalance(account, auditorEncryptedBalance);
1327 if (!prevAuditorBalance)
1328 Throw<std::runtime_error>("Failed to get Pre-convert balance");
1329 }
1330
1331 auto const prevOutstanding = getIssuanceOutstandingBalance();
1332
1333 if (submit(arg, {jv, loc}) == tesSUCCESS)
1334 {
1335 auto const postConfidentialOutstanding = getIssuanceConfidentialBalance();
1336 auto const postOutstanding = getIssuanceOutstandingBalance();
1337 env_.require(MptBalance(*this, account, holderAmt - amt, loc));
1338 env_.require(RequireAny(
1339 [&] -> bool {
1340 return prevOutstanding && postOutstanding && *prevOutstanding == *postOutstanding;
1341 },
1342 loc));
1343 env_.require(RequireAny(
1344 [&] -> bool {
1345 return prevConfidentialOutstanding + amt == postConfidentialOutstanding;
1346 },
1347 loc));
1348
1349 env_.require(RequireAny(
1350 [&] -> bool { return getEncryptedBalance(account, holderEncryptedInbox).has_value(); },
1351 loc));
1352 env_.require(RequireAny(
1353 [&] -> bool {
1354 return getEncryptedBalance(account, holderEncryptedSpending).has_value();
1355 },
1356 loc));
1357 env_.require(RequireAny(
1358 [&] -> bool {
1359 return getEncryptedBalance(account, issuerEncryptedBalance).has_value();
1360 },
1361 loc));
1362
1363 auto const postInboxBalance = getDecryptedBalance(account, holderEncryptedInbox);
1364 auto const postIssuerBalance = getDecryptedBalance(account, issuerEncryptedBalance);
1365 auto const postSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
1366
1367 if (!postInboxBalance || !postIssuerBalance || !postSpendingBalance)
1368 Throw<std::runtime_error>("Failed to get post-convert balance");
1369
1370 if (hasAuditorAmt)
1371 {
1372 auto const postAuditorBalance = getDecryptedBalance(account, auditorEncryptedBalance);
1373
1374 if (!postAuditorBalance)
1375 Throw<std::runtime_error>("Failed to get post-convert auditor balance");
1376
1377 env_.require(RequireAny(
1378 [&] -> bool {
1379 return getEncryptedBalance(account, auditorEncryptedBalance).has_value();
1380 },
1381 loc));
1382
1383 // auditor's encrypted balance is updated correctly
1384 env_.require(RequireAny(
1385 [&] -> bool { return *prevAuditorBalance + amt == *postAuditorBalance; }, loc));
1386 }
1387 // spending balance should not change
1388 env_.require(
1389 RequireAny([&] -> bool { return *postSpendingBalance == *prevSpendingBalance; }, loc));
1390
1391 // issuer's encrypted balance is updated correctly
1392 env_.require(RequireAny(
1393 [&] -> bool { return *prevIssuerBalance + amt == *postIssuerBalance; }, loc));
1394
1395 // holder's inbox balance is updated correctly
1396 env_.require(
1397 RequireAny([&] -> bool { return *prevInboxBalance + amt == *postInboxBalance; }, loc));
1398
1399 // sum of holder's inbox and spending balance should equal to issuer's
1400 // encrypted balance
1401 env_.require(RequireAny(
1402 [&] -> bool { return *postInboxBalance + *postSpendingBalance == *postIssuerBalance; },
1403 loc));
1404
1405 if (arg.holderPubKey)
1406 {
1407 env_.require(RequireAny(
1408 [&] -> bool {
1409 return forObject(
1410 [&](SLEP const& sle) -> bool {
1411 if (sle)
1412 {
1413 auto const holderPubKey = getPubKey(account);
1414 if (!holderPubKey)
1415 {
1417 "MPTTester::convert: holder's pubkey is "
1418 "not set");
1419 }
1420
1421 return strHex((*sle)[sfHolderEncryptionKey]) ==
1422 strHex(*holderPubKey);
1423 }
1424 return false;
1425 },
1426 account);
1427 },
1428 loc));
1429 }
1430 }
1431}
1432
1435{
1436 json::Value jv;
1437 Account const& account = setAccountField(jv, arg.account);
1438
1439 jv[jss::TransactionType] = jss::ConfidentialMPTConvert;
1440 setIssuanceIdField(jv, arg.id);
1441
1442 auto const amt = requireValue(arg.amt, "amt");
1443 jv[sfMPTAmount.jsonName] = std::to_string(amt);
1444 if (arg.holderPubKey)
1445 jv[sfHolderEncryptionKey.jsonName] = strHex(*arg.holderPubKey);
1446
1447 fillConversionCiphertexts(arg, jv, account, amt);
1448
1449 if (arg.proof)
1450 {
1451 jv[sfZKProof.jsonName] = *arg.proof;
1452 }
1453 else if (arg.fillSchnorrProof.value_or(arg.holderPubKey.has_value()))
1454 {
1455 auto const contextHash = getConvertContextHash(account.id(), issuanceID(), seq);
1456 setProofOrDummy(jv, getSchnorrProof(account, contextHash), kEcSchnorrProofLength);
1457 }
1458
1459 return jv;
1460}
1461
1462void
1464{
1465 json::Value const jv = sendJV(arg, ticketOrSeq(arg.ticketSeq, arg.account));
1466
1467 Account const& account = requireValue(arg.account, "account");
1468 Account const& dest = requireValue(arg.dest, "dest");
1469 auto const amt = requireValue(arg.amt, "amt");
1470
1471 // Version counters before send
1472 auto const prevSenderVersion = getMPTokenVersion(account);
1473 auto const prevDestVersion = getMPTokenVersion(dest);
1474
1475 // Sender's previous confidential state
1476 auto const prevSenderInbox = getDecryptedBalance(account, holderEncryptedInbox);
1477 auto const prevSenderSpending = getDecryptedBalance(account, holderEncryptedSpending);
1478 auto const prevSenderIssuer = getDecryptedBalance(account, issuerEncryptedBalance);
1479 if (!prevSenderInbox || !prevSenderSpending || !prevSenderIssuer)
1480 Throw<std::runtime_error>("Failed to get Pre-send balance");
1481
1482 std::optional<uint64_t> prevSenderAuditor;
1483 if (arg.auditorEncryptedAmt || auditor_)
1484 {
1485 prevSenderAuditor = getDecryptedBalance(account, auditorEncryptedBalance);
1486 if (!prevSenderAuditor)
1487 Throw<std::runtime_error>("Failed to get Pre-send balance");
1488 }
1489
1490 // Destination's previous confidential state
1491 auto const prevDestInbox = getDecryptedBalance(dest, holderEncryptedInbox);
1492 auto const prevDestSpending = getDecryptedBalance(dest, holderEncryptedSpending);
1493 auto const prevDestIssuer = getDecryptedBalance(dest, issuerEncryptedBalance);
1494 if (!prevDestInbox || !prevDestSpending || !prevDestIssuer)
1495 Throw<std::runtime_error>("Failed to get Pre-send balance");
1496
1497 std::optional<uint64_t> prevDestAuditor;
1498 if (arg.auditorEncryptedAmt || auditor_)
1499 {
1500 prevDestAuditor = getDecryptedBalance(dest, auditorEncryptedBalance);
1501 if (!prevDestAuditor)
1502 Throw<std::runtime_error>("Failed to get Pre-send balance");
1503 }
1504
1505 auto const senderPubAmt = getBalance(account);
1506 auto const destPubAmt = getBalance(dest);
1507 auto const prevCOA = getIssuanceConfidentialBalance();
1508 auto const prevOA = getIssuanceOutstandingBalance();
1509
1510 if (submit(arg, {jv, loc}) == tesSUCCESS)
1511 {
1512 auto const postCOA = getIssuanceConfidentialBalance();
1513 auto const postOA = getIssuanceOutstandingBalance();
1514
1515 // Sender's post confidential state
1516 auto const postSenderInbox = getDecryptedBalance(account, holderEncryptedInbox);
1517 auto const postSenderSpending = getDecryptedBalance(account, holderEncryptedSpending);
1518 auto const postSenderIssuer = getDecryptedBalance(account, issuerEncryptedBalance);
1519
1520 if (!postSenderInbox || !postSenderSpending || !postSenderIssuer)
1521 Throw<std::runtime_error>("Failed to get Post-send balance");
1522
1523 // Destination's post confidential state
1524 auto const postDestInbox = getDecryptedBalance(dest, holderEncryptedInbox);
1525 auto const postDestSpending = getDecryptedBalance(dest, holderEncryptedSpending);
1526 auto const postDestIssuer = getDecryptedBalance(dest, issuerEncryptedBalance);
1527
1528 if (!postDestInbox || !postDestSpending || !postDestIssuer)
1529 Throw<std::runtime_error>("Failed to get Post-send balance");
1530
1531 // Public balances unchanged
1532 env_.require(MptBalance(*this, account, senderPubAmt, loc));
1533 env_.require(MptBalance(*this, dest, destPubAmt, loc));
1534
1535 // OA and COA unchanged
1536 env_.require(
1537 RequireAny([&] -> bool { return prevOA && postOA && *prevOA == *postOA; }, loc));
1538 env_.require(RequireAny([&] -> bool { return prevCOA == postCOA; }, loc));
1539
1540 // Verify sender changes
1541 env_.require(RequireAny(
1542 [&] -> bool {
1543 return *prevSenderSpending >= amt &&
1544 *postSenderSpending == *prevSenderSpending - amt;
1545 },
1546 loc));
1547 env_.require(RequireAny([&] -> bool { return postSenderInbox == prevSenderInbox; }, loc));
1548 env_.require(RequireAny(
1549 [&] -> bool {
1550 return *prevSenderIssuer >= amt && *postSenderIssuer == *prevSenderIssuer - amt;
1551 },
1552 loc));
1553
1554 // Verify destination changes
1555 env_.require(
1556 RequireAny([&] -> bool { return *postDestInbox == *prevDestInbox + amt; }, loc));
1557 env_.require(
1558 RequireAny([&] -> bool { return *postDestSpending == *prevDestSpending; }, loc));
1559 env_.require(
1560 RequireAny([&] -> bool { return *postDestIssuer == *prevDestIssuer + amt; }, loc));
1561
1562 // Cross checks
1563 env_.require(RequireAny(
1564 [&] -> bool { return *postSenderInbox + *postSenderSpending == *postSenderIssuer; },
1565 loc));
1566 env_.require(RequireAny(
1567 [&] -> bool { return *postDestInbox + *postDestSpending == *postDestIssuer; }, loc));
1568
1569 // Version: sender increments by 1; receiver version is unchanged by incoming sends
1570 env_.require(RequireAny(
1571 [&] -> bool { return getMPTokenVersion(account) == prevSenderVersion + 1; }, loc));
1572 env_.require(
1573 RequireAny([&] -> bool { return getMPTokenVersion(dest) == prevDestVersion; }, loc));
1574
1575 if (arg.auditorEncryptedAmt || auditor_)
1576 {
1577 auto const postSenderAuditor = getDecryptedBalance(account, auditorEncryptedBalance);
1578 auto const postDestAuditor = getDecryptedBalance(dest, auditorEncryptedBalance);
1579 if (!postSenderAuditor || !postDestAuditor)
1580 Throw<std::runtime_error>("Failed to get Post-send balance");
1581
1582 env_.require(RequireAny(
1583 [&] -> bool {
1584 return *postSenderAuditor == *postSenderIssuer &&
1585 *postDestAuditor == *postDestIssuer;
1586 },
1587 loc));
1588
1589 // verify sender
1590 env_.require(RequireAny(
1591 [&] -> bool {
1592 return *prevSenderAuditor >= amt &&
1593 *postSenderAuditor == *prevSenderAuditor - amt;
1594 },
1595 loc));
1596
1597 // verify dest
1598 env_.require(RequireAny(
1599 [&] -> bool { return *postDestAuditor == *prevDestAuditor + amt; }, loc));
1600 }
1601 }
1602}
1603
1606 MPTConfidentialSend const& arg,
1607 std::uint32_t seq,
1609{
1610 json::Value jv;
1611 jv[jss::TransactionType] = jss::ConfidentialMPTSend;
1612
1613 Account const& account = setAccountField(jv, arg.account);
1614 Account const& dest = setDestinationField(jv, arg.dest);
1615 auto const amt = requireValue(arg.amt, "amt");
1616
1617 setIssuanceIdField(jv, arg.id);
1618
1619 Buffer const blindingFactor =
1621
1622 auto const senderAmt = arg.senderEncryptedAmt ? *arg.senderEncryptedAmt
1623 : encryptAmount(account, amt, blindingFactor);
1624 auto const destAmt =
1625 arg.destEncryptedAmt ? *arg.destEncryptedAmt : encryptAmount(dest, amt, blindingFactor);
1626 auto const issuerAmt = arg.issuerEncryptedAmt ? *arg.issuerEncryptedAmt
1627 : encryptAmount(issuer_, amt, blindingFactor);
1628
1629 std::optional<Buffer> auditorAmt;
1630 if (arg.auditorEncryptedAmt)
1631 {
1632 auditorAmt = arg.auditorEncryptedAmt;
1633 }
1634 else if (auditor_.has_value() && arg.fillAuditorEncryptedAmt.value_or(false))
1635 {
1636 auditorAmt = encryptAmount(requireValue(auditor_, "auditor"), amt, blindingFactor);
1637 }
1638
1639 jv[sfSenderEncryptedAmount] = strHex(senderAmt);
1640 jv[sfDestinationEncryptedAmount] = strHex(destAmt);
1641 jv[sfIssuerEncryptedAmount] = strHex(issuerAmt);
1642 if (auditorAmt)
1643 jv[sfAuditorEncryptedAmount] = strHex(*auditorAmt);
1644
1645 if (arg.credentials)
1646 {
1647 auto& arr(jv[sfCredentialIDs.jsonName] = json::ValueType::Array);
1648 for (auto const& hash : *arg.credentials)
1649 arr.append(hash);
1650 }
1651
1652 std::uint64_t prevSenderSpending = 0;
1653 std::optional<Buffer> prevEncryptedSenderSpending;
1654 std::uint32_t version = 0;
1655 if (chain)
1656 {
1657 prevSenderSpending = chain->spending;
1658 prevEncryptedSenderSpending = chain->encSpending;
1659 version = chain->version;
1660 }
1661 else
1662 {
1663 auto const ledgerSpending = getDecryptedBalance(account, holderEncryptedSpending);
1664 if (!ledgerSpending)
1665 Throw<std::runtime_error>("Failed to get sender spending balance");
1666 prevSenderSpending = *ledgerSpending;
1667 prevEncryptedSenderSpending = getEncryptedBalance(account, holderEncryptedSpending);
1668 version = getMPTokenVersion(account);
1669 }
1670
1671 // The amount commitment must use the same blinding factor as the tx ElGamal
1672 // encryption blinding factor.
1673 Buffer amountCommitment, balanceCommitment;
1674 if (arg.amountCommitment)
1675 {
1676 amountCommitment = *arg.amountCommitment;
1677 }
1678 else
1679 {
1680 amountCommitment = getPedersenCommitment(amt, blindingFactor);
1681 }
1682
1683 jv[sfAmountCommitment] = strHex(amountCommitment);
1684
1685 auto const balanceBlindingFactor = generateBlindingFactor();
1686 if (arg.balanceCommitment)
1687 {
1688 balanceCommitment = *arg.balanceCommitment;
1689 }
1690 else
1691 {
1692 balanceCommitment = getPedersenCommitment(prevSenderSpending, balanceBlindingFactor);
1693 }
1694
1695 jv[sfBalanceCommitment] = strHex(balanceCommitment);
1696
1697 if (arg.proof)
1698 {
1699 jv[sfZKProof.jsonName] = *arg.proof;
1700 }
1701 else
1702 {
1703 auto const ctxHash =
1704 getSendContextHash(account.id(), issuanceID(), seq, dest.id(), version);
1705
1707
1708 auto const senderPubKey = getPubKey(account);
1709 auto const destPubKey = getPubKey(dest);
1710 auto const issuerPubKey = getPubKey(issuer_);
1711
1712 if (senderPubKey)
1713 {
1714 recipients.push_back({
1715 .publicKey = Slice(*senderPubKey),
1716 .encryptedAmount = senderAmt,
1717 });
1718 }
1719 if (destPubKey)
1720 {
1721 recipients.push_back({
1722 .publicKey = Slice(*destPubKey),
1723 .encryptedAmount = destAmt,
1724 });
1725 }
1726 if (issuerPubKey)
1727 {
1728 recipients.push_back({
1729 .publicKey = Slice(*issuerPubKey),
1730 .encryptedAmount = issuerAmt,
1731 });
1732 }
1733
1734 std::optional<Buffer> auditorPubKey;
1735 if (auditorAmt)
1736 {
1737 if (!auditor_)
1738 Throw<std::runtime_error>("Auditor not registered");
1739 auditorPubKey = getPubKey(*auditor_);
1740 if (auditorPubKey)
1741 {
1742 recipients.push_back({
1743 .publicKey = Slice(*auditorPubKey),
1744 .encryptedAmount = *auditorAmt,
1745 });
1746 }
1747 }
1748
1750
1751 // Skip proof generation when spending balance is 0
1752 if (prevEncryptedSenderSpending && prevSenderSpending > 0)
1753 {
1755 account,
1756 amt,
1757 recipients,
1758 blindingFactor,
1759 ctxHash,
1760 {
1761 .pedersenCommitment = amountCommitment,
1762 .amt = amt,
1763 .encryptedAmt = senderAmt,
1764 .blindingFactor = blindingFactor,
1765 },
1766 {
1767 .pedersenCommitment = balanceCommitment,
1768 .amt = prevSenderSpending,
1769 .encryptedAmt = *prevEncryptedSenderSpending,
1770 .blindingFactor = balanceBlindingFactor,
1771 });
1772 }
1773
1774 setProofOrDummy(jv, proof, kEcSendProofLength);
1775 }
1776
1777 return jv;
1778}
1779
1780static Buffer
1782{
1783 auto const hexStr = jv[sfSenderEncryptedAmount.jsonName].asString();
1784 auto const bytes = strUnHex(hexStr);
1785 if (!bytes)
1786 Throw<std::runtime_error>("chainAfterSend: invalid hex in sfSenderEncryptedAmount");
1787 return Buffer(bytes->data(), bytes->size());
1788}
1789
1791MPTTester::chainAfterSend(Account const& sender, std::uint64_t sendAmt, json::Value const& jv) const
1792{
1793 auto const prevSpending = getDecryptedBalance(sender, holderEncryptedSpending);
1794 auto const prevEncSpending = getEncryptedBalance(sender, holderEncryptedSpending);
1795 auto const prevVersion = getMPTokenVersion(sender);
1796
1797 if (!prevSpending || !prevEncSpending)
1798 Throw<std::runtime_error>("chainAfterSend: failed to read sender state from ledger");
1799
1800 Buffer const senderEncAmt = parseSenderEncAmt(jv);
1801 auto chain = computeNextSendChainState(
1802 *prevSpending, Slice(*prevEncSpending), prevVersion, sendAmt, Slice(senderEncAmt));
1803 if (!chain)
1804 Throw<std::runtime_error>("chainAfterSend: computeNextSendChainState failed");
1805 return std::move(*chain);
1806}
1807
1810 std::uint64_t currentSpending,
1811 Slice const& currentEncSpending,
1812 std::uint32_t currentVersion,
1813 std::uint64_t sendAmt,
1814 Slice const& senderEncAmt)
1815{
1816 if (sendAmt > currentSpending)
1817 return std::nullopt; // LCOV_EXCL_LINE
1818
1819 auto newEncSpending = homomorphicSubtract(currentEncSpending, senderEncAmt);
1820 if (!newEncSpending)
1821 return std::nullopt; // LCOV_EXCL_LINE
1822
1824 .spending = currentSpending - sendAmt,
1825 .encSpending = std::move(*newEncSpending),
1826 .version = currentVersion + 1,
1827 };
1828}
1829
1830void
1832{
1833 json::Value jv;
1834 auto const account = arg.account ? *arg.account : issuer_;
1835 jv[sfAccount] = account.human();
1836
1837 Account const& holder = requireValue(arg.holder, "holder");
1838 jv[sfHolder] = holder.human();
1839
1840 jv[jss::TransactionType] = jss::ConfidentialMPTClawback;
1841 setIssuanceIdField(jv, arg.id);
1842
1843 auto const amt = requireValue(arg.amt, "amt");
1844 jv[sfMPTAmount] = std::to_string(amt);
1845
1846 if (arg.proof)
1847 {
1848 jv[sfZKProof] = *arg.proof;
1849 }
1850 else
1851 {
1852 auto const seq = arg.ticketSeq ? *arg.ticketSeq : env_.seq(account);
1853 auto const contextHash =
1854 getClawbackContextHash(account.id(), issuanceID(), seq, holder.id());
1855
1856 auto const privKey = getPrivKey(account);
1857 if (!privKey || privKey->size() != kEcPrivKeyLength)
1858 Throw<std::runtime_error>("Failed to get clawback private key");
1859
1860 auto const proof =
1861 getClawbackProof(holder, amt, requireValue(privKey, "privKey"), contextHash);
1862
1863 setProofOrDummy(jv, proof, kEcClawbackProofLength);
1864 }
1865
1866 auto const holderPubAmt = getBalance(holder);
1867 auto const prevCOA = getIssuanceConfidentialBalance();
1868 auto const prevOA = getIssuanceOutstandingBalance();
1869 auto const prevVersion = getMPTokenVersion(holder);
1870
1871 if (submit(arg, {jv, loc}) == tesSUCCESS)
1872 {
1873 auto const postCOA = getIssuanceConfidentialBalance();
1874 auto const postOA = getIssuanceOutstandingBalance();
1875 auto const postVersion = getMPTokenVersion(holder);
1876
1877 // Verify holder's public balance is unchanged
1878 env_.require(MptBalance(*this, holder, holderPubAmt, loc));
1879
1880 // Verify COA and OA are reduced correctly
1881 env_.require(
1882 RequireAny([&] -> bool { return prevCOA >= amt && postCOA == prevCOA - amt; }, loc));
1883 env_.require(RequireAny(
1884 [&] -> bool { return prevOA && postOA && *prevOA >= amt && *postOA == *prevOA - amt; },
1885 loc));
1886
1887 // Verify holder's confidential balances are zeroed out
1888 env_.require(RequireAny(
1889 [&] -> bool { return getDecryptedBalance(holder, holderEncryptedInbox) == 0; }, loc));
1890 env_.require(RequireAny(
1891 [&] -> bool { return getDecryptedBalance(holder, holderEncryptedSpending) == 0; },
1892 loc));
1893 env_.require(RequireAny(
1894 [&] -> bool { return getDecryptedBalance(holder, issuerEncryptedBalance) == 0; }, loc));
1895 env_.require(RequireAny(
1896 [&] -> bool { return getDecryptedBalance(holder, auditorEncryptedBalance) == 0; },
1897 loc));
1898
1899 // Verify version is incremented
1900 env_.require(RequireAny([&] -> bool { return postVersion == prevVersion + 1; }, loc));
1901 }
1902}
1903
1906{
1907 unsigned char privKey[kEcPrivKeyLength];
1908 secp256k1_pubkey pubKey;
1909 if (secp256k1_elgamal_generate_keypair(secp256k1Context(), privKey, &pubKey) == 0)
1910 Throw<std::runtime_error>("failed to generate key pair");
1911
1912 // Serialize public key to compressed format (33 bytes)
1913 unsigned char compressedPubKey[kEcPubKeyLength];
1914 size_t outLen = kEcPubKeyLength;
1915 if (secp256k1_ec_pubkey_serialize(
1916 secp256k1Context(), compressedPubKey, &outLen, &pubKey, SECP256K1_EC_COMPRESSED) != 1 ||
1917 outLen != kEcPubKeyLength)
1918 {
1919 Throw<std::runtime_error>("failed to serialize public key");
1920 }
1921
1922 auto& pubKeyEpochs = pubKeys_[account.id()];
1923 pubKeyEpochs.emplace_back(compressedPubKey, kEcPubKeyLength);
1924 privKeys_[account.id()].emplace_back(privKey, kEcPrivKeyLength);
1925
1926 return static_cast<std::uint32_t>(pubKeyEpochs.size() - 1);
1927}
1928
1931{
1932 return keyAtEpoch(pubKeys_, account.id(), epoch);
1933}
1934
1937{
1938 return keyAtEpoch(privKeys_, account.id(), epoch);
1939}
1940
1941Buffer
1942MPTTester::encryptAmount(Account const& account, uint64_t const amt, Buffer const& blindingFactor)
1943 const
1944{
1945 if (auto const pubKey = getPubKey(account))
1946 {
1947 if (auto const result = xrpl::encryptAmount(amt, *pubKey, blindingFactor))
1948 return *result;
1949 }
1950
1951 // Return a dummy buffer on failure to allow testing of
1952 // failures that occur prior to encryption.
1954}
1955
1958 Account const& account,
1959 Buffer const& amt,
1960 std::optional<std::uint32_t> epoch) const
1961{
1963 return std::nullopt;
1964
1965 auto const pair = makeEcPair(amt);
1966 if (!pair)
1967 return std::nullopt;
1968
1969 auto const privKey = getPrivKey(account, epoch);
1970 if (!privKey || privKey->size() != kEcPrivKeyLength)
1971 return std::nullopt;
1972
1973 uint64_t decryptedAmt = 0;
1974 if (secp256k1_elgamal_decrypt(
1976 &decryptedAmt,
1977 &pair->c1,
1978 &pair->c2,
1979 privKey->data(),
1980 kElGamalDecryptRangeLow,
1981 kElGamalDecryptRangeHigh) == 0)
1982 {
1983 return std::nullopt;
1984 }
1985
1986 return decryptedAmt;
1987}
1988
1991{
1992 auto const encryptedAmt = getEncryptedBalance(account, balanceType);
1993
1994 // Return zero to test cases like Feature Disabled, where the ledger object
1995 // does not exist.
1996 if (!encryptedAmt)
1997 return 0;
1998
1999 Account decryptor = account;
2000
2001 // A mirror stays encrypted under the key it was written with, so a rotation
2002 // leaves it readable only by that generation of the key, not the latest one.
2004
2005 if (balanceType == issuerEncryptedBalance)
2006 {
2007 decryptor = issuer_;
2008 epoch = getMirrorEpoch(account, sfIssuerKeyMirrorEpoch).value_or(0);
2009 }
2010 else if (balanceType == auditorEncryptedBalance)
2011 {
2012 if (!auditor_)
2013 return std::nullopt;
2014 decryptor = *auditor_;
2015 epoch = getMirrorEpoch(account, sfAuditorKeyMirrorEpoch).value_or(0);
2016 }
2017
2018 return decryptAmount(decryptor, *encryptedAmt, epoch);
2019}
2020
2023{
2024 json::Value jv;
2025 setAccountField(jv, arg.account);
2026 setIssuanceIdField(jv, arg.id);
2027 jv[sfTransactionType] = jss::ConfidentialMPTMergeInbox;
2028 return jv;
2029}
2030
2031void
2033{
2034 json::Value const jv = mergeInboxJV(arg);
2035 Account const& account = requireValue(arg.account, "account");
2036
2037 auto const holderPubAmt = getBalance(account);
2038 auto const prevCOA = getIssuanceConfidentialBalance();
2039 auto const prevOA = getIssuanceOutstandingBalance();
2040 auto const prevInboxBalance = getDecryptedBalance(account, holderEncryptedInbox);
2041 auto const prevSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
2042 auto const prevIssuerBalance = getDecryptedBalance(account, issuerEncryptedBalance);
2043 auto const prevIssuerEncrypted = getEncryptedBalance(account, issuerEncryptedBalance);
2044 auto const prevAuditorEncrypted = getEncryptedBalance(account, auditorEncryptedBalance);
2045 auto const prevVersion = getMPTokenVersion(account);
2046
2047 if (!prevInboxBalance || !prevSpendingBalance || !prevIssuerBalance)
2048 Throw<std::runtime_error>("Failed to get pre-mergeInbox balances");
2049
2050 if (submit(arg, {jv, loc}) == tesSUCCESS)
2051 {
2052 auto const postCOA = getIssuanceConfidentialBalance();
2053 auto const postOA = getIssuanceOutstandingBalance();
2054 auto const postInboxBalance = getDecryptedBalance(account, holderEncryptedInbox);
2055 auto const postSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
2056 auto const postIssuerBalance = getDecryptedBalance(account, issuerEncryptedBalance);
2057 auto const postInboxEncrypted = getEncryptedBalance(account, holderEncryptedInbox);
2058 auto const postIssuerEncrypted = getEncryptedBalance(account, issuerEncryptedBalance);
2059 auto const postAuditorEncrypted = getEncryptedBalance(account, auditorEncryptedBalance);
2060 auto const postVersion = getMPTokenVersion(account);
2061
2062 if (!postInboxBalance || !postSpendingBalance || !postIssuerBalance ||
2063 !prevIssuerEncrypted || !postInboxEncrypted || !postIssuerEncrypted)
2064 Throw<std::runtime_error>("Failed to get post-mergeInbox balances");
2065
2066 env_.require(MptBalance(*this, account, holderPubAmt, loc));
2067 env_.require(
2068 RequireAny([&] -> bool { return prevOA && postOA && *prevOA == *postOA; }, loc));
2069 env_.require(RequireAny([&] -> bool { return prevCOA == postCOA; }, loc));
2070
2071 env_.require(RequireAny(
2072 [&] -> bool {
2073 return *postSpendingBalance == *prevInboxBalance + *prevSpendingBalance &&
2074 *postInboxBalance == 0;
2075 },
2076 loc));
2077
2078 env_.require(
2079 RequireAny([&] -> bool { return *prevIssuerBalance == *postIssuerBalance; }, loc));
2080
2081 auto const holderPubKey = getPubKey(account);
2082 if (!holderPubKey)
2083 Throw<std::runtime_error>("Failed to get holder public key");
2084
2085 auto const expectedInbox = encryptCanonicalZeroAmount(
2086 requireValue(holderPubKey, "holderPubKey"), account.id(), issuanceID());
2087 if (!expectedInbox)
2088 Throw<std::runtime_error>("Failed to get canonical zero encryption");
2089
2090 env_.require(
2091 RequireAny([&] -> bool { return *postInboxEncrypted == *expectedInbox; }, loc));
2092 env_.require(
2093 RequireAny([&] -> bool { return *postIssuerEncrypted == *prevIssuerEncrypted; }, loc));
2094 env_.require(RequireAny(
2095 [&] -> bool {
2096 return postAuditorEncrypted.has_value() == prevAuditorEncrypted.has_value() &&
2097 (!postAuditorEncrypted || *postAuditorEncrypted == *prevAuditorEncrypted);
2098 },
2099 loc));
2100 env_.require(RequireAny([&] -> bool { return postVersion == prevVersion + 1; }, loc));
2101
2102 env_.require(RequireAny(
2103 [&] -> bool { return *postSpendingBalance + *postInboxBalance == *postIssuerBalance; },
2104 loc));
2105 }
2106}
2107
2110{
2111 if (!id_)
2112 return std::nullopt;
2113
2114 auto const sle = env_.current()->read(keylet::mptokenIssuance(*id_));
2115
2116 if (!sle)
2117 return std::nullopt;
2118
2119 return (*sle)[sfOutstandingAmount];
2120}
2121
2124{
2125 if (!id_)
2126 Throw<std::runtime_error>("Issuance ID does not exist");
2127
2128 auto const sle = env_.current()->read(keylet::mptoken(*id_, account));
2129
2130 // return 0 here instead of throwing an exception since tests for
2131 // preclaim will check if the MPToken exists
2132 if (!sle)
2133 return 0;
2134
2135 return (*sle)[~sfConfidentialBalanceVersion].value_or(0);
2136}
2137
2138void
2140{
2141 json::Value const jv = convertBackJV(arg, ticketOrSeq(arg.ticketSeq, arg.account));
2142
2143 Account const& account = requireValue(arg.account, "account");
2144 auto const amt = requireValue(arg.amt, "amt");
2145
2146 auto const prevInboxBalance = getDecryptedBalance(account, holderEncryptedInbox);
2147 auto const prevSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
2148 auto const prevIssuerBalance = getDecryptedBalance(account, issuerEncryptedBalance);
2149
2150 if (!prevInboxBalance || !prevSpendingBalance || !prevIssuerBalance)
2151 Throw<std::runtime_error>("Failed to get Pre-convertBack balance");
2152
2153 auto const holderAmt = getBalance(account);
2154 auto const prevConfidentialOutstanding = getIssuanceConfidentialBalance();
2155
2156 std::optional<uint64_t> prevAuditorBalance;
2157 if (arg.auditorEncryptedAmt || auditor_)
2158 {
2159 prevAuditorBalance = getDecryptedBalance(account, auditorEncryptedBalance);
2160 if (!prevAuditorBalance)
2161 Throw<std::runtime_error>("Failed to get Pre-convertBack balance");
2162 }
2163
2164 auto const prevOutstanding = getIssuanceOutstandingBalance();
2165 auto const prevVersion = getMPTokenVersion(account);
2166
2167 if (submit(arg, {jv, loc}) == tesSUCCESS)
2168 {
2169 auto const postConfidentialOutstanding = getIssuanceConfidentialBalance();
2170 auto const postOutstanding = getIssuanceOutstandingBalance();
2171 auto const postVersion = getMPTokenVersion(account);
2172 env_.require(MptBalance(*this, account, holderAmt + amt, loc));
2173 env_.require(RequireAny(
2174 [&] -> bool {
2175 return prevOutstanding && postOutstanding && *prevOutstanding == *postOutstanding;
2176 },
2177 loc));
2178 env_.require(RequireAny(
2179 [&] -> bool {
2180 return prevConfidentialOutstanding - amt == postConfidentialOutstanding;
2181 },
2182 loc));
2183
2184 auto const postInboxBalance = getDecryptedBalance(account, holderEncryptedInbox);
2185 auto const postIssuerBalance = getDecryptedBalance(account, issuerEncryptedBalance);
2186 auto const postSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
2187
2188 if (!postInboxBalance || !postIssuerBalance || !postSpendingBalance)
2189 Throw<std::runtime_error>("Failed to get post-convertBack balance");
2190
2191 if (arg.auditorEncryptedAmt || auditor_)
2192 {
2193 auto const postAuditorBalance = getDecryptedBalance(account, auditorEncryptedBalance);
2194
2195 if (!postAuditorBalance)
2196 Throw<std::runtime_error>("Failed to get post-convertBack balance");
2197
2198 // auditor's encrypted balance is updated correctly
2199 env_.require(RequireAny(
2200 [&] -> bool { return *prevAuditorBalance - amt == *postAuditorBalance; }, loc));
2201 }
2202
2203 // inbox balance should not change
2204 env_.require(
2205 RequireAny([&] -> bool { return *postInboxBalance == *prevInboxBalance; }, loc));
2206
2207 // issuer's encrypted balance is updated correctly
2208 env_.require(RequireAny(
2209 [&] -> bool { return *prevIssuerBalance - amt == *postIssuerBalance; }, loc));
2210
2211 // holder's spending balance is updated correctly
2212 env_.require(RequireAny(
2213 [&] -> bool { return *prevSpendingBalance - amt == *postSpendingBalance; }, loc));
2214
2215 // holder's confidential balance version is updated correctly
2216 env_.require(RequireAny([&] -> bool { return postVersion == prevVersion + 1; }, loc));
2217
2218 // sum of holder's inbox and spending balance should equal to issuer's
2219 // encrypted balance
2220 env_.require(RequireAny(
2221 [&] -> bool { return *postInboxBalance + *postSpendingBalance == *postIssuerBalance; },
2222 loc));
2223 }
2224}
2225
2228{
2229 json::Value jv;
2230 Account const& account = setAccountField(jv, arg.account);
2231
2232 jv[jss::TransactionType] = jss::ConfidentialMPTConvertBack;
2233 setIssuanceIdField(jv, arg.id);
2234
2235 auto const amt = requireValue(arg.amt, "amt");
2236 jv[sfMPTAmount.jsonName] = std::to_string(amt);
2237
2238 fillConversionCiphertexts(arg, jv, account, amt);
2239
2240 auto const prevSpendingBalance = getDecryptedBalance(account, holderEncryptedSpending);
2241 if (!prevSpendingBalance)
2242 Throw<std::runtime_error>("convertBackJV: failed to read spending balance from ledger");
2243
2244 Buffer pedersenCommitment;
2245 Buffer const pcBlindingFactor = generateBlindingFactor();
2246 if (arg.pedersenCommitment)
2247 {
2248 pedersenCommitment = *arg.pedersenCommitment;
2249 }
2250 else
2251 {
2252 pedersenCommitment = getPedersenCommitment(*prevSpendingBalance, pcBlindingFactor);
2253 }
2254
2255 jv[sfBalanceCommitment] = strHex(pedersenCommitment);
2256
2257 if (arg.proof)
2258 {
2259 jv[sfZKProof.jsonName] = strHex(*arg.proof);
2260 }
2261 else
2262 {
2263 auto const version = getMPTokenVersion(account);
2264 auto const prevEncSpending = getEncryptedBalance(account, holderEncryptedSpending);
2265 auto const contextHash =
2266 getConvertBackContextHash(account.id(), issuanceID(), seq, version);
2267
2269 if (prevEncSpending)
2270 {
2271 proof = getConvertBackProof(
2272 account,
2273 amt,
2274 contextHash,
2275 {
2276 .pedersenCommitment = pedersenCommitment,
2277 .amt = *prevSpendingBalance,
2278 .encryptedAmt = *prevEncSpending,
2279 .blindingFactor = pcBlindingFactor,
2280 });
2281 }
2282
2283 setProofOrDummy(jv, proof, kEcConvertBackProofLength);
2284 }
2285
2286 return jv;
2287}
2288
2289void
2291{
2292 json::Value jv;
2293 jv[jss::TransactionType] = jss::ConfidentialMPTMirrorUpdate;
2294
2295 setAccountField(jv, arg.account);
2296 setIssuanceIdField(jv, arg.id);
2297
2298 if (arg.holder)
2299 jv[sfHolder] = arg.holder->human();
2300 if (arg.issuerEncryptedAmount)
2301 jv[sfIssuerEncryptedAmount] = strHex(*arg.issuerEncryptedAmount);
2302 if (arg.auditorEncryptedAmount)
2303 jv[sfAuditorEncryptedAmount] = strHex(*arg.auditorEncryptedAmount);
2304
2305 // Placeholder for proof, the logic will be added in the future
2306 if (arg.zkProof)
2307 {
2308 jv[sfZKProof] = strHex(*arg.zkProof);
2309 }
2310 else
2311 {
2313 }
2314
2315 submit(arg, {jv, loc});
2316}
2317
2318void
2320{
2321 json::Value jv;
2322 jv[jss::TransactionType] = jss::ConfidentialMPTHolderKeyUpdate;
2323
2324 setAccountField(jv, arg.account);
2325 setIssuanceIdField(jv, arg.id);
2326
2327 if (arg.holderPubKey)
2328 jv[sfHolderEncryptionKey.jsonName] = strHex(*arg.holderPubKey);
2329 if (arg.spendingCiphertext)
2330 jv[sfConfidentialBalanceSpending.jsonName] = strHex(*arg.spendingCiphertext);
2331 if (arg.inboxCiphertext)
2332 jv[sfConfidentialBalanceInbox.jsonName] = strHex(*arg.inboxCiphertext);
2333 if (arg.proof)
2334 jv[sfZKProof.jsonName] = strHex(*arg.proof);
2335
2336 submit(arg, {jv, loc});
2337}
2338
2339} // namespace xrpl::test::jtx
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:235
Represents a JSON value.
Definition json_value.h:121
std::string asString() const
Returns the unquoted string value.
pointer data()
Definition base_uint.h:117
Like std::vector<char> but better.
Definition Buffer.h:19
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Definition Buffer.h:123
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition Buffer.h:148
constexpr value_type value() const
Returns the underlying value.
Definition MPTAmount.h:135
static constexpr std::array< FlagMapping, 7 > flagMapping
Identifies fields.
Definition SField.h:131
An immutable linear range of bytes.
Definition Slice.h:28
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition Slice.h:88
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition Slice.h:70
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
AccountID id() const
Returns the Account ID.
A transaction testing environment.
Definition Env.h:161
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
beast::unit_test::Suite & test
Definition Env.h:163
std::unordered_map< AccountID, std::vector< Buffer > > pubKeys_
Definition mpt.h:521
static constexpr auto holderEncryptedInbox
Definition mpt.h:533
void mirrorUpdate(MPTMirrorUpdate const &arg=MPTMirrorUpdate{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:2290
std::optional< std::uint32_t > getMirrorEpoch(Account const &holder, SF_UINT32 const &field) const
Definition mpt.cpp:797
std::unordered_map< std::string, Account > const holders_
Definition mpt.h:515
Buffer encryptAmount(Account const &account, uint64_t const amt, Buffer const &blindingFactor) const
Definition mpt.cpp:1942
bool forObject(std::function< bool(SLEP const &sle)> const &cb, std::optional< Account > const &holder=std::nullopt) const
Definition mpt.cpp:679
void mergeInbox(MPTMergeInbox const &arg=MPTMergeInbox{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:2032
bool checkMPTokenAmount(Account const &holder, std::int64_t expectedAmount) const
Definition mpt.cpp:702
std::optional< MPTID > id_
Definition mpt.h:517
json::Value convertJV(MPTConvert const &arg, std::uint32_t seq)
Build a confidential convert JV without submitting it.
Definition mpt.cpp:1434
static Buffer getPedersenCommitment(std::uint64_t const amount, Buffer const &pedersenBlindingFactor)
Definition mpt.cpp:1110
static json::Value destroyJV(MPTDestroy const &arg=MPTDestroy{})
Definition mpt.cpp:412
void setIssuanceIdField(json::Value &jv, std::optional< MPTID > const &id) const
Sets sfMPTokenIssuanceID on jv, falling back to id_ if arg's id is not set.
Definition mpt.cpp:1219
std::optional< Buffer > getEncryptedBalance(Account const &account, EncryptedBalanceType option=holderEncryptedInbox) const
Definition mpt.cpp:1171
void convertBack(MPTConvertBack const &arg=MPTConvertBack{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:2139
std::optional< uint64_t > getDecryptedBalance(Account const &account, EncryptedBalanceType balanceType) const
Definition mpt.cpp:1990
bool checkMirrorEpochs(Account const &holder, std::optional< std::uint32_t > issuerKeyMirrorEpoch, std::optional< std::uint32_t > auditorKeyMirrorEpoch) const
Definition mpt.cpp:783
Account const & holder(std::string const &h) const
Definition mpt.cpp:435
static json::Value authorizeJV(MPTAuthorize const &arg=MPTAuthorize{})
Definition mpt.cpp:444
bool isTransferFeePresent() const
Definition mpt.cpp:757
std::optional< Buffer > getClawbackProof(Account const &holder, std::uint64_t amount, Buffer const &privateKey, UInt256 const &txHash) const
Definition mpt.cpp:986
bool checkMetadata(std::string const &metadata) const
Definition mpt.cpp:730
std::uint32_t generateKeyPair(Account const &account)
Definition mpt.cpp:1905
bool checkFlags(uint32_t const expectedFlags, std::optional< Account > const &holder=std::nullopt) const
Definition mpt.cpp:724
bool isMetadataPresent() const
Definition mpt.cpp:740
MPT operator[](std::string const &name) const
Definition mpt.cpp:1246
void holderKeyUpdate(MPTHolderKeyUpdate const &arg=MPTHolderKeyUpdate{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:2319
std::optional< Buffer > getSchnorrProof(Account const &account, UInt256 const &ctxHash) const
Definition mpt.cpp:1026
static constexpr auto issuerEncryptedBalance
Definition mpt.h:532
bool checkDomainID(std::optional< UInt256 > expected) const
Definition mpt.cpp:692
std::uint32_t getMPTokenVersion(Account const account) const
Definition mpt.cpp:2123
bool checkIssuerMirrorEncryptionKey(std::optional< Buffer > const &expected, Account const &holder) const
Definition mpt.cpp:853
Account const & issuer() const
Definition mpt.h:750
std::optional< std::int64_t > getIssuanceOutstandingBalance() const
Definition mpt.cpp:2109
static json::Value createJV(MPTCreate const &arg=MPTCreate{})
Definition mpt.cpp:322
MPTTester(Env &env, Account issuer, MPTInit const &constr={}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:229
json::Value sendJV(MPTConfidentialSend const &arg, std::uint32_t seq, std::optional< ConfidentialSendChainState > chain=std::nullopt)
Build a confidential send JV.
Definition mpt.cpp:1605
ConfidentialSendChainState chainAfterSend(Account const &sender, std::uint64_t sendAmt, json::Value const &jv) const
Compute the projected sender state after a confidential send in a batch.
Definition mpt.cpp:1791
static json::Value setJV(MPTSet const &set={})
Definition mpt.cpp:538
MPTID const & issuanceID() const
Definition mpt.h:777
static constexpr auto holderEncryptedSpending
Definition mpt.h:534
std::optional< uint64_t > decryptAmount(Account const &account, Buffer const &amt, std::optional< std::uint32_t > epoch=std::nullopt) const
Definition mpt.cpp:1957
void send(MPTConfidentialSend const &arg=MPTConfidentialSend{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:1463
bool checkEncryptionKeys(std::optional< Account > const &issuerKeyOwner, std::optional< Account > const &auditorKeyOwner) const
Definition mpt.cpp:810
bool checkImmutableFlags(std::uint32_t expectedFlags) const
Definition mpt.cpp:763
std::int64_t getBalance(Account const &account) const
Definition mpt.cpp:956
TER submit(A const &arg, WithSourceLocation< json::Value > jv)
Definition mpt.h:886
void fillConversionCiphertexts(T const &arg, json::Value &jv, Account const &account, std::uint64_t const amount) const
Definition mpt.cpp:1259
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
Definition mpt.cpp:1049
std::optional< Buffer > getPubKey(Account const &account, std::optional< std::uint32_t > epoch=std::nullopt) const
Definition mpt.cpp:1930
std::optional< Account > const auditor_
Definition mpt.h:516
Account const issuer_
Definition mpt.h:514
json::Value mergeInboxJV(MPTMergeInbox const &arg=MPTMergeInbox{}) const
Definition mpt.cpp:2022
void authorizeHolders(Holders const &holders, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:529
SLE::const_pointer SLEP
Definition mpt.h:874
static constexpr auto auditorEncryptedBalance
Definition mpt.h:535
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, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:861
std::unordered_map< AccountID, std::vector< Buffer > > privKeys_
Definition mpt.h:522
void claw(Account const &issuer, Account const &holder, std::int64_t amount, std::optional< TER > err=std::nullopt, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:916
void confidentialClaw(MPTConfidentialClawback const &arg=MPTConfidentialClawback{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:1831
PrettyAmount mpt(std::int64_t amount) const
Definition mpt.cpp:940
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:346
void set(MPTSet const &set={}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:581
std::int64_t getIssuanceConfidentialBalance() const
Definition mpt.cpp:974
std::uint32_t ticketOrSeq(std::optional< std::uint32_t > const &ticketSeq, std::optional< Account > const &account) const
Definition mpt.cpp:1236
bool checkTransferFee(std::uint16_t transferFee) const
Definition mpt.cpp:747
bool checkInitialIssuerKey(std::optional< Buffer > const &expected) const
Definition mpt.cpp:847
bool checkIssuanceConfidentialBalance(std::int64_t expectedAmount) const
Definition mpt.cpp:716
void authorize(MPTAuthorize const &arg=MPTAuthorize{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:459
bool checkEncryptionKey(std::optional< Buffer > const &expected, SF_VL const &field, std::optional< Account > const &holder=std::nullopt) const
Definition mpt.cpp:831
PrettyAmount operator()(std::int64_t amount) const
Definition mpt.cpp:1252
std::uint32_t getFlags(std::optional< Account > const &holder) const
Definition mpt.cpp:1205
bool checkKeyEpochs(std::optional< std::uint32_t > issuerKeyEpoch, std::optional< std::uint32_t > auditorKeyEpoch) const
Definition mpt.cpp:772
static std::unordered_map< std::string, Account > makeHolders(std::vector< Account > const &holders)
Definition mpt.cpp:217
bool checkMPTokenOutstandingAmount(std::int64_t expectedAmount) const
Definition mpt.cpp:709
void convert(MPTConvert const &arg=MPTConvert{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:1301
std::optional< Buffer > getPrivKey(Account const &account, std::optional< std::uint32_t > epoch=std::nullopt) const
Definition mpt.cpp:1936
void destroy(MPTDestroy const &arg=MPTDestroy{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:425
std::optional< Buffer > getConvertBackProof(Account const &holder, std::uint64_t const amount, UInt256 const &contextHash, PedersenProofParams const &pcParams) const
Definition mpt.cpp:1136
json::Value convertBackJV(MPTConvertBack const &arg, std::uint32_t seq)
Build a confidential convertBack JV without submitting it.
Definition mpt.cpp:2227
Converts to MPT Issue or STAmount.
Test helper that checks MPT issuance or holder balances.
Definition mpt.h:103
std::source_location testLoc_
Definition mpt.h:109
MPTTester const & tester_
Definition mpt.h:105
std::int64_t const amount_
Definition mpt.h:107
Account const & account_
Definition mpt.h:106
void operator()(Env &env) const
Definition mpt.cpp:201
std::source_location checkLoc_
Definition mpt.h:111
Test helper that checks MPT flag settings after creation.
Definition mpt.h:74
std::uint32_t flags_
Definition mpt.h:77
std::source_location checkLoc_
Definition mpt.h:82
void operator()(Env &env) const
Definition mpt.cpp:191
std::optional< Account > holder_
Definition mpt.h:78
MPTTester & tester_
Definition mpt.h:76
std::source_location testLoc_
Definition mpt.h:80
Match the number of items in the account's owner directory.
Definition owners.h:55
Test helper that accepts any condition supplied by a callback.
Definition mpt.h:136
std::function< bool()> cb_
Definition mpt.h:138
std::source_location testLoc_
Definition mpt.h:140
void operator()(Env &env) const
Definition mpt.cpp:211
std::source_location checkLoc_
Definition mpt.h:142
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
T current(T... args)
T data(T... args)
T emplace(T... args)
T cend(T... args)
T file_name(T... args)
T find(T... args)
T get_if(T... args)
T is_same_v
T memcpy(T... args)
T memset(T... args)
T min(T... args)
@ Array
array value (ordered list)
Definition json_value.h:32
STL namespace.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Definition Indexes.cpp:547
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Definition Indexes.cpp:541
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount, NetClock::duration const &settleDelay, PublicKey const &pk, std::optional< NetClock::time_point > const &cancelAfter, std::optional< std::uint32_t > const &dstTag)
Definition paychan.cpp:31
json::Value claw(Account const &account, STAmount const &amount, std::optional< Account > const &mptHolder)
Definition trust.cpp:51
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
std::vector< STAmount > fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
Definition AMMTest.cpp:34
static MPTCreate makeMPTCreate(MPTInitDef const &arg)
Definition mpt.cpp:275
Buffer gMakeZeroBuffer(std::size_t size)
Create a zero-initialized buffer for malformed cryptography test inputs.
Definition mpt.h:62
std::vector< Account > Holders
Definition mpt.h:157
std::optional< ConfidentialSendChainState > computeNextSendChainState(std::uint64_t currentSpending, Slice const &currentEncSpending, std::uint32_t currentVersion, std::uint64_t sendAmt, Slice const &senderEncAmt)
Use this when building a second (or later) confidential send from the same account in the same batch.
Definition mpt.cpp:1809
static Buffer parseSenderEncAmt(json::Value const &jv)
Definition mpt.cpp:1781
constexpr std::size_t kEcPubKeyLength
Length of EC public key (compressed).
Definition Protocol.h:512
constexpr std::uint8_t kEcCompressedPrefixEvenY
Compressed EC point prefix for even y-coordinate.
Definition Protocol.h:588
constexpr std::size_t kEcBlindingFactorLength
Length of the EC blinding factor in bytes.
Definition Protocol.h:522
std::optional< Buffer > encryptCanonicalZeroAmount(Slice const &pubKeySlice, AccountID const &account, MPTID const &mptId)
Generates the canonical zero encryption for a specific MPToken.
UInt256 getConvertContextHash(AccountID const &account, UInt192 const &issuanceID, std::uint32_t sequence)
Generates the context hash for ConfidentialMPTConvert transactions.
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
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.
UInt256 getConvertBackContextHash(AccountID const &account, UInt192 const &issuanceID, std::uint32_t sequence, std::uint32_t version)
Generates the context hash for ConfidentialMPTConvertBack transactions.
constexpr std::size_t kEcClawbackProofLength
Length of the ZKProof for ConfidentialMPTClawback.
Definition Protocol.h:568
std::optional< Buffer > encryptAmount(uint64_t const amt, Slice const &pubKeySlice, Slice const &blindingFactor)
Encrypts an amount using ElGamal encryption.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
constexpr std::size_t kEcSchnorrProofLength
Length of Schnorr ZKProof for public key registration (compact form) in bytes.
Definition Protocol.h:527
std::optional< EcPair > makeEcPair(Slice const &buffer)
Parses an ElGamal ciphertext into two secp256k1 public key components.
bool matches(char const *string, char const *regex)
Return true if the string loosely matches the regex.
Definition STTx_test.cpp:49
constexpr std::size_t kEcGamalEncryptedTotalLength
EC ElGamal ciphertext length: two compressed EC points concatenated.
Definition Protocol.h:507
TypedField< STInteger< std::uint32_t > > SF_UINT32
Definition SField.h:343
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
constexpr std::size_t kEcConvertBackProofLength
128 bytes compact sigma proof + 688 bytes single bulletproof.
Definition Protocol.h:562
BaseUInt< 256 > UInt256
Definition base_uint.h:581
constexpr std::size_t kEcPedersenCommitmentLength
Length of Pedersen Commitment (compressed).
Definition Protocol.h:532
std::optional< Buffer > homomorphicSubtract(Slice const &a, Slice const &b)
Homomorphically subtracts two ElGamal ciphertexts.
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
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:54
TypedField< STBlob > SF_VL
Definition SField.h:361
secp256k1_context const * secp256k1Context()
Definition secp256k1.h:9
constexpr std::size_t kEcEqualityProofLength
Length of compact equality proof.
Definition Protocol.h:573
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).
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
Definition Indexes.cpp:219
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
constexpr std::size_t kEcSendProofLength
192 bytes compact sigma proof + 754 bytes double bulletproof.
Definition Protocol.h:552
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
@ tecDUPLICATE
Definition TER.h:326
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
constexpr std::size_t kEcPrivKeyLength
Length of EC private key in bytes.
Definition Protocol.h:517
@ tesSUCCESS
Definition TER.h:253
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
T has_value(T... args)
T push_back(T... args)
T size(T... args)
When building multiple confidential sends from the same account inside a single batch transaction,...
Definition mpt.h:468
Arguments for building an MPTokenAuthorize test transaction.
Definition mpt.h:240
std::optional< Account > holder
Definition mpt.h:242
std::optional< Account > account
Definition mpt.h:241
std::optional< MPTID > id
Definition mpt.h:243
std::optional< std::uint32_t > flags
Definition mpt.h:246
Arguments for building a ConfidentialMPTClawback test transaction.
Definition mpt.h:378
std::optional< std::uint32_t > ticketSeq
Definition mpt.h:385
std::optional< std::string > proof
Definition mpt.h:383
std::optional< std::uint64_t > amt
Definition mpt.h:382
std::optional< MPTID > id
Definition mpt.h:381
std::optional< Account > account
Definition mpt.h:379
std::optional< Account > holder
Definition mpt.h:380
Arguments for building a ConfidentialMPTSend test transaction.
Definition mpt.h:322
std::optional< std::vector< std::string > > credentials
Definition mpt.h:334
std::optional< Buffer > balanceCommitment
Definition mpt.h:338
std::optional< MPTID > id
Definition mpt.h:325
std::optional< std::uint32_t > ticketSeq
Definition mpt.h:341
std::optional< std::uint64_t > amt
Definition mpt.h:327
std::optional< bool > fillAuditorEncryptedAmt
Definition mpt.h:333
std::optional< Account > account
Definition mpt.h:323
std::optional< Buffer > auditorEncryptedAmt
Definition mpt.h:332
std::optional< Account > dest
Definition mpt.h:324
std::optional< Buffer > blindingFactor
Definition mpt.h:336
std::optional< Buffer > amountCommitment
Definition mpt.h:337
std::optional< std::string > proof
Definition mpt.h:328
std::optional< Buffer > senderEncryptedAmt
Definition mpt.h:329
std::optional< Buffer > destEncryptedAmt
Definition mpt.h:330
std::optional< Buffer > issuerEncryptedAmt
Definition mpt.h:331
Arguments for building a ConfidentialMPTConvertBack test transaction.
Definition mpt.h:353
std::optional< Buffer > auditorEncryptedAmt
Definition mpt.h:360
std::optional< MPTID > id
Definition mpt.h:355
std::optional< std::uint64_t > amt
Definition mpt.h:356
std::optional< Account > account
Definition mpt.h:354
std::optional< std::uint32_t > ticketSeq
Definition mpt.h:366
std::optional< Buffer > proof
Definition mpt.h:357
std::optional< Buffer > pedersenCommitment
Definition mpt.h:364
Arguments for building a ConfidentialMPTConvert test transaction.
Definition mpt.h:276
std::optional< bool > fillAuditorEncryptedAmt
Definition mpt.h:281
std::optional< MPTID > id
Definition mpt.h:278
std::optional< std::uint64_t > amt
Definition mpt.h:279
std::optional< Buffer > auditorEncryptedAmt
Definition mpt.h:290
std::optional< bool > fillSchnorrProof
Definition mpt.h:286
std::optional< Buffer > holderPubKey
Definition mpt.h:287
std::optional< Account > account
Definition mpt.h:277
std::optional< std::string > proof
Definition mpt.h:280
std::optional< std::uint32_t > ticketSeq
Definition mpt.h:294
Arguments for building an MPTokenIssuanceCreate test transaction.
Definition mpt.h:163
std::optional< std::uint8_t > assetScale
Definition mpt.h:167
std::optional< std::uint32_t > immutableFlags
Definition mpt.h:179
std::optional< std::string > metadata
Definition mpt.h:169
std::optional< std::uint32_t > flags
Definition mpt.h:178
std::optional< std::uint64_t > maxAmt
Definition mpt.h:166
std::optional< UInt256 > domainID
Definition mpt.h:181
std::optional< Account > issuer
Definition mpt.h:165
std::optional< std::pair< std::vector< Account >, std::uint64_t > > pay
Definition mpt.h:177
std::optional< std::uint16_t > transferFee
Definition mpt.h:168
std::optional< std::vector< Account > > authorize
Definition mpt.h:174
Arguments for building an MPTokenIssuanceDestroy test transaction.
Definition mpt.h:227
std::optional< Account > issuer
Definition mpt.h:228
std::optional< MPTID > id
Definition mpt.h:229
Arguments for building a ConfidentialMPTHolderKeyUpdate test transaction.
Definition mpt.h:415
std::optional< Account > account
Definition mpt.h:416
std::optional< Buffer > inboxCiphertext
Definition mpt.h:420
std::optional< Buffer > proof
Definition mpt.h:421
std::optional< MPTID > id
Definition mpt.h:417
std::optional< Buffer > spendingCiphertext
Definition mpt.h:419
std::optional< Buffer > holderPubKey
Definition mpt.h:418
Full constructor arguments for MPTTester initialization.
Definition mpt.h:207
std::uint16_t transferFee
Definition mpt.h:212
std::uint32_t flags
Definition mpt.h:214
std::optional< std::uint64_t > maxAmt
Definition mpt.h:219
std::optional< std::uint32_t > immutableFlags
Definition mpt.h:215
std::optional< std::uint64_t > pay
Definition mpt.h:213
Arguments for initializing funded MPT test accounts and issuance.
Definition mpt.h:189
std::optional< Account > auditor
Definition mpt.h:193
Arguments for building a ConfidentialMPTMergeInbox test transaction.
Definition mpt.h:306
std::optional< MPTID > id
Definition mpt.h:308
std::optional< Account > account
Definition mpt.h:307
Arguments for building a ConfidentialMPTMirrorUpdate test transaction.
Definition mpt.h:397
std::optional< Buffer > auditorEncryptedAmount
Definition mpt.h:402
std::optional< Account > holder
Definition mpt.h:399
std::optional< Account > account
Definition mpt.h:398
std::optional< Buffer > zkProof
Definition mpt.h:403
std::optional< MPTID > id
Definition mpt.h:400
std::optional< Buffer > issuerEncryptedAmount
Definition mpt.h:401
Arguments for building an MPTokenIssuanceSet test transaction.
Definition mpt.h:254
std::optional< Account > account
Definition mpt.h:255
std::optional< Buffer > auditorPubKey
Definition mpt.h:267
std::optional< MPTID > id
Definition mpt.h:257
std::optional< std::uint32_t > immutableFlags
Definition mpt.h:261
std::optional< std::uint16_t > transferFee
Definition mpt.h:262
std::optional< std::uint32_t > flags
Definition mpt.h:260
std::optional< std::variant< Account, AccountID > > holder
Definition mpt.h:256
std::optional< std::string > metadata
Definition mpt.h:263
std::optional< Buffer > issuerPubKey
Definition mpt.h:266
std::optional< UInt256 > domainID
Definition mpt.h:265
std::optional< Account > delegate
Definition mpt.h:264
Stores the parameters that are exclusively used to generate a Pedersen linkage proof.
Definition mpt.h:434
Buffer const pedersenCommitment
The Pedersen commitment used by the proof.
Definition mpt.h:438
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...
Wrapper that captures std::source_location when implicitly constructed.
Definition Env.h:69
T to_string(T... args)
T value_or(T... args)
T visit(T... args)