1#include <test/jtx/Account.h>
2#include <test/jtx/ConfidentialTransfer.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/flags.h>
6#include <test/jtx/mpt.h>
7#include <test/jtx/pay.h>
8#include <test/jtx/ter.h>
9#include <test/jtx/vault.h>
11#include <xrpl/basics/Buffer.h>
12#include <xrpl/basics/Slice.h>
13#include <xrpl/basics/base_uint.h>
14#include <xrpl/basics/contract.h>
15#include <xrpl/basics/strHex.h>
16#include <xrpl/beast/unit_test/suite.h>
17#include <xrpl/beast/utility/Journal.h>
18#include <xrpl/core/ServiceRegistry.h>
19#include <xrpl/json/json_value.h>
20#include <xrpl/ledger/ApplyView.h>
21#include <xrpl/ledger/OpenView.h>
22#include <xrpl/protocol/AccountID.h>
23#include <xrpl/protocol/ConfidentialTransfer.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/Indexes.h>
26#include <xrpl/protocol/LedgerFormats.h>
27#include <xrpl/protocol/Protocol.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/STObject.h>
30#include <xrpl/protocol/Serializer.h>
31#include <xrpl/protocol/TER.h>
32#include <xrpl/protocol/TxFlags.h>
33#include <xrpl/protocol/UintTypes.h>
34#include <xrpl/protocol/jss.h>
35#include <xrpl/tx/apply.h>
37#include <openssl/evp.h>
38#include <utility/mpt_utility.h>
41#include <secp256k1_mpt.h>
69 Env env{*
this, features};
72 MPTTester mptAlice(env, alice, {.holders = {bob}});
76 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
82 mptAlice.pay(alice, bob, 100);
84 mptAlice.generateKeyPair(alice);
86 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
88 mptAlice.generateKeyPair(bob);
93 .holderPubKey = mptAlice.getPubKey(bob),
114 Env env{*
this, features};
117 MPTTester mptAlice(env, alice, {.holders = {bob}});
121 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
127 mptAlice.pay(alice, bob, 1);
129 mptAlice.generateKeyPair(alice);
130 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
132 mptAlice.generateKeyPair(bob);
136 .holderPubKey = mptAlice.getPubKey(bob),
149 Env env{*
this, features};
152 MPTTester mptAlice(env, alice, {.holders = {bob}});
156 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
164 mptAlice.generateKeyPair(alice);
165 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
167 mptAlice.generateKeyPair(bob);
173 .holderPubKey = mptAlice.getPubKey(bob),
178 auto const holderCiphertext =
180 auto const issuerCiphertext =
184 jv[jss::Account] = bob.human();
185 jv[jss::TransactionType] = jss::ConfidentialMPTConvert;
186 jv[sfMPTokenIssuanceID] =
to_string(mptAlice.issuanceID());
188 jv[sfHolderEncryptedAmount.jsonName] =
strHex(holderCiphertext);
189 jv[sfIssuerEncryptedAmount.jsonName] =
strHex(issuerCiphertext);
190 jv[sfBlindingFactor.jsonName] =
strHex(blindingFactor);
195 env.require(MptBalance(mptAlice, bob, 0));
205 Env env{*
this, features};
208 Account const auditor(
"auditor");
219 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
225 mptAlice.pay(alice, bob, 100);
227 mptAlice.generateKeyPair(alice);
228 mptAlice.generateKeyPair(auditor);
232 .issuerPubKey = mptAlice.getPubKey(alice),
233 .auditorPubKey = mptAlice.getPubKey(auditor),
236 mptAlice.generateKeyPair(bob);
241 .holderPubKey = mptAlice.getPubKey(bob),
263 Env env{*
this, features};
265 MPTTester mptAlice(env, alice);
268 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
270 mptAlice.generateKeyPair(alice);
275 .holderPubKey = mptAlice.getPubKey(alice),
281 Env env{*
this, features - featureConfidentialTransfer};
284 MPTTester mptAlice(env, alice, {.holders = {bob}});
288 .flags = tfMPTCanTransfer | tfMPTCanLock,
294 mptAlice.pay(alice, bob, 100);
296 mptAlice.generateKeyPair(alice);
297 mptAlice.generateKeyPair(bob);
301 .issuerPubKey = mptAlice.getPubKey(alice),
308 .holderPubKey = mptAlice.getPubKey(bob),
314 Env env{*
this, features};
317 MPTTester mptAlice(env, alice, {.holders = {bob}});
321 .flags = tfMPTCanTransfer | tfMPTCanLock,
327 mptAlice.pay(alice, bob, 100);
329 mptAlice.generateKeyPair(alice);
330 mptAlice.generateKeyPair(bob);
335 .holderPubKey = mptAlice.getPubKey(bob),
343 .holderPubKey = mptAlice.getPubKey(bob),
344 .holderEncryptedAmt =
Buffer{},
352 .holderPubKey = mptAlice.getPubKey(bob),
353 .issuerEncryptedAmt =
Buffer{},
361 .holderPubKey = mptAlice.getPubKey(bob),
362 .auditorEncryptedAmt = gMakeZeroBuffer(10),
370 .holderPubKey = mptAlice.getPubKey(bob),
379 .holderPubKey = mptAlice.getPubKey(bob),
387 .holderPubKey = mptAlice.getPubKey(bob),
397 .holderPubKey = mptAlice.getPubKey(bob),
422 Env env{*
this, features};
425 MPTTester mptAlice(env, alice, {.holders = {bob}});
429 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
435 mptAlice.pay(alice, bob, 100);
437 mptAlice.generateKeyPair(alice);
438 mptAlice.generateKeyPair(bob);
440 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
445 .fillSchnorrProof =
false,
446 .holderPubKey = mptAlice.getPubKey(bob),
453 .fillSchnorrProof =
false,
454 .holderPubKey = mptAlice.getPubKey(bob),
463 .holderPubKey = mptAlice.getPubKey(bob),
471 Env env{*
this, features};
474 MPTTester mptAlice(env, alice, {.holders = {bob}});
478 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
484 mptAlice.pay(alice, bob, 100);
486 mptAlice.generateKeyPair(alice);
487 mptAlice.generateKeyPair(bob);
489 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
496 .holderPubKey = mptAlice.getPubKey(bob),
503 .fillSchnorrProof =
true,
512 testcase(
"Convert proof context binding");
515 auto const runBadProof = [&](
auto makeContextHash) {
516 Env env{*
this, features};
520 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
524 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
526 mptAlice.authorize({.account = bob});
527 mptAlice.authorize({.account = carol});
528 mptAlice.pay(alice, bob, 100);
530 mptAlice.generateKeyPair(alice);
531 mptAlice.generateKeyPair(bob);
532 mptAlice.generateKeyPair(carol);
533 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
536 mptAlice.getSchnorrProof(bob, makeContextHash(env, mptAlice, alice, bob, carol));
537 if (!BEAST_EXPECT(proof.has_value()))
544 .holderPubKey = mptAlice.getPubKey(bob),
550 runBadProof([&](Env& env,
551 MPTTester
const& mpt,
559 runBadProof([&](Env& env,
565 bob.id(),
makeMptID(env.seq(alice) + 100, alice), env.seq(bob));
569 runBadProof([&](Env& env,
570 MPTTester
const& mpt,
586 Env env{*
this, features};
588 Account const auditor(
"auditor");
589 MPTTester mptAlice(env, alice, {.holders = {}, .auditor = auditor});
593 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
596 mptAlice.generateKeyPair(alice);
597 mptAlice.generateKeyPair(auditor);
601 .issuerPubKey = mptAlice.getPubKey(alice),
602 .auditorPubKey = mptAlice.getPubKey(auditor),
608 Env env{*
this, features};
610 MPTTester mptAlice(env, alice, {.holders = {}});
614 .flags = tfMPTCanTransfer | tfMPTCanLock,
619 .flags = tfMPTSetCanHoldConfidentialBalance,
625 Env env{*
this, features};
627 Account const auditor(
"auditor");
628 MPTTester mptAlice(env, alice, {.holders = {}, .auditor = auditor});
632 .flags = tfMPTCanTransfer | tfMPTCanLock,
635 mptAlice.generateKeyPair(alice);
636 mptAlice.generateKeyPair(auditor);
640 .flags = tfMPTSetCanHoldConfidentialBalance,
641 .issuerPubKey = mptAlice.getPubKey(alice),
642 .auditorPubKey = mptAlice.getPubKey(auditor),
646 BEAST_EXPECT(mptAlice.checkFlags(
647 lsfMPTCanTransfer | lsfMPTCanLock | lsfMPTCanHoldConfidentialBalance));
652 BEAST_EXPECT(sle->isFieldPresent(sfIssuerEncryptionKey));
653 BEAST_EXPECT(sle->isFieldPresent(sfAuditorEncryptionKey));
664 Env env{*
this, features - featureConfidentialTransfer};
667 MPTTester mptAlice(env, alice, {.holders = {bob}});
671 .flags = tfMPTCanTransfer | tfMPTCanLock,
677 mptAlice.pay(alice, bob, 100);
679 mptAlice.generateKeyPair(alice);
680 mptAlice.generateKeyPair(bob);
684 .issuerPubKey = mptAlice.getPubKey(alice),
691 Env env{*
this, features};
694 MPTTester mptAlice(env, alice, {.holders = {bob}});
698 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
704 mptAlice.pay(alice, bob, 100);
706 mptAlice.generateKeyPair(alice);
707 mptAlice.generateKeyPair(bob);
726 .issuerPubKey = mptAlice.getPubKey(alice),
727 .auditorPubKey = gMakeZeroBuffer(10),
734 .issuerPubKey = mptAlice.getPubKey(alice),
746 .issuerPubKey = mptAlice.getPubKey(alice),
754 .auditorPubKey = mptAlice.getPubKey(alice),
768 Env env{*
this, features};
770 MPTTester mptAlice(env, alice, {.holders = {}});
774 .flags = tfMPTCanTransfer | tfMPTCanLock,
777 mptAlice.generateKeyPair(alice);
781 .issuerPubKey = mptAlice.getPubKey(alice),
788 Env env{*
this, features - featureConfidentialMPTKeyRotation};
791 MPTTester mptAlice(env, alice, {.holders = {bob}});
795 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
798 mptAlice.generateKeyPair(alice);
799 mptAlice.generateKeyPair(bob);
804 .issuerPubKey = mptAlice.getPubKey(alice),
810 .issuerPubKey = mptAlice.getPubKey(bob),
820 Env env{*
this, features - featureConfidentialMPTKeyRotation};
823 Account const auditor(
"auditor");
824 MPTTester mptAlice(env, alice, {.holders = {bob}, .auditor = auditor});
828 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
831 mptAlice.generateKeyPair(alice);
832 mptAlice.generateKeyPair(bob);
833 mptAlice.generateKeyPair(auditor);
838 .issuerPubKey = mptAlice.getPubKey(alice),
839 .auditorPubKey = mptAlice.getPubKey(auditor),
845 .issuerPubKey = mptAlice.getPubKey(bob),
846 .auditorPubKey = mptAlice.getPubKey(alice),
853 Env env{*
this, features};
855 Account const auditor(
"auditor");
856 MPTTester mptAlice(env, alice, {.holders = {}, .auditor = auditor});
860 .flags = tfMPTCanTransfer | tfMPTCanLock,
863 mptAlice.generateKeyPair(alice);
864 mptAlice.generateKeyPair(auditor);
868 .issuerPubKey = mptAlice.getPubKey(alice),
869 .auditorPubKey = mptAlice.getPubKey(auditor),
876 Env env{*
this, features};
878 MPTTester mptAlice(env, alice, {.holders = {}});
883 .flags = tfMPTCanTransfer | tfMPTCanLock,
887 mptAlice.generateKeyPair(alice);
893 .flags = tfMPTSetCanHoldConfidentialBalance,
894 .issuerPubKey = mptAlice.getPubKey(alice),
902 Env env{*
this, features - featureConfidentialMPTKeyRotation};
904 Account const auditor(
"auditor");
905 MPTTester mptAlice(env, alice, {.holders = {}, .auditor = auditor});
909 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
912 mptAlice.generateKeyPair(alice);
913 mptAlice.generateKeyPair(auditor);
918 .issuerPubKey = mptAlice.getPubKey(alice),
926 .issuerPubKey = mptAlice.getPubKey(alice),
927 .auditorPubKey = mptAlice.getPubKey(auditor),
942 Env env{*
this, features};
944 MPTTester mptAlice(env, alice, {.holders = {}});
948 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
955 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
962 Env env{*
this, features};
964 MPTTester mptAlice(env, alice, {.holders = {}});
966 mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock});
970 .flags = tfMPTSetCanHoldConfidentialBalance,
979 Env env{*
this, features};
981 MPTTester mptAlice(env, alice, {.holders = {}});
984 {.transferFee = 100, .ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock});
988 .flags = tfMPTSetCanHoldConfidentialBalance,
996 Env env{*
this, features};
998 MPTTester mptAlice(env, alice, {.holders = {}});
1002 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1027 Env env{*
this, features};
1030 MPTTester mptAlice(env, alice, {.holders = {bob}});
1034 .flags = tfMPTCanTransfer | tfMPTCanLock,
1037 mptAlice.authorize({
1040 mptAlice.pay(alice, bob, 100);
1042 mptAlice.generateKeyPair(alice);
1043 mptAlice.generateKeyPair(bob);
1048 .holderPubKey = mptAlice.getPubKey(bob),
1055 Env env{*
this, features};
1058 MPTTester mptAlice(env, alice, {.holders = {bob}});
1062 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1065 mptAlice.authorize({
1068 mptAlice.pay(alice, bob, 100);
1070 mptAlice.generateKeyPair(alice);
1071 mptAlice.generateKeyPair(bob);
1076 .holderPubKey = mptAlice.getPubKey(bob),
1083 Env env{*
this, features};
1086 MPTTester mptAlice(env, alice, {.holders = {bob}});
1090 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1093 mptAlice.authorize({
1096 mptAlice.generateKeyPair(alice);
1098 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1101 mptAlice.generateKeyPair(bob);
1106 .holderPubKey = mptAlice.getPubKey(bob),
1113 Env env{*
this, features};
1116 MPTTester mptAlice(env, alice, {.holders = {bob}});
1120 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1123 mptAlice.generateKeyPair(alice);
1124 mptAlice.generateKeyPair(bob);
1126 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1131 .holderPubKey = mptAlice.getPubKey(bob),
1138 Env env{*
this, features};
1142 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
1146 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1149 mptAlice.authorize({
1152 mptAlice.pay(alice, bob, 100);
1154 mptAlice.generateKeyPair(alice);
1155 mptAlice.generateKeyPair(bob);
1156 mptAlice.generateKeyPair(carol);
1158 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1163 .holderPubKey = mptAlice.getPubKey(bob),
1171 .holderPubKey = mptAlice.getPubKey(bob),
1178 Buffer const holderCiphertext = mptAlice.encryptAmount(bob, amount, blindingFactor);
1183 Buffer const wrongIssuerCiphertext =
1184 mptAlice.encryptAmount(carol, amount, blindingFactor);
1189 .holderPubKey = mptAlice.getPubKey(bob),
1190 .holderEncryptedAmt = holderCiphertext,
1191 .issuerEncryptedAmt = wrongIssuerCiphertext,
1192 .blindingFactor = blindingFactor,
1199 Env env{*
this, features};
1202 MPTTester mptAlice(env, alice, {.holders = {bob}});
1206 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1209 mptAlice.authorize({
1212 mptAlice.pay(alice, bob, 100);
1214 mptAlice.generateKeyPair(alice);
1216 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1218 mptAlice.generateKeyPair(bob);
1223 .holderPubKey = mptAlice.getPubKey(bob),
1230 Env env{*
this, features};
1233 MPTTester mptAlice(env, alice, {.holders = {bob}});
1237 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1240 mptAlice.authorize({
1243 mptAlice.pay(alice, bob, 100);
1245 mptAlice.generateKeyPair(alice);
1247 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1249 mptAlice.generateKeyPair(bob);
1251 mptAlice.convert({.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob)});
1257 .holderPubKey = mptAlice.getPubKey(bob),
1264 Env env{*
this, features};
1267 MPTTester mptAlice(env, alice, {.holders = {bob}});
1271 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1274 mptAlice.authorize({
1277 mptAlice.pay(alice, bob, 100);
1279 mptAlice.generateKeyPair(alice);
1281 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1289 mptAlice.generateKeyPair(bob);
1294 .holderPubKey = mptAlice.getPubKey(bob),
1301 .flags = tfMPTUnlock,
1307 .holderPubKey = mptAlice.getPubKey(bob),
1313 Env env{*
this, features};
1316 MPTTester mptAlice(env, alice, {.holders = {bob}});
1320 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth |
1321 tfMPTCanHoldConfidentialBalance,
1324 mptAlice.authorize({
1327 mptAlice.authorize({
1331 mptAlice.pay(alice, bob, 100);
1333 mptAlice.generateKeyPair(alice);
1335 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1337 mptAlice.generateKeyPair(bob);
1340 mptAlice.authorize({
1343 .flags = tfMPTUnauthorize,
1349 .holderPubKey = mptAlice.getPubKey(bob),
1354 mptAlice.authorize({
1362 .holderPubKey = mptAlice.getPubKey(bob),
1368 Env env{*
this, features};
1371 MPTTester mptAlice(env, alice, {.holders = {bob}});
1375 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1378 mptAlice.authorize({
1381 mptAlice.pay(alice, bob, 100);
1383 mptAlice.generateKeyPair(alice);
1385 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1394 mptAlice.generateKeyPair(bob);
1400 .holderPubKey = mptAlice.getPubKey(bob),
1407 Env env{*
this, features};
1410 MPTTester mptAlice(env, alice, {.holders = {bob}});
1414 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth |
1415 tfMPTCanHoldConfidentialBalance,
1418 mptAlice.authorize({
1421 mptAlice.authorize({
1425 mptAlice.pay(alice, bob, 100);
1427 mptAlice.generateKeyPair(alice);
1429 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1431 mptAlice.generateKeyPair(bob);
1434 mptAlice.authorize({
1437 .flags = tfMPTUnauthorize,
1444 .holderPubKey = mptAlice.getPubKey(bob),
1452 Env env{*
this, features};
1455 Account const auditor(
"auditor");
1466 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1469 mptAlice.authorize({
1472 mptAlice.pay(alice, bob, 100);
1474 mptAlice.generateKeyPair(alice);
1475 mptAlice.generateKeyPair(bob);
1476 mptAlice.generateKeyPair(auditor);
1480 .issuerPubKey = mptAlice.getPubKey(alice),
1481 .auditorPubKey = mptAlice.getPubKey(auditor),
1488 .fillAuditorEncryptedAmt =
false,
1489 .holderPubKey = mptAlice.getPubKey(bob),
1497 Env env{*
this, features};
1500 MPTTester mptAlice(env, alice, {.holders = {bob}});
1504 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1507 mptAlice.authorize({
1510 mptAlice.pay(alice, bob, 100);
1512 mptAlice.generateKeyPair(alice);
1513 mptAlice.generateKeyPair(bob);
1516 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1521 .holderPubKey = mptAlice.getPubKey(bob),
1530 Env env{*
this, features};
1533 Account const auditor(
"auditor");
1543 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1546 mptAlice.authorize({
1549 mptAlice.pay(alice, bob, 100);
1551 mptAlice.generateKeyPair(alice);
1552 mptAlice.generateKeyPair(bob);
1553 mptAlice.generateKeyPair(auditor);
1557 .issuerPubKey = mptAlice.getPubKey(alice),
1558 .auditorPubKey = mptAlice.getPubKey(auditor),
1564 .holderPubKey = mptAlice.getPubKey(bob),
1572 Env env{*
this, features};
1575 MPTTester mptAlice(env, alice, {.holders = {bob}});
1579 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1582 mptAlice.authorize({
1585 mptAlice.pay(alice, bob, 100);
1587 mptAlice.generateKeyPair(alice);
1588 mptAlice.generateKeyPair(bob);
1590 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1596 .holderPubKey = mptAlice.getPubKey(bob),
1603 Env env{*
this, features};
1606 MPTTester mptAlice(env, alice, {.holders = {bob}});
1610 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1613 mptAlice.authorize({
1616 mptAlice.pay(alice, bob, 100);
1618 mptAlice.generateKeyPair(alice);
1619 mptAlice.generateKeyPair(bob);
1621 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1633 Env env{*
this, features};
1636 MPTTester mptAlice(env, alice, {.holders = {bob}});
1640 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1643 mptAlice.authorize({
1646 mptAlice.pay(alice, bob, 100);
1648 mptAlice.generateKeyPair(alice);
1650 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1652 mptAlice.generateKeyPair(bob);
1658 .holderPubKey = mptAlice.getPubKey(bob),
1661 env.require(MptBalance(mptAlice, bob, 0));
1680 Env env{*
this, features};
1683 MPTTester mptAlice(env, alice, {.holders = {bob}});
1687 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1689 mptAlice.authorize({.account = bob});
1690 mptAlice.pay(alice, bob, 100);
1692 mptAlice.generateKeyPair(alice);
1693 mptAlice.generateKeyPair(bob);
1696 .issuerPubKey = mptAlice.getPubKey(alice),
1702 .holderPubKey = mptAlice.getPubKey(bob),
1705 mptAlice.mergeInbox({.account = bob});
1707 mptAlice.mergeInbox({.account = bob});
1713 Env env{*
this, features};
1716 MPTTester mptAlice(env, alice, {.holders = {bob}});
1720 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1722 mptAlice.authorize({.account = bob});
1723 mptAlice.pay(alice, bob, 100);
1725 mptAlice.generateKeyPair(alice);
1726 mptAlice.generateKeyPair(bob);
1729 .issuerPubKey = mptAlice.getPubKey(alice),
1735 .holderPubKey = mptAlice.getPubKey(bob),
1741 auto const jt = env.jt(mptAlice.mergeInboxJV({.account = bob}));
1743 auto const sle = std::const_pointer_cast<SLE>(
1744 view.read(keylet::mptoken(mptAlice.issuanceID(), bob.id())));
1748 (*sle)[sfConfidentialBalanceVersion] = wrappedFrom;
1749 view.rawReplace(sle);
1751 auto const result = xrpl::apply(env.app(), view, *jt.stx, TapNone, env.journal);
1752 BEAST_EXPECT(result.ter == tesSUCCESS);
1753 return result.applied;
1756 BEAST_EXPECT(mptAlice.getMPTokenVersion(bob) == 0);
1765 Env env{*
this, features};
1768 MPTTester mptAlice(env, alice, {.holders = {bob}});
1772 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1775 mptAlice.authorize({
1778 mptAlice.pay(alice, bob, 100);
1780 mptAlice.generateKeyPair(alice);
1782 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1784 mptAlice.generateKeyPair(bob);
1789 .holderPubKey = mptAlice.getPubKey(bob),
1792 mptAlice.mergeInbox({
1797 env.disableFeature(featureConfidentialTransfer);
1800 mptAlice.mergeInbox({
1814 Env env{*
this, features};
1817 MPTTester mptAlice(env, alice, {.holders = {bob}});
1821 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1824 mptAlice.authorize({
1827 mptAlice.generateKeyPair(alice);
1829 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1832 mptAlice.generateKeyPair(bob);
1834 mptAlice.mergeInbox({
1842 Env env{*
this, features};
1845 MPTTester mptAlice(env, alice, {.holders = {bob}});
1849 .flags = tfMPTCanTransfer | tfMPTCanLock,
1852 mptAlice.authorize({
1855 mptAlice.pay(alice, bob, 100);
1857 mptAlice.generateKeyPair(alice);
1858 mptAlice.generateKeyPair(bob);
1860 mptAlice.mergeInbox({
1868 Env env{*
this, features};
1871 MPTTester mptAlice(env, alice, {.holders = {bob}});
1875 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1878 mptAlice.generateKeyPair(alice);
1880 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1882 mptAlice.mergeInbox({
1890 Env env{*
this, features};
1893 MPTTester mptAlice(env, alice, {.holders = {bob}});
1897 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1900 mptAlice.authorize({
1903 mptAlice.pay(alice, bob, 100);
1905 mptAlice.generateKeyPair(alice);
1907 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1909 mptAlice.generateKeyPair(bob);
1911 mptAlice.mergeInbox({
1919 Env env{*
this, features};
1922 MPTTester mptAlice(env, alice, {.holders = {bob}});
1926 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
1929 mptAlice.authorize({
1932 mptAlice.pay(alice, bob, 100);
1934 mptAlice.generateKeyPair(alice);
1935 mptAlice.generateKeyPair(bob);
1937 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
1942 .holderPubKey = mptAlice.getPubKey(bob),
1952 mptAlice.mergeInbox({
1961 .flags = tfMPTUnlock,
1965 mptAlice.mergeInbox({
1972 Env env{*
this, features};
1975 MPTTester mptAlice(env, alice, {.holders = {bob}});
1979 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance |
1983 mptAlice.authorize({
1986 mptAlice.authorize({
1990 mptAlice.pay(alice, bob, 100);
1992 mptAlice.generateKeyPair(alice);
1993 mptAlice.generateKeyPair(bob);
1995 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
2000 .holderPubKey = mptAlice.getPubKey(bob),
2004 mptAlice.authorize({
2007 .flags = tfMPTUnauthorize,
2010 mptAlice.mergeInbox({
2016 mptAlice.authorize({
2022 mptAlice.mergeInbox({
2031 testcase(
"test confidential send");
2033 Env env{*
this, features};
2034 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
2039 {.account = bob, .payAmount = 100, .convertAmount = 60},
2040 {.account = carol, .payAmount = 50, .convertAmount = 20},
2042 auto& mptAlice = confEnv.
mpt;
2058 mptAlice.mergeInbox({
2073 testcase(
"test confidential send with auditor");
2075 Env env{*
this, features};
2079 Account const auditor(
"auditor");
2084 {.account = bob, .payAmount = 100, .convertAmount = 60},
2085 {.account = carol, .payAmount = 50, .convertAmount = 20},
2087 tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
2089 auto& mptAlice = confEnv.
mpt;
2105 mptAlice.mergeInbox({
2120 testcase(
"test ConfidentialMPTSend Preflight");
2125 Env env{*
this, features - featureConfidentialTransfer};
2129 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
2132 mptAlice.authorize({
2135 mptAlice.authorize({
2152 Env env{*
this, features};
2156 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
2160 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
2163 mptAlice.authorize({
2166 mptAlice.authorize({
2169 mptAlice.generateKeyPair(alice);
2170 mptAlice.generateKeyPair(bob);
2171 mptAlice.generateKeyPair(carol);
2172 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
2173 mptAlice.pay(alice, bob, 100);
2174 mptAlice.pay(alice, carol, 50);
2179 .holderPubKey = mptAlice.getPubKey(bob),
2185 .holderPubKey = mptAlice.getPubKey(carol),
2218 .senderEncryptedAmt = gMakeZeroBuffer(10),
2227 .destEncryptedAmt = gMakeZeroBuffer(10),
2236 .issuerEncryptedAmt = gMakeZeroBuffer(10),
2293 .amountCommitment = gMakeZeroBuffer(100),
2305 .balanceCommitment = gMakeZeroBuffer(100),
2334 Env env{*
this, features};
2338 Account const auditor(
"auditor");
2343 .holders = {bob, carol},
2349 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
2352 mptAlice.authorize({
2355 mptAlice.authorize({
2358 mptAlice.generateKeyPair(alice);
2359 mptAlice.generateKeyPair(bob);
2360 mptAlice.generateKeyPair(carol);
2361 mptAlice.generateKeyPair(auditor);
2365 .issuerPubKey = mptAlice.getPubKey(alice),
2366 .auditorPubKey = mptAlice.getPubKey(auditor),
2368 mptAlice.pay(alice, bob, 100);
2369 mptAlice.pay(alice, carol, 50);
2374 .holderPubKey = mptAlice.getPubKey(bob),
2380 .holderPubKey = mptAlice.getPubKey(carol),
2389 .auditorEncryptedAmt = gMakeZeroBuffer(10),
2412 testcase(
"test ConfidentialMPTSend Preclaim");
2415 Env env{*
this, features};
2421 MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave, eve}});
2425 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth |
2426 tfMPTCanHoldConfidentialBalance,
2428 mptAlice.authorize({
2431 mptAlice.authorize({
2435 mptAlice.authorize({
2438 mptAlice.authorize({
2442 mptAlice.authorize({
2445 mptAlice.authorize({
2451 mptAlice.pay(alice, bob, 100);
2452 mptAlice.pay(alice, carol, 50);
2454 mptAlice.generateKeyPair(alice);
2455 mptAlice.generateKeyPair(bob);
2456 mptAlice.generateKeyPair(carol);
2457 mptAlice.generateKeyPair(dave);
2458 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
2464 .holderPubKey = mptAlice.getPubKey(bob),
2470 .holderPubKey = mptAlice.getPubKey(carol),
2475 mptAlice.mergeInbox({
2478 mptAlice.mergeInbox({
2484 Env env{*
this, features};
2488 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
2491 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
2493 mptAlice.authorize({
2496 mptAlice.authorize({
2499 mptAlice.generateKeyPair(alice);
2500 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
2506 jv[jss::Account] = bob.human();
2507 jv[jss::Destination] = carol.human();
2508 jv[jss::TransactionType] = jss::ConfidentialMPTSend;
2509 jv[sfMPTokenIssuanceID] =
to_string(mptAlice.issuanceID());
2522 Account const unknown(
"unknown");
2539 env(fset(carol, asfRequireDest));
2555 env(fclear(carol, asfRequireDest));
2619 .flags = tfMPTUnlock,
2647 .flags = tfMPTUnlock,
2675 .flags = tfMPTUnlock,
2688 mptAlice.authorize({
2691 .flags = tfMPTUnauthorize,
2700 mptAlice.authorize({
2715 mptAlice.authorize({
2718 .flags = tfMPTUnauthorize,
2727 mptAlice.authorize({
2741 Env env{*
this, features};
2749 {.account = bob, .payAmount = 100, .convertAmount = 60},
2750 {.account = carol, .payAmount = 50, .convertAmount = 20},
2752 tfMPTCanLock | tfMPTCanHoldConfidentialBalance};
2753 auto& mptAlice = confEnv.
mpt;
2767 Env env{*
this, features};
2775 {.account = bob, .payAmount = 100, .convertAmount = 60},
2776 {.account = carol, .payAmount = 50, .convertAmount = 20},
2778 auto& mptAlice = confEnv.
mpt;
2781 auto const issuance = std::const_pointer_cast<SLE>(
2782 view.read(keylet::mptokenIssuance(mptAlice.issuanceID())));
2786 issuance->setFieldU16(sfTransferFee, 1);
2787 view.rawReplace(issuance);
2802 Env env{*
this, features};
2810 {.account = bob, .payAmount = 100, .convertAmount = 60},
2811 {.account = carol, .payAmount = 50, .convertAmount = 20},
2813 auto& mptAlice = confEnv.
mpt;
2838 Env env{*
this, features};
2842 Account const auditor(
"auditor");
2847 .holders = {bob, carol},
2853 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
2856 mptAlice.authorize({
2859 mptAlice.authorize({
2862 mptAlice.generateKeyPair(alice);
2863 mptAlice.generateKeyPair(bob);
2864 mptAlice.generateKeyPair(carol);
2865 mptAlice.generateKeyPair(auditor);
2869 .issuerPubKey = mptAlice.getPubKey(alice),
2870 .auditorPubKey = mptAlice.getPubKey(auditor),
2872 mptAlice.pay(alice, bob, 100);
2873 mptAlice.pay(alice, carol, 50);
2878 .holderPubKey = mptAlice.getPubKey(bob),
2884 .holderPubKey = mptAlice.getPubKey(carol),
2903 testcase(
"test ConfidentialMPTSend Range Proof");
2906 Env env{*
this, features};
2907 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
2912 {.account = bob, .payAmount = 1000, .convertAmount = 60},
2913 {.account = carol, .payAmount = 1000, .convertAmount = 50},
2915 auto& mptAlice = confEnv.
mpt;
2933 mptAlice.mergeInbox({
2957 Env env2{*
this, features};
2958 Account const alice2(
"alice"), bob2(
"bob"), carol2(
"carol");
2963 {.account = bob2, .payAmount = 100, .convertAmount = 0},
2964 {.account = carol2, .payAmount = 50, .convertAmount = 0},
2966 auto& mptAlice2 = zeroEnv.
mpt;
2975 mptAlice2.getDecryptedBalance(bob2, MPTTester::holderEncryptedSpending) == 0);
2989 testcase(
"Send: zero amount — equality and range proof verifier behavior");
2992 Env env{*
this, features};
2996 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
3000 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3002 mptAlice.authorize({.account = bob});
3003 mptAlice.authorize({.account = carol});
3004 mptAlice.pay(alice, bob, 100);
3005 mptAlice.pay(alice, carol, 50);
3007 mptAlice.generateKeyPair(alice);
3008 mptAlice.generateKeyPair(bob);
3009 mptAlice.generateKeyPair(carol);
3011 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3013 mptAlice.convert({.account = bob, .amt = 100, .holderPubKey = mptAlice.getPubKey(bob)});
3014 mptAlice.mergeInbox({.account = bob});
3016 mptAlice.convert({.account = carol, .amt = 50, .holderPubKey = mptAlice.getPubKey(carol)});
3017 mptAlice.mergeInbox({.account = carol});
3032 .senderEncryptedAmt = mptAlice.encryptAmount(bob, 0, bf),
3033 .destEncryptedAmt = mptAlice.encryptAmount(carol, 0, bf),
3034 .issuerEncryptedAmt = mptAlice.encryptAmount(alice, 0, bf),
3050 .senderEncryptedAmt = mptAlice.encryptAmount(bob, 0, bf2),
3051 .destEncryptedAmt = mptAlice.encryptAmount(carol, 0, bf2),
3052 .issuerEncryptedAmt = mptAlice.encryptAmount(alice, 0, bf2),
3059 BEAST_EXPECT(mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
3060 BEAST_EXPECT(mptAlice.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
3071 Env env{*
this, features};
3074 MPTTester mptAlice(env, alice, {.holders = {bob}});
3078 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3081 mptAlice.authorize({
3084 mptAlice.pay(alice, bob, 100);
3086 mptAlice.generateKeyPair(alice);
3088 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3090 mptAlice.generateKeyPair(bob);
3095 .holderPubKey = mptAlice.getPubKey(bob),
3098 mptAlice.authorize({
3100 .flags = tfMPTUnauthorize,
3107 Env env{*
this, features};
3111 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
3115 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3118 mptAlice.authorize({
3121 mptAlice.authorize({
3124 mptAlice.pay(alice, bob, 100);
3126 mptAlice.generateKeyPair(alice);
3128 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3130 mptAlice.generateKeyPair(bob);
3131 mptAlice.generateKeyPair(carol);
3136 .holderPubKey = mptAlice.getPubKey(bob),
3142 .holderPubKey = mptAlice.getPubKey(carol),
3146 mptAlice.authorize({
3148 .flags = tfMPTUnauthorize,
3155 Env env{*
this, features};
3158 MPTTester mptAlice(env, alice, {.holders = {bob}});
3162 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3165 mptAlice.authorize({
3168 mptAlice.generateKeyPair(alice);
3170 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3172 mptAlice.generateKeyPair(bob);
3177 .holderPubKey = mptAlice.getPubKey(bob),
3180 mptAlice.authorize({
3182 .flags = tfMPTUnauthorize,
3189 Env env{*
this, features};
3192 MPTTester mptAlice(env, alice, {.holders = {bob}});
3196 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3199 mptAlice.authorize({
3202 mptAlice.generateKeyPair(alice);
3204 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3206 mptAlice.generateKeyPair(bob);
3211 .holderPubKey = mptAlice.getPubKey(bob),
3216 mptAlice.authorize({
3218 .flags = tfMPTUnauthorize,
3224 Env env{*
this, features};
3228 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 100}}};
3229 auto& mptAlice = confEnv.
mpt;
3236 mptAlice.pay(bob, alice, 100);
3239 mptAlice.authorize({
3241 .flags = tfMPTUnauthorize,
3248 Env env{*
this, features | featureSingleAssetVault};
3249 Account const issuer(
"issuer");
3251 Account const depositor(
"depositor");
3253 MPTTester mptt{env, issuer, {.holders = {owner, depositor}}};
3255 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback,
3257 PrettyAsset
const asset = mptt.issuanceID();
3258 mptt.authorize({.account = owner});
3259 mptt.authorize({.account = depositor});
3260 env(pay(issuer, depositor, asset(1000)));
3264 auto [tx, vaultKeylet] = vault.create({.owner = owner, .asset = asset});
3269 auto const vaultSle = env.le(vaultKeylet);
3270 BEAST_EXPECT(vaultSle !=
nullptr);
3271 auto const share = vaultSle->at(sfShareMPTID);
3275 {.depositor = depositor, .id = vaultKeylet.key, .amount = asset(100)});
3281 BEAST_EXPECT(shareMpt !=
nullptr);
3289 auto const issuance =
3293 issuance->setFlag(lsfMPTCanHoldConfidentialBalance);
3307 sle->setFieldVL(sfConfidentialBalanceSpending, dummyCiphertext);
3308 sle->setFieldVL(sfConfidentialBalanceInbox, dummyCiphertext);
3309 sle->setFieldVL(sfIssuerEncryptedBalance, dummyCiphertext);
3315 tx = vault.withdraw(
3316 {.depositor = depositor, .id = vaultKeylet.key, .amount = asset(100)});
3322 BEAST_EXPECT(shareMpt !=
nullptr);
3334 Env env{*
this, features};
3338 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 40}}};
3339 auto& mptAlice = confEnv.
mpt;
3346 mptAlice.convertBack({
3354 Env env{*
this, features};
3358 env, alice, {{.account = bob, .payAmount = 2, .convertAmount = 2}}};
3359 auto& mptAlice = confEnv.
mpt;
3373 Env env{*
this, features};
3376 MPTTester mptAlice(env, alice, {.holders = {bob}});
3380 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3383 mptAlice.authorize({
3388 mptAlice.generateKeyPair(alice);
3389 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3391 mptAlice.generateKeyPair(bob);
3395 auto const convertHolderCiphertext =
3397 auto const convertIssuerCiphertext =
3399 auto const convertContextHash =
3402 mptAlice.getSchnorrProof(bob, convertContextHash),
"Missing schnorr proof");
3406 jv[jss::Account] = bob.human();
3407 jv[jss::TransactionType] = jss::ConfidentialMPTConvert;
3408 jv[sfMPTokenIssuanceID] =
to_string(mptAlice.issuanceID());
3410 jv[sfHolderEncryptionKey.jsonName] =
3412 jv[sfHolderEncryptedAmount.jsonName] =
strHex(convertHolderCiphertext);
3413 jv[sfIssuerEncryptedAmount.jsonName] =
strHex(convertIssuerCiphertext);
3414 jv[sfBlindingFactor.jsonName] =
strHex(convertBlindingFactor);
3415 jv[sfZKProof.jsonName] =
strHex(schnorrProof);
3423 jv[jss::Account] = bob.human();
3424 jv[jss::TransactionType] = jss::ConfidentialMPTMergeInbox;
3425 jv[sfMPTokenIssuanceID] =
to_string(mptAlice.issuanceID());
3436 auto const convertBackHolderCiphertext =
3437 mptAlice.encryptAmount(bob, convertBackAmt, convertBackBlindingFactor);
3438 auto const convertBackIssuerCiphertext =
3439 mptAlice.encryptAmount(alice, convertBackAmt, convertBackBlindingFactor);
3443 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
3444 "Missing encrypted spending balance");
3448 Buffer const pedersenCommitment =
3452 auto const version = mptAlice.getMPTokenVersion(bob);
3453 UInt256 const convertBackContextHash =
3456 auto const proof = mptAlice.getConvertBackProof(
3459 convertBackContextHash,
3461 .pedersenCommitment = pedersenCommitment,
3463 .encryptedAmt = encryptedSpendingBalance,
3464 .blindingFactor = pcBlindingFactor,
3466 if (!BEAST_EXPECT(proof.has_value()))
3471 jv[jss::Account] = bob.human();
3472 jv[jss::TransactionType] = jss::ConfidentialMPTConvertBack;
3473 jv[sfMPTokenIssuanceID] =
to_string(mptAlice.issuanceID());
3475 jv[sfHolderEncryptedAmount.jsonName] =
strHex(convertBackHolderCiphertext);
3476 jv[sfIssuerEncryptedAmount.jsonName] =
strHex(convertBackIssuerCiphertext);
3477 jv[sfBlindingFactor.jsonName] =
strHex(convertBackBlindingFactor);
3478 jv[sfBalanceCommitment.jsonName] =
strHex(pedersenCommitment);
3485 env.require(MptBalance(mptAlice, bob, convertBackAmt));
3492 testcase(
"Convert back with auditor");
3495 Env env{*
this, features};
3498 Account const auditor(
"auditor");
3502 {{.account = bob, .payAmount = 100, .convertAmount = 40}},
3503 tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3505 auto& mptAlice = confEnv.
mpt;
3516 testcase(
"Convert back preflight");
3520 Env env{*
this, features - featureConfidentialTransfer};
3523 MPTTester mptAlice(env, alice, {.holders = {bob}});
3527 .flags = tfMPTCanTransfer | tfMPTCanLock,
3530 mptAlice.authorize({
3533 mptAlice.pay(alice, bob, 100);
3535 mptAlice.generateKeyPair(alice);
3536 mptAlice.generateKeyPair(bob);
3538 mptAlice.convertBack({
3546 Env env{*
this, features};
3550 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 40}}};
3551 auto& mptAlice = confEnv.
mpt;
3559 mptAlice.convertBack({
3565 mptAlice.convertBack({
3572 mptAlice.convertBack({
3579 mptAlice.convertBack({
3582 .holderEncryptedAmt =
Buffer{},
3586 mptAlice.convertBack({
3589 .issuerEncryptedAmt =
Buffer{},
3593 mptAlice.convertBack({
3600 mptAlice.convertBack({
3607 mptAlice.convertBack({
3610 .auditorEncryptedAmt = gMakeZeroBuffer(10),
3614 mptAlice.convertBack({
3622 mptAlice.convertBack({
3629 mptAlice.convertBack({
3632 .proof = gMakeZeroBuffer(100),
3646 Env env{*
this, features};
3649 MPTTester mptAlice(env, alice, {.holders = {bob}});
3653 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3656 mptAlice.authorize({
3659 mptAlice.generateKeyPair(alice);
3661 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3664 mptAlice.generateKeyPair(bob);
3666 mptAlice.convertBack({
3675 Env env{*
this, features};
3678 MPTTester mptAlice(env, alice, {.holders = {bob}});
3682 .flags = tfMPTCanTransfer | tfMPTCanLock,
3685 mptAlice.authorize({
3688 mptAlice.pay(alice, bob, 100);
3690 mptAlice.generateKeyPair(alice);
3691 mptAlice.generateKeyPair(bob);
3693 mptAlice.convertBack({
3702 Env env{*
this, features};
3705 MPTTester mptAlice(env, alice, {.holders = {bob}});
3709 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3712 mptAlice.generateKeyPair(alice);
3713 mptAlice.generateKeyPair(bob);
3715 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3717 mptAlice.convertBack({
3726 Env env{*
this, features};
3729 MPTTester mptAlice(env, alice, {.holders = {bob}});
3733 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
3736 mptAlice.authorize({
3740 mptAlice.pay(alice, bob, 100);
3741 mptAlice.generateKeyPair(alice);
3742 mptAlice.generateKeyPair(bob);
3743 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3746 auto const sleBobMpt = env.le(
keylet::mptoken(mptAlice.issuanceID(), bob.id()));
3747 BEAST_EXPECT(sleBobMpt);
3748 BEAST_EXPECT(!sleBobMpt->isFieldPresent(sfHolderEncryptionKey));
3749 BEAST_EXPECT(!sleBobMpt->isFieldPresent(sfConfidentialBalanceSpending));
3750 BEAST_EXPECT(!sleBobMpt->isFieldPresent(sfIssuerEncryptedBalance));
3752 mptAlice.convertBack({
3761 Env env{*
this, features};
3765 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
3769 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3772 mptAlice.authorize({
3775 mptAlice.authorize({
3778 mptAlice.pay(alice, bob, 100);
3779 mptAlice.pay(alice, carol, 100);
3781 mptAlice.generateKeyPair(alice);
3783 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3785 mptAlice.generateKeyPair(bob);
3786 mptAlice.generateKeyPair(carol);
3791 .holderPubKey = mptAlice.getPubKey(bob),
3794 mptAlice.mergeInbox({
3801 .holderPubKey = mptAlice.getPubKey(carol),
3804 mptAlice.convertBack({
3813 Env env{*
this, features};
3816 MPTTester mptAlice(env, alice, {.holders = {bob}});
3820 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth |
3821 tfMPTCanHoldConfidentialBalance,
3824 mptAlice.authorize({
3827 mptAlice.authorize({
3831 mptAlice.pay(alice, bob, 100);
3833 mptAlice.generateKeyPair(alice);
3835 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
3837 mptAlice.generateKeyPair(bob);
3842 .holderPubKey = mptAlice.getPubKey(bob),
3845 mptAlice.mergeInbox({
3855 mptAlice.convertBack({
3864 .flags = tfMPTUnlock,
3867 mptAlice.convertBack({
3872 mptAlice.authorize({
3875 .flags = tfMPTUnauthorize,
3878 mptAlice.convertBack({
3884 mptAlice.authorize({
3889 mptAlice.convertBack({
3897 Env env{*
this, features};
3901 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 50}}};
3902 auto& mptAlice = confEnv.
mpt;
3915 mptAlice.convertBack({
3926 Env env{*
this, features};
3930 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 50}}};
3931 auto& mptAlice = confEnv.
mpt;
3944 Env env{*
this, features};
3947 Account const auditor(
"auditor");
3951 {{.account = bob, .payAmount = 100, .convertAmount = 50}},
3952 tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
3954 auto& mptAlice = confEnv.
mpt;
3960 .fillAuditorEncryptedAmt =
false,
3966 mptAlice.convertBack({
3978 testcase(
"test ConfidentialMPTClawback");
3981 Env env{*
this, features};
3986 MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave}});
3989 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback |
3990 tfMPTCanHoldConfidentialBalance,
3992 mptAlice.authorize({
3995 mptAlice.pay(alice, bob, 100);
3996 mptAlice.authorize({
3999 mptAlice.pay(alice, carol, 200);
4000 mptAlice.authorize({
4003 mptAlice.pay(alice, dave, 300);
4005 mptAlice.generateKeyPair(alice);
4006 mptAlice.generateKeyPair(bob);
4007 mptAlice.generateKeyPair(carol);
4008 mptAlice.generateKeyPair(dave);
4009 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
4015 mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)});
4018 mptAlice.mergeInbox({
4028 {.account = carol, .amt = 120, .holderPubKey = mptAlice.getPubKey(carol)});
4031 mptAlice.mergeInbox({
4039 mptAlice.convert({.account = dave, .amt = 200, .holderPubKey = mptAlice.getPubKey(dave)});
4053 auto const preBobPublicBalance = mptAlice.getBalance(bob);
4054 auto const preOutstandingAmount = mptAlice.getIssuanceOutstandingBalance();
4055 auto const preConfidentialOutstandingAmount = mptAlice.getIssuanceConfidentialBalance();
4056 BEAST_EXPECT(!env.le(
keylet::mptoken(mptAlice.issuanceID(), alice.id())));
4062 mptAlice.confidentialClaw({
4067 BEAST_EXPECT(mptAlice.getBalance(bob) == preBobPublicBalance);
4068 auto const postOutstandingAmount = mptAlice.getIssuanceOutstandingBalance();
4070 preOutstandingAmount && postOutstandingAmount &&
4071 *postOutstandingAmount == *preOutstandingAmount - 110);
4073 mptAlice.getIssuanceConfidentialBalance() == preConfidentialOutstandingAmount - 110);
4074 BEAST_EXPECT(!env.le(
keylet::mptoken(mptAlice.issuanceID(), alice.id())));
4078 mptAlice.confidentialClaw({
4086 mptAlice.confidentialClaw({
4096 testcase(
"test ConfidentialMPTClawback with auditor");
4099 Env env{*
this, features};
4104 Account const auditor(
"auditor");
4109 .holders = {bob, carol, dave},
4114 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback |
4115 tfMPTCanHoldConfidentialBalance,
4117 mptAlice.authorize({
4120 mptAlice.pay(alice, bob, 100);
4121 mptAlice.authorize({
4124 mptAlice.pay(alice, carol, 200);
4125 mptAlice.authorize({
4128 mptAlice.pay(alice, dave, 300);
4130 mptAlice.generateKeyPair(alice);
4131 mptAlice.generateKeyPair(bob);
4132 mptAlice.generateKeyPair(carol);
4133 mptAlice.generateKeyPair(dave);
4134 mptAlice.generateKeyPair(auditor);
4137 .issuerPubKey = mptAlice.getPubKey(alice),
4138 .auditorPubKey = mptAlice.getPubKey(auditor),
4145 mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)});
4148 mptAlice.mergeInbox({
4158 {.account = carol, .amt = 120, .holderPubKey = mptAlice.getPubKey(carol)});
4161 mptAlice.mergeInbox({
4169 mptAlice.convert({.account = dave, .amt = 200, .holderPubKey = mptAlice.getPubKey(dave)});
4185 mptAlice.confidentialClaw({
4193 mptAlice.confidentialClaw({
4201 mptAlice.confidentialClaw({
4211 testcase(
"ConfidentialMPTClawback context binding");
4214 auto const runBadProof = [&](
auto makeContextHash) {
4215 Env env{*
this, features};
4222 {{.account = bob, .payAmount = 100, .convertAmount = 60}},
4223 tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback |
4224 tfMPTCanHoldConfidentialBalance};
4225 auto& mptAlice = confEnv.
mpt;
4227 auto const privKey = mptAlice.
getPrivKey(alice);
4228 if (!BEAST_EXPECT(privKey.has_value()))
4231 auto const proof = mptAlice.getClawbackProof(
4235 makeContextHash(env, mptAlice, alice, bob, carol));
4236 if (!BEAST_EXPECT(proof.has_value()))
4239 mptAlice.confidentialClaw({
4249 runBadProof([&](Env& env,
4250 MPTTester
const& mpt,
4258 runBadProof([&](Env& env,
4264 alice.id(),
makeMptID(env.seq(alice) + 100, alice), env.seq(alice), bob.id());
4268 runBadProof([&](Env& env,
4269 MPTTester
const& mpt,
4274 alice.id(), mpt.issuanceID(), env.seq(alice) + 1, bob.id());
4278 runBadProof([&](Env& env,
4279 MPTTester
const& mpt,
4297 testcase(
"test ConfidentialMPTClawback Preflight");
4302 Env env{*
this, features - featureConfidentialTransfer};
4305 MPTTester mptAlice(env, alice, {.holders = {bob}});
4308 mptAlice.authorize({
4312 mptAlice.confidentialClaw({
4324 Env env{*
this, features};
4328 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
4332 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
4335 mptAlice.authorize({
4338 mptAlice.authorize({
4341 mptAlice.generateKeyPair(alice);
4342 mptAlice.generateKeyPair(bob);
4343 mptAlice.generateKeyPair(carol);
4344 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
4345 mptAlice.pay(alice, bob, 100);
4346 mptAlice.pay(alice, carol, 50);
4349 mptAlice.confidentialClaw({
4359 jv[jss::Account] = alice.human();
4360 jv[sfHolder] = bob.human();
4361 jv[jss::TransactionType] = jss::ConfidentialMPTClawback;
4363 jv[sfZKProof] =
"123";
4366 jv[sfMPTokenIssuanceID] =
"00000004AE123A8556F3CF91154711376AFB0F894F832B3E";
4372 mptAlice.confidentialClaw({
4380 mptAlice.confidentialClaw({
4388 mptAlice.confidentialClaw({
4401 testcase(
"Clawback Preclaim Errors");
4408 Env env{*
this, features};
4413 MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave}});
4416 .flags = tfMPTCanTransfer | tfMPTCanClawback | tfMPTRequireAuth |
4417 tfMPTCanHoldConfidentialBalance,
4419 mptAlice.authorize({
4422 mptAlice.authorize({
4426 mptAlice.authorize({
4429 mptAlice.authorize({
4434 mptAlice.pay(alice, bob, 100);
4435 mptAlice.pay(alice, carol, 50);
4436 mptAlice.generateKeyPair(alice);
4437 mptAlice.generateKeyPair(bob);
4438 mptAlice.generateKeyPair(carol);
4439 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
4444 .holderPubKey = mptAlice.getPubKey(bob),
4446 mptAlice.mergeInbox({
4452 Account const unknown(
"unknown");
4453 mptAlice.confidentialClaw({
4463 mptAlice.confidentialClaw({
4473 mptAlice.confidentialClaw({
4484 Env env{*
this, features};
4487 MPTTester mptAlice(env, alice, {.holders = {bob}});
4490 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
4492 mptAlice.authorize({
4495 mptAlice.generateKeyPair(alice);
4496 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
4498 mptAlice.confidentialClaw({
4508 Env env{*
this, features};
4511 MPTTester mptAlice(env, alice, {.holders = {bob}});
4513 .flags = tfMPTCanClawback | tfMPTCanHoldConfidentialBalance,
4515 mptAlice.authorize({
4518 mptAlice.generateKeyPair(alice);
4520 mptAlice.confidentialClaw({
4530 Env env{*
this, features};
4533 MPTTester mptAlice(env, alice, {.holders = {bob}});
4535 .flags = tfMPTCanClawback | tfMPTCanHoldConfidentialBalance,
4537 mptAlice.authorize({
4540 mptAlice.generateKeyPair(alice);
4541 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
4547 jv[jss::Account] = alice.human();
4548 jv[sfHolder] = bob.human();
4549 jv[jss::TransactionType] = jss::ConfidentialMPTClawback;
4552 jv[sfZKProof] = dummyProof;
4553 jv[sfMPTokenIssuanceID] =
to_string(mptAlice.issuanceID());
4559 std::uint32_t const setupFlags = tfMPTCanTransfer | tfMPTCanClawback | tfMPTRequireAuth |
4560 tfMPTCanLock | tfMPTCanHoldConfidentialBalance;
4563 auto const removeMPTokenField =
4564 [&](Env& env, MPTTester
const& mpt,
Account const& holder,
SField const& field) {
4566 auto const sle = std::const_pointer_cast<SLE>(
4567 view.read(keylet::mptoken(mpt.issuanceID(), holder.id())));
4571 sle->makeFieldAbsent(field);
4572 view.rawReplace(sle);
4581 Env env{*
this, features};
4585 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4586 auto& mptAlice = confEnv.
mpt;
4594 mptAlice.confidentialClaw({
4598 .proof = dummyClawbackProof,
4606 Env env{*
this, features};
4610 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4611 auto& mptAlice = confEnv.
mpt;
4613 removeMPTokenField(env, mptAlice, bob, sfIssuerEncryptedBalance);
4614 mptAlice.confidentialClaw({
4618 .proof = dummyClawbackProof,
4625 Env env{*
this, features};
4629 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4630 auto& mptAlice = confEnv.
mpt;
4632 removeMPTokenField(env, mptAlice, bob, sfHolderEncryptionKey);
4633 mptAlice.confidentialClaw({
4637 .proof = dummyClawbackProof,
4644 Env env{*
this, features};
4648 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4649 auto& mptAlice = confEnv.
mpt;
4657 mptAlice.confidentialClaw({
4666 Env env{*
this, features};
4670 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4671 auto& mptAlice = confEnv.
mpt;
4678 mptAlice.confidentialClaw({
4687 Env env{*
this, features};
4691 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4692 auto& mptAlice = confEnv.
mpt;
4698 .flags = tfMPTUnauthorize,
4701 mptAlice.confidentialClaw({
4711 Env env{*
this, features};
4715 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 60}}, setupFlags};
4716 auto& mptAlice = confEnv.
mpt;
4730 testcase(
"ConfidentialMPTClawback Proof");
4740 auto const setupEnv = [&](Env& env) -> MPTTester {
4741 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
4744 .flags = tfMPTCanTransfer | tfMPTCanClawback | tfMPTCanHoldConfidentialBalance,
4747 for (
auto const& [acct, amt] : {
std::pair{bob, 1000}, {carol, 2000}})
4749 mptAlice.authorize({
4752 mptAlice.pay(alice, acct, amt);
4753 mptAlice.generateKeyPair(acct);
4756 mptAlice.generateKeyPair(alice);
4757 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
4764 auto const checkBadProofs =
4766 for (
auto const badAmt : amts)
4768 mpt.confidentialClaw({
4782 Env env{*
this, features};
4783 auto mptAlice = setupEnv(env);
4786 mptAlice.convert({.account = bob, .amt = 500, .holderPubKey = mptAlice.getPubKey(bob)});
4787 mptAlice.mergeInbox({
4792 {.account = carol, .amt = 1000, .holderPubKey = mptAlice.getPubKey(carol)});
4828 mptAlice.confidentialClaw({
4833 mptAlice.confidentialClaw({
4847 Env env{*
this, features};
4848 auto mptAlice = setupEnv(env);
4850 mptAlice.convert({.account = bob, .amt = 300, .holderPubKey = mptAlice.getPubKey(bob)});
4851 mptAlice.mergeInbox({
4855 {.account = carol, .amt = 400, .holderPubKey = mptAlice.getPubKey(carol)});
4856 mptAlice.mergeInbox({
4903 mptAlice.confidentialClaw({
4908 mptAlice.confidentialClaw({
4920 Env env{*
this, features};
4921 auto mptAlice = setupEnv(env);
4923 mptAlice.convert({.account = bob, .amt = 500, .holderPubKey = mptAlice.getPubKey(bob)});
4924 mptAlice.mergeInbox({
4928 auto const privKey = mptAlice.getPrivKey(alice);
4929 if (!BEAST_EXPECT(privKey.has_value()))
4932 auto const proof = mptAlice.getClawbackProof(
4937 alice.id(), mptAlice.issuanceID(), env.seq(alice), bob.id()));
4938 if (!BEAST_EXPECT(proof.has_value()))
4944 auto const versionBefore = mptAlice.getMPTokenVersion(bob);
4945 mptAlice.mergeInbox({.account = bob});
4946 BEAST_EXPECT(mptAlice.getMPTokenVersion(bob) != versionBefore);
4949 mptAlice.confidentialClaw({
4961 testcase(
"Public transfers after clearing Confidential Flag");
4971 auto const runPublicPayments = [&](MPTTester& mpt) {
4972 mpt.pay(bob, carol, 10);
4973 mpt.pay(carol, bob, 5);
4974 mpt.pay(alice, bob, 1);
4975 mpt.pay(carol, alice, 5);
4978 auto const drainAndDeleteBobMPToken = [&](Env& env, MPTTester& mpt) {
4979 auto const bobBalance = mpt.getBalance(bob);
4980 BEAST_EXPECT(bobBalance > 0);
4982 mpt.pay(bob, alice, bobBalance);
4983 BEAST_EXPECT(mpt.getBalance(bob) == 0);
4985 mpt.authorize({.account = bob, .flags = tfMPTUnauthorize});
4992 Env env{*
this, features};
4996 {{.account = bob, .payAmount = 100, .convertAmount = 50}},
4997 tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance};
4999 env.fund(XRP(1'000), carol);
5001 ct.
mpt.
pay(alice, carol, 50);
5005 runPublicPayments(ct.
mpt);
5006 drainAndDeleteBobMPToken(env, ct.
mpt);
5011 Env env{*
this, features};
5012 Account const auditor(
"auditor");
5013 MPTTester mptAlice(env, alice, {.holders = {bob, carol}, .auditor = auditor});
5017 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
5020 mptAlice.authorize({.account = bob});
5021 mptAlice.authorize({.account = carol});
5022 mptAlice.pay(alice, bob, 100);
5023 mptAlice.pay(alice, carol, 50);
5025 mptAlice.generateKeyPair(alice);
5026 mptAlice.generateKeyPair(bob);
5027 mptAlice.generateKeyPair(auditor);
5030 .issuerPubKey = mptAlice.getPubKey(alice),
5031 .auditorPubKey = mptAlice.getPubKey(auditor),
5037 .holderPubKey = mptAlice.getPubKey(bob),
5039 mptAlice.mergeInbox({.account = bob});
5040 mptAlice.convertBack({.account = bob, .amt = 50});
5042 runPublicPayments(mptAlice);
5043 drainAndDeleteBobMPToken(env, mptAlice);
5049 Env env{*
this, features};
5053 {{.account = bob, .payAmount = 100, .convertAmount = 50}},
5054 tfMPTCanTransfer | tfMPTCanClawback | tfMPTCanHoldConfidentialBalance};
5056 env.fund(XRP(1'000), carol);
5058 ct.
mpt.
pay(alice, carol, 50);
5062 runPublicPayments(ct.
mpt);
5063 drainAndDeleteBobMPToken(env, ct.
mpt);
5070 testcase(
"mutate lsfMPTCanHoldConfidentialBalance");
5076 Env env{*
this, features - featureDynamicMPT};
5079 MPTTester mptAlice(env, alice, {.holders = {bob}});
5091 Env env{*
this, features - featureConfidentialTransfer};
5094 MPTTester mptAlice(env, alice, {.holders = {bob}});
5106 Env env{*
this, features};
5109 MPTTester mptAlice(env, alice, {.holders = {bob}});
5113 .flags = tfMPTCanTransfer,
5119 .flags = tfMPTSetCanHoldConfidentialBalance,
5126 Env env{*
this, features};
5129 MPTTester mptAlice(env, alice, {.holders = {bob}});
5133 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
5137 mptAlice.authorize({
5140 mptAlice.pay(alice, bob, 100);
5142 mptAlice.generateKeyPair(alice);
5143 mptAlice.generateKeyPair(bob);
5144 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
5146 auto holderPubKeySet =
false;
5147 auto const verifyToggle = [&](
TER expectedResult, uint64_t amt) {
5148 if (!holderPubKeySet)
5153 .holderPubKey = mptAlice.getPubKey(bob),
5154 .err = expectedResult,
5162 .err = expectedResult,
5168 holderPubKeySet =
true;
5169 mptAlice.mergeInbox({
5175 mptAlice.convertBack({
5186 .flags = tfMPTSetCanHoldConfidentialBalance,
5193 .flags = tfMPTSetCanHoldConfidentialBalance,
5201 Env env{*
this, features};
5204 MPTTester mptAlice(env, alice, {.holders = {bob}});
5210 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
5213 mptAlice.authorize({
5216 mptAlice.pay(alice, bob, 100);
5218 mptAlice.generateKeyPair(alice);
5219 mptAlice.generateKeyPair(bob);
5220 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
5223 mptAlice.convert({.account = bob, .amt = 50, .holderPubKey = mptAlice.getPubKey(bob)});
5229 .flags = tfMPTSetCanHoldConfidentialBalance,
5238 testcase(
"Convert back pedersen proof");
5241 Env env{*
this, features};
5245 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 40}}};
5246 auto& mptAlice = confEnv.
mpt;
5250 uint64_t
const amt = 10;
5255 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
5256 "Missing spending balance");
5258 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
5259 "Missing encrypted spending balance");
5260 BEAST_EXPECT(!encryptedSpendingBalance.empty());
5262 Buffer const pedersenCommitment =
5263 mptAlice.getPedersenCommitment(spendingBalance, pcBlindingFactor);
5264 Buffer const issuerCiphertext = mptAlice.encryptAmount(alice, amt, blindingFactor);
5265 Buffer const bobCiphertext = mptAlice.encryptAmount(bob, amt, blindingFactor);
5266 auto const version = mptAlice.getMPTokenVersion(bob);
5279 Buffer const badPedersenCommitment =
5280 mptAlice.getPedersenCommitment(1, pcBlindingFactor);
5281 auto const proof = mptAlice.getConvertBackProof(
5286 .pedersenCommitment = badPedersenCommitment,
5287 .amt = spendingBalance,
5288 .encryptedAmt = encryptedSpendingBalance,
5289 .blindingFactor = pcBlindingFactor,
5291 if (!BEAST_EXPECT(proof.has_value()))
5294 mptAlice.convertBack({
5298 .holderEncryptedAmt = bobCiphertext,
5299 .issuerEncryptedAmt = issuerCiphertext,
5300 .blindingFactor = blindingFactor,
5301 .pedersenCommitment = pedersenCommitment,
5313 auto const proof = mptAlice.getConvertBackProof(
5318 .pedersenCommitment = pedersenCommitment,
5319 .amt = spendingBalance,
5320 .encryptedAmt = encryptedSpendingBalance,
5323 if (!BEAST_EXPECT(proof.has_value()))
5326 mptAlice.convertBack({
5330 .holderEncryptedAmt = bobCiphertext,
5331 .issuerEncryptedAmt = issuerCiphertext,
5332 .blindingFactor = blindingFactor,
5333 .pedersenCommitment = pedersenCommitment,
5347 uint64_t
constexpr claimedBalance = 20;
5356 encryptedSpendingBalance,
5360 mptAlice.convertBack({
5364 .holderEncryptedAmt = bobCiphertext,
5365 .issuerEncryptedAmt = issuerCiphertext,
5366 .blindingFactor = blindingFactor,
5367 .pedersenCommitment = pedersenCommitment,
5379 Buffer const badPedersenCommitment =
5380 mptAlice.getPedersenCommitment(1, pcBlindingFactor);
5381 auto const proof = mptAlice.getConvertBackProof(
5386 .pedersenCommitment = pedersenCommitment,
5387 .amt = spendingBalance,
5388 .encryptedAmt = encryptedSpendingBalance,
5389 .blindingFactor = pcBlindingFactor,
5391 if (!BEAST_EXPECT(proof.has_value()))
5394 mptAlice.convertBack({
5398 .holderEncryptedAmt = bobCiphertext,
5399 .issuerEncryptedAmt = issuerCiphertext,
5400 .blindingFactor = blindingFactor,
5401 .pedersenCommitment = badPedersenCommitment,
5411 UInt256 const badContextHash{1};
5413 auto const proof = mptAlice.getConvertBackProof(
5418 .pedersenCommitment = pedersenCommitment,
5419 .amt = spendingBalance,
5420 .encryptedAmt = encryptedSpendingBalance,
5421 .blindingFactor = pcBlindingFactor,
5423 if (!BEAST_EXPECT(proof.has_value()))
5426 mptAlice.convertBack({
5430 .holderEncryptedAmt = bobCiphertext,
5431 .issuerEncryptedAmt = issuerCiphertext,
5432 .blindingFactor = blindingFactor,
5433 .pedersenCommitment = pedersenCommitment,
5444 auto const proof = mptAlice.getConvertBackProof(
5449 .pedersenCommitment = pedersenCommitment,
5450 .amt = spendingBalance,
5451 .encryptedAmt = encryptedSpendingBalance,
5452 .blindingFactor = pcBlindingFactor,
5454 if (!BEAST_EXPECT(proof.has_value()))
5457 mptAlice.convertBack({
5461 .holderEncryptedAmt = bobCiphertext,
5462 .issuerEncryptedAmt = issuerCiphertext,
5463 .blindingFactor = blindingFactor,
5464 .pedersenCommitment = pedersenCommitment,
5472 uint64_t
const balance = 100;
5480 testcase(
"Send: overdraft prevention via bulletproof");
5489 Env env{*
this, features};
5490 Account const alice(
"alice"), bob(
"bob"), issuer(
"issuer");
5492 uint64_t
const aliceBalance = balance;
5493 uint64_t
const aliceAmount = amt;
5494 uint64_t
const aliceRemaining = aliceBalance - aliceAmount;
5501 {.account = alice, .payAmount = 1000, .convertAmount = aliceBalance},
5502 {.account = bob, .payAmount = 1000, .convertAmount = 30},
5504 auto& mptIssuer = confEnv.
mpt;
5510 unsigned const numParticipants = 3;
5515 mptIssuer.getDecryptedBalance(alice, MPTTester::holderEncryptedSpending),
5516 "Missing Alice's balance");
5517 BEAST_EXPECT(balance == aliceBalance);
5529 Buffer const aliceEncAmt = mptIssuer.encryptAmount(alice, aliceAmount, randomElgamal);
5530 Buffer const bobEncAmt = mptIssuer.encryptAmount(bob, aliceAmount, randomElgamal);
5531 Buffer const issuerEncAmt = mptIssuer.encryptAmount(issuer, aliceAmount, randomElgamal);
5535 Buffer const amtCommit = mptIssuer.getPedersenCommitment(aliceAmount, randomElgamal);
5536 Buffer const balanceCommit = mptIssuer.getPedersenCommitment(aliceBalance, randomBalance);
5540 mptIssuer.getEncryptedBalance(alice, MPTTester::holderEncryptedSpending),
5541 "Missing Alice's encrypted spending balance");
5543 uint32_t
const version = mptIssuer.getMPTokenVersion(alice);
5545 alice.id(), mptIssuer.issuanceID(), env.seq(alice), bob.id(), version);
5553 auto const* ctx = mpt_secp256k1_context();
5554 Buffer sigmaProof(SECP256K1_COMPACT_STANDARD_PROOF_SIZE);
5557 secp256k1_pubkey c1, c2Alice, c2Bob, c2Issuer;
5560 if (!BEAST_EXPECTS(x == 1,
"Failed to parse C1"))
5563 x = secp256k1_ec_pubkey_parse(
5565 auto y = secp256k1_ec_pubkey_parse(
5567 auto z = secp256k1_ec_pubkey_parse(
5572 if (!BEAST_EXPECTS(x == 1 && y == 1 && z == 1,
"Failed to parse C2 components"))
5574 secp256k1_pubkey c2Vec[] = {c2Alice, c2Bob, c2Issuer};
5577 secp256k1_pubkey pkAlice, pkBob, pkIssuer;
5578 auto alicePubKey =
requireOptional(mptIssuer.getPubKey(alice),
"Missing alice pubkey");
5579 auto bobPubKey =
requireOptional(mptIssuer.getPubKey(bob),
"Missing bob pubkey");
5580 auto issuerPubKey =
requireOptional(mptIssuer.getPubKey(issuer),
"Missing issuer pubkey");
5583 z = secp256k1_ec_pubkey_parse(
5585 if (!BEAST_EXPECTS(x == 1 && y == 1 && z == 1,
"Failed to parse public keys"))
5587 secp256k1_pubkey pkVec[] = {pkAlice, pkBob, pkIssuer};
5590 secp256k1_pubkey pcAmount, pcBalance, b1, b2;
5592 y = secp256k1_ec_pubkey_parse(
5594 if (!BEAST_EXPECTS(x == 1 && y == 1,
"Failed to parse commitments"))
5598 y = secp256k1_ec_pubkey_parse(
5600 if (!BEAST_EXPECTS(x == 1 && y == 1,
"Failed to parse balance ciphertext"))
5604 auto alicePrivKey =
requireOptional(mptIssuer.getPrivKey(alice),
"Missing alice privkey");
5608 x = secp256k1_compact_standard_prove(
5613 randomElgamal.
data(),
5614 alicePrivKey.data(),
5615 randomBalance.
data(),
5626 if (!BEAST_EXPECTS(x == 1,
"Failed to generate sigma proof"))
5630 x = secp256k1_compact_standard_verify(
5643 if (!BEAST_EXPECTS(x == 1,
"Sigma verification failed"))
5651 secp256k1_mpt_scalar_negate(negRandomElgamal.
data(), randomElgamal.
data());
5652 secp256k1_mpt_scalar_add(
5653 randomRemaining.
data(), randomBalance.
data(), negRandomElgamal.
data());
5657 {aliceAmount, aliceRemaining}, {randomElgamal, randomRemaining}, ctxHash);
5661 std::memcpy(combinedProof.data(), sigmaProof.
data(), SECP256K1_COMPACT_STANDARD_PROOF_SIZE);
5663 combinedProof.data() + SECP256K1_COMPACT_STANDARD_PROOF_SIZE,
5664 forgedBulletproof.data(),
5668 x = mpt_verify_send_range_proof(
5669 combinedProof.data() + SECP256K1_COMPACT_STANDARD_PROOF_SIZE,
5671 balanceCommit.
data(),
5673 if (!BEAST_EXPECTS(x == errors.
first,
"Forged proof passed validation"))
5682 .proof =
strHex(combinedProof),
5683 .senderEncryptedAmt = aliceEncAmt,
5684 .destEncryptedAmt = bobEncAmt,
5685 .issuerEncryptedAmt = issuerEncAmt,
5686 .amountCommitment = amtCommit,
5687 .balanceCommitment = balanceCommit,
5694 mptIssuer.getDecryptedBalance(alice, MPTTester::holderEncryptedSpending),
5695 "Missing post-attack balance");
5696 if (aliceAmount > aliceBalance)
5698 BEAST_EXPECT(balance == aliceBalance);
5702 BEAST_EXPECT(balance < aliceBalance);
5710 uint64_t
const balance = 100;
5718 testcase(
"Convert back: overdraft prevention via bulletproof");
5727 Env env{*
this, features};
5728 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
5730 uint64_t
const bobBalance = balance;
5741 {.account = bob, .payAmount = 1000, .convertAmount = bobBalance},
5748 auto& mptAlice = confEnv.
mpt;
5757 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
5758 "Missing Bob's balance");
5759 BEAST_EXPECT(balance == bobBalance);
5774 Buffer const balanceCommit = mptAlice.getPedersenCommitment(bobBalance, pcBlindingFactor);
5778 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
5779 "Missing Bob's encrypted spending balance");
5781 uint32_t
const version = mptAlice.getMPTokenVersion(bob);
5782 auto const ctxHash =
5786 auto const* ctx = mpt_secp256k1_context();
5787 Buffer sigmaProof(SECP256K1_COMPACT_CONVERTBACK_PROOF_SIZE);
5790 secp256k1_pubkey pkBob;
5791 auto bobPubKey =
requireOptional(mptAlice.getPubKey(bob),
"Missing bob pubkey");
5793 if (!BEAST_EXPECTS(x == 1,
"Failed to parse Bob's public key"))
5797 secp256k1_pubkey pcBalance;
5798 x = secp256k1_ec_pubkey_parse(
5800 if (!BEAST_EXPECTS(x == 1,
"Failed to parse balance commitment"))
5804 secp256k1_pubkey b1, b2;
5806 auto const y = secp256k1_ec_pubkey_parse(
5808 if (!BEAST_EXPECTS(x == 1 && y == 1,
"Failed to parse balance ciphertext"))
5812 auto bobPrivKey =
requireOptional(mptAlice.getPrivKey(bob),
"Missing bob privkey");
5816 x = secp256k1_compact_convertback_prove(
5821 pcBlindingFactor.
data(),
5827 if (!BEAST_EXPECTS(x == 1,
"Failed to generate convertback sigma proof"))
5831 x = secp256k1_compact_convertback_verify(
5832 ctx, sigmaProof.
data(), &pkBob, &b1, &b2, &pcBalance, ctxHash.data());
5833 if (!BEAST_EXPECTS(x == 1,
"Sigma verification failed"))
5844 auto const forgedBulletproof =
5850 combinedProof.
data(), sigmaProof.
data(), SECP256K1_COMPACT_CONVERTBACK_PROOF_SIZE);
5852 combinedProof.
data() + SECP256K1_COMPACT_CONVERTBACK_PROOF_SIZE,
5853 forgedBulletproof.data(),
5857 x = mpt_verify_convert_back_proof(
5858 combinedProof.
data(),
5860 bobEncBalance.
data(),
5861 balanceCommit.
data(),
5864 if (!BEAST_EXPECTS(x == errors.
first,
"Forged proof verification mismatch"))
5869 mptAlice.convertBack({
5872 .proof = combinedProof,
5873 .holderEncryptedAmt = bobEncAmt,
5874 .issuerEncryptedAmt = issuerEncAmt,
5875 .blindingFactor = blindingFactor,
5876 .pedersenCommitment = balanceCommit,
5883 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
5884 "Missing post-attack balance");
5887 BEAST_EXPECT(postBalance == bobBalance);
5891 BEAST_EXPECT(postBalance < bobBalance);
5899 testcase(
"Convert back bulletproof");
5902 Env env{*
this, features};
5906 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 40}}};
5907 auto& mptAlice = confEnv.
mpt;
5911 uint64_t
const amt = 10;
5916 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
5917 "Missing spending balance");
5919 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
5920 "Missing encrypted spending balance");
5921 BEAST_EXPECT(!encryptedSpendingBalance.empty());
5923 Buffer const pedersenCommitment =
5924 mptAlice.getPedersenCommitment(spendingBalance, pcBlindingFactor);
5925 Buffer const issuerCiphertext = mptAlice.encryptAmount(alice, amt, blindingFactor);
5926 Buffer const bobCiphertext = mptAlice.encryptAmount(bob, amt, blindingFactor);
5927 auto const version = mptAlice.getMPTokenVersion(bob);
5943 uint64_t
constexpr claimedBalance = 20;
5952 encryptedSpendingBalance,
5956 mptAlice.convertBack({
5960 .holderEncryptedAmt = bobCiphertext,
5961 .issuerEncryptedAmt = issuerCiphertext,
5962 .blindingFactor = blindingFactor,
5963 .pedersenCommitment = pedersenCommitment,
5976 auto const proof = mptAlice.getConvertBackProof(
5981 .pedersenCommitment = pedersenCommitment,
5982 .amt = spendingBalance,
5983 .encryptedAmt = encryptedSpendingBalance,
5986 if (!BEAST_EXPECT(proof.has_value()))
5989 mptAlice.convertBack({
5993 .holderEncryptedAmt = bobCiphertext,
5994 .issuerEncryptedAmt = issuerCiphertext,
5995 .blindingFactor = blindingFactor,
5996 .pedersenCommitment = pedersenCommitment,
6006 UInt256 const badContextHash{1};
6007 auto const proof = mptAlice.getConvertBackProof(
6012 .pedersenCommitment = pedersenCommitment,
6013 .amt = spendingBalance,
6014 .encryptedAmt = encryptedSpendingBalance,
6015 .blindingFactor = pcBlindingFactor,
6017 if (!BEAST_EXPECT(proof.has_value()))
6020 mptAlice.convertBack({
6024 .holderEncryptedAmt = bobCiphertext,
6025 .issuerEncryptedAmt = issuerCiphertext,
6026 .blindingFactor = blindingFactor,
6027 .pedersenCommitment = pedersenCommitment,
6038 auto const proof = mptAlice.getConvertBackProof(
6043 .pedersenCommitment = pedersenCommitment,
6044 .amt = spendingBalance,
6045 .encryptedAmt = encryptedSpendingBalance,
6046 .blindingFactor = pcBlindingFactor,
6048 if (!BEAST_EXPECT(proof.has_value()))
6051 mptAlice.convertBack({
6055 .holderEncryptedAmt = bobCiphertext,
6056 .issuerEncryptedAmt = issuerCiphertext,
6057 .blindingFactor = blindingFactor,
6058 .pedersenCommitment = pedersenCommitment,
6070 testcase(
"ConvertBack proof context binding");
6073 auto const runBadProof = [&](
auto makeContextHash) {
6074 Env env{*
this, features};
6079 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 40}}};
6080 auto& mptAlice = confEnv.
mpt;
6086 auto const spendingBalance =
6087 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
6088 auto const encryptedSpendingBalance =
6089 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending);
6090 if (!BEAST_EXPECT(spendingBalance && encryptedSpendingBalance))
6093 Buffer const pedersenCommitment = mptAlice.getPedersenCommitment(
6094 requireOptional(spendingBalance,
"Missing spending balance"), pcBlindingFactor);
6095 Buffer const issuerCiphertext = mptAlice.encryptAmount(alice, amt, blindingFactor);
6096 Buffer const bobCiphertext = mptAlice.encryptAmount(bob, amt, blindingFactor);
6097 auto const version = mptAlice.getMPTokenVersion(bob);
6099 auto const proof = mptAlice.getConvertBackProof(
6102 makeContextHash(env, mptAlice, alice, bob, carol, version),
6104 .pedersenCommitment = pedersenCommitment,
6107 encryptedSpendingBalance,
"Missing encrypted spending balance"),
6108 .blindingFactor = pcBlindingFactor,
6110 if (!BEAST_EXPECT(proof.has_value()))
6113 mptAlice.convertBack({
6117 .holderEncryptedAmt = bobCiphertext,
6118 .issuerEncryptedAmt = issuerCiphertext,
6119 .blindingFactor = blindingFactor,
6120 .pedersenCommitment = pedersenCommitment,
6126 runBadProof([&](Env& env,
6127 MPTTester
const& mpt,
6136 runBadProof([&](Env& env,
6143 bob.id(),
makeMptID(env.seq(alice) + 100, alice), env.seq(bob), version);
6147 runBadProof([&](Env& env,
6148 MPTTester
const& mpt,
6157 runBadProof([&](Env& env,
6158 MPTTester
const& mpt,
6175 testcase(
"ConvertBack: proof ciphertext binding");
6178 Env env{*
this, features};
6179 Account const alice(
"alice"), bob(
"bob");
6181 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 50}}};
6182 auto& mptAlice = confEnv.
mpt;
6185 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
6186 "Missing spending balance");
6188 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
6189 "Missing encrypted spending balance");
6190 auto const version = mptAlice.getMPTokenVersion(bob);
6192 Buffer const pedersenCommitment =
6193 mptAlice.getPedersenCommitment(spendingBalance, pcBlindingFactor);
6196 uint64_t
const amtA = 10;
6197 uint32_t
const currentSeq = env.seq(bob);
6201 auto const proofA = mptAlice.getConvertBackProof(
6206 .pedersenCommitment = pedersenCommitment,
6207 .amt = spendingBalance,
6208 .encryptedAmt = encryptedSpendingBalance,
6209 .blindingFactor = pcBlindingFactor,
6211 if (!BEAST_EXPECT(proofA.has_value()))
6215 uint64_t
const amtB = 20;
6217 Buffer const bobCiphertextB = mptAlice.encryptAmount(bob, amtB, blindingFactorB);
6218 Buffer const issuerCiphertextB = mptAlice.encryptAmount(alice, amtB, blindingFactorB);
6221 mptAlice.convertBack({
6225 .holderEncryptedAmt = bobCiphertextB,
6226 .issuerEncryptedAmt = issuerCiphertextB,
6227 .blindingFactor = blindingFactorB,
6228 .pedersenCommitment = pedersenCommitment,
6240 testcase(
"ConvertBack: proof version mismatch");
6243 Env env{*
this, features};
6244 Account const alice(
"alice"), bob(
"bob");
6246 env, alice, {{.account = bob, .payAmount = 1000, .convertAmount = 100}}};
6247 auto& mptAlice = confEnv.
mpt;
6251 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
6252 "Missing spending balance");
6254 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
6255 "Missing encrypted spending balance");
6258 uint64_t
const amt = 10;
6261 Buffer const pedersenCommitment =
6262 mptAlice.getPedersenCommitment(spendingBalanceV, pcBlindingFactor);
6263 Buffer const issuerCiphertext = mptAlice.encryptAmount(alice, amt, blindingFactor);
6264 Buffer const bobCiphertext = mptAlice.encryptAmount(bob, amt, blindingFactor);
6272 mptAlice.mergeInbox({
6276 BEAST_EXPECT(mptAlice.getMPTokenVersion(bob) > versionV);
6279 uint32_t
const currentSeq = env.seq(bob);
6281 UInt256 const oldContextHash =
6284 auto const oldProof = mptAlice.getConvertBackProof(
6289 .pedersenCommitment = pedersenCommitment,
6290 .amt = spendingBalanceV,
6291 .encryptedAmt = encryptedSpendingBalanceV,
6292 .blindingFactor = pcBlindingFactor,
6294 if (!BEAST_EXPECT(oldProof.has_value()))
6298 mptAlice.convertBack({
6302 .holderEncryptedAmt = bobCiphertext,
6303 .issuerEncryptedAmt = issuerCiphertext,
6304 .blindingFactor = blindingFactor,
6305 .pedersenCommitment = pedersenCommitment,
6318 testcase(
"ConvertBack: homomorphic ciphertext modification");
6321 Env env{*
this, features};
6322 Account const alice(
"alice"), bob(
"bob");
6324 env, alice, {{.account = bob, .payAmount = 100, .convertAmount = 50}}};
6325 auto& mptAlice = confEnv.
mpt;
6328 uint64_t
const amt = 10;
6331 auto const holderCipherText = mptAlice.encryptAmount(bob, amt, bf);
6332 auto const issuerCipherText = mptAlice.encryptAmount(alice, amt, bf);
6337 auto const deltaCipherText = mptAlice.encryptAmount(bob, 1, deltaBf);
6341 homomorphicAdd(holderCipherText, deltaCipherText),
"Missing tampered ciphertext");
6345 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
6346 "Missing spending balance");
6348 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
6349 "Missing encrypted spending balance");
6351 auto const pedersenCommitment = mptAlice.getPedersenCommitment(spendingBal, pcBf);
6353 auto const currentVersion = mptAlice.getMPTokenVersion(bob);
6358 auto const proof = mptAlice.getConvertBackProof(
6363 .pedersenCommitment = pedersenCommitment,
6365 .encryptedAmt = spendingBalEnc,
6366 .blindingFactor = pcBf,
6368 if (!BEAST_EXPECT(proof.has_value()))
6375 mptAlice.convertBack({
6379 .holderEncryptedAmt = tamperedHolderCipherText,
6380 .issuerEncryptedAmt = issuerCipherText,
6381 .blindingFactor = bf,
6382 .pedersenCommitment = pedersenCommitment,
6397 testcase(
"Send: homomorphic overflow attack via Enc(MAX) + Enc(1)");
6400 Env env{*
this, features};
6401 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6406 {.account = bob, .payAmount = 100, .convertAmount = 100},
6407 {.account = carol, .payAmount = 50, .convertAmount = 50},
6409 auto& mptAlice = confEnv.
mpt;
6413 mptAlice.
send({.account = bob, .dest = carol, .amt = 10});
6416 auto const bobSpendingBefore =
6417 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
6418 BEAST_EXPECT(bobSpendingBefore == 90);
6426 Buffer const encOne = mptAlice.encryptAmount(bob, 1, bf2);
6440 .senderEncryptedAmt = overflowedCt,
6444 auto const bobSpendingAfter =
6445 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
6446 BEAST_EXPECT(bobSpendingBefore == bobSpendingAfter);
6459 testcase(
"ConvertBack: homomorphic underflow attack via Enc(0) - Enc(1)");
6462 Env env{*
this, features};
6463 Account const alice(
"alice"), bob(
"bob");
6465 env, alice, {{.account = bob, .payAmount = 10, .convertAmount = 10}}};
6466 auto& mptAlice = confEnv.
mpt;
6473 auto const bobSpendingBefore =
6474 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
6475 BEAST_EXPECT(bobSpendingBefore == 9);
6476 auto const bobPublicBefore = mptAlice.getBalance(bob);
6477 BEAST_EXPECT(bobPublicBefore == 1);
6481 Buffer const encZero = mptAlice.encryptAmount(bob, 0, bf1);
6485 Buffer const encOne = mptAlice.encryptAmount(bob, 1, bf2);
6499 Buffer const pedersenCommitment = mptAlice.getPedersenCommitment(kUnderflowedAmt, pcBf);
6501 auto const currentVersion = mptAlice.getMPTokenVersion(bob);
6505 auto const proof = mptAlice.getConvertBackProof(
6510 .pedersenCommitment = pedersenCommitment,
6511 .amt = kUnderflowedAmt,
6512 .encryptedAmt = underflowedCt,
6513 .blindingFactor = pcBf,
6515 if (!BEAST_EXPECT(proof.has_value()))
6518 mptAlice.convertBack({
6522 .holderEncryptedAmt = underflowedCt,
6523 .pedersenCommitment = pedersenCommitment,
6529 BEAST_EXPECT(mptAlice.getBalance(bob) == bobPublicBefore);
6530 auto const bobSpendingAfter =
6531 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
6532 BEAST_EXPECT(bobSpendingBefore == bobSpendingAfter);
6543 testcase(
"Send: off-curve EC points");
6551 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6552 Env env{*
this, features};
6557 {.account = bob, .payAmount = 100, .convertAmount = 60},
6558 {.account = carol, .payAmount = 50, .convertAmount = 30},
6560 auto& mptAlice = confEnv.
mpt;
6611 .amountCommitment = badCommitment,
6622 .balanceCommitment = badCommitment,
6633 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6634 Env env{*
this, features};
6639 {.account = bob, .payAmount = 100, .convertAmount = 60},
6640 {.account = carol, .payAmount = 50, .convertAmount = 30},
6642 auto& mptAlice = confEnv.
mpt;
6652 .proof =
strHex(badProof),
6662 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6663 Env env{*
this, features};
6668 {.account = bob, .payAmount = 100, .convertAmount = 60},
6669 {.account = carol, .payAmount = 50, .convertAmount = 30},
6671 auto& mptAlice = confEnv.
mpt;
6698 .senderEncryptedAmt = badC1goodC2,
6710 .senderEncryptedAmt = goodC1badC2,
6722 .destEncryptedAmt = badC1goodC2,
6734 .destEncryptedAmt = goodC1badC2,
6756 testcase(
"Send: wrong-group point injection rejected");
6759 Env env{*
this, features};
6760 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6765 {.account = bob, .payAmount = 100, .convertAmount = 60},
6766 {.account = carol, .payAmount = 50, .convertAmount = 30},
6768 auto& mptAlice = confEnv.
mpt;
6779 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6,
6780 0xE5, 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB,
6781 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96,
6802 .senderEncryptedAmt = wrongGroupCt,
6814 .destEncryptedAmt = wrongGroupCt,
6826 .issuerEncryptedAmt = wrongGroupCt,
6838 .amountCommitment = wrongGroupCommitment,
6850 .balanceCommitment = wrongGroupCommitment,
6866 testcase(
"Convert: all-zero public key rejected");
6875 Env env{*
this, features};
6876 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6877 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
6880 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
6882 mptAlice.authorize({.account = bob});
6883 mptAlice.authorize({.account = carol});
6884 mptAlice.pay(alice, bob, 100);
6885 mptAlice.pay(alice, carol, 50);
6886 mptAlice.generateKeyPair(alice);
6887 mptAlice.generateKeyPair(bob);
6888 mptAlice.generateKeyPair(carol);
6889 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
6895 .holderPubKey = nullKey,
6903 .holderPubKey = nullKey,
6912 Env env{*
this, features};
6913 Account const alice(
"alice"), bob(
"bob");
6914 MPTTester mptAlice(env, alice, {.holders = {bob}});
6917 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
6919 mptAlice.authorize({.account = bob});
6920 mptAlice.pay(alice, bob, 100);
6921 mptAlice.generateKeyPair(alice);
6922 mptAlice.generateKeyPair(bob);
6926 .issuerPubKey = nullKey,
6943 testcase(
"Send: issuer ciphertext encrypted under wrong public key");
6946 Env env{*
this, features};
6947 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
6952 {.account = bob, .payAmount = 100, .convertAmount = 100},
6953 {.account = carol, .payAmount = 50, .convertAmount = 50},
6955 auto& mptAlice = confEnv.
mpt;
6957 auto const bobSpendingBefore =
6964 Buffer const wrongIssuerCt = mptAlice.encryptAmount(carol, 10, bf);
6970 .issuerEncryptedAmt = wrongIssuerCt,
6979 Buffer const wrongIssuerCt = mptAlice.encryptAmount(bob, 10, bf);
6985 .issuerEncryptedAmt = wrongIssuerCt,
6992 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) ==
6994 BEAST_EXPECT(mptAlice.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
7002 testcase(
"divergent C1 across participants in ConfidentialMPTSend");
7005 Env env{*
this, features};
7009 Account const auditor(
"auditor");
7014 {.account = bob, .payAmount = 100, .convertAmount = 50},
7015 {.account = carol, .payAmount = 50, .convertAmount = 50},
7017 tfMPTCanLock | tfMPTCanHoldConfidentialBalance | tfMPTCanTransfer,
7019 auto& mptAlice = confEnv.
mpt;
7022 uint64_t
const amt = 10;
7024 enum class Participant { Sender, Dest, Issuer, Auditor };
7035 auto const proofOpt =
7049 case Participant::Sender:
7050 senderCt = mptAlice.encryptAmount(bob, amt, bfDivergent);
7052 case Participant::Dest:
7053 destCt = mptAlice.encryptAmount(carol, amt, bfDivergent);
7055 case Participant::Issuer:
7056 issuerCt = mptAlice.encryptAmount(alice, amt, bfDivergent);
7058 case Participant::Auditor:
7059 auditorCt = mptAlice.encryptAmount(auditor, amt, bfDivergent);
7070 .proof =
strHex(proofOpt),
7071 .senderEncryptedAmt = senderCt,
7072 .destEncryptedAmt = destCt,
7073 .issuerEncryptedAmt = issuerCt,
7074 .auditorEncryptedAmt = auditorCt,
7082 auto const spendingAfter =
7083 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
7090 BEAST_EXPECT(spendingAfter == setup.
prevSpending - amt);
7096 submitWithDivergentC1(std::nullopt);
7099 submitWithDivergentC1(Participant::Sender);
7100 submitWithDivergentC1(Participant::Dest);
7101 submitWithDivergentC1(Participant::Issuer);
7102 submitWithDivergentC1(Participant::Auditor);
7108 testcase(
"test confidential transactions fee");
7115 .flags = tfMPTCanLock | tfMPTCanHoldConfidentialBalance | tfMPTCanTransfer |
7118 mpt.authorize({.account = bob});
7119 mpt.authorize({.account = carol});
7120 mpt.pay(alice, bob, 100);
7121 mpt.pay(alice, carol, 50);
7122 mpt.generateKeyPair(alice);
7123 mpt.generateKeyPair(bob);
7124 mpt.generateKeyPair(carol);
7125 mpt.set({.account = alice, .issuerPubKey = mpt.getPubKey(alice)});
7130 Env env{*
this, features};
7131 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7132 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
7133 setup(mptAlice, alice, bob, carol);
7135 auto const baseFee = env.current()->fees().base;
7140 auto const checkFee = [&](
Account const& acct,
auto&& submitFn) {
7141 auto const before = env.balance(acct);
7143 auto const after = env.balance(acct);
7144 BEAST_EXPECT(before -
after == expectedFee);
7151 .holderPubKey = mptAlice.getPubKey(bob),
7155 checkFee(carol, [&] {
7159 .holderPubKey = mptAlice.getPubKey(carol),
7163 checkFee(bob, [&] { mptAlice.mergeInbox({.account = bob, .fee = expectedFee}); });
7164 checkFee(carol, [&] { mptAlice.mergeInbox({.account = carol, .fee = expectedFee}); });
7166 mptAlice.send({.account = bob, .dest = carol, .amt = 5, .fee = expectedFee});
7169 bob, [&] { mptAlice.convertBack({.account = bob, .amt = 5, .fee = expectedFee}); });
7170 checkFee(alice, [&] {
7171 mptAlice.confidentialClaw(
7172 {.account = alice, .holder = carol, .amt = 15, .fee = expectedFee});
7176 Account const newIssuerKey(
"newIssuerKey");
7177 mptAlice.generateKeyPair(newIssuerKey);
7178 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(newIssuerKey)});
7179 checkFee(alice, [&] {
7180 mptAlice.mirrorUpdate({
7191 Env env{*
this, features};
7192 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7193 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
7194 setup(mptAlice, alice, bob, carol);
7195 auto const baseFee = env.current()->fees().base;
7201 .holderPubKey = mptAlice.getPubKey(bob),
7202 .fee = expectedFee - 1,
7205 mptAlice.mergeInbox({.account = bob, .fee = baseFee, .err =
telINSUF_FEE_P});
7213 mptAlice.convertBack({.account = bob, .amt = 1, .fee = baseFee, .err =
telINSUF_FEE_P});
7214 mptAlice.confidentialClaw({
7221 mptAlice.mirrorUpdate({
7232 Env env{*
this, features};
7233 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7234 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
7235 setup(mptAlice, alice, bob, carol);
7237 auto const baseFee = env.current()->fees().base;
7239 auto const bobBefore = env.balance(bob);
7243 .holderPubKey = mptAlice.getPubKey(bob),
7246 BEAST_EXPECT(env.balance(bob) == bobBefore - highFee);
7253 testcase(
"Send: forged equality proof");
7260 Env env{*
this, features};
7261 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7265 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}}};
7266 auto& mptAlice = confEnv.
mpt;
7272 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7273 if (!BEAST_EXPECT(proof.has_value()))
7277 auto const forgedDestAmt = mptAlice.encryptAmount(carol, 20, forgedBlindingFactor);
7282 mptAlice.send(args);
7287 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7288 if (!BEAST_EXPECT(proof.has_value()))
7292 auto const forgedSenderAmt = mptAlice.encryptAmount(bob, 5, forgedBlindingFactor);
7297 mptAlice.send(args);
7302 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7303 if (!BEAST_EXPECT(proof.has_value()))
7307 auto const forgedIssuerAmt = mptAlice.encryptAmount(alice, 100, forgedBlindingFactor);
7312 mptAlice.send(args);
7319 testcase(
"Send: forged range proof");
7327 Env env{*
this, features};
7328 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7332 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}}};
7333 auto& mptAlice = confEnv.
mpt;
7339 auto const senderAmt = mptAlice.encryptAmount(bob, badAmount, blindingFactor);
7340 auto const destAmt = mptAlice.encryptAmount(carol, badAmount, blindingFactor);
7341 auto const issuerAmt = mptAlice.encryptAmount(alice, badAmount, blindingFactor);
7342 auto const amountCommitment = mptAlice.getPedersenCommitment(badAmount, blindingFactor);
7346 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
7347 "Missing previous spending balance");
7349 auto const balanceCommitment =
7350 mptAlice.getPedersenCommitment(prevSpending, balanceBlindingFactor);
7355 auto const validProof = setup.
generateProof(mptAlice, env, bob, carol);
7356 if (!BEAST_EXPECT(validProof.has_value()))
7362 forgedProof.
data()[i] ^= 0xFF;
7369 .proof =
strHex(forgedProof),
7370 .senderEncryptedAmt = senderAmt,
7371 .destEncryptedAmt = destAmt,
7372 .issuerEncryptedAmt = issuerAmt,
7373 .amountCommitment = amountCommitment,
7374 .balanceCommitment = balanceCommitment,
7380 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
7381 "Missing post spending balance");
7382 BEAST_EXPECT(postSpending == prevSpending);
7388 testcase(
"Send: negative value malleability");
7397 Env env{*
this, features};
7398 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7403 {.account = bob, .payAmount = 1000, .convertAmount = 10},
7404 {.account = carol, .payAmount = 1000, .convertAmount = 50},
7406 auto& mptAlice = confEnv.
mpt;
7408 uint64_t
const sendAmount = 10;
7409 auto const negativeRemaining =
static_cast<uint64_t
>(-10);
7414 bob.id(), mptAlice.issuanceID(), env.seq(bob), carol.id(), setup.
version);
7416 auto const validProof = setup.
generateProof(mptAlice, env, bob, carol);
7417 if (!BEAST_EXPECT(validProof.has_value()))
7422 {sendAmount, negativeRemaining},
7433 forgedBulletproof.data(),
7440 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
7441 "Missing post spending balance");
7448 testcase(
"Send proof context binding");
7451 auto const runBadProof = [&](
auto makeContextHash) {
7452 Env env{*
this, features};
7459 {{.account = bob, .payAmount = 100, .convertAmount = 40}, {.account = carol}}};
7460 auto& mptAlice = confEnv.
mpt;
7464 auto const proof = mptAlice.getConfidentialSendProof(
7469 makeContextHash(env, mptAlice, alice, bob, carol, setup.
version),
7471 .pedersenCommitment = setup.amountCommitment,
7472 .amt = setup.sendAmount,
7473 .encryptedAmt = setup.senderAmt,
7474 .blindingFactor = setup.amountBlindingFactor,
7477 .pedersenCommitment = setup.balanceCommitment,
7478 .amt = setup.prevSpending,
7479 .encryptedAmt = setup.prevEncryptedSpending,
7480 .blindingFactor = setup.balanceBlindingFactor,
7482 if (!BEAST_EXPECT(proof.has_value()))
7490 runBadProof([&](Env& env,
7491 MPTTester
const& mpt,
7497 carol.id(), mpt.issuanceID(), env.seq(bob), carol.id(), version);
7501 runBadProof([&](Env& env,
7516 runBadProof([&](Env& env,
7517 MPTTester
const& mpt,
7523 bob.id(), mpt.issuanceID(), env.seq(bob) + 1, carol.id(), version);
7527 runBadProof([&](Env& env,
7528 MPTTester
const& mpt,
7533 return getSendContextHash(bob.id(), mpt.issuanceID(), env.seq(bob), bob.id(), version);
7537 runBadProof([&](Env& env,
7538 MPTTester
const& mpt,
7544 bob.id(), mpt.issuanceID(), env.seq(bob), carol.id(), version + 1);
7551 testcase(
"Send: Fiat-Shamir Binding");
7554 Env env{*
this, features};
7555 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7559 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}}};
7560 auto& mptAlice = confEnv.
mpt;
7566 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7567 if (!BEAST_EXPECT(proof.has_value()))
7571 auto const forgedCommitment =
7572 mptAlice.getPedersenCommitment(setup.
sendAmount + 5, forgedBlindingFactor);
7577 mptAlice.send(args);
7582 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7583 if (!BEAST_EXPECT(proof.has_value()))
7586 mptAlice.pay(bob, carol, 1);
7595 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7596 if (!BEAST_EXPECT(proof.has_value()))
7600 Buffer tamperedProof(proofRef.size());
7602 size_t const tamperOffset = tamperedProof.
size() / 2;
7603 tamperedProof.
data()[tamperOffset] ^= 0xFF;
7612 testcase(
"Send: Proof Component Reuse");
7615 Env env{*
this, features};
7616 Account const alice(
"alice"), bob(
"bob"), carol(
"carol"), dan(
"dan");
7622 {.account = carol, .payAmount = 1000, .convertAmount = 50},
7623 {.account = dan, .payAmount = 1000, .convertAmount = 50},
7625 auto& mptAlice = confEnv.
mpt;
7627 uint64_t
const sendAmount = 10;
7633 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7634 if (!BEAST_EXPECT(proof.has_value()))
7638 mptAlice.mergeInbox({.account = carol});
7648 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7649 if (!BEAST_EXPECT(proof.has_value()))
7653 mptAlice.mergeInbox({.account = carol});
7655 auto const destAmtDan = mptAlice.encryptAmount(dan, sendAmount, setup.
blindingFactor);
7656 auto const issuerAmtDan =
7662 args.issuerEncryptedAmt = issuerAmtDan;
7663 mptAlice.send(args);
7670 testcase(
"Send: special witness values");
7673 Env env{*
this, features};
7674 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7678 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}}};
7679 auto& mptAlice = confEnv.
mpt;
7685 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7686 if (!BEAST_EXPECT(proof.has_value()))
7691 static constexpr size_t kSigmaScalarSize = 32;
7692 static constexpr size_t kChallengeOffset = 0;
7693 static constexpr size_t kResponseOffset = kChallengeOffset + kSigmaScalarSize;
7694 static constexpr size_t kResponseSize = 5 * kSigmaScalarSize;
7702 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7703 if (!BEAST_EXPECT(proof.has_value()))
7712 mptAlice.send(args);
7717 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7718 if (!BEAST_EXPECT(proof.has_value()))
7727 mptAlice.send(args);
7732 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7733 if (!BEAST_EXPECT(proof.has_value()))
7738 static constexpr unsigned char kCurveOrder[32] = {
7739 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
7740 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
7741 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
7742 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41,
7752 auto const proof = setup.
generateProof(mptAlice, env, bob, carol);
7753 if (!BEAST_EXPECT(proof.has_value()))
7758 static constexpr unsigned char kOverflowScalar[32] = {
7759 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
7760 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
7761 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
7762 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x42,
7774 testcase(
"Send: cross-statement proof substitution");
7781 Env env{*
this, features};
7782 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7786 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}},
7787 tfMPTCanLock | tfMPTCanHoldConfidentialBalance | tfMPTCanTransfer | tfMPTCanClawback};
7788 auto& mptAlice = confEnv.
mpt;
7790 uint64_t
const sendAmount = 10;
7807 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
7808 "Missing spending balance");
7810 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
7811 "Missing encrypted spending balance");
7814 Buffer const pedersenCommitment =
7815 mptAlice.getPedersenCommitment(spendingBalance, pcBlindingFactor);
7817 auto const version = mptAlice.getMPTokenVersion(bob);
7818 UInt256 const convertBackCtxHash =
7821 auto const convertBackProof = mptAlice.getConvertBackProof(
7826 .pedersenCommitment = pedersenCommitment,
7827 .amt = spendingBalance,
7828 .encryptedAmt = encryptedSpending,
7829 .blindingFactor = pcBlindingFactor,
7831 if (!BEAST_EXPECT(convertBackProof.has_value()))
7838 Buffer resizedProof(expectedSendSize);
7839 Buffer const& convertBackProofRef =
7841 auto const copyLen =
std::min(convertBackProofRef.
size(), expectedSendSize);
7844 if (copyLen < expectedSendSize)
7845 std::memset(resizedProof.
data() + copyLen, 0, expectedSendSize - copyLen);
7861 UInt192 const fakeIssuanceID{1};
7863 bob.id(), fakeIssuanceID, env.seq(bob), carol.id(), setup.
version);
7866 auto const wrongProof = mptAlice.getConfidentialSendProof(
7873 .pedersenCommitment = setup.amountCommitment,
7875 .encryptedAmt = setup.senderAmt,
7876 .blindingFactor = setup.amountBlindingFactor,
7879 .pedersenCommitment = setup.balanceCommitment,
7880 .amt = setup.prevSpending,
7881 .encryptedAmt = setup.prevEncryptedSpending,
7882 .blindingFactor = setup.balanceBlindingFactor,
7885 if (!BEAST_EXPECT(wrongProof.has_value()))
7899 testcase(
"Send: ciphertext malleability");
7906 Env env{*
this, features};
7907 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
7911 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}},
7912 tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance};
7913 auto& mptAlice = confEnv.
mpt;
7915 uint64_t
const sendAmount = 10;
7922 auto const seq = env.seq(bob);
7924 mptAlice.sendJV({.account = bob, .dest = carol, .amt = sendAmount}, seq);
7925 auto const jtx = env.jt(jv);
7926 BEAST_EXPECT(jtx.stx);
7937 auto const inflatedCiphertext = mptAlice.encryptAmount(carol, sendAmount * 2, bf);
7938 obj.
setFieldVL(sfDestinationEncryptedAmount, inflatedCiphertext);
7945 auto const jr = env.rpc(
"submit",
strHex(tampered.
slice()));
7946 BEAST_EXPECT(jr[jss::result][jss::error] ==
"invalidTransaction");
7947 BEAST_EXPECT(!jr[jss::result].isMember(jss::error_code));
7948 BEAST_EXPECT(jr[jss::result][jss::error_message].isNull());
7960 bob.id(), mptAlice.issuanceID(), env.seq(bob), carol.id(), setup.
version);
7962 auto const validProof = mptAlice.getConfidentialSendProof(
7969 .pedersenCommitment = setup.amountCommitment,
7971 .encryptedAmt = setup.senderAmt,
7972 .blindingFactor = setup.amountBlindingFactor,
7975 .pedersenCommitment = setup.balanceCommitment,
7976 .amt = setup.prevSpending,
7977 .encryptedAmt = setup.prevEncryptedSpending,
7978 .blindingFactor = setup.balanceBlindingFactor,
7981 if (!BEAST_EXPECT(validProof.has_value()))
7987 auto const inflatedDestAmt =
7988 mptAlice.encryptAmount(carol, sendAmount * 2, setup.
blindingFactor);
7993 mptAlice.send(args);
8000 testcase(
"Send: ciphertext negation");
8007 Env env{*
this, features};
8008 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
8012 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}},
8013 tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance};
8014 auto& mptAlice = confEnv.
mpt;
8016 uint64_t
const sendAmount = 10;
8022 auto const negateCiphertext = [](
Buffer const& ct) ->
Buffer {
8024 neg.
data()[0] ^= 0x01;
8033 auto const seq = env.seq(bob);
8035 mptAlice.sendJV({.account = bob, .dest = carol, .amt = sendAmount}, seq);
8036 auto const jtx = env.jt(jv);
8037 BEAST_EXPECT(jtx.stx);
8045 auto const origDestAmt = obj.
getFieldVL(sfDestinationEncryptedAmount);
8046 Buffer const origBuf(origDestAmt.data(), origDestAmt.size());
8047 auto const negDestAmt = negateCiphertext(origBuf);
8049 sfDestinationEncryptedAmount,
Slice(negDestAmt.data(), negDestAmt.size()));
8054 auto const jr = env.rpc(
"submit",
strHex(tampered.
slice()));
8055 BEAST_EXPECT(jr[jss::result][jss::error] ==
"invalidTransaction");
8056 BEAST_EXPECT(!jr[jss::result].isMember(jss::error_code));
8057 BEAST_EXPECT(jr[jss::result][jss::error_message].isNull());
8066 auto const validProof = setup.
generateProof(mptAlice, env, bob, carol);
8067 if (!BEAST_EXPECT(validProof.has_value()))
8071 auto const negSenderAmt = negateCiphertext(setup.
senderAmt);
8072 auto const negDestAmt = negateCiphertext(setup.
destAmt);
8073 auto const negIssuerAmt = negateCiphertext(setup.
issuerAmt);
8078 args.destEncryptedAmt = negDestAmt;
8079 args.issuerEncryptedAmt = negIssuerAmt;
8080 mptAlice.send(args);
8091 auto const validProof = setup.
generateProof(mptAlice, env, bob, carol);
8092 if (!BEAST_EXPECT(validProof.has_value()))
8095 auto const negSenderAmt = negateCiphertext(setup.
senderAmt);
8100 mptAlice.send(args);
8107 testcase(
"Send: ciphertext combination");
8114 Env env{*
this, features};
8115 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
8120 {.account = bob, .payAmount = 1000, .convertAmount = 200},
8121 {.account = carol, .payAmount = 1000, .convertAmount = 100},
8123 tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance};
8124 auto& mptAlice = confEnv.
mpt;
8126 uint64_t
const m1 = 10;
8127 uint64_t
const m2 = 5;
8133 auto const seq = env.seq(bob);
8134 auto const jv = mptAlice.sendJV({.account = bob, .dest = carol, .amt = m1}, seq);
8135 auto const jtx = env.jt(jv);
8136 BEAST_EXPECT(jtx.stx);
8144 auto const origDestCt = obj.
getFieldVL(sfDestinationEncryptedAmount);
8148 auto const encM2 = mptAlice.encryptAmount(carol, m2, bf2);
8151 Slice(origDestCt.data(), origDestCt.size()),
Slice(encM2.data(), encM2.size())),
8152 "Missing combined ciphertext");
8154 obj.
setFieldVL(sfDestinationEncryptedAmount, combined);
8159 auto const jr = env.rpc(
"submit",
strHex(tampered.
slice()));
8160 BEAST_EXPECT(jr[jss::result][jss::error] ==
"invalidTransaction");
8161 BEAST_EXPECT(!jr[jss::result].isMember(jss::error_code));
8162 BEAST_EXPECT(jr[jss::result][jss::error_message].isNull());
8173 auto const validProof = setup.
generateProof(mptAlice, env, bob, carol);
8174 if (!BEAST_EXPECT(validProof.has_value()))
8179 auto const encM2 = mptAlice.encryptAmount(carol, m2, bf2);
8181 BEAST_EXPECT(combinedDest.has_value());
8186 mptAlice.send(args);
8198 auto const proof1 = setup1.
generateProof(mptAlice, env, bob, carol);
8199 if (!BEAST_EXPECT(proof1.has_value()))
8205 auto const proof2 = setup2.
generateProof(mptAlice, env, bob, carol);
8206 if (!BEAST_EXPECT(proof2.has_value()))
8211 BEAST_EXPECT(crossCombined.has_value());
8216 mptAlice.send(args);
8223 testcase(
"Send: ciphertext rerandomization");
8234 Env env{*
this, features};
8235 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
8239 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}},
8240 tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance};
8241 auto& mptAlice = confEnv.
mpt;
8243 uint64_t
const sendAmount = 10;
8259 auto const seq = env.seq(bob);
8261 mptAlice.sendJV({.account = bob, .dest = carol, .amt = sendAmount}, seq);
8262 auto const jtx = env.jt(jv);
8263 BEAST_EXPECT(jtx.stx);
8272 auto const otherCt = mptAlice.encryptAmount(carol, 99, bf2);
8275 auto const origDestAmt = obj.
getFieldVL(sfDestinationEncryptedAmount);
8276 Buffer const origBuf(origDestAmt.data(), origDestAmt.size());
8277 auto const rerandomized = substituteC1(origBuf, otherCt);
8279 sfDestinationEncryptedAmount,
Slice(rerandomized.data(), rerandomized.size()));
8285 auto const jr = env.rpc(
"submit",
strHex(tampered.
slice()));
8286 BEAST_EXPECT(jr[jss::result][jss::error] ==
"invalidTransaction");
8287 BEAST_EXPECT(!jr[jss::result].isMember(jss::error_code));
8288 BEAST_EXPECT(jr[jss::result][jss::error_message].isNull());
8299 auto const validProof = setup.
generateProof(mptAlice, env, bob, carol);
8300 if (!BEAST_EXPECT(validProof.has_value()))
8305 auto const otherCt = mptAlice.encryptAmount(carol, sendAmount, bf2);
8308 auto const rerandomizedDest = substituteC1(setup.
destAmt, otherCt);
8313 mptAlice.send(args);
8320 testcase(
"Send: zero randomness ciphertext");
8326 Env env{*
this, features};
8327 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
8331 {{.account = bob}, {.account = carol, .payAmount = 1000, .convertAmount = 50}},
8332 tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance};
8333 auto& mptAlice = confEnv.
mpt;
8335 uint64_t
const sendAmount = 10;
8346 auto const seq = env.seq(bob);
8348 mptAlice.sendJV({.account = bob, .dest = carol, .amt = sendAmount}, seq);
8349 auto const jtx = env.jt(jv);
8350 BEAST_EXPECT(jtx.stx);
8369 obj.
setFieldVL(sfSenderEncryptedAmount, zeroCiphertext);
8377 auto const jr = env.rpc(
"submit",
strHex(tampered.
slice()));
8378 BEAST_EXPECT(jr[jss::result][jss::error] ==
"invalidTransaction");
8379 BEAST_EXPECT(!jr[jss::result].isMember(jss::error_code));
8380 BEAST_EXPECT(jr[jss::result][jss::error_message].isNull());
8406 .senderEncryptedAmt = zeroCiphertext,
8423 auto const proof1 = setup1.
generateProof(mptAlice, env, bob, carol);
8424 if (!BEAST_EXPECT(proof1.has_value()))
8430 mptAlice.mergeInbox({.account = carol});
8445 testcase(
"Send: recipient inbox rerandomization prevents merge cancellation");
8451 auto const getCanonicalZeroBlindingFactor = [](
AccountID const& account,
8452 MPTID const& mptID) {
8473 if (secp256k1_ec_seckey_verify(mpt_secp256k1_context(), scalar.data()))
8482 auto const negateScalarSum = [](
Buffer const& lhs,
Buffer const& rhs) {
8485 secp256k1_mpt_scalar_add(
sum.data(), lhs.
data(), rhs.data());
8486 secp256k1_mpt_scalar_negate(negated.
data(),
sum.data());
8494 Env env{*
this, features};
8495 Account const alice(
"alice"), bob(
"bob"), carol(
"carol");
8496 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
8500 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
8503 mptAlice.authorize({.account = bob});
8504 mptAlice.authorize({.account = carol});
8505 mptAlice.pay(alice, bob, 100);
8506 mptAlice.pay(alice, carol, 100);
8508 mptAlice.generateKeyPair(alice);
8509 mptAlice.generateKeyPair(bob);
8510 mptAlice.generateKeyPair(carol);
8511 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
8516 .holderPubKey = mptAlice.getPubKey(carol),
8518 mptAlice.mergeInbox({.account = carol});
8524 .holderPubKey = mptAlice.getPubKey(bob),
8525 .blindingFactor = convertBlindingFactor,
8528 Buffer const canonicalZeroBlindingFactor =
8529 getCanonicalZeroBlindingFactor(bob.id(), mptAlice.issuanceID());
8533 Buffer const maliciousSendBlindingFactor =
8534 negateScalarSum(canonicalZeroBlindingFactor, convertBlindingFactor);
8540 .blindingFactor = maliciousSendBlindingFactor,
8543 mptAlice.mergeInbox({.account = bob});
8545 auto const bobSpending =
8546 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending);
8547 BEAST_EXPECT(bobSpending && *bobSpending == 25);
8555 Env env{*
this, features};
8556 Account const alice(
"alice"), bob(
"bob"), carol(
"carol"), auditor(
"auditor");
8557 MPTTester mptAlice(env, alice, {.holders = {bob, carol}, .auditor = auditor});
8561 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
8564 mptAlice.authorize({.account = bob});
8565 mptAlice.authorize({.account = carol});
8566 mptAlice.pay(alice, bob, 100);
8567 mptAlice.pay(alice, carol, 100);
8569 mptAlice.generateKeyPair(alice);
8570 mptAlice.generateKeyPair(bob);
8571 mptAlice.generateKeyPair(carol);
8572 mptAlice.generateKeyPair(auditor);
8575 .issuerPubKey = mptAlice.getPubKey(alice),
8576 .auditorPubKey = mptAlice.getPubKey(auditor),
8582 .holderPubKey = mptAlice.getPubKey(carol),
8584 mptAlice.mergeInbox({.account = carol});
8590 .holderPubKey = mptAlice.getPubKey(bob),
8591 .blindingFactor = convertBlindingFactor,
8595 Buffer const maliciousSendBlindingFactor =
8602 .blindingFactor = maliciousSendBlindingFactor,
8605 auto const bobAuditor =
8606 mptAlice.getDecryptedBalance(bob, MPTTester::auditorEncryptedBalance);
8607 BEAST_EXPECT(bobAuditor && *bobAuditor == 25);
A generic endpoint for log messages.
TestcaseT testcase
Memberspace for declaring test cases.
Like std::vector<char> but better.
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
static Buffer getForgedSingleBulletproof(uint64_t value, Buffer const &blindingFactor, UInt256 const &contextHash)
static constexpr size_t kBulletproofOffset
static Buffer getForgedSendProof(test::jtx::MPTTester &mpt, test::jtx::Env &env, test::jtx::Account const &sender, test::jtx::Account const &dest, ConfidentialSendSetup const &setup)
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 Buffer getForgedBulletproof(std::array< uint64_t, 2 > const &values, std::array< Buffer, 2 > const &blindingFactors, UInt256 const &contextHash)
static std::string getTrivialSendProofHex()
static Buffer getForgedConvertBackProof(test::jtx::MPTTester &mpt, test::jtx::Account const &holder, uint64_t claimedBalance, uint64_t realBalance, uint64_t amt, Buffer const &pedersenCommitment, Buffer const &encryptedSpendingBalance, Buffer const &pcBlindingFactor, UInt256 const &contextHash)
static Buffer const & getTrivialCommitment()
static Buffer const & getTrivialCiphertext()
void testConvertBackPreflight(FeatureBitset features)
void testConvertBackBulletproof(FeatureBitset features)
void testClawbackInvalidProofContextBinding(FeatureBitset features)
void testConfidentialMPTBaseFee(FeatureBitset features)
void testSendRangeProof(FeatureBitset features)
void testConvertBack(FeatureBitset features)
void testPublicTransfersAfterClearingConfidentialFlag(FeatureBitset features)
void testTransferFee(FeatureBitset features)
void testConvert(FeatureBitset features)
void testConvertBackPedersenProof(FeatureBitset features)
void testConvertBackHomomorphicCiphertextModification(FeatureBitset features)
void testSendRerandomizesRecipientInboxAgainstMergeCancellation(FeatureBitset features)
void testConvertIdentityElementRejection(FeatureBitset features)
void testSetPreclaim(FeatureBitset features)
void testSetPreflight(FeatureBitset features)
void testSend(FeatureBitset features)
void testMutatePrivacy(FeatureBitset features)
void testSet(FeatureBitset features)
void testSendCiphertextCombination(FeatureBitset features)
void testSendFiatShamirBinding(FeatureBitset features)
void testSendCiphertextRerandomization(FeatureBitset features)
void testSendPreclaim(FeatureBitset features)
void testConvertBackPreclaim(FeatureBitset features)
void testSendInvalidCurvePoints(FeatureBitset features)
void testDelete(FeatureBitset features)
void testClawbackPreclaim(FeatureBitset features)
void testSendWrongIssuerPublicKey(FeatureBitset features)
void testConvertBackWithAuditor(FeatureBitset features)
void testSendOverdraftBulletproof(FeatureBitset features)
void testSendZeroRandomnessCiphertext(FeatureBitset features)
void testSendCiphertextMalleability(FeatureBitset features)
void testSendPreflight(FeatureBitset features)
void testClawbackPreflight(FeatureBitset features)
void testMergeInboxPreclaim(FeatureBitset features)
void testClawback(FeatureBitset features)
void testSendNegativeValueMalleability(FeatureBitset features)
void testMergeInbox(FeatureBitset features)
void testClawbackProof(FeatureBitset features)
void testConvertBackOverdraftBulletproof(FeatureBitset features)
void testSendCiphertextNegation(FeatureBitset features)
void testSendForgedRangeProof(FeatureBitset features)
void testConvertBackOverdraftBulletproofImpl(FeatureBitset features, uint64_t balance, uint64_t amt)
void testSendInvalidProofContextBinding(FeatureBitset features)
void testSendForgedEqualityProof(FeatureBitset features)
void testClawbackWithAuditor(FeatureBitset features)
void testSendCrossStatementProofSubstitution(FeatureBitset features)
void testSendProofComponentReuse(FeatureBitset features)
void testWithFeats(FeatureBitset features)
void testSendWithAuditor(FeatureBitset features)
void testConvertWithAuditor(FeatureBitset features)
void run() override
Runs the suite.
void testSendHomomorphicOverflow(FeatureBitset features)
void testConvertBackProofCiphertextBinding(FeatureBitset features)
void testSendSharedRandomnessViolation(FeatureBitset features)
void testConvertPreclaim(FeatureBitset features)
void testConvertBackHomomorphicUnderflow(FeatureBitset features)
void testConvertBackInvalidProofContextBinding(FeatureBitset features)
void testConvertInvalidProofContextBinding(FeatureBitset features)
void testSendOverdraftBulletproofImpl(FeatureBitset features, unsigned balance, unsigned amt)
void testMergeInboxPreflight(FeatureBitset features)
void testConvertBackProofVersionMismatch(FeatureBitset features)
void testSendWrongGroupPointInjection(FeatureBitset features)
void testSendZeroAmount(FeatureBitset features)
void testConvertPreflight(FeatureBitset features)
void testSendSpecialWitnessValues(FeatureBitset features)
Writable ledger view that accumulates state and tx changes.
void rawReplace(SLE::Ref sle) override
Unconditionally replace a state item.
SLE::const_pointer read(Keylet const &k) const override
Return the state item associated with a key.
Blob getFieldVL(SField const &field) const
void setFieldVL(SField const &field, Blob const &)
void add(Serializer &s) const override
Slice slice() const noexcept
An immutable linear range of bytes.
void convertBack(MPTConvertBack const &arg=MPTConvertBack{}, std::source_location const &loc=std::source_location::current())
std::optional< uint64_t > getDecryptedBalance(Account const &account, EncryptedBalanceType balanceType) const
std::uint32_t getMPTokenVersion(Account const account) const
void send(MPTConfidentialSend const &arg=MPTConfidentialSend{}, std::source_location const &loc=std::source_location::current())
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())
void confidentialClaw(MPTConfidentialClawback const &arg=MPTConfidentialClawback{}, std::source_location const &loc=std::source_location::current())
void set(MPTSet const &set={}, std::source_location const &loc=std::source_location::current())
void authorize(MPTAuthorize const &arg=MPTAuthorize{}, std::source_location const &loc=std::source_location::current())
std::optional< Buffer > getPrivKey(Account const &account, std::optional< std::uint32_t > epoch=std::nullopt) const
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::size_t kEcPubKeyLength
Length of EC public key (compressed).
constexpr std::uint8_t kEcCompressedPrefixEvenY
Compressed EC point prefix for even y-coordinate.
static auto sum(TCollection const &col)
STAmount convertAmount(STAmount const &amt, bool all)
constexpr std::size_t kEcBlindingFactorLength
Length of the EC blinding factor in bytes.
UInt256 getConvertContextHash(AccountID const &account, UInt192 const &issuanceID, std::uint32_t sequence)
Generates the context hash for ConfidentialMPTConvert transactions.
constexpr std::size_t kCompressedEcPointLength
Length of EC point (compressed).
std::string strHex(FwdIt begin, FwdIt end)
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::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT 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.
constexpr std::size_t kEcSchnorrProofLength
Length of Schnorr ZKProof for public key registration (compact form) in bytes.
constexpr std::size_t kEcGamalEncryptedTotalLength
EC ElGamal ciphertext length: two compressed EC points concatenated.
std::string to_string(BaseUInt< Bits, Tag > const &a)
constexpr std::size_t kEcConvertBackProofLength
128 bytes compact sigma proof + 688 bytes single bulletproof.
constexpr std::size_t kEcSingleBulletproofLength
Length of single bulletproof (range proof for 1 commitment) in bytes.
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.
std::optional< Buffer > homomorphicSubtract(Slice const &a, Slice const &b)
Homomorphically subtracts two ElGamal ciphertexts.
constexpr std::size_t kEcDoubleBulletproofLength
Length of double bulletproof (range proof for 2 commitments) in bytes.
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
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)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
constexpr FlagValue tifMPTCanHoldConfidentialBalance
constexpr std::size_t kEcSendProofLength
192 bytes compact sigma proof + 754 bytes double bulletproof.
TERSubset< CanCvtToTER > TER
constexpr FlagValue tifMPTCanLock
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
std::optional< Buffer > homomorphicAdd(Slice const &a, Slice const &b)
Homomorphically adds two ElGamal ciphertexts.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
T const_pointer_cast(T... args)
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::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
std::optional< Buffer > auditorAmt
Buffer balanceBlindingFactor
std::optional< Buffer > amountCommitment
std::optional< Buffer > senderEncryptedAmt
std::optional< Buffer > destEncryptedAmt
std::optional< Buffer > issuerEncryptedAmt