xrpld
Loading...
Searching...
No Matches
MultiSign_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/JTx.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/balance.h>
7#include <test/jtx/envconfig.h>
8#include <test/jtx/fee.h>
9#include <test/jtx/flags.h>
10#include <test/jtx/multisign.h>
11#include <test/jtx/noop.h>
12#include <test/jtx/offer.h>
13#include <test/jtx/owners.h>
14#include <test/jtx/pay.h>
15#include <test/jtx/regkey.h>
16#include <test/jtx/require.h>
17#include <test/jtx/rpc.h>
18#include <test/jtx/seq.h>
19#include <test/jtx/sig.h>
20#include <test/jtx/tags.h>
21#include <test/jtx/ter.h>
22#include <test/jtx/ticket.h>
23#include <test/jtx/trust.h>
24#include <test/jtx/txflags.h>
25
26#include <xrpld/core/Config.h>
27
28#include <xrpl/basics/base_uint.h>
29#include <xrpl/basics/strHex.h>
30#include <xrpl/beast/unit_test/suite.h>
31#include <xrpl/config/Constants.h>
32#include <xrpl/json/json_value.h>
33#include <xrpl/json/to_string.h>
34#include <xrpl/protocol/ErrorCodes.h>
35#include <xrpl/protocol/Feature.h>
36#include <xrpl/protocol/Indexes.h>
37#include <xrpl/protocol/KeyType.h>
38#include <xrpl/protocol/SField.h>
39#include <xrpl/protocol/STArray.h>
40#include <xrpl/protocol/STTx.h>
41#include <xrpl/protocol/TER.h>
42#include <xrpl/protocol/TxFlags.h>
43#include <xrpl/protocol/jss.h>
44
45#include <algorithm>
46#include <cstdint>
47#include <memory>
48#include <vector>
49
50namespace xrpl::test {
51
53{
54 // Unfunded accounts to use for phantom signing.
87
88public:
89 void
91 {
92 testcase("No Reserve");
93
94 using namespace jtx;
95 Env env{*this, features};
96 Account const alice{"alice", KeyType::Secp256k1};
97
98 // Pay alice enough to meet the initial reserve, but not enough to
99 // meet the reserve for a SignerListSet.
100 auto const fee = env.current()->fees().base;
101 env.fund(XRP(250) - drops(1), alice);
102 env.close();
103 env.require(Owners(alice, 0));
104
105 {
106 // Attach a signer list to alice. Should fail.
107 json::Value const signersList = signers(alice, 1, {{bogie_, 1}});
108 env(signersList, Ter(tecINSUFFICIENT_RESERVE));
109 env.close();
110 env.require(Owners(alice, 0));
111
112 // Fund alice enough to set the signer list, then attach signers.
113 env(pay(env.master, alice, fee + drops(1)));
114 env.close();
115 env(signersList);
116 env.close();
117 env.require(Owners(alice, 1));
118 }
119 {
120 // Pay alice enough to almost make the reserve for the biggest
121 // possible list.
122 env(pay(env.master, alice, fee - drops(1)));
123
124 // Replace with the biggest possible signer list. Should fail.
125 json::Value const bigSigners = signers(
126 alice,
127 1,
128 {
129 {bogie_, 1},
130 {demon_, 1},
131 {ghost_, 1},
132 {haunt_, 1},
133 {jinni_, 1},
134 {phase_, 1},
135 {shade_, 1},
136 {spook_, 1},
137 });
138 env(bigSigners, Ter(tecINSUFFICIENT_RESERVE));
139 env.close();
140 env.require(Owners(alice, 1));
141
142 // Fund alice one more drop (plus the fee) and succeed.
143 env(pay(env.master, alice, fee + drops(1)));
144 env.close();
145 env(bigSigners);
146 env.close();
147 env.require(Owners(alice, 1));
148 }
149 // Remove alice's signer list and get the owner count back.
150 env(signers(alice, jtx::kNone));
151 env.close();
152 env.require(Owners(alice, 0));
153 }
154
155 void
157 {
158 testcase("SignerListSet");
159
160 using namespace jtx;
161 Env env{*this, features};
162 Account const alice{"alice", KeyType::Ed25519};
163 env.fund(XRP(1000), alice);
164 env.close();
165
166 // Add alice as a multisigner for herself. Should fail.
167 env(signers(alice, 1, {{alice, 1}}), Ter(temBAD_SIGNER));
168
169 // Add a signer with a weight of zero. Should fail.
170 env(signers(alice, 1, {{bogie_, 0}}), Ter(temBAD_WEIGHT));
171
172 // Add a signer where the weight is too big. Should fail since
173 // the weight field is only 16 bits. The jtx framework can't do
174 // this kind of test, so it's commented out.
175 // env(signers(alice, 1, { { bogie, 0x10000} }), ter
176 // (temBAD_WEIGHT));
177
178 // Add the same signer twice. Should fail.
179 env(signers(
180 alice,
181 1,
182 {
183 {bogie_, 1},
184 {demon_, 1},
185 {ghost_, 1},
186 {haunt_, 1},
187 {jinni_, 1},
188 {phase_, 1},
189 {demon_, 1},
190 {spook_, 1},
191 }),
193
194 // Set a quorum of zero. Should fail.
195 env(signers(alice, 0, {{bogie_, 1}}), Ter(temMALFORMED));
196
197 // Make a signer list where the quorum can't be met. Should fail.
198 env(signers(
199 alice,
200 9,
201 {
202 {bogie_, 1},
203 {demon_, 1},
204 {ghost_, 1},
205 {haunt_, 1},
206 {jinni_, 1},
207 {phase_, 1},
208 {shade_, 1},
209 {spook_, 1},
210 }),
212
213 // Make a signer list that's too big. Should fail.
214 Account const spare("spare", KeyType::Secp256k1);
215 env(signers(
216 alice,
217 1,
219 {bogie_, 1}, {demon_, 1}, {ghost_, 1}, {haunt_, 1}, {jinni_, 1}, {phase_, 1},
220 {shade_, 1}, {spook_, 1}, {spare, 1}, {acc10_, 1}, {acc11_, 1}, {acc12_, 1},
221 {acc13_, 1}, {acc14_, 1}, {acc15_, 1}, {acc16_, 1}, {acc17_, 1}, {acc18_, 1},
222 {acc19_, 1}, {acc20_, 1}, {acc21_, 1}, {acc22_, 1}, {acc23_, 1}, {acc24_, 1},
223 {acc25_, 1}, {acc26_, 1}, {acc27_, 1}, {acc28_, 1}, {acc29_, 1}, {acc30_, 1},
224 {acc31_, 1}, {acc32_, 1}, {acc33_, 1},
225 }),
227 // clang-format on
228 env.close();
229 env.require(Owners(alice, 0));
230 }
231
232 void
234 {
235 testcase("Phantom Signers");
236
237 using namespace jtx;
238 Env env{*this, features};
239 Account const alice{"alice", KeyType::Ed25519};
240 env.fund(XRP(1000), alice);
241 env.close();
242
243 // Attach phantom signers to alice and use them for a transaction.
244 env(signers(alice, 1, {{bogie_, 1}, {demon_, 1}}));
245 env.close();
246 env.require(Owners(alice, 1));
247
248 // This should work.
249 auto const baseFee = env.current()->fees().base;
250 std::uint32_t aliceSeq = env.seq(alice);
251 env(noop(alice), Msig(bogie_, demon_), Fee(3 * baseFee));
252 env.close();
253 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
254
255 // Either signer alone should work.
256 aliceSeq = env.seq(alice);
257 env(noop(alice), Msig(bogie_), Fee(2 * baseFee));
258 env.close();
259 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
260
261 aliceSeq = env.seq(alice);
262 env(noop(alice), Msig(demon_), Fee(2 * baseFee));
263 env.close();
264 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
265
266 // Duplicate signers should fail.
267 aliceSeq = env.seq(alice);
268 env(noop(alice),
270 Fee(3 * baseFee),
271 Rpc("invalidTransaction", "fails local checks: Duplicate Signers not allowed."));
272 env.close();
273 BEAST_EXPECT(env.seq(alice) == aliceSeq);
274
275 // A non-signer should fail.
276 aliceSeq = env.seq(alice);
277 env(noop(alice), Msig(bogie_, spook_), Fee(3 * baseFee), Ter(tefBAD_SIGNATURE));
278 env.close();
279 BEAST_EXPECT(env.seq(alice) == aliceSeq);
280
281 // Don't meet the quorum. Should fail.
282 env(signers(alice, 2, {{bogie_, 1}, {demon_, 1}}));
283 aliceSeq = env.seq(alice);
284 env(noop(alice), Msig(bogie_), Fee(2 * baseFee), Ter(tefBAD_QUORUM));
285 env.close();
286 BEAST_EXPECT(env.seq(alice) == aliceSeq);
287
288 // Meet the quorum. Should succeed.
289 aliceSeq = env.seq(alice);
290 env(noop(alice), Msig(bogie_, demon_), Fee(3 * baseFee));
291 env.close();
292 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
293 }
294
295 void
297 {
298 testcase("Fee");
299
300 using namespace jtx;
301 Env env{*this, features};
302 Account const alice{"alice", KeyType::Ed25519};
303 env.fund(XRP(1000), alice);
304 env.close();
305
306 // Attach maximum possible number of signers to alice.
307 env(signers(
308 alice,
309 1,
310 {
311 {bogie_, 1},
312 {demon_, 1},
313 {ghost_, 1},
314 {haunt_, 1},
315 {jinni_, 1},
316 {phase_, 1},
317 {shade_, 1},
318 {spook_, 1},
319 }));
320 env.close();
321 env.require(Owners(alice, 1));
322
323 // This should work.
324 auto const baseFee = env.current()->fees().base;
325 std::uint32_t aliceSeq = env.seq(alice);
326 env(noop(alice), Msig(bogie_), Fee(2 * baseFee));
327 env.close();
328
329 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
330
331 // This should fail because the fee is too small.
332 aliceSeq = env.seq(alice);
333 env(noop(alice), Msig(bogie_), Fee((2 * baseFee) - 1), Ter(telINSUF_FEE_P));
334 env.close();
335
336 BEAST_EXPECT(env.seq(alice) == aliceSeq);
337
338 // This should work.
339 aliceSeq = env.seq(alice);
340 env(noop(alice),
342 Fee(9 * baseFee));
343 env.close();
344
345 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
346
347 // This should fail because the fee is too small.
348 aliceSeq = env.seq(alice);
349 env(noop(alice),
351 Fee((9 * baseFee) - 1),
353 env.close();
354
355 BEAST_EXPECT(env.seq(alice) == aliceSeq);
356 }
357
358 void
360 {
361 testcase("Misordered Signers");
362
363 using namespace jtx;
364 Env env{*this, features};
365 Account const alice{"alice", KeyType::Ed25519};
366 env.fund(XRP(1000), alice);
367 env.close();
368
369 // The signatures in a transaction must be submitted in sorted order.
370 // Make sure the transaction fails if they are not.
371 env(signers(alice, 1, {{bogie_, 1}, {demon_, 1}}));
372 env.close();
373 env.require(Owners(alice, 1));
374
375 Msig phantoms{bogie_, demon_};
377 std::uint32_t const aliceSeq = env.seq(alice);
378 env(noop(alice),
379 phantoms,
380 Rpc("invalidTransaction", "fails local checks: Unsorted Signers array."));
381 env.close();
382 BEAST_EXPECT(env.seq(alice) == aliceSeq);
383 }
384
385 void
387 {
388 testcase("Master Signers");
389
390 using namespace jtx;
391 Env env{*this, features};
392 Account const alice{"alice", KeyType::Ed25519};
393 Account const becky{"becky", KeyType::Secp256k1};
394 Account const cheri{"cheri", KeyType::Ed25519};
395 env.fund(XRP(1000), alice, becky, cheri);
396 env.close();
397
398 // For a different situation, give alice a regular key but don't use it.
399 Account const alie{"alie", KeyType::Secp256k1};
400 env(regkey(alice, alie));
401 env.close();
402 std::uint32_t aliceSeq = env.seq(alice);
403 env(noop(alice), Sig(alice));
404 env(noop(alice), Sig(alie));
405 env.close();
406 BEAST_EXPECT(env.seq(alice) == aliceSeq + 2);
407
408 // Attach signers to alice
409 env(signers(alice, 4, {{becky, 3}, {cheri, 4}}), Sig(alice));
410 env.close();
411 env.require(Owners(alice, 1));
412
413 // Attempt a multisigned transaction that meets the quorum.
414 auto const baseFee = env.current()->fees().base;
415 aliceSeq = env.seq(alice);
416 env(noop(alice), Msig(cheri), Fee(2 * baseFee));
417 env.close();
418 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
419
420 // If we don't meet the quorum the transaction should fail.
421 aliceSeq = env.seq(alice);
422 env(noop(alice), Msig(becky), Fee(2 * baseFee), Ter(tefBAD_QUORUM));
423 env.close();
424 BEAST_EXPECT(env.seq(alice) == aliceSeq);
425
426 // Give becky and cheri regular keys.
427 Account const beck{"beck", KeyType::Ed25519};
428 env(regkey(becky, beck));
429 Account const cher{"cher", KeyType::Ed25519};
430 env(regkey(cheri, cher));
431 env.close();
432
433 // becky's and cheri's master keys should still work.
434 aliceSeq = env.seq(alice);
435 env(noop(alice), Msig(becky, cheri), Fee(3 * baseFee));
436 env.close();
437 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
438 }
439
440 void
442 {
443 testcase("Regular Signers");
444
445 using namespace jtx;
446 Env env{*this, features};
447 Account const alice{"alice", KeyType::Secp256k1};
448 Account const becky{"becky", KeyType::Ed25519};
449 Account const cheri{"cheri", KeyType::Secp256k1};
450 env.fund(XRP(1000), alice, becky, cheri);
451 env.close();
452
453 // Attach signers to alice.
454 env(signers(alice, 1, {{becky, 1}, {cheri, 1}}), Sig(alice));
455
456 // Give everyone regular keys.
457 Account const alie{"alie", KeyType::Ed25519};
458 env(regkey(alice, alie));
459 Account const beck{"beck", KeyType::Secp256k1};
460 env(regkey(becky, beck));
461 Account const cher{"cher", KeyType::Ed25519};
462 env(regkey(cheri, cher));
463 env.close();
464
465 // Disable cheri's master key to mix things up.
466 env(fset(cheri, asfDisableMaster), Sig(cheri));
467 env.close();
468
469 // Attempt a multisigned transaction that meets the quorum.
470 auto const baseFee = env.current()->fees().base;
471 std::uint32_t aliceSeq = env.seq(alice);
472 env(noop(alice), Msig(Reg{cheri, cher}), Fee(2 * baseFee));
473 env.close();
474 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
475
476 // cheri should not be able to multisign using her master key.
477 aliceSeq = env.seq(alice);
478 env(noop(alice), Msig(cheri), Fee(2 * baseFee), Ter(tefMASTER_DISABLED));
479 env.close();
480 BEAST_EXPECT(env.seq(alice) == aliceSeq);
481
482 // becky should be able to multisign using either of her keys.
483 aliceSeq = env.seq(alice);
484 env(noop(alice), Msig(becky), Fee(2 * baseFee));
485 env.close();
486 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
487
488 aliceSeq = env.seq(alice);
489 env(noop(alice), Msig(Reg{becky, beck}), Fee(2 * baseFee));
490 env.close();
491 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
492
493 // Both becky and cheri should be able to sign using regular keys.
494 aliceSeq = env.seq(alice);
495 env(noop(alice), Fee(3 * baseFee), Msig(Reg{becky, beck}, Reg{cheri, cher}));
496 env.close();
497 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
498 }
499
500 void
502 {
503 testcase("Regular Signers Using submit_multisigned");
504
505 using namespace jtx;
506 Env env(
507 *this,
509 cfg->loadFromString(std::string("[") + Sections::kSigningSupport + "]\ntrue");
510 return cfg;
511 }),
512 features);
513 Account const alice{"alice", KeyType::Secp256k1};
514 Account const becky{"becky", KeyType::Ed25519};
515 Account const cheri{"cheri", KeyType::Secp256k1};
516 env.fund(XRP(1000), alice, becky, cheri);
517 env.close();
518
519 // Attach signers to alice.
520 env(signers(alice, 2, {{becky, 1}, {cheri, 1}}), Sig(alice));
521
522 // Give everyone regular keys.
523 Account const beck{"beck", KeyType::Secp256k1};
524 env(regkey(becky, beck));
525 Account const cher{"cher", KeyType::Ed25519};
526 env(regkey(cheri, cher));
527 env.close();
528
529 // Disable cheri's master key to mix things up.
530 env(fset(cheri, asfDisableMaster), Sig(cheri));
531 env.close();
532
533 auto const baseFee = env.current()->fees().base;
534 std::uint32_t aliceSeq = 0;
535
536 // these represent oft-repeated setup for input json below
537 auto const setupTx = [&] -> json::Value {
538 json::Value jv;
539 jv[jss::tx_json][jss::Account] = alice.human();
540 jv[jss::tx_json][jss::TransactionType] = jss::AccountSet;
541 jv[jss::tx_json][jss::Fee] = (8 * baseFee).jsonClipped();
542 jv[jss::tx_json][jss::Sequence] = env.seq(alice);
543 jv[jss::tx_json][jss::SigningPubKey] = "";
544 return jv;
545 };
546 auto const cheriSign = [&](json::Value& jv) {
547 jv[jss::account] = cheri.human();
548 jv[jss::key_type] = "ed25519";
549 jv[jss::passphrase] = cher.name();
550 };
551 auto const beckySign = [&](json::Value& jv) {
552 jv[jss::account] = becky.human();
553 jv[jss::secret] = beck.name();
554 };
555
556 {
557 // Attempt a multisigned transaction that meets the quorum.
558 // using sign_for and submit_multisigned
559 aliceSeq = env.seq(alice);
560 json::Value jvOne = setupTx();
561 cheriSign(jvOne);
562 auto jrr = env.rpc("json", "sign_for", to_string(jvOne))[jss::result];
563 BEAST_EXPECT(jrr[jss::status] == "success");
564
565 // for the second sign_for, use the returned tx_json with
566 // first signer info
567 json::Value jvTwo;
568 jvTwo[jss::tx_json] = jrr[jss::tx_json];
569 beckySign(jvTwo);
570 jrr = env.rpc("json", "sign_for", to_string(jvTwo))[jss::result];
571 BEAST_EXPECT(jrr[jss::status] == "success");
572
573 json::Value jvSubmit;
574 jvSubmit[jss::tx_json] = jrr[jss::tx_json];
575 jrr = env.rpc("json", "submit_multisigned", to_string(jvSubmit))[jss::result];
576 BEAST_EXPECT(jrr[jss::status] == "success");
577 env.close();
578 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
579 }
580
581 {
582 // failure case -- SigningPubKey not empty
583 aliceSeq = env.seq(alice);
584 json::Value jvOne = setupTx();
585 jvOne[jss::tx_json][jss::SigningPubKey] = strHex(alice.pk().slice());
586 cheriSign(jvOne);
587 auto jrr = env.rpc("json", "sign_for", to_string(jvOne))[jss::result];
588 BEAST_EXPECT(jrr[jss::status] == "error");
589 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
590 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
591 BEAST_EXPECT(
592 jrr[jss::error_message] ==
593 "When multi-signing 'tx_json.SigningPubKey' must be empty.");
594 }
595
596 {
597 // failure case - bad fee
598 aliceSeq = env.seq(alice);
599 json::Value jvOne = setupTx();
600 jvOne[jss::tx_json][jss::Fee] = -1;
601 cheriSign(jvOne);
602 auto jrr = env.rpc("json", "sign_for", to_string(jvOne))[jss::result];
603 BEAST_EXPECT(jrr[jss::status] == "success");
604
605 // for the second sign_for, use the returned tx_json with
606 // first signer info
607 json::Value jvTwo;
608 jvTwo[jss::tx_json] = jrr[jss::tx_json];
609 beckySign(jvTwo);
610 jrr = env.rpc("json", "sign_for", to_string(jvTwo))[jss::result];
611 BEAST_EXPECT(jrr[jss::status] == "success");
612
613 json::Value jvSubmit;
614 jvSubmit[jss::tx_json] = jrr[jss::tx_json];
615 jrr = env.rpc("json", "submit_multisigned", to_string(jvSubmit))[jss::result];
616 BEAST_EXPECT(jrr[jss::status] == "error");
617 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
618 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
619 BEAST_EXPECT(
620 jrr[jss::error_message] == "Invalid Fee field. Fees must be greater than zero.");
621 }
622
623 {
624 // failure case - bad fee v2
625 aliceSeq = env.seq(alice);
626 json::Value jvOne = setupTx();
627 jvOne[jss::tx_json][jss::Fee] = alice["USD"](10).value().getFullText();
628 cheriSign(jvOne);
629 auto jrr = env.rpc("json", "sign_for", to_string(jvOne))[jss::result];
630 BEAST_EXPECT(jrr[jss::status] == "success");
631
632 // for the second sign_for, use the returned tx_json with
633 // first signer info
634 json::Value jvTwo;
635 jvTwo[jss::tx_json] = jrr[jss::tx_json];
636 beckySign(jvTwo);
637 jrr = env.rpc("json", "sign_for", to_string(jvTwo))[jss::result];
638 BEAST_EXPECT(jrr[jss::status] == "success");
639
640 json::Value jvSubmit;
641 jvSubmit[jss::tx_json] = jrr[jss::tx_json];
642 jrr = env.rpc("json", "submit_multisigned", to_string(jvSubmit))[jss::result];
643 BEAST_EXPECT(jrr[jss::status] == "error");
644 BEAST_EXPECT(jrr[jss::error] == "internal");
645 BEAST_EXPECT(jrr[jss::error_code] == RpcInternal);
646 BEAST_EXPECT(jrr[jss::error_message] == "Internal error.");
647 }
648
649 {
650 // cheri should not be able to multisign using her master key.
651 aliceSeq = env.seq(alice);
652 json::Value jv = setupTx();
653 jv[jss::account] = cheri.human();
654 jv[jss::secret] = cheri.name();
655 auto jrr = env.rpc("json", "sign_for", to_string(jv))[jss::result];
656 BEAST_EXPECT(jrr[jss::status] == "error");
657 BEAST_EXPECT(jrr[jss::error] == "masterDisabled");
658 BEAST_EXPECT(jrr[jss::error_code] == RpcMasterDisabled);
659 BEAST_EXPECT(jrr[jss::error_message] == "Master key is disabled.");
660 env.close();
661 BEAST_EXPECT(env.seq(alice) == aliceSeq);
662 }
663
664 {
665 // Unlike cheri, becky should also be able to sign using her master
666 // key
667 aliceSeq = env.seq(alice);
668 json::Value jvOne = setupTx();
669 cheriSign(jvOne);
670 auto jrr = env.rpc("json", "sign_for", to_string(jvOne))[jss::result];
671 BEAST_EXPECT(jrr[jss::status] == "success");
672
673 // for the second sign_for, use the returned tx_json with
674 // first signer info
675 json::Value jvTwo;
676 jvTwo[jss::tx_json] = jrr[jss::tx_json];
677 jvTwo[jss::account] = becky.human();
678 jvTwo[jss::key_type] = "ed25519";
679 jvTwo[jss::passphrase] = becky.name();
680 jrr = env.rpc("json", "sign_for", to_string(jvTwo))[jss::result];
681 BEAST_EXPECT(jrr[jss::status] == "success");
682
683 json::Value jvSubmit;
684 jvSubmit[jss::tx_json] = jrr[jss::tx_json];
685 jrr = env.rpc("json", "submit_multisigned", to_string(jvSubmit))[jss::result];
686 BEAST_EXPECT(jrr[jss::status] == "success");
687 env.close();
688 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
689 }
690
691 {
692 // check for bad or bogus accounts in the tx
693 json::Value jv = setupTx();
694 jv[jss::tx_json][jss::Account] = "DEADBEEF";
695 cheriSign(jv);
696 auto jrr = env.rpc("json", "sign_for", to_string(jv))[jss::result];
697 BEAST_EXPECT(jrr[jss::status] == "error");
698 BEAST_EXPECT(jrr[jss::error] == "srcActMalformed");
699 BEAST_EXPECT(jrr[jss::error_code] == RpcSrcActMalformed);
700 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'tx_json.Account'.");
701
702 Account const jimmy{"jimmy"};
703 jv[jss::tx_json][jss::Account] = jimmy.human();
704 jrr = env.rpc("json", "sign_for", to_string(jv))[jss::result];
705 BEAST_EXPECT(jrr[jss::status] == "error");
706 BEAST_EXPECT(jrr[jss::error] == "srcActNotFound");
707 BEAST_EXPECT(jrr[jss::error_code] == RpcSrcActNotFound);
708 BEAST_EXPECT(jrr[jss::error_message] == "Source account not found.");
709 }
710
711 {
712 aliceSeq = env.seq(alice);
713 json::Value jv = setupTx();
714 jv[jss::tx_json][sfSigners.fieldName] = json::Value{json::ValueType::Array};
715 beckySign(jv);
716 auto jrr = env.rpc("json", "submit_multisigned", to_string(jv))[jss::result];
717 BEAST_EXPECT(jrr[jss::status] == "error");
718 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
719 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
720 BEAST_EXPECT(jrr[jss::error_message] == "tx_json.Signers array may not be empty.");
721 env.close();
722 BEAST_EXPECT(env.seq(alice) == aliceSeq);
723 }
724 }
725
726 void
728 {
729 testcase("Heterogeneous Signers");
730
731 using namespace jtx;
732 Env env{*this, features};
733 Account const alice{"alice", KeyType::Secp256k1};
734 Account const becky{"becky", KeyType::Ed25519};
735 Account const cheri{"cheri", KeyType::Secp256k1};
736 Account const daria{"daria", KeyType::Ed25519};
737 env.fund(XRP(1000), alice, becky, cheri, daria);
738 env.close();
739
740 // alice uses a regular key with the master disabled.
741 Account const alie{"alie", KeyType::Secp256k1};
742 env(regkey(alice, alie));
743 env(fset(alice, asfDisableMaster), Sig(alice));
744
745 // becky is master only without a regular key.
746
747 // cheri has a regular key, but leaves the master key enabled.
748 Account const cher{"cher", KeyType::Secp256k1};
749 env(regkey(cheri, cher));
750
751 // daria has a regular key and disables her master key.
752 Account const dari{"dari", KeyType::Ed25519};
753 env(regkey(daria, dari));
754 env(fset(daria, asfDisableMaster), Sig(daria));
755 env.close();
756
757 // Attach signers to alice.
758 env(signers(alice, 1, {{becky, 1}, {cheri, 1}, {daria, 1}, {jinni_, 1}}), Sig(alie));
759 env.close();
760 env.require(Owners(alice, 1));
761
762 // Each type of signer should succeed individually.
763 auto const baseFee = env.current()->fees().base;
764 std::uint32_t aliceSeq = env.seq(alice);
765 env(noop(alice), Msig(becky), Fee(2 * baseFee));
766 env.close();
767 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
768
769 aliceSeq = env.seq(alice);
770 env(noop(alice), Msig(cheri), Fee(2 * baseFee));
771 env.close();
772 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
773
774 aliceSeq = env.seq(alice);
775 env(noop(alice), Msig(Reg{cheri, cher}), Fee(2 * baseFee));
776 env.close();
777 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
778
779 aliceSeq = env.seq(alice);
780 env(noop(alice), Msig(Reg{daria, dari}), Fee(2 * baseFee));
781 env.close();
782 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
783
784 aliceSeq = env.seq(alice);
785 env(noop(alice), Msig(jinni_), Fee(2 * baseFee));
786 env.close();
787 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
788
789 // Should also work if all signers sign.
790 aliceSeq = env.seq(alice);
791 env(noop(alice), Fee(5 * baseFee), Msig(becky, Reg{cheri, cher}, Reg{daria, dari}, jinni_));
792 env.close();
793 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
794
795 // Require all signers to sign.
796 env(signers(
797 alice,
798 0x3FFFC,
799 {{becky, 0xFFFF}, {cheri, 0xFFFF}, {daria, 0xFFFF}, {jinni_, 0xFFFF}}),
800 Sig(alie));
801 env.close();
802 env.require(Owners(alice, 1));
803
804 aliceSeq = env.seq(alice);
805 env(noop(alice), Fee(9 * baseFee), Msig(becky, Reg{cheri, cher}, Reg{daria, dari}, jinni_));
806 env.close();
807 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
808
809 // Try cheri with both key types.
810 aliceSeq = env.seq(alice);
811 env(noop(alice), Fee(5 * baseFee), Msig(becky, cheri, Reg{daria, dari}, jinni_));
812 env.close();
813 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
814
815 // Makes sure the maximum allowed number of signers works.
816 env(signers(
817 alice,
818 0x7FFF8,
819 {
820 {becky, 0xFFFF},
821 {cheri, 0xFFFF},
822 {daria, 0xFFFF},
823 {haunt_, 0xFFFF},
824 {jinni_, 0xFFFF},
825 {phase_, 0xFFFF},
826 {shade_, 0xFFFF},
827 {spook_, 0xFFFF},
828 }),
829 Sig(alie));
830 env.close();
831 env.require(Owners(alice, 1));
832
833 aliceSeq = env.seq(alice);
834 env(noop(alice),
835 Fee(9 * baseFee),
836 Msig(
837 becky, Reg{cheri, cher}, Reg{daria, dari}, haunt_, jinni_, phase_, shade_, spook_));
838 env.close();
839 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
840
841 // One signer short should fail.
842 aliceSeq = env.seq(alice);
843 env(noop(alice),
844 Msig(becky, cheri, haunt_, jinni_, phase_, shade_, spook_),
845 Fee(8 * baseFee),
847 env.close();
848 BEAST_EXPECT(env.seq(alice) == aliceSeq);
849
850 // Remove alice's signer list and get the owner count back.
851 env(signers(alice, jtx::kNone), Sig(alie));
852 env.close();
853 env.require(Owners(alice, 0));
854 }
855
856 // We want to always leave an account signable. Make sure the that we
857 // disallow removing the last way a transaction may be signed.
858 void
860 {
861 testcase("Key Disable");
862
863 using namespace jtx;
864 Env env{*this, features};
865 Account const alice{"alice", KeyType::Ed25519};
866 env.fund(XRP(1000), alice);
867 env.close();
868
869 // There are three negative tests we need to make:
870 // M0. A lone master key cannot be disabled.
871 // R0. A lone regular key cannot be removed.
872 // L0. A lone signer list cannot be removed.
873 //
874 // Additionally, there are 6 positive tests we need to make:
875 // M1. The master key can be disabled if there's a regular key.
876 // M2. The master key can be disabled if there's a signer list.
877 //
878 // R1. The regular key can be removed if there's a signer list.
879 // R2. The regular key can be removed if the master key is enabled.
880 //
881 // L1. The signer list can be removed if the master key is enabled.
882 // L2. The signer list can be removed if there's a regular key.
883
884 // Master key tests.
885 // M0: A lone master key cannot be disabled.
886 env(fset(alice, asfDisableMaster), Sig(alice), Ter(tecNO_ALTERNATIVE_KEY));
887
888 // Add a regular key.
889 Account const alie{"alie", KeyType::Ed25519};
890 env(regkey(alice, alie));
891
892 // M1: The master key can be disabled if there's a regular key.
893 env(fset(alice, asfDisableMaster), Sig(alice));
894
895 // R0: A lone regular key cannot be removed.
896 env(regkey(alice, kDisabled), Sig(alie), Ter(tecNO_ALTERNATIVE_KEY));
897
898 // Add a signer list.
899 env(signers(alice, 1, {{bogie_, 1}}), Sig(alie));
900
901 // R1: The regular key can be removed if there's a signer list.
902 env(regkey(alice, kDisabled), Sig(alie));
903
904 // L0: A lone signer list cannot be removed.
905 auto const baseFee = env.current()->fees().base;
906 env(signers(alice, jtx::kNone), Msig(bogie_), Fee(2 * baseFee), Ter(tecNO_ALTERNATIVE_KEY));
907
908 // Enable the master key.
909 env(fclear(alice, asfDisableMaster), Msig(bogie_), Fee(2 * baseFee));
910
911 // L1: The signer list can be removed if the master key is enabled.
912 env(signers(alice, jtx::kNone), Msig(bogie_), Fee(2 * baseFee));
913
914 // Add a signer list.
915 env(signers(alice, 1, {{bogie_, 1}}), Sig(alice));
916
917 // M2: The master key can be disabled if there's a signer list.
918 env(fset(alice, asfDisableMaster), Sig(alice));
919
920 // Add a regular key.
921 env(regkey(alice, alie), Msig(bogie_), Fee(2 * baseFee));
922
923 // L2: The signer list can be removed if there's a regular key.
924 env(signers(alice, jtx::kNone), Sig(alie));
925
926 // Enable the master key.
927 env(fclear(alice, asfDisableMaster), Sig(alie));
928
929 // R2: The regular key can be removed if the master key is enabled.
930 env(regkey(alice, kDisabled), Sig(alie));
931 }
932
933 // Verify that the first regular key can be made for free using the
934 // master key, but not when multisigning.
935 void
937 {
938 testcase("Regular Key");
939
940 using namespace jtx;
941 Env env{*this, features};
942 Account const alice{"alice", KeyType::Secp256k1};
943 env.fund(XRP(1000), alice);
944 env.close();
945
946 // Give alice a regular key with a zero fee. Should succeed. Once.
947 Account const alie{"alie", KeyType::Ed25519};
948 env(regkey(alice, alie), Sig(alice), Fee(0));
949
950 // Try it again and creating the regular key for free should fail.
951 Account const liss{"liss", KeyType::Secp256k1};
952 env(regkey(alice, liss), Sig(alice), Fee(0), Ter(telINSUF_FEE_P));
953
954 // But paying to create a regular key should succeed.
955 env(regkey(alice, liss), Sig(alice));
956
957 // In contrast, trying to multisign for a regular key with a zero
958 // fee should always fail. Even the first time.
959 Account const becky{"becky", KeyType::Ed25519};
960 env.fund(XRP(1000), becky);
961 env.close();
962
963 env(signers(becky, 1, {{alice, 1}}), Sig(becky));
964 env(regkey(becky, alie), Msig(alice), Fee(0), Ter(telINSUF_FEE_P));
965
966 // Using the master key to sign for a regular key for free should
967 // still work.
968 env(regkey(becky, alie), Sig(becky), Fee(0));
969 }
970
971 // See if every kind of transaction can be successfully multi-signed.
972 void
974 {
975 testcase("Transaction Types");
976
977 using namespace jtx;
978 Env env{*this, features};
979 Account const alice{"alice", KeyType::Secp256k1};
980 Account const becky{"becky", KeyType::Ed25519};
981 Account const zelda{"zelda", KeyType::Secp256k1};
982 Account const gw{"gw"};
983 auto const usd = gw["USD"];
984 env.fund(XRP(1000), alice, becky, zelda, gw);
985 env.close();
986
987 // alice uses a regular key with the master disabled.
988 Account const alie{"alie", KeyType::Secp256k1};
989 env(regkey(alice, alie));
990 env(fset(alice, asfDisableMaster), Sig(alice));
991
992 // Attach signers to alice.
993 env(signers(alice, 2, {{becky, 1}, {bogie_, 1}}), Sig(alie));
994 env.close();
995 env.require(Owners(alice, 1));
996
997 // Multisign a ttPAYMENT.
998 auto const baseFee = env.current()->fees().base;
999 std::uint32_t aliceSeq = env.seq(alice);
1000 env(pay(alice, env.master, XRP(1)), Msig(becky, bogie_), Fee(3 * baseFee));
1001 env.close();
1002 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1003
1004 // Multisign a ttACCOUNT_SET.
1005 aliceSeq = env.seq(alice);
1006 env(noop(alice), Msig(becky, bogie_), Fee(3 * baseFee));
1007 env.close();
1008 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1009
1010 // Multisign a ttREGULAR_KEY_SET.
1011 aliceSeq = env.seq(alice);
1012 Account const ace{"ace", KeyType::Secp256k1};
1013 env(regkey(alice, ace), Msig(becky, bogie_), Fee(3 * baseFee));
1014 env.close();
1015 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1016
1017 // Multisign a ttTRUST_SET
1018 env(trust("alice", usd(100)),
1019 Msig(becky, bogie_),
1020 Fee(3 * baseFee),
1021 Require(Lines("alice", 1)));
1022 env.close();
1023 env.require(Owners(alice, 2));
1024
1025 // Multisign a ttOFFER_CREATE transaction.
1026 env(pay(gw, alice, usd(50)));
1027 env.close();
1028 env.require(Balance(alice, usd(50)));
1029 env.require(Balance(gw, alice["USD"](-50)));
1030
1031 std::uint32_t const offerSeq = env.seq(alice);
1032 env(offer(alice, XRP(50), usd(50)), Msig(becky, bogie_), Fee(3 * baseFee));
1033 env.close();
1034 env.require(Owners(alice, 3));
1035
1036 // Now multisign a ttOFFER_CANCEL canceling the offer we just created.
1037 {
1038 aliceSeq = env.seq(alice);
1039 env(offerCancel(alice, offerSeq), Seq(aliceSeq), Msig(becky, bogie_), Fee(3 * baseFee));
1040 env.close();
1041 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1042 env.require(Owners(alice, 2));
1043 }
1044
1045 // Multisign a ttSIGNER_LIST_SET.
1046 env(signers(alice, 3, {{becky, 1}, {bogie_, 1}, {demon_, 1}}),
1047 Msig(becky, bogie_),
1048 Fee(3 * baseFee));
1049 env.close();
1050 env.require(Owners(alice, 2));
1051 }
1052
1053 void
1055 {
1056 testcase("Bad Signature Text");
1057
1058 // Verify that the text returned for signature failures is correct.
1059 using namespace jtx;
1060
1061 Env env{*this, features};
1062
1063 // lambda that submits an STTx and returns the resulting JSON.
1064 auto const submitSTTx = [&env](STTx const& stx) {
1065 json::Value jvResult;
1066 jvResult[jss::tx_blob] = strHex(stx.getSerializer().slice());
1067 return env.rpc("json", "submit", to_string(jvResult));
1068 };
1069
1070 Account const alice{"alice"};
1071 env.fund(XRP(1000), alice);
1072 env.close();
1073 env(signers(alice, 1, {{bogie_, 1}, {demon_, 1}}), Sig(alice));
1074
1075 auto const baseFee = env.current()->fees().base;
1076 {
1077 // Single-sign, but leave an empty SigningPubKey.
1078 JTx const tx = env.jt(noop(alice), Sig(alice));
1079 STTx local = *tx.stx;
1080 local.setFieldVL(sfSigningPubKey, Blob()); // Empty SigningPubKey
1081 auto const info = submitSTTx(local);
1082 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1083 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1084 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1085 BEAST_EXPECT(
1086 info[jss::result][jss::error_exception] ==
1087 "fails local checks: Empty SigningPubKey.");
1088 }
1089 {
1090 // Single-sign, but invalidate the signature.
1091 JTx const tx = env.jt(noop(alice), Sig(alice));
1092 STTx local = *tx.stx;
1093 // Flip some bits in the signature.
1094 auto badSig = local.getFieldVL(sfTxnSignature);
1095 badSig[20] ^= 0xAA;
1096 local.setFieldVL(sfTxnSignature, badSig);
1097 // Signature should fail.
1098 auto const info = submitSTTx(local);
1099 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1100 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1101 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1102 BEAST_EXPECT(
1103 info[jss::result][jss::error_exception] ==
1104 "fails local checks: Invalid signature.");
1105 }
1106 {
1107 // Single-sign, but invalidate the sequence number.
1108 JTx const tx = env.jt(noop(alice), Sig(alice));
1109 STTx local = *tx.stx;
1110 // Flip some bits in the signature.
1111 auto seq = local.getFieldU32(sfSequence);
1112 local.setFieldU32(sfSequence, seq + 1);
1113 // Signature should fail.
1114 auto const info = submitSTTx(local);
1115 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1116 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1117 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1118 BEAST_EXPECT(
1119 info[jss::result][jss::error_exception] ==
1120 "fails local checks: Invalid signature.");
1121 }
1122 {
1123 // Multisign, but leave a nonempty sfSigningPubKey.
1124 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(bogie_));
1125 STTx local = *tx.stx;
1126 local[sfSigningPubKey] = alice.pk(); // Insert sfSigningPubKey
1127 auto const info = submitSTTx(local);
1128 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1129 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1130 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1131 BEAST_EXPECT(
1132 info[jss::result][jss::error_exception] ==
1133 "fails local checks: Cannot both single- and multi-sign.");
1134 }
1135 {
1136 // Both multi- and single-sign with an empty SigningPubKey.
1137 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(bogie_));
1138 STTx local = *tx.stx;
1139 local.sign(alice.pk(), alice.sk());
1140 local.setFieldVL(sfSigningPubKey, Blob()); // Empty SigningPubKey
1141 auto const info = submitSTTx(local);
1142 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1143 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1144 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1145 BEAST_EXPECT(
1146 info[jss::result][jss::error_exception] ==
1147 "fails local checks: Cannot both single- and multi-sign.");
1148 }
1149 {
1150 // Multisign but invalidate one of the signatures.
1151 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(bogie_));
1152 STTx local = *tx.stx;
1153 // Flip some bits in the signature.
1154 auto& signer = local.peekFieldArray(sfSigners).back();
1155 auto badSig = signer.getFieldVL(sfTxnSignature);
1156 badSig[20] ^= 0xAA;
1157 signer.setFieldVL(sfTxnSignature, badSig);
1158 // Signature should fail.
1159 auto const info = submitSTTx(local);
1160 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1161 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1162 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1163 BEAST_EXPECT(
1164 info[jss::result][jss::error_exception].asString().contains(
1165 "Invalid signature on account r"));
1166 }
1167 {
1168 // Multisign with an empty signers array should fail.
1169 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(bogie_));
1170 STTx local = *tx.stx;
1171 local.peekFieldArray(sfSigners).clear(); // Empty Signers array.
1172 auto const info = submitSTTx(local);
1173 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1174 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1175 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1176 BEAST_EXPECT(
1177 info[jss::result][jss::error_exception] ==
1178 "fails local checks: Invalid Signers array size.");
1179 }
1180 {
1181 JTx const tx = env.jt(
1182 noop(alice),
1183 Fee(2 * baseFee),
1184
1185 Msig(
1186 bogie_,
1187 bogie_,
1188 bogie_,
1189 bogie_,
1190 bogie_,
1191 bogie_,
1192 bogie_,
1193 bogie_,
1194 bogie_,
1195 bogie_,
1196 bogie_,
1197 bogie_,
1198 bogie_,
1199 bogie_,
1200 bogie_,
1201 bogie_,
1202 bogie_,
1203 bogie_,
1204 bogie_,
1205 bogie_,
1206 bogie_,
1207 bogie_,
1208 bogie_,
1209 bogie_,
1210 bogie_,
1211 bogie_,
1212 bogie_,
1213 bogie_,
1214 bogie_,
1215 bogie_,
1216 bogie_,
1217 bogie_,
1218 bogie_));
1219 STTx const local = *tx.stx;
1220 auto const info = submitSTTx(local);
1221 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1222 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1223 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1224 BEAST_EXPECT(
1225 info[jss::result][jss::error_exception] ==
1226 "fails local checks: Invalid Signers array size.");
1227 }
1228 {
1229 // The account owner may not multisign for themselves.
1230 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(alice));
1231 STTx const local = *tx.stx;
1232 auto const info = submitSTTx(local);
1233 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1234 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1235 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1236 BEAST_EXPECT(
1237 info[jss::result][jss::error_exception] ==
1238 "fails local checks: Invalid multisigner.");
1239 }
1240 {
1241 // No duplicate multisignatures allowed.
1242 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(bogie_, bogie_));
1243 STTx const local = *tx.stx;
1244 auto const info = submitSTTx(local);
1245 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1246 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1247 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1248 BEAST_EXPECT(
1249 info[jss::result][jss::error_exception] ==
1250 "fails local checks: Duplicate Signers not allowed.");
1251 }
1252 {
1253 // Multisignatures must be submitted in sorted order.
1254 JTx const tx = env.jt(noop(alice), Fee(2 * baseFee), Msig(bogie_, demon_));
1255 STTx local = *tx.stx;
1256 // Unsort the Signers array.
1257 auto& signers = local.peekFieldArray(sfSigners);
1259 // Signature should fail.
1260 auto const info = submitSTTx(local);
1261 BEAST_EXPECT(info[jss::result][jss::error] == "invalidTransaction");
1262 BEAST_EXPECT(!info[jss::result].isMember(jss::error_code));
1263 BEAST_EXPECT(info[jss::result][jss::error_message].isNull());
1264 BEAST_EXPECT(
1265 info[jss::result][jss::error_exception] ==
1266 "fails local checks: Unsorted Signers array.");
1267 }
1268 }
1269
1270 void
1272 {
1273 testcase("No Multisigners");
1274
1275 using namespace jtx;
1276 Env env{*this, features};
1277 Account const alice{"alice", KeyType::Ed25519};
1278 Account const becky{"becky", KeyType::Secp256k1};
1279 env.fund(XRP(1000), alice, becky);
1280 env.close();
1281
1282 auto const baseFee = env.current()->fees().base;
1283 env(noop(alice), Msig(becky, demon_), Fee(3 * baseFee), Ter(tefNOT_MULTI_SIGNING));
1284 }
1285
1286 void
1288 {
1289 testcase("Multisigning multisigner");
1290
1291 // Set up a signer list where one of the signers has both the
1292 // master disabled and no regular key (because that signer is
1293 // exclusively multisigning). That signer should no longer be
1294 // able to successfully sign the signer list.
1295
1296 using namespace jtx;
1297 Env env{*this, features};
1298 Account const alice{"alice", KeyType::Ed25519};
1299 Account const becky{"becky", KeyType::Secp256k1};
1300 env.fund(XRP(1000), alice, becky);
1301 env.close();
1302
1303 // alice sets up a signer list with becky as a signer.
1304 env(signers(alice, 1, {{becky, 1}}));
1305 env.close();
1306
1307 // becky sets up her signer list.
1308 env(signers(becky, 1, {{bogie_, 1}, {demon_, 1}}));
1309 env.close();
1310
1311 // Because becky has not (yet) disabled her master key, she can
1312 // multisign a transaction for alice.
1313 auto const baseFee = env.current()->fees().base;
1314 env(noop(alice), Msig(becky), Fee(2 * baseFee));
1315 env.close();
1316
1317 // Now becky disables her master key.
1318 env(fset(becky, asfDisableMaster));
1319 env.close();
1320
1321 // Since becky's master key is disabled she can no longer
1322 // multisign for alice.
1323 env(noop(alice), Msig(becky), Fee(2 * baseFee), Ter(tefMASTER_DISABLED));
1324 env.close();
1325
1326 // Becky cannot 2-level multisign for alice. 2-level multisigning
1327 // is not supported.
1328 env(noop(alice), Msig(Reg{becky, bogie_}), Fee(2 * baseFee), Ter(tefBAD_SIGNATURE));
1329 env.close();
1330
1331 // Verify that becky cannot sign with a regular key that she has
1332 // not yet enabled.
1333 Account const beck{"beck", KeyType::Ed25519};
1334 env(noop(alice), Msig(Reg{becky, beck}), Fee(2 * baseFee), Ter(tefBAD_SIGNATURE));
1335 env.close();
1336
1337 // Once becky gives herself the regular key, she can sign for alice
1338 // using that regular key.
1339 env(regkey(becky, beck), Msig(demon_), Fee(2 * baseFee));
1340 env.close();
1341
1342 env(noop(alice), Msig(Reg{becky, beck}), Fee(2 * baseFee));
1343 env.close();
1344
1345 // The presence of becky's regular key does not influence whether she
1346 // can 2-level multisign; it still won't work.
1347 env(noop(alice), Msig(Reg{becky, demon_}), Fee(2 * baseFee), Ter(tefBAD_SIGNATURE));
1348 env.close();
1349 }
1350
1351 void
1353 {
1354 testcase("sign_for Hash");
1355
1356 // Make sure that the "hash" field returned by the "sign_for" RPC
1357 // command matches the hash returned when that command is sent
1358 // through "submit_multisigned". Make sure that hash also locates
1359 // the transaction in the ledger.
1360 using namespace jtx;
1361 Account const alice{"alice", KeyType::Ed25519};
1362
1363 Env env(
1364 *this,
1366 cfg->loadFromString(std::string("[") + Sections::kSigningSupport + "]\ntrue");
1367 return cfg;
1368 }),
1369 features);
1370 env.fund(XRP(1000), alice);
1371 env.close();
1372
1373 env(signers(alice, 2, {{bogie_, 1}, {ghost_, 1}}));
1374 env.close();
1375
1376 // Use sign_for to sign a transaction where alice pays 10 XRP to
1377 // masterpassphrase.
1378 auto const baseFee = env.current()->fees().base;
1379 json::Value jvSig1;
1380 jvSig1[jss::account] = bogie_.human();
1381 jvSig1[jss::secret] = bogie_.name();
1382 jvSig1[jss::tx_json][jss::Account] = alice.human();
1383 jvSig1[jss::tx_json][jss::Amount] = 10000000;
1384 jvSig1[jss::tx_json][jss::Destination] = env.master.human();
1385 jvSig1[jss::tx_json][jss::Fee] = (3 * baseFee).jsonClipped();
1386 jvSig1[jss::tx_json][jss::Sequence] = env.seq(alice);
1387 jvSig1[jss::tx_json][jss::TransactionType] = jss::Payment;
1388
1389 json::Value jvSig2 = env.rpc("json", "sign_for", to_string(jvSig1));
1390 BEAST_EXPECT(jvSig2[jss::result][jss::status].asString() == "success");
1391
1392 // Save the hash with one signature for use later.
1393 std::string const hash1 = jvSig2[jss::result][jss::tx_json][jss::hash].asString();
1394
1395 // Add the next signature and sign again.
1396 jvSig2[jss::result][jss::account] = ghost_.human();
1397 jvSig2[jss::result][jss::secret] = ghost_.name();
1398 json::Value jvSubmit = env.rpc("json", "sign_for", to_string(jvSig2[jss::result]));
1399 BEAST_EXPECT(jvSubmit[jss::result][jss::status].asString() == "success");
1400
1401 // Save the hash with two signatures for use later.
1402 std::string const hash2 = jvSubmit[jss::result][jss::tx_json][jss::hash].asString();
1403 BEAST_EXPECT(hash1 != hash2);
1404
1405 // Submit the result of the two signatures.
1406 json::Value jvResult =
1407 env.rpc("json", "submit_multisigned", to_string(jvSubmit[jss::result]));
1408 BEAST_EXPECT(jvResult[jss::result][jss::status].asString() == "success");
1409 BEAST_EXPECT(jvResult[jss::result][jss::engine_result].asString() == "tesSUCCESS");
1410
1411 // The hash from the submit should be the same as the hash from the
1412 // second signing.
1413 BEAST_EXPECT(hash2 == jvResult[jss::result][jss::tx_json][jss::hash].asString());
1414 env.close();
1415
1416 // The transaction we just submitted should now be available and
1417 // validated.
1418 json::Value jvTx = env.rpc("tx", hash2);
1419 BEAST_EXPECT(jvTx[jss::result][jss::status].asString() == "success");
1420 BEAST_EXPECT(jvTx[jss::result][jss::validated].asString() == "true");
1421 BEAST_EXPECT(
1422 jvTx[jss::result][jss::meta][sfTransactionResult.jsonName].asString() == "tesSUCCESS");
1423 }
1424
1425 void
1427 {
1428 testcase("Signers With Tickets");
1429
1430 using namespace jtx;
1431 Env env{*this, features};
1432 Account const alice{"alice", KeyType::Ed25519};
1433 env.fund(XRP(2000), alice);
1434 env.close();
1435
1436 // Create a few tickets that alice can use up.
1437 std::uint32_t aliceTicketSeq{env.seq(alice) + 1};
1438 env(ticket::create(alice, 20));
1439 env.close();
1440 std::uint32_t const aliceSeq = env.seq(alice);
1441
1442 // Attach phantom signers to alice using a ticket.
1443 env(signers(alice, 1, {{bogie_, 1}, {demon_, 1}}), ticket::Use(aliceTicketSeq++));
1444 env.close();
1445 env.require(Tickets(alice, env.seq(alice) - aliceTicketSeq));
1446 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1447
1448 // This should work.
1449 auto const baseFee = env.current()->fees().base;
1450 env(noop(alice), Msig(bogie_, demon_), Fee(3 * baseFee), ticket::Use(aliceTicketSeq++));
1451 env.close();
1452 env.require(Tickets(alice, env.seq(alice) - aliceTicketSeq));
1453 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1454
1455 // Should also be able to remove the signer list using a ticket.
1456 env(signers(alice, jtx::kNone), ticket::Use(aliceTicketSeq++));
1457 env.close();
1458 env.require(Tickets(alice, env.seq(alice) - aliceTicketSeq));
1459 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1460 }
1461
1462 void
1464 {
1465 testcase("Signers With Tags");
1466
1467 using namespace jtx;
1468 Env env{*this, features};
1469 Account const alice{"alice", KeyType::Ed25519};
1470 env.fund(XRP(1000), alice);
1471 env.close();
1472 uint8_t tag1[] = {
1473 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03,
1474 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
1475 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
1476 };
1477
1478 uint8_t tag2[] = "hello world some ascii 32b long"; // including 1 byte for NUL
1479
1480 UInt256 bogieTag = xrpl::BaseUInt<256>::fromVoid(tag1);
1481 UInt256 demonTag = xrpl::BaseUInt<256>::fromVoid(tag2);
1482
1483 // Attach phantom signers to alice and use them for a transaction.
1484 env(signers(alice, 1, {{bogie_, 1, bogieTag}, {demon_, 1, demonTag}}));
1485 env.close();
1486 env.require(Owners(alice, 1));
1487
1488 // This should work.
1489 auto const baseFee = env.current()->fees().base;
1490 std::uint32_t aliceSeq = env.seq(alice);
1491 env(noop(alice), Msig(bogie_, demon_), Fee(3 * baseFee));
1492 env.close();
1493 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1494
1495 // Either signer alone should work.
1496 aliceSeq = env.seq(alice);
1497 env(noop(alice), Msig(bogie_), Fee(2 * baseFee));
1498 env.close();
1499 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1500
1501 aliceSeq = env.seq(alice);
1502 env(noop(alice), Msig(demon_), Fee(2 * baseFee));
1503 env.close();
1504 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1505
1506 // Duplicate signers should fail.
1507 aliceSeq = env.seq(alice);
1508 env(noop(alice),
1509 Msig(demon_, demon_),
1510 Fee(3 * baseFee),
1511 Rpc("invalidTransaction", "fails local checks: Duplicate Signers not allowed."));
1512 env.close();
1513 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1514
1515 // A non-signer should fail.
1516 aliceSeq = env.seq(alice);
1517 env(noop(alice), Msig(bogie_, spook_), Fee(3 * baseFee), Ter(tefBAD_SIGNATURE));
1518 env.close();
1519 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1520
1521 // Don't meet the quorum. Should fail.
1522 env(signers(alice, 2, {{bogie_, 1}, {demon_, 1}}));
1523 aliceSeq = env.seq(alice);
1524 env(noop(alice), Msig(bogie_), Fee(2 * baseFee), Ter(tefBAD_QUORUM));
1525 env.close();
1526 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1527
1528 // Meet the quorum. Should succeed.
1529 aliceSeq = env.seq(alice);
1530 env(noop(alice), Msig(bogie_, demon_), Fee(3 * baseFee));
1531 env.close();
1532 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1533 }
1534
1535 void
1537 {
1538 using namespace test::jtx;
1539
1540 Env env{*this, features};
1541 Account const alice{"alice"};
1542
1543 env.fund(XRP(1000), alice);
1544 env.close();
1545
1546 bool const enabled = features[fixInvalidTxFlags];
1547 testcase(std::string("SignerListSet flag, fix ") + (enabled ? "enabled" : "disabled"));
1548
1549 Ter const expected(enabled ? TER(temINVALID_FLAG) : TER(tesSUCCESS));
1550 env(signers(alice, 2, {{bogie_, 1}, {ghost_, 1}}), expected, Txflags(tfPassive));
1551 env.close();
1552 }
1553
1554 void
1556 {
1557 testcase("SignerList Object");
1558
1559 // Verify that the SignerList object is created correctly.
1560 using namespace jtx;
1561 Env env{*this, features};
1562 Account const alice{"alice", KeyType::Ed25519};
1563 env.fund(XRP(1000), alice);
1564 env.close();
1565
1566 // Attach phantom signers to alice.
1567 env(signers(alice, 1, {{bogie_, 1}, {demon_, 1}}));
1568 env.close();
1569
1570 // Verify that the SignerList object was created correctly.
1571 auto const& sle = env.le(keylet::signerList(alice.id()));
1572 BEAST_EXPECT(sle);
1573 BEAST_EXPECT(sle->getFieldArray(sfSignerEntries).size() == 2);
1574 if (features[fixIncludeKeyletFields])
1575 {
1576 BEAST_EXPECT((*sle)[sfOwner] == alice.id());
1577 }
1578 else
1579 {
1580 BEAST_EXPECT(!sle->isFieldPresent(sfOwner));
1581 }
1582 }
1583
1584 void
1586 {
1587 testNoReserve(features);
1588 testSignerListSet(features);
1589 testPhantomSigners(features);
1590 testFee(features);
1591 testMisorderedSigners(features);
1592 testMasterSigners(features);
1593 testRegularSigners(features);
1595 testHeterogeneousSigners(features);
1596 testKeyDisable(features);
1597 testRegKey(features);
1598 testTxTypes(features);
1599 testBadSignatureText(features);
1600 testNoMultiSigners(features);
1602 testSignForHash(features);
1603 testSignersWithTickets(features);
1604 testSignersWithTags(features);
1605 }
1606
1607 void
1608 run() override
1609 {
1610 using namespace jtx;
1611 auto const all = testableAmendments();
1612
1613 testAll(all);
1614
1615 testSignerListSetFlags(all - fixInvalidTxFlags);
1617
1618 testSignerListObject(all - fixIncludeKeyletFields);
1620 }
1621};
1622
1624
1625} // namespace xrpl::test
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Represents a JSON value.
Definition json_value.h:121
std::string asString() const
Returns the unquoted string value.
static BaseUInt fromVoid(void const *data)
Definition base_uint.h:340
void clear()
Definition STArray.h:260
STObject & back()
Definition STArray.h:193
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:649
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:601
void setFieldVL(SField const &field, Blob const &)
Definition STObject.cpp:791
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:743
STArray & peekFieldArray(SField const &field)
Definition STObject.cpp:481
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Sign the transaction as its account.
Definition STTx.cpp:215
void testMultisigningMultisigner(FeatureBitset features)
void testRegKey(FeatureBitset features)
void testAll(FeatureBitset features)
void testPhantomSigners(FeatureBitset features)
void testBadSignatureText(FeatureBitset features)
void testSignForHash(FeatureBitset features)
void testTxTypes(FeatureBitset features)
void testRegularSigners(FeatureBitset features)
void testKeyDisable(FeatureBitset features)
void testMisorderedSigners(FeatureBitset features)
void testSignersWithTags(FeatureBitset features)
void testSignerListSet(FeatureBitset features)
void testSignerListSetFlags(FeatureBitset features)
void testRegularSignersUsingSubmitMulti(FeatureBitset features)
void testSignerListObject(FeatureBitset features)
void testHeterogeneousSigners(FeatureBitset features)
void testMasterSigners(FeatureBitset features)
void testFee(FeatureBitset features)
void run() override
Runs the suite.
void testNoMultiSigners(FeatureBitset features)
void testNoReserve(FeatureBitset features)
void testSignersWithTickets(FeatureBitset features)
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
SecretKey const & sk() const
Return the secret key.
Definition jtx/Account.h:93
std::string const & human() const
Returns the human readable public key.
std::string const & name() const
Return the name.
Definition jtx/Account.h:75
PublicKey const & pk() const
Return the public key.
Definition jtx/Account.h:84
AccountID id() const
Returns the Account ID.
A balance matches.
Definition balance.h:24
A transaction testing environment.
Definition Env.h:161
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:302
Account const & master
Definition Env.h:165
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1058
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:723
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:766
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
Set the fee on a JTx.
Definition fee.h:20
Set a multisignature on a JTx.
Definition multisign.h:53
std::vector< Reg > signers
Definition multisign.h:55
Match the number of items in the account's owner directory.
Definition owners.h:55
Check a set of conditions.
Definition require.h:49
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:20
Set the regular signature on a JTx.
Definition sig.h:19
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
Set the flags on a JTx.
Definition txflags.h:14
Set a ticket sequence on a JTx.
Definition ticket.h:36
@ Array
array value (ordered list)
Definition json_value.h:32
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:360
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
Definition ticket.cpp:16
static NoneT const kNone
Definition tags.h:9
static DisabledT const kDisabled
Definition tags.h:21
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
json::Value regkey(Account const &account, DisabledT)
Disable the regular key.
Definition regkey.cpp:13
json::Value offerCancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Definition offer.cpp:31
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
json::Value noop(Account const &account)
The null transaction.
Definition noop.h:14
json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Definition flags.h:110
FeatureBitset testableAmendments()
Definition Env.h:92
OwnerCount< ltRIPPLE_STATE > Lines
Match the number of trust lines in the account's owner directory.
Definition owners.h:132
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:14
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
json::Value signers(Account const &account, std::uint32_t quorum, std::vector< Signer > const &v)
Definition multisign.cpp:31
OwnerCount< ltTICKET > Tickets
Match the number of tickets on the account.
Definition ticket.h:54
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:15
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ telINSUF_FEE_P
Definition TER.h:43
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcSrcActMalformed
Definition ErrorCodes.h:103
@ RpcMasterDisabled
Definition ErrorCodes.h:57
@ RpcInvalidParams
Definition ErrorCodes.h:67
@ RpcSrcActNotFound
Definition ErrorCodes.h:105
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
@ tefBAD_QUORUM
Definition TER.h:174
@ tefMASTER_DISABLED
Definition TER.h:171
@ tefBAD_SIGNATURE
Definition TER.h:173
@ tefNOT_MULTI_SIGNING
Definition TER.h:175
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
BaseUInt< 256 > UInt256
Definition base_uint.h:581
@ temINVALID_FLAG
Definition TER.h:99
@ temMALFORMED
Definition TER.h:75
@ temBAD_QUORUM
Definition TER.h:104
@ temBAD_SIGNER
Definition TER.h:103
@ temBAD_WEIGHT
Definition TER.h:105
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecNO_ALTERNATIVE_KEY
Definition TER.h:307
@ tecINSUFFICIENT_RESERVE
Definition TER.h:318
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
@ tesSUCCESS
Definition TER.h:253
T reverse(T... args)
static constexpr auto kSigningSupport
Definition Constants.h:58
Execution context for applying a JSON transaction.
Definition JTx.h:27
std::shared_ptr< STTx const > stx
Definition JTx.h:37
Set the sequence number on a JTx.
Definition seq.h:16