-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathapi.rs
2936 lines (2546 loc) · 94.8 KB
/
api.rs
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
use std::collections::BTreeMap;
use std::fs::{metadata, read_dir, remove_file, File, OpenOptions};
use std::io::{self, Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use anyhow::{ensure, Context, Error, Result};
use bellperson::groth16;
use bincode::serialize;
use blstrs::{Bls12, Scalar as Fr};
use ff::Field;
use filecoin_hashers::Hasher;
use filecoin_proofs::{
add_piece, aggregate_empty_sector_update_proofs, aggregate_seal_commit_proofs, clear_cache,
clear_synthetic_proofs, compute_comm_d, decode_from, decode_from_range, encode_into,
fauxrep_aux, generate_empty_sector_update_proof,
generate_empty_sector_update_proof_with_vanilla, generate_fallback_sector_challenges,
generate_partition_proofs, generate_piece_commitment, generate_single_partition_proof,
generate_single_vanilla_proof, generate_single_window_post_with_vanilla, generate_synth_proofs,
generate_tree_c, generate_tree_r_last, generate_window_post, generate_window_post_with_vanilla,
generate_winning_post, generate_winning_post_sector_challenge,
generate_winning_post_with_vanilla, get_num_partition_for_fallback_post, get_seal_inputs,
get_sector_update_h_select_from_porep_config, get_sector_update_inputs,
merge_window_post_partition_proofs, remove_encoded_data, seal_commit_phase1,
seal_commit_phase2, seal_commit_phase2_circuit_proofs, seal_pre_commit_phase1,
seal_pre_commit_phase2, unseal_range, validate_cache_for_commit,
validate_cache_for_precommit_phase2, verify_aggregate_seal_commit_proofs,
verify_aggregate_sector_update_proofs, verify_empty_sector_update_proof,
verify_partition_proofs, verify_seal, verify_single_partition_proof, verify_window_post,
verify_winning_post, Commitment, DefaultTreeDomain, EmptySectorUpdateProof, MerkleTreeTrait,
PaddedBytesAmount, PieceInfo, PoRepConfig, PoStConfig, PoStType, PrivateReplicaInfo, ProverId,
PublicReplicaInfo, SealCommitOutput, SealPreCommitOutput, SealPreCommitPhase1Output,
SectorShape16KiB, SectorShape2KiB, SectorShape32GiB, SectorShape32KiB, SectorShape4KiB,
SectorUpdateConfig, SectorUpdateProofInputs, UnpaddedByteIndex, UnpaddedBytesAmount,
SECTOR_SIZE_16_KIB, SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_GIB, SECTOR_SIZE_32_KIB,
SECTOR_SIZE_4_KIB, WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT,
WINNING_POST_CHALLENGE_COUNT, WINNING_POST_SECTOR_COUNT,
};
use fr32::bytes_into_fr;
use log::{info, trace};
use memmap2::MmapOptions;
use merkletree::store::StoreConfig;
use rand::{random, Rng, SeedableRng};
use rand_xorshift::XorShiftRng;
use sha2::{Digest, Sha256};
use storage_proofs_core::{
api_version::{ApiFeature, ApiVersion},
cache_key::CacheKey,
is_legacy_porep_id,
merkle::get_base_tree_count,
sector::SectorId,
util::NODE_SIZE,
};
use storage_proofs_update::constants::TreeRHasher;
use tempfile::{tempdir, NamedTempFile, TempDir};
use filecoin_proofs::constants::{
FIP92_MAX_NI_POREP_AGGREGATION_PROOFS, FIP92_MIN_NI_POREP_AGGREGATION_PROOFS,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID,
};
#[cfg(feature = "big-tests")]
use filecoin_proofs::{
SectorShape512MiB, SectorShape64GiB, SECTOR_SIZE_512_MIB, SECTOR_SIZE_64_GIB,
};
// Use a fixed PoRep ID, so that the parents cache can be re-used between some tests.
// Note however, that parents caches cannot be shared when testing the differences
// between API v1 and v2 behaviour (since the parent caches will be different for the
// same porep_ids).
const ARBITRARY_POREP_ID_V1_0_0: [u8; 32] = [127; 32];
const ARBITRARY_POREP_ID_V1_1_0: [u8; 32] = [128; 32];
const ARBITRARY_POREP_ID_V1_2_0: [u8; 32] = [129; 32];
const TEST_SEED: [u8; 16] = [
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5,
];
fn to_porep_id_verified(registered_seal_proof: u64, api_version: ApiVersion) -> [u8; 32] {
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(®istered_seal_proof.to_le_bytes());
assert!(match api_version {
ApiVersion::V1_0_0 => is_legacy_porep_id(porep_id),
ApiVersion::V1_1_0 | ApiVersion::V1_2_0 => !is_legacy_porep_id(porep_id),
});
porep_id
}
#[test]
fn test_get_sector_update_inputs() -> Result<()> {
fil_logger::maybe_init();
let porep_id_v1_1_2k: u64 = 5; // This is a RegisteredSealProof value
let porep_id_v1_1_32g: u64 = 8; // This is a RegisteredSealProof value
let mut porep_id_2k = [0u8; 32];
porep_id_2k[..8].copy_from_slice(&porep_id_v1_1_2k.to_le_bytes());
assert!(!is_legacy_porep_id(porep_id_2k));
let mut porep_id_32g = [0u8; 32];
porep_id_32g[..8].copy_from_slice(&porep_id_v1_1_32g.to_le_bytes());
assert!(!is_legacy_porep_id(porep_id_32g));
let porep_config_2k =
PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id_2k, ApiVersion::V1_2_0);
let sector_config_2k = SectorUpdateConfig::from_porep_config(&porep_config_2k);
let porep_config_32g =
PoRepConfig::new_groth16(SECTOR_SIZE_32_GIB, porep_id_32g, ApiVersion::V1_2_0);
let sector_config_32g = SectorUpdateConfig::from_porep_config(&porep_config_32g);
let comm_r_old = [5u8; 32];
let comm_r_new = [6u8; 32];
let comm_d_new = [7u8; 32];
let inputs_2k = get_sector_update_inputs::<SectorShape2KiB>(
&porep_config_2k,
comm_r_old,
comm_r_new,
comm_d_new,
)?;
// Ensure the num inputs is equal to the number of partitions
info!("2k sector inputs count is {}", inputs_2k.len());
ensure!(
inputs_2k.len() == usize::from(sector_config_2k.update_partitions),
"2k sector_update_inputs length mismatch"
);
let inputs_32g = get_sector_update_inputs::<SectorShape32GiB>(
&porep_config_32g,
comm_r_old,
comm_r_new,
comm_d_new,
)?;
// Ensure the num inputs is equal to the number of partitions
info!("32g sector inputs count is {}", inputs_32g.len());
ensure!(
inputs_32g.len() == usize::from(sector_config_32g.update_partitions),
"32g sector_update_inputs length mismatch"
);
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_2kib_base_8() -> Result<()> {
// The first value is RegisteredSealProof value
// The second value is the ApiVersion to use
// The third value is enabled Api features
let test_inputs = vec![
(0u64, ApiVersion::V1_0_0, Vec::new()),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id_num, api_version, features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_2_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle::<SectorShape2KiB>(&porep_config)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_upgrade_2kib_base_8() -> Result<()> {
// The first value is RegisteredSealProof value
// The second value is the ApiVersion to use
// The third value is enabled Api features
let test_inputs = vec![
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id_num, api_version, features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_2_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle_upgrade::<SectorShape2KiB>(&porep_config)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_4kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_4_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle::<SectorShape4KiB>(&porep_config)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_upgrade_4kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_4_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle_upgrade::<SectorShape4KiB>(&porep_config)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_16kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_16_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle::<SectorShape16KiB>(&porep_config)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_upgrade_16kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_16_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle_upgrade::<SectorShape16KiB>(&porep_config)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_lifecycle_32kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_32_KIB,
porep_id,
api_version,
features,
)?;
seal_lifecycle::<SectorShape32KiB>(&porep_config)?;
}
Ok(())
}
// These tests are good to run, but take a long time.
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_512mib_porep_id_v1_top_8_0_0_api_v1() -> Result<()> {
use filecoin_proofs::{SectorShape512MiB, SECTOR_SIZE_512_MIB};
let porep_id_v1: u64 = 2; // This is a RegisteredSealProof value
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1.to_le_bytes());
assert!(is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_512_MIB, porep_id, ApiVersion::V1_0_0);
seal_lifecycle::<SectorShape512MiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_512mib_porep_id_v1_top_8_0_0_api_v1_1() -> Result<()> {
use filecoin_proofs::{SectorShape512MiB, SECTOR_SIZE_512_MIB};
let porep_id_v1_1: u64 = 7; // This is a RegisteredSealProof value
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes());
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_512_MIB, porep_id, ApiVersion::V1_1_0);
seal_lifecycle::<SectorShape512MiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_upgrade_512mib_top_8_0_0_v1_1() -> Result<()> {
let porep_config = PoRepConfig::new_groth16(
SECTOR_SIZE_512_MIB,
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
);
seal_lifecycle_upgrade::<SectorShape512MiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_32gib_porep_id_v1_top_8_8_0_api_v1() -> Result<()> {
let porep_id_v1: u64 = 3; // This is a RegisteredSealProof value
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1.to_le_bytes());
assert!(is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_32_GIB, porep_id, ApiVersion::V1_0_0);
seal_lifecycle::<SectorShape32GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_32gib_porep_id_v1_1_top_8_8_0_api_v1_1() -> Result<()> {
let porep_id_v1_1: u64 = 8; // This is a RegisteredSealProof value
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes());
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_32_GIB, porep_id, ApiVersion::V1_1_0);
seal_lifecycle::<SectorShape32GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_32gib_porep_id_v1_2_top_8_8_0_api_v1_2() -> Result<()> {
let porep_id_v1_2: u64 = 8; // This is a RegisteredSealProof value
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_32_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
)?;
seal_lifecycle::<SectorShape32GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_32gib_porep_id_v1_2_ni_top_8_8_0_api_v1_2() -> Result<()> {
let porep_id_v1_2: u64 = 8; // This is a RegisteredSealProof value
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_32_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
)?;
seal_lifecycle::<SectorShape32GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_max_ni_seal_proof_aggregation_32gib() -> Result<()> {
let porep_id_v1_2: u64 = 8; // This is a RegisteredSealProof value
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_32_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
)?;
aggregate_seal_proofs::<SectorShape32GiB>(&porep_config, FIP92_MAX_NI_POREP_AGGREGATION_PROOFS)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_max_ni_seal_proof_aggregation_64gib() -> Result<()> {
let porep_id_v1_2: u64 = 9; // This is a RegisteredSealProof value
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_64_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
)?;
aggregate_seal_proofs::<SectorShape64GiB>(&porep_config, FIP92_MAX_NI_POREP_AGGREGATION_PROOFS)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_upgrade_32gib_top_8_8_0_v1_2() -> Result<()> {
let porep_config = PoRepConfig::new_groth16(
SECTOR_SIZE_32_GIB,
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
);
seal_lifecycle_upgrade::<SectorShape32GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_64gib_porep_id_v1_top_8_8_2_api_v1() -> Result<()> {
let porep_id_v1: u64 = 4; // This is a RegisteredSealProof value
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1.to_le_bytes());
assert!(is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_64_GIB, porep_id, ApiVersion::V1_0_0);
seal_lifecycle::<SectorShape64GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_64gib_porep_id_v1_1_top_8_8_2_api_v1_1() -> Result<()> {
let porep_id_v1_1: u64 = 9; // This is a RegisteredSealProof value
let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes());
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_64_GIB, porep_id, ApiVersion::V1_1_0);
seal_lifecycle::<SectorShape64GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_64gib_porep_id_v1_2_top_8_8_2_api_v1_2() -> Result<()> {
let porep_id_v1_2: u64 = 9; // This is a RegisteredSealProof value
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_64_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
)?;
seal_lifecycle::<SectorShape64GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_64gib_porep_id_v1_2_ni_top_8_8_2_api_v1_2() -> Result<()> {
let porep_id_v1_2: u64 = 9; // This is a RegisteredSealProof value
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_64_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
)?;
seal_lifecycle::<SectorShape64GiB>(&porep_config)
}
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_upgrade_64gib_top_8_8_2_v1_1() -> Result<()> {
let porep_config = PoRepConfig::new_groth16(
SECTOR_SIZE_64_GIB,
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
);
seal_lifecycle_upgrade::<SectorShape64GiB>(&porep_config)
}
fn seal_lifecycle<Tree: 'static + MerkleTreeTrait>(porep_config: &PoRepConfig) -> Result<()> {
let mut rng = XorShiftRng::from_seed(TEST_SEED);
let prover_fr: DefaultTreeDomain = Fr::random(&mut rng).into();
let mut prover_id = [0u8; 32];
prover_id.copy_from_slice(AsRef::<[u8]>::as_ref(&prover_fr));
info!(
"Creating seal proof with ApiVersion {} and PoRep ID {:?}",
porep_config.api_version, porep_config.porep_id
);
let (_, replica, _, _) = create_seal::<_, Tree>(porep_config, &mut rng, prover_id, false)?;
replica.close()?;
Ok(())
}
fn seal_lifecycle_upgrade<Tree: 'static + MerkleTreeTrait<Hasher = TreeRHasher>>(
porep_config: &PoRepConfig,
) -> Result<()> {
let mut rng = &mut XorShiftRng::from_seed(TEST_SEED);
let prover_fr: DefaultTreeDomain = Fr::random(&mut rng).into();
let mut prover_id = [0u8; 32];
prover_id.copy_from_slice(AsRef::<[u8]>::as_ref(&prover_fr));
info!(
"Creating seal proof for upgrade with ApiVersion {}",
porep_config.api_version
);
let (_, replica, _, _) = create_seal_for_upgrade::<_, Tree>(porep_config, &mut rng, prover_id)?;
replica.close()?;
Ok(())
}
#[test]
#[ignore]
fn test_seal_proof_aggregation_2kib() -> Result<()> {
let test_inputs = vec![
(
1,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
vec![],
),
(
5,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
FIP92_MAX_NI_POREP_AGGREGATION_PROOFS,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (proofs_to_aggregate, porep_id_num, api_version, api_features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_2_KIB,
porep_id,
api_version,
api_features,
)?;
aggregate_seal_proofs::<SectorShape2KiB>(&porep_config, proofs_to_aggregate)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_proof_aggregation_2kib_failures() -> Result<()> {
let test_inputs = vec![
(
FIP92_MIN_NI_POREP_AGGREGATION_PROOFS - 1,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
(
FIP92_MAX_NI_POREP_AGGREGATION_PROOFS + 1,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (proofs_to_aggregate, porep_id_num, api_version, api_features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_2_KIB,
porep_id,
api_version,
api_features,
)?;
ensure!(
aggregate_seal_proofs::<SectorShape2KiB>(&porep_config, proofs_to_aggregate).is_err(),
"test case failure passed unexpectedly"
);
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_proof_aggregation_4kib() -> Result<()> {
let test_inputs = vec![
(
7,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
vec![],
),
(
24,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
17,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (proofs_to_aggregate, porep_id_num, api_version, api_features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_4_KIB,
porep_id,
api_version,
api_features,
)?;
aggregate_seal_proofs::<SectorShape4KiB>(&porep_config, proofs_to_aggregate)?;
}
Ok(())
}
#[test]
#[ignore]
fn test_seal_proof_aggregation_32kib() -> Result<()> {
let test_inputs = vec![
(
220,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
vec![],
),
(
500,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
(
5,
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
),
];
for (proofs_to_aggregate, porep_id_num, api_version, api_features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_32_KIB,
porep_id,
api_version,
api_features,
)?;
aggregate_seal_proofs::<SectorShape32KiB>(&porep_config, proofs_to_aggregate)?;
}
Ok(())
}
//#[test]
//#[ignore]
//fn test_seal_proof_aggregation_818_32gib_porep_id_v1_1_base_8() -> Result<()> {
// let proofs_to_aggregate = 818; // Requires auto-padding
//
// let porep_id = ARBITRARY_POREP_ID_V1_1_0;
// assert!(!is_legacy_porep_id(porep_id));
// let verified = aggregate_seal_proofs::<SectorShape32GiB>(
// SECTOR_SIZE_32_GIB,
// &porep_id,
// ApiVersion::V1_1_0,
// proofs_to_aggregate,
// )?;
// assert!(verified);
//
// Ok(())
//}
//#[test]
//#[ignore]
//fn test_seal_proof_aggregation_818_64gib_porep_id_v1_1_base_8() -> Result<()> {
// let proofs_to_aggregate = 818; // Requires auto-padding
//
// let porep_id = ARBITRARY_POREP_ID_V1_1_0;
// assert!(!is_legacy_porep_id(porep_id));
// let verified = aggregate_seal_proofs::<SectorShape64GiB>(
// SECTOR_SIZE_64_GIB,
// &porep_id,
// ApiVersion::V1_1_0,
// proofs_to_aggregate,
// )?;
// assert!(verified);
//
// Ok(())
//}
#[test]
#[ignore]
fn test_sector_update_proof_aggregation_1011_2kib() -> Result<()> {
let proofs_to_aggregate = 1011; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_2_KIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape2KiB>(&porep_config, proofs_to_aggregate)
}
#[test]
#[ignore]
fn test_sector_update_proof_aggregation_33_4kib() -> Result<()> {
let proofs_to_aggregate = 33; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_4_KIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape4KiB>(&porep_config, proofs_to_aggregate)
}
#[test]
#[ignore]
fn test_sector_update_proof_aggregation_508_16kib() -> Result<()> {
let proofs_to_aggregate = 508; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_16_KIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape16KiB>(&porep_config, proofs_to_aggregate)
}
#[test]
#[ignore]
fn test_sector_update_proof_aggregation_818_32kib() -> Result<()> {
let proofs_to_aggregate = 818; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_32_KIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape32KiB>(&porep_config, proofs_to_aggregate)
}
#[test]
#[cfg(feature = "big-tests")]
fn test_sector_update_proof_aggregation_11_512mib() -> Result<()> {
let proofs_to_aggregate = 11; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_512_MIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape512MiB>(&porep_config, proofs_to_aggregate)
}
#[test]
#[cfg(feature = "big-tests")]
fn test_sector_update_proof_aggregation_455_32gib() -> Result<()> {
let proofs_to_aggregate = 455; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_32_GIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape32GiB>(&porep_config, proofs_to_aggregate)
}
#[test]
#[cfg(feature = "big-tests")]
fn test_sector_update_proof_aggregation_3_64gib() -> Result<()> {
let proofs_to_aggregate = 3; // Requires auto-padding
let api_version = ApiVersion::V1_2_0;
let porep_id = ARBITRARY_POREP_ID_V1_2_0;
assert!(!is_legacy_porep_id(porep_id));
let porep_config = porep_config(SECTOR_SIZE_64_GIB, porep_id, api_version);
aggregate_sector_update_proofs::<SectorShape64GiB>(&porep_config, proofs_to_aggregate)
}
fn aggregate_seal_proofs<Tree: 'static + MerkleTreeTrait>(
porep_config: &PoRepConfig,
num_proofs_to_aggregate: usize,
) -> Result<()> {
fil_logger::maybe_init();
let mut rng = XorShiftRng::from_seed(TEST_SEED);
let prover_fr: DefaultTreeDomain = Fr::random(&mut rng).into();
let mut prover_id = [0u8; 32];
prover_id.copy_from_slice(AsRef::<[u8]>::as_ref(&prover_fr));
// Note that ApiVersion 1.2.0 only supports SnarkPack v2, so only
// allow that testing here.
let aggregate_versions = match porep_config.api_version {
ApiVersion::V1_2_0 => vec![groth16::aggregate::AggregateVersion::V2],
ApiVersion::V1_1_0 => vec![
groth16::aggregate::AggregateVersion::V1,
groth16::aggregate::AggregateVersion::V2,
],
ApiVersion::V1_0_0 => vec![groth16::aggregate::AggregateVersion::V1],
};
info!(
"Aggregating {} seal proof with ApiVersion {}, Features {:?}, and PoRep ID {:?}",
num_proofs_to_aggregate,
porep_config.api_version,
porep_config.api_features,
porep_config.porep_id
);
for aggregate_version in aggregate_versions {
let mut commit_outputs = Vec::with_capacity(num_proofs_to_aggregate);
let mut commit_inputs = Vec::with_capacity(num_proofs_to_aggregate);
let mut seeds = Vec::with_capacity(num_proofs_to_aggregate);
let mut comm_rs = Vec::with_capacity(num_proofs_to_aggregate);
let (commit_output, commit_input, seed, comm_r) =
create_seal_for_aggregation::<_, Tree>(&mut rng, porep_config, prover_id)?;
for _ in 0..num_proofs_to_aggregate {
commit_outputs.push(commit_output.clone());
commit_inputs.extend(commit_input.clone());
seeds.push(seed);
comm_rs.push(comm_r);
}
let aggregate_proof = aggregate_seal_commit_proofs::<Tree>(
porep_config,
&comm_rs,
&seeds,
commit_outputs.as_slice(),
aggregate_version,
)?;
info!("Aggregate proof size is {} bytes", aggregate_proof.len());
assert!(verify_aggregate_seal_commit_proofs::<Tree>(
porep_config,
aggregate_proof.clone(),
&comm_rs,
&seeds,
commit_inputs.clone(),
aggregate_version,
)?);
// This ensures that once we generate an snarkpack proof
// with one version, it cannot verify with another.
let conflicting_aggregate_version = match aggregate_version {
groth16::aggregate::AggregateVersion::V1 => groth16::aggregate::AggregateVersion::V2,