1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
|
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "gtest/gtest.h"
#include <cstdint>
#include <algorithm>
#include <sstream>
#include "ringct/rctTypes.h"
#include "ringct/rctSigs.h"
#include "ringct/rctOps.h"
#include "device/device.hpp"
using namespace std;
using namespace crypto;
using namespace rct;
TEST(ringct, Borromean)
{
int j = 0;
//Tests for Borromean signatures
//#boro true one, false one, C != sum Ci, and one out of the range..
int N = 64;
key64 xv;
key64 P1v;
key64 P2v;
bits indi;
for (j = 0 ; j < N ; j++) {
indi[j] = (int)randXmrAmount(2);
xv[j] = skGen();
if ( (int)indi[j] == 0 ) {
scalarmultBase(P1v[j], xv[j]);
} else {
addKeys1(P1v[j], xv[j], H2[j]);
}
subKeys(P2v[j], P1v[j], H2[j]);
}
//#true one
boroSig bb = genBorromean(xv, P1v, P2v, indi);
ASSERT_TRUE(verifyBorromean(bb, P1v, P2v));
//#false one
indi[3] = (indi[3] + 1) % 2;
bb = genBorromean(xv, P1v, P2v, indi);
ASSERT_FALSE(verifyBorromean(bb, P1v, P2v));
//#true one again
indi[3] = (indi[3] + 1) % 2;
bb = genBorromean(xv, P1v, P2v, indi);
ASSERT_TRUE(verifyBorromean(bb, P1v, P2v));
//#false one
bb = genBorromean(xv, P2v, P1v, indi);
ASSERT_FALSE(verifyBorromean(bb, P1v, P2v));
}
TEST(ringct, MG_sigs)
{
int j = 0;
int N = 0;
//Tests for MG Sigs
//#MG sig: true one
N = 3;// #cols
int R = 3;// #rows
keyV xtmp = skvGen(R);
keyM xm = keyMInit(R, N);// = [[None]*N] #just used to generate test public keys
keyV sk = skvGen(R);
keyM P = keyMInit(R, N);// = keyM[[None]*N] #stores the public keys;
int ind = 2;
int i = 0;
for (j = 0 ; j < R ; j++) {
for (i = 0 ; i < N ; i++)
{
xm[i][j] = skGen();
P[i][j] = scalarmultBase(xm[i][j]);
}
}
for (j = 0 ; j < R ; j++) {
sk[j] = xm[ind][j];
}
key message = identity();
mgSig IIccss = MLSAG_Gen(message, P, sk, NULL, NULL, ind, R, hw::get_device("default"));
ASSERT_TRUE(MLSAG_Ver(message, P, IIccss, R));
//#MG sig: false one
N = 3;// #cols
R = 3;// #rows
xtmp = skvGen(R);
keyM xx(N, xtmp);// = [[None]*N] #just used to generate test public keys
sk = skvGen(R);
//P (N, xtmp);// = keyM[[None]*N] #stores the public keys;
ind = 2;
for (j = 0 ; j < R ; j++) {
for (i = 0 ; i < N ; i++)
{
xx[i][j] = skGen();
P[i][j] = scalarmultBase(xx[i][j]);
}
sk[j] = xx[ind][j];
}
sk[2] = skGen();//assume we don't know one of the private keys..
IIccss = MLSAG_Gen(message, P, sk, NULL, NULL, ind, R, hw::get_device("default"));
ASSERT_FALSE(MLSAG_Ver(message, P, IIccss, R));
}
TEST(ringct, range_proofs)
{
//Ring CT Stuff
//ct range proofs
ctkeyV sc, pc;
ctkey sctmp, pctmp;
//add fake input 5000
tie(sctmp, pctmp) = ctskpkGen(6000);
sc.push_back(sctmp);
pc.push_back(pctmp);
tie(sctmp, pctmp) = ctskpkGen(7000);
sc.push_back(sctmp);
pc.push_back(pctmp);
vector<xmr_amount >amounts;
rct::keyV amount_keys;
key mask;
//add output 500
amounts.push_back(500);
amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
keyV destinations;
key Sk, Pk;
skpkGen(Sk, Pk);
destinations.push_back(Pk);
//add output for 12500
amounts.push_back(12500);
amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
skpkGen(Sk, Pk);
destinations.push_back(Pk);
//compute rct data with mixin 500
rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3, hw::get_device("default"));
//verify rct data
ASSERT_TRUE(verRct(s));
//decode received amount
decodeRct(s, amount_keys[1], 1, mask, hw::get_device("default"));
// Ring CT with failing MG sig part should not verify!
// Since sum of inputs != outputs
amounts[1] = 12501;
skpkGen(Sk, Pk);
destinations[1] = Pk;
//compute rct data with mixin 500
s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3, hw::get_device("default"));
//verify rct data
ASSERT_FALSE(verRct(s));
//decode received amount
decodeRct(s, amount_keys[1], 1, mask, hw::get_device("default"));
}
TEST(ringct, range_proofs_with_fee)
{
//Ring CT Stuff
//ct range proofs
ctkeyV sc, pc;
ctkey sctmp, pctmp;
//add fake input 5000
tie(sctmp, pctmp) = ctskpkGen(6001);
sc.push_back(sctmp);
pc.push_back(pctmp);
tie(sctmp, pctmp) = ctskpkGen(7000);
sc.push_back(sctmp);
pc.push_back(pctmp);
vector<xmr_amount >amounts;
keyV amount_keys;
key mask;
//add output 500
amounts.push_back(500);
amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
keyV destinations;
key Sk, Pk;
skpkGen(Sk, Pk);
destinations.push_back(Pk);
//add txn fee for 1
//has no corresponding destination..
amounts.push_back(1);
//add output for 12500
amounts.push_back(12500);
amount_keys.push_back(hash_to_scalar(zero()));
skpkGen(Sk, Pk);
destinations.push_back(Pk);
//compute rct data with mixin 500
rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3, hw::get_device("default"));
//verify rct data
ASSERT_TRUE(verRct(s));
//decode received amount
decodeRct(s, amount_keys[1], 1, mask, hw::get_device("default"));
// Ring CT with failing MG sig part should not verify!
// Since sum of inputs != outputs
amounts[1] = 12501;
skpkGen(Sk, Pk);
destinations[1] = Pk;
//compute rct data with mixin 500
s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3, hw::get_device("default"));
//verify rct data
ASSERT_FALSE(verRct(s));
//decode received amount
decodeRct(s, amount_keys[1], 1, mask, hw::get_device("default"));
}
TEST(ringct, simple)
{
ctkeyV sc, pc;
ctkey sctmp, pctmp;
//this vector corresponds to output amounts
vector<xmr_amount>outamounts;
//this vector corresponds to input amounts
vector<xmr_amount>inamounts;
//this keyV corresponds to destination pubkeys
keyV destinations;
keyV amount_keys;
key mask;
//add fake input 3000
//the sc is secret data
//pc is public data
tie(sctmp, pctmp) = ctskpkGen(3000);
sc.push_back(sctmp);
pc.push_back(pctmp);
inamounts.push_back(3000);
//add fake input 3000
//the sc is secret data
//pc is public data
tie(sctmp, pctmp) = ctskpkGen(3000);
sc.push_back(sctmp);
pc.push_back(pctmp);
inamounts.push_back(3000);
//add output 5000
outamounts.push_back(5000);
amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
//add the corresponding destination pubkey
key Sk, Pk;
skpkGen(Sk, Pk);
destinations.push_back(Pk);
//add output 999
outamounts.push_back(999);
amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
//add the corresponding destination pubkey
skpkGen(Sk, Pk);
destinations.push_back(Pk);
key message = skGen(); //real message later (hash of txn..)
//compute sig with mixin 2
xmr_amount txnfee = 1;
rctSig s = genRctSimple(message, sc, pc, destinations,inamounts, outamounts, amount_keys, NULL, NULL, txnfee, 2, hw::get_device("default"));
//verify ring ct signature
ASSERT_TRUE(verRctSimple(s));
//decode received amount corresponding to output pubkey index 1
decodeRctSimple(s, amount_keys[1], 1, mask, hw::get_device("default"));
}
static rct::rctSig make_sample_rct_sig(int n_inputs, const uint64_t input_amounts[], int n_outputs, const uint64_t output_amounts[], bool last_is_fee)
{
ctkeyV sc, pc;
ctkey sctmp, pctmp;
vector<xmr_amount >amounts;
keyV destinations;
keyV amount_keys;
key Sk, Pk;
for (int n = 0; n < n_inputs; ++n) {
tie(sctmp, pctmp) = ctskpkGen(input_amounts[n]);
sc.push_back(sctmp);
pc.push_back(pctmp);
}
for (int n = 0; n < n_outputs; ++n) {
amounts.push_back(output_amounts[n]);
skpkGen(Sk, Pk);
if (n < n_outputs - 1 || !last_is_fee)
{
destinations.push_back(Pk);
amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
}
}
return genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3, hw::get_device("default"));
}
static rct::rctSig make_sample_simple_rct_sig(int n_inputs, const uint64_t input_amounts[], int n_outputs, const uint64_t output_amounts[], uint64_t fee)
{
ctkeyV sc, pc;
ctkey sctmp, pctmp;
vector<xmr_amount> inamounts, outamounts;
keyV destinations;
keyV amount_keys;
key Sk, Pk;
for (int n = 0; n < n_inputs; ++n) {
inamounts.push_back(input_amounts[n]);
tie(sctmp, pctmp) = ctskpkGen(input_amounts[n]);
sc.push_back(sctmp);
pc.push_back(pctmp);
}
for (int n = 0; n < n_outputs; ++n) {
outamounts.push_back(output_amounts[n]);
amount_keys.push_back(hash_to_scalar(zero()));
skpkGen(Sk, Pk);
destinations.push_back(Pk);
}
return genRctSimple(rct::zero(), sc, pc, destinations, inamounts, outamounts, amount_keys, NULL, NULL, fee, 3, hw::get_device("default"));
}
static bool range_proof_test(bool expected_valid,
int n_inputs, const uint64_t input_amounts[], int n_outputs, const uint64_t output_amounts[], bool last_is_fee, bool simple)
{
//compute rct data
bool valid;
try {
rctSig s;
// simple takes fee as a parameter, non-simple takes it as an extra element to output amounts
if (simple) {
s = make_sample_simple_rct_sig(n_inputs, input_amounts, last_is_fee ? n_outputs - 1 : n_outputs, output_amounts, last_is_fee ? output_amounts[n_outputs - 1] : 0);
valid = verRctSimple(s);
}
else {
s = make_sample_rct_sig(n_inputs, input_amounts, n_outputs, output_amounts, last_is_fee);
valid = verRct(s);
}
}
catch (const std::exception &e) {
valid = false;
}
if (valid == expected_valid) {
return testing::AssertionSuccess();
}
else {
return testing::AssertionFailure();
}
}
#define NELTS(array) (sizeof(array)/sizeof(array[0]))
TEST(ringct, range_proofs_reject_empty_outs)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_empty_outs_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_empty_ins)
{
const uint64_t inputs[] = {};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_empty_ins_simple)
{
const uint64_t inputs[] = {};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_all_empty)
{
const uint64_t inputs[] = {};
const uint64_t outputs[] = {};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_all_empty_simple)
{
const uint64_t inputs[] = {};
const uint64_t outputs[] = {};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_empty)
{
const uint64_t inputs[] = {0};
const uint64_t outputs[] = {};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_empty_simple)
{
const uint64_t inputs[] = {0};
const uint64_t outputs[] = {};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_empty_zero)
{
const uint64_t inputs[] = {};
const uint64_t outputs[] = {0};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_empty_zero_simple)
{
const uint64_t inputs[] = {};
const uint64_t outputs[] = {0};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_zero)
{
const uint64_t inputs[] = {0};
const uint64_t outputs[] = {0};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_zero_simple)
{
const uint64_t inputs[] = {0};
const uint64_t outputs[] = {0};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_out_first)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {0, 5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_out_first_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {0, 5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_out_last)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {5000, 0};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_out_last_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {5000, 0};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_out_middle)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {2500, 0, 2500};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_out_middle_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {2500, 0, 2500};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_in_first)
{
const uint64_t inputs[] = {0, 5000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_in_first_simple)
{
const uint64_t inputs[] = {0, 5000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_in_last)
{
const uint64_t inputs[] = {5000, 0};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_in_last_simple)
{
const uint64_t inputs[] = {5000, 0};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_zero_in_middle)
{
const uint64_t inputs[] = {2500, 0, 2500};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_zero_in_middle_simple)
{
const uint64_t inputs[] = {2500, 0, 2500};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_single_lower)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {1};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_single_lower_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {1};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_single_higher)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {5001};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_single_higher_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {5001};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_single_out_negative)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {(uint64_t)-1000ll};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_single_out_negative_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {(uint64_t)-1000ll};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_out_negative_first)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {(uint64_t)-1000ll, 6000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_out_negative_first_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {(uint64_t)-1000ll, 6000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_out_negative_last)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {6000, (uint64_t)-1000ll};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_out_negative_last_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {6000, (uint64_t)-1000ll};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_out_negative_middle)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {3000, (uint64_t)-1000ll, 3000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_out_negative_middle_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {3000, (uint64_t)-1000ll, 3000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_single_in_negative)
{
const uint64_t inputs[] = {(uint64_t)-1000ll};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_single_in_negative_simple)
{
const uint64_t inputs[] = {(uint64_t)-1000ll};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_in_negative_first)
{
const uint64_t inputs[] = {(uint64_t)-1000ll, 6000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_in_negative_first_simple)
{
const uint64_t inputs[] = {(uint64_t)-1000ll, 6000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_in_negative_last)
{
const uint64_t inputs[] = {6000, (uint64_t)-1000ll};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_in_negative_last_simple)
{
const uint64_t inputs[] = {6000, (uint64_t)-1000ll};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_in_negative_middle)
{
const uint64_t inputs[] = {3000, (uint64_t)-1000ll, 3000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_in_negative_middle_simple)
{
const uint64_t inputs[] = {3000, (uint64_t)-1000ll, 3000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_reject_higher_list)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {1000, 1000, 1000, 1000, 1000, 1000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_reject_higher_list_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {1000, 1000, 1000, 1000, 1000, 1000};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_1_to_1)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_1_to_1_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_1_to_N)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {1000, 1000, 1000, 1000, 1000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_1_to_N_simple)
{
const uint64_t inputs[] = {5000};
const uint64_t outputs[] = {1000, 1000, 1000, 1000, 1000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false,true));
}
TEST(ringct, range_proofs_accept_N_to_1)
{
const uint64_t inputs[] = {1000, 1000, 1000, 1000, 1000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_N_to_1_simple)
{
const uint64_t inputs[] = {1000, 1000, 1000, 1000, 1000};
const uint64_t outputs[] = {5000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_N_to_N)
{
const uint64_t inputs[] = {1000, 1000, 1000, 1000, 1000};
const uint64_t outputs[] = {1000, 1000, 1000, 1000, 1000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_N_to_N_simple)
{
const uint64_t inputs[] = {1000, 1000, 1000, 1000, 1000};
const uint64_t outputs[] = {1000, 1000, 1000, 1000, 1000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, range_proofs_accept_very_long)
{
const size_t N=12;
uint64_t inputs[N];
uint64_t outputs[N];
for (size_t n = 0; n < N; ++n) {
inputs[n] = n;
outputs[n] = n;
}
std::random_shuffle(inputs, inputs + N);
std::random_shuffle(outputs, outputs + N);
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, false));
}
TEST(ringct, range_proofs_accept_very_long_simple)
{
const size_t N=12;
uint64_t inputs[N];
uint64_t outputs[N];
for (size_t n = 0; n < N; ++n) {
inputs[n] = n;
outputs[n] = n;
}
std::random_shuffle(inputs, inputs + N);
std::random_shuffle(outputs, outputs + N);
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, false, true));
}
TEST(ringct, HPow2)
{
key G = scalarmultBase(d2h(1));
key H = hashToPointSimple(G);
for (int j = 0 ; j < ATOMS ; j++) {
ASSERT_TRUE(equalKeys(H, H2[j]));
addKeys(H, H, H);
}
}
static const xmr_amount test_amounts[]={0, 1, 2, 3, 4, 5, 10000, 10000000000000000000ull, 10203040506070809000ull, 123456789123456789};
TEST(ringct, ecdh_roundtrip)
{
key k;
ecdhTuple t0, t1;
for (auto amount: test_amounts) {
skGen(k);
t0.mask = skGen();
t0.amount = d2h(amount);
t1 = t0;
ecdhEncode(t1, k);
ecdhDecode(t1, k);
ASSERT_TRUE(t0.mask == t1.mask);
ASSERT_TRUE(equalKeys(t0.mask, t1.mask));
ASSERT_TRUE(t0.amount == t1.amount);
ASSERT_TRUE(equalKeys(t0.amount, t1.amount));
}
}
TEST(ringct, d2h)
{
key k, P1;
skpkGen(k, P1);
for (auto amount: test_amounts) {
d2h(k, amount);
ASSERT_TRUE(amount == h2d(k));
}
}
TEST(ringct, d2b)
{
for (auto amount: test_amounts) {
bits b;
d2b(b, amount);
ASSERT_TRUE(amount == b2d(b));
}
}
TEST(ringct, prooveRange_is_non_deterministic)
{
key C[2], mask[2];
for (int n = 0; n < 2; ++n)
proveRange(C[n], mask[n], 80);
ASSERT_TRUE(memcmp(C[0].bytes, C[1].bytes, sizeof(C[0].bytes)));
ASSERT_TRUE(memcmp(mask[0].bytes, mask[1].bytes, sizeof(mask[0].bytes)));
}
TEST(ringct, fee_0_valid)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {2000, 0};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, false));
}
TEST(ringct, fee_0_valid_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {2000, 0};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, true));
}
TEST(ringct, fee_non_0_valid)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1900, 100};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, false));
}
TEST(ringct, fee_non_0_valid_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1900, 100};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, true));
}
TEST(ringct, fee_non_0_invalid_higher)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1990, 100};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, true, false));
}
TEST(ringct, fee_non_0_invalid_higher_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1990, 100};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, true, true));
}
TEST(ringct, fee_non_0_invalid_lower)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1000, 100};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, true, false));
}
TEST(ringct, fee_non_0_invalid_lower_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1000, 100};
EXPECT_TRUE(range_proof_test(false, NELTS(inputs), inputs, NELTS(outputs), outputs, true, true));
}
TEST(ringct, fee_burn_valid_one_out)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {0, 2000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, false));
}
TEST(ringct, fee_burn_valid_one_out_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {0, 2000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, true));
}
TEST(ringct, fee_burn_valid_zero_out)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {2000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, false));
}
TEST(ringct, fee_burn_valid_zero_out_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {2000};
EXPECT_TRUE(range_proof_test(true, NELTS(inputs), inputs, NELTS(outputs), outputs, true, true));
}
static rctSig make_sig()
{
static const uint64_t inputs[] = {1000, 1000};
static const uint64_t outputs[] = {1000, 1000};
static rct::rctSig sig = make_sample_rct_sig(NELTS(inputs), inputs, NELTS(outputs), outputs, true);
return sig;
}
#define TEST_rctSig_elements(name, op) \
TEST(ringct, rctSig_##name) \
{ \
const uint64_t inputs[] = {1000, 1000}; \
const uint64_t outputs[] = {1000, 1000}; \
rct::rctSig sig = make_sig(); \
ASSERT_TRUE(rct::verRct(sig)); \
op; \
ASSERT_FALSE(rct::verRct(sig)); \
}
TEST_rctSig_elements(rangeSigs_empty, sig.p.rangeSigs.resize(0));
TEST_rctSig_elements(rangeSigs_too_many, sig.p.rangeSigs.push_back(sig.p.rangeSigs.back()));
TEST_rctSig_elements(rangeSigs_too_few, sig.p.rangeSigs.pop_back());
TEST_rctSig_elements(mgSig_MG_empty, sig.p.MGs.resize(0));
TEST_rctSig_elements(mgSig_ss_empty, sig.p.MGs[0].ss.resize(0));
TEST_rctSig_elements(mgSig_ss_too_many, sig.p.MGs[0].ss.push_back(sig.p.MGs[0].ss.back()));
TEST_rctSig_elements(mgSig_ss_too_few, sig.p.MGs[0].ss.pop_back());
TEST_rctSig_elements(mgSig_ss0_empty, sig.p.MGs[0].ss[0].resize(0));
TEST_rctSig_elements(mgSig_ss0_too_many, sig.p.MGs[0].ss[0].push_back(sig.p.MGs[0].ss[0].back()));
TEST_rctSig_elements(mgSig_ss0_too_few, sig.p.MGs[0].ss[0].pop_back());
TEST_rctSig_elements(mgSig_II_empty, sig.p.MGs[0].II.resize(0));
TEST_rctSig_elements(mgSig_II_too_many, sig.p.MGs[0].II.push_back(sig.p.MGs[0].II.back()));
TEST_rctSig_elements(mgSig_II_too_few, sig.p.MGs[0].II.pop_back());
TEST_rctSig_elements(mixRing_empty, sig.mixRing.resize(0));
TEST_rctSig_elements(mixRing_too_many, sig.mixRing.push_back(sig.mixRing.back()));
TEST_rctSig_elements(mixRing_too_few, sig.mixRing.pop_back());
TEST_rctSig_elements(mixRing0_empty, sig.mixRing[0].resize(0));
TEST_rctSig_elements(mixRing0_too_many, sig.mixRing[0].push_back(sig.mixRing[0].back()));
TEST_rctSig_elements(mixRing0_too_few, sig.mixRing[0].pop_back());
TEST_rctSig_elements(ecdhInfo_empty, sig.ecdhInfo.resize(0));
TEST_rctSig_elements(ecdhInfo_too_many, sig.ecdhInfo.push_back(sig.ecdhInfo.back()));
TEST_rctSig_elements(ecdhInfo_too_few, sig.ecdhInfo.pop_back());
TEST_rctSig_elements(outPk_empty, sig.outPk.resize(0));
TEST_rctSig_elements(outPk_too_many, sig.outPk.push_back(sig.outPk.back()));
TEST_rctSig_elements(outPk_too_few, sig.outPk.pop_back());
static rct::rctSig make_sig_simple()
{
static const uint64_t inputs[] = {1000, 1000};
static const uint64_t outputs[] = {1000};
static rct::rctSig sig = make_sample_simple_rct_sig(NELTS(inputs), inputs, NELTS(outputs), outputs, 1000);
return sig;
}
#define TEST_rctSig_elements_simple(name, op) \
TEST(ringct, rctSig_##name##_simple) \
{ \
rct::rctSig sig = make_sig_simple(); \
ASSERT_TRUE(rct::verRctSimple(sig)); \
op; \
ASSERT_FALSE(rct::verRctSimple(sig)); \
}
TEST_rctSig_elements_simple(rangeSigs_empty, sig.p.rangeSigs.resize(0));
TEST_rctSig_elements_simple(rangeSigs_too_many, sig.p.rangeSigs.push_back(sig.p.rangeSigs.back()));
TEST_rctSig_elements_simple(rangeSigs_too_few, sig.p.rangeSigs.pop_back());
TEST_rctSig_elements_simple(mgSig_empty, sig.p.MGs.resize(0));
TEST_rctSig_elements_simple(mgSig_too_many, sig.p.MGs.push_back(sig.p.MGs.back()));
TEST_rctSig_elements_simple(mgSig_too_few, sig.p.MGs.pop_back());
TEST_rctSig_elements_simple(mgSig0_ss_empty, sig.p.MGs[0].ss.resize(0));
TEST_rctSig_elements_simple(mgSig0_ss_too_many, sig.p.MGs[0].ss.push_back(sig.p.MGs[0].ss.back()));
TEST_rctSig_elements_simple(mgSig0_ss_too_few, sig.p.MGs[0].ss.pop_back());
TEST_rctSig_elements_simple(mgSig_ss0_empty, sig.p.MGs[0].ss[0].resize(0));
TEST_rctSig_elements_simple(mgSig_ss0_too_many, sig.p.MGs[0].ss[0].push_back(sig.p.MGs[0].ss[0].back()));
TEST_rctSig_elements_simple(mgSig_ss0_too_few, sig.p.MGs[0].ss[0].pop_back());
TEST_rctSig_elements_simple(mgSig0_II_empty, sig.p.MGs[0].II.resize(0));
TEST_rctSig_elements_simple(mgSig0_II_too_many, sig.p.MGs[0].II.push_back(sig.p.MGs[0].II.back()));
TEST_rctSig_elements_simple(mgSig0_II_too_few, sig.p.MGs[0].II.pop_back());
TEST_rctSig_elements_simple(mixRing_empty, sig.mixRing.resize(0));
TEST_rctSig_elements_simple(mixRing_too_many, sig.mixRing.push_back(sig.mixRing.back()));
TEST_rctSig_elements_simple(mixRing_too_few, sig.mixRing.pop_back());
TEST_rctSig_elements_simple(mixRing0_empty, sig.mixRing[0].resize(0));
TEST_rctSig_elements_simple(mixRing0_too_many, sig.mixRing[0].push_back(sig.mixRing[0].back()));
TEST_rctSig_elements_simple(mixRing0_too_few, sig.mixRing[0].pop_back());
TEST_rctSig_elements_simple(pseudoOuts_empty, sig.pseudoOuts.resize(0));
TEST_rctSig_elements_simple(pseudoOuts_too_many, sig.pseudoOuts.push_back(sig.pseudoOuts.back()));
TEST_rctSig_elements_simple(pseudoOuts_too_few, sig.pseudoOuts.pop_back());
TEST_rctSig_elements_simple(ecdhInfo_empty, sig.ecdhInfo.resize(0));
TEST_rctSig_elements_simple(ecdhInfo_too_many, sig.ecdhInfo.push_back(sig.ecdhInfo.back()));
TEST_rctSig_elements_simple(ecdhInfo_too_few, sig.ecdhInfo.pop_back());
TEST_rctSig_elements_simple(outPk_empty, sig.outPk.resize(0));
TEST_rctSig_elements_simple(outPk_too_many, sig.outPk.push_back(sig.outPk.back()));
TEST_rctSig_elements_simple(outPk_too_few, sig.outPk.pop_back());
TEST(ringct, reject_gen_simple_ver_non_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1000};
rct::rctSig sig = make_sample_simple_rct_sig(NELTS(inputs), inputs, NELTS(outputs), outputs, 1000);
ASSERT_FALSE(rct::verRct(sig));
}
TEST(ringct, reject_gen_non_simple_ver_simple)
{
const uint64_t inputs[] = {1000, 1000};
const uint64_t outputs[] = {1000, 1000};
rct::rctSig sig = make_sample_rct_sig(NELTS(inputs), inputs, NELTS(outputs), outputs, true);
ASSERT_FALSE(rct::verRctSimple(sig));
}
TEST(ringct, key_ostream)
{
std::stringstream out;
out << "BEGIN" << rct::H << "END";
EXPECT_EQ(
std::string{"BEGIN<8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94>END"},
out.str()
);
}
TEST(ringct, zeroCommmit)
{
static const uint64_t amount = crypto::rand<uint64_t>();
const rct::key z = rct::zeroCommit(amount);
const rct::key a = rct::scalarmultBase(rct::identity());
const rct::key b = rct::scalarmultH(rct::d2h(amount));
const rct::key manual = rct::addKeys(a, b);
ASSERT_EQ(z, manual);
}
TEST(ringct, H)
{
ge_p3 p3;
ASSERT_EQ(ge_frombytes_vartime(&p3, rct::H.bytes), 0);
ASSERT_EQ(memcmp(&p3, &ge_p3_H, sizeof(ge_p3)), 0);
}
TEST(ringct, mul8)
{
ASSERT_EQ(rct::scalarmult8(rct::identity()), rct::identity());
ASSERT_EQ(rct::scalarmult8(rct::H), rct::scalarmultKey(rct::H, rct::EIGHT));
ASSERT_EQ(rct::scalarmultKey(rct::scalarmultKey(rct::H, rct::INV_EIGHT), rct::EIGHT), rct::H);
}
TEST(ringct, aggregated)
{
static const size_t N_PROOFS = 16;
std::vector<rctSig> s(N_PROOFS);
std::vector<const rctSig*> sp(N_PROOFS);
for (size_t n = 0; n < N_PROOFS; ++n)
{
static const uint64_t inputs[] = {1000, 1000};
static const uint64_t outputs[] = {500, 1500};
s[n] = make_sample_simple_rct_sig(NELTS(inputs), inputs, NELTS(outputs), outputs, 0);
sp[n] = &s[n];
}
ASSERT_TRUE(verRctSemanticsSimple(sp));
}
|