Skip to content

Commit a8192c6

Browse files
authored
Synthetic PoRep (#87)
* feat: api and dep updates for proofs compatibility * feat: add new seal proof types to support synth-porep feature * feat: add method to remove persisted synthetic proofs * feat: add synth proof generation * feat: expose generate_synth_proofs method * feat: expose clear_layer_data API * feat: update to the latest proofs release
1 parent e588eb7 commit a8192c6

File tree

4 files changed

+350
-73
lines changed

4 files changed

+350
-73
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ readme = "README.md"
1010

1111
[dependencies]
1212
anyhow = "1.0.26"
13-
bellperson = { version = "0.25", default-features = false }
13+
bellperson = { version = "0.26", default-features = false }
1414
bincode = "1.1.2"
1515
blstrs = "0.7"
1616
lazy_static = "1.2"
1717
serde = "1.0.104"
18-
filecoin-proofs-v1 = { package = "filecoin-proofs", version = "~15.0.0", default-features = false }
19-
filecoin-hashers = { version = "~10.0.0", default-features = false, features = ["poseidon", "sha256"] }
20-
fr32 = { version = "~8.0.0", default-features = false }
21-
storage-proofs-core = { version = "~15.0.0", default-features = false }
18+
filecoin-proofs-v1 = { package = "filecoin-proofs", version = "~16.0.0", default-features = false }
19+
filecoin-hashers = { version = "~11.0.0", default-features = false, features = ["poseidon", "sha256"] }
20+
fr32 = { version = "~9.0.0", default-features = false }
21+
storage-proofs-core = { version = "~16.0.0", default-features = false }
2222

2323
[features]
2424
default = ["opencl", "cuda"]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use filecoin_proofs_v1::types::{
3636
pub use filecoin_proofs_v1::{FallbackPoStSectorProof, SnarkProof, VanillaProof};
3737
pub use fr32;
3838
pub use storage_proofs_core::{
39-
api_version::ApiVersion,
39+
api_version::{ApiFeature, ApiVersion},
4040
error::Error as StorageProofsError,
4141
merkle::MerkleTreeTrait,
4242
parameter_cache::{get_parameter_data, get_verifying_key_data},

src/registry.rs

Lines changed: 177 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ use filecoin_proofs_v1::{PoRepConfig, PoRepProofPartitions, PoStConfig, PoStType
99
use lazy_static::lazy_static;
1010
use serde::{Deserialize, Serialize};
1111

12-
use crate::{get_parameter_data, get_verifying_key_data, ApiVersion, MerkleTreeTrait};
12+
use crate::{get_parameter_data, get_verifying_key_data, ApiFeature, ApiVersion, MerkleTreeTrait};
1313

1414
/// Available seal proofs.
1515
// Enum is append-only: once published, a `RegisteredSealProof` value must never change.
16+
#[allow(non_camel_case_types)]
1617
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1718
pub enum RegisteredSealProof {
1819
StackedDrg2KiBV1,
@@ -26,6 +27,12 @@ pub enum RegisteredSealProof {
2627
StackedDrg512MiBV1_1,
2728
StackedDrg32GiBV1_1,
2829
StackedDrg64GiBV1_1,
30+
31+
StackedDrg2KiBV1_1_Feat_SyntheticPoRep,
32+
StackedDrg8MiBV1_1_Feat_SyntheticPoRep,
33+
StackedDrg512MiBV1_1_Feat_SyntheticPoRep,
34+
StackedDrg32GiBV1_1_Feat_SyntheticPoRep,
35+
StackedDrg64GiBV1_1_Feat_SyntheticPoRep,
2936
}
3037

3138
// This maps all registered seal proof enum types to porep_id values.
@@ -41,6 +48,26 @@ lazy_static! {
4148
(RegisteredSealProof::StackedDrg512MiBV1_1, 7),
4249
(RegisteredSealProof::StackedDrg32GiBV1_1, 8),
4350
(RegisteredSealProof::StackedDrg64GiBV1_1, 9),
51+
(
52+
RegisteredSealProof::StackedDrg2KiBV1_1_Feat_SyntheticPoRep,
53+
10
54+
),
55+
(
56+
RegisteredSealProof::StackedDrg8MiBV1_1_Feat_SyntheticPoRep,
57+
11
58+
),
59+
(
60+
RegisteredSealProof::StackedDrg512MiBV1_1_Feat_SyntheticPoRep,
61+
12
62+
),
63+
(
64+
RegisteredSealProof::StackedDrg32GiBV1_1_Feat_SyntheticPoRep,
65+
13
66+
),
67+
(
68+
RegisteredSealProof::StackedDrg64GiBV1_1_Feat_SyntheticPoRep,
69+
14
70+
),
4471
]
4572
.into_iter()
4673
.collect();
@@ -85,8 +112,16 @@ impl RegisteredSealProof {
85112
match self {
86113
StackedDrg2KiBV1 | StackedDrg8MiBV1 | StackedDrg512MiBV1 | StackedDrg32GiBV1
87114
| StackedDrg64GiBV1 => ApiVersion::V1_0_0,
88-
StackedDrg2KiBV1_1 | StackedDrg8MiBV1_1 | StackedDrg512MiBV1_1
89-
| StackedDrg32GiBV1_1 | StackedDrg64GiBV1_1 => ApiVersion::V1_1_0,
115+
StackedDrg2KiBV1_1
116+
| StackedDrg8MiBV1_1
117+
| StackedDrg512MiBV1_1
118+
| StackedDrg32GiBV1_1
119+
| StackedDrg64GiBV1_1
120+
| StackedDrg2KiBV1_1_Feat_SyntheticPoRep
121+
| StackedDrg8MiBV1_1_Feat_SyntheticPoRep
122+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep
123+
| StackedDrg32GiBV1_1_Feat_SyntheticPoRep
124+
| StackedDrg64GiBV1_1_Feat_SyntheticPoRep => ApiVersion::V1_1_0,
90125
}
91126
}
92127

@@ -109,11 +144,21 @@ impl RegisteredSealProof {
109144
pub fn sector_size(self) -> SectorSize {
110145
use RegisteredSealProof::*;
111146
let size = match self {
112-
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 => constants::SECTOR_SIZE_2_KIB,
113-
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 => constants::SECTOR_SIZE_8_MIB,
114-
StackedDrg512MiBV1 | StackedDrg512MiBV1_1 => constants::SECTOR_SIZE_512_MIB,
115-
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 => constants::SECTOR_SIZE_32_GIB,
116-
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 => constants::SECTOR_SIZE_64_GIB,
147+
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 | StackedDrg2KiBV1_1_Feat_SyntheticPoRep => {
148+
constants::SECTOR_SIZE_2_KIB
149+
}
150+
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 | StackedDrg8MiBV1_1_Feat_SyntheticPoRep => {
151+
constants::SECTOR_SIZE_8_MIB
152+
}
153+
StackedDrg512MiBV1
154+
| StackedDrg512MiBV1_1
155+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep => constants::SECTOR_SIZE_512_MIB,
156+
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 | StackedDrg32GiBV1_1_Feat_SyntheticPoRep => {
157+
constants::SECTOR_SIZE_32_GIB
158+
}
159+
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 | StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
160+
constants::SECTOR_SIZE_64_GIB
161+
}
117162
};
118163
SectorSize(size)
119164
}
@@ -122,31 +167,41 @@ impl RegisteredSealProof {
122167
pub fn partitions(self) -> u8 {
123168
use RegisteredSealProof::*;
124169
match self {
125-
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 => *constants::POREP_PARTITIONS
126-
.read()
127-
.expect("porep partitions read error")
128-
.get(&constants::SECTOR_SIZE_2_KIB)
129-
.expect("invalid sector size"),
130-
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 => *constants::POREP_PARTITIONS
131-
.read()
132-
.expect("porep partitions read error")
133-
.get(&constants::SECTOR_SIZE_8_MIB)
134-
.expect("invalid sector size"),
135-
StackedDrg512MiBV1 | StackedDrg512MiBV1_1 => *constants::POREP_PARTITIONS
170+
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 | StackedDrg2KiBV1_1_Feat_SyntheticPoRep => {
171+
*constants::POREP_PARTITIONS
172+
.read()
173+
.expect("porep partitions read error")
174+
.get(&constants::SECTOR_SIZE_2_KIB)
175+
.expect("invalid sector size")
176+
}
177+
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 | StackedDrg8MiBV1_1_Feat_SyntheticPoRep => {
178+
*constants::POREP_PARTITIONS
179+
.read()
180+
.expect("porep partitions read error")
181+
.get(&constants::SECTOR_SIZE_8_MIB)
182+
.expect("invalid sector size")
183+
}
184+
StackedDrg512MiBV1
185+
| StackedDrg512MiBV1_1
186+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep => *constants::POREP_PARTITIONS
136187
.read()
137188
.expect("porep partitions read error")
138189
.get(&constants::SECTOR_SIZE_512_MIB)
139190
.expect("invalid sector size"),
140-
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 => *constants::POREP_PARTITIONS
141-
.read()
142-
.expect("porep partitions read error")
143-
.get(&constants::SECTOR_SIZE_32_GIB)
144-
.expect("invalid sector size"),
145-
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 => *constants::POREP_PARTITIONS
146-
.read()
147-
.expect("porep partitions read error")
148-
.get(&constants::SECTOR_SIZE_64_GIB)
149-
.expect("invalid sector size"),
191+
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 | StackedDrg32GiBV1_1_Feat_SyntheticPoRep => {
192+
*constants::POREP_PARTITIONS
193+
.read()
194+
.expect("porep partitions read error")
195+
.get(&constants::SECTOR_SIZE_32_GIB)
196+
.expect("invalid sector size")
197+
}
198+
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 | StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
199+
*constants::POREP_PARTITIONS
200+
.read()
201+
.expect("porep partitions read error")
202+
.get(&constants::SECTOR_SIZE_64_GIB)
203+
.expect("invalid sector size")
204+
}
150205
}
151206
}
152207

@@ -155,9 +210,21 @@ impl RegisteredSealProof {
155210
use RegisteredSealProof::*;
156211

157212
match self {
158-
StackedDrg2KiBV1 | StackedDrg8MiBV1 | StackedDrg512MiBV1 | StackedDrg32GiBV1
159-
| StackedDrg64GiBV1 | StackedDrg2KiBV1_1 | StackedDrg8MiBV1_1
160-
| StackedDrg512MiBV1_1 | StackedDrg32GiBV1_1 | StackedDrg64GiBV1_1 => {
213+
StackedDrg2KiBV1
214+
| StackedDrg8MiBV1
215+
| StackedDrg512MiBV1
216+
| StackedDrg32GiBV1
217+
| StackedDrg64GiBV1
218+
| StackedDrg2KiBV1_1
219+
| StackedDrg8MiBV1_1
220+
| StackedDrg512MiBV1_1
221+
| StackedDrg32GiBV1_1
222+
| StackedDrg64GiBV1_1
223+
| StackedDrg2KiBV1_1_Feat_SyntheticPoRep
224+
| StackedDrg8MiBV1_1_Feat_SyntheticPoRep
225+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep
226+
| StackedDrg32GiBV1_1_Feat_SyntheticPoRep
227+
| StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
161228
filecoin_proofs_v1::SINGLE_PARTITION_PROOF_LEN
162229
}
163230
}
@@ -208,10 +275,29 @@ impl RegisteredSealProof {
208275
api_version: self.version(),
209276
api_features: Vec::new(),
210277
}
278+
}
279+
StackedDrg2KiBV1_1_Feat_SyntheticPoRep
280+
| StackedDrg8MiBV1_1_Feat_SyntheticPoRep
281+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep
282+
| StackedDrg32GiBV1_1_Feat_SyntheticPoRep
283+
| StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
284+
assert_eq!(self.version(), ApiVersion::V1_1_0);
285+
PoRepConfig {
286+
sector_size: self.sector_size(),
287+
partitions: PoRepProofPartitions(self.partitions()),
288+
porep_id: self.porep_id(),
289+
api_version: self.version(),
290+
api_features: vec![ApiFeature::SyntheticPoRep],
291+
}
211292
} // _ => panic!("Can only be called on V1 configs"),
212293
}
213294
}
214295

296+
/// Returns if the feature is enabled based on the proof type
297+
pub fn feature_enabled(self, api_feature: ApiFeature) -> bool {
298+
self.as_v1_config().api_features.contains(&api_feature)
299+
}
300+
215301
/// Returns the circuit identifier.
216302
pub fn circuit_identifier(self) -> Result<String> {
217303
match self.version() {
@@ -284,11 +370,21 @@ impl RegisteredSealProof {
284370
use RegisteredPoStProof::*;
285371
use RegisteredSealProof::*;
286372
match self {
287-
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 => StackedDrgWinning2KiBV1,
288-
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 => StackedDrgWinning8MiBV1,
289-
StackedDrg512MiBV1 | StackedDrg512MiBV1_1 => StackedDrgWinning512MiBV1,
290-
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 => StackedDrgWinning32GiBV1,
291-
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 => StackedDrgWinning64GiBV1,
373+
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 | StackedDrg2KiBV1_1_Feat_SyntheticPoRep => {
374+
StackedDrgWinning2KiBV1
375+
}
376+
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 | StackedDrg8MiBV1_1_Feat_SyntheticPoRep => {
377+
StackedDrgWinning8MiBV1
378+
}
379+
StackedDrg512MiBV1
380+
| StackedDrg512MiBV1_1
381+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep => StackedDrgWinning512MiBV1,
382+
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 | StackedDrg32GiBV1_1_Feat_SyntheticPoRep => {
383+
StackedDrgWinning32GiBV1
384+
}
385+
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 | StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
386+
StackedDrgWinning64GiBV1
387+
}
292388
}
293389
}
294390

@@ -304,11 +400,21 @@ impl RegisteredSealProof {
304400
use RegisteredPoStProof::*;
305401
use RegisteredSealProof::*;
306402
match self {
307-
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 => StackedDrgWindow2KiBV1_2,
308-
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 => StackedDrgWindow8MiBV1_2,
309-
StackedDrg512MiBV1 | StackedDrg512MiBV1_1 => StackedDrgWindow512MiBV1_2,
310-
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 => StackedDrgWindow32GiBV1_2,
311-
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 => StackedDrgWindow64GiBV1_2,
403+
StackedDrg2KiBV1 | StackedDrg2KiBV1_1 | StackedDrg2KiBV1_1_Feat_SyntheticPoRep => {
404+
StackedDrgWindow2KiBV1_2
405+
}
406+
StackedDrg8MiBV1 | StackedDrg8MiBV1_1 | StackedDrg8MiBV1_1_Feat_SyntheticPoRep => {
407+
StackedDrgWindow8MiBV1_2
408+
}
409+
StackedDrg512MiBV1
410+
| StackedDrg512MiBV1_1
411+
| StackedDrg512MiBV1_1_Feat_SyntheticPoRep => StackedDrgWindow512MiBV1_2,
412+
StackedDrg32GiBV1 | StackedDrg32GiBV1_1 | StackedDrg32GiBV1_1_Feat_SyntheticPoRep => {
413+
StackedDrgWindow32GiBV1_2
414+
}
415+
StackedDrg64GiBV1 | StackedDrg64GiBV1_1 | StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
416+
StackedDrgWindow64GiBV1_2
417+
}
312418
}
313419
}
314420
}
@@ -770,7 +876,7 @@ mod tests {
770876
use super::*;
771877
use filecoin_proofs_v1::MAX_LEGACY_REGISTERED_SEAL_PROOF_ID;
772878

773-
const REGISTERED_SEAL_PROOFS: [RegisteredSealProof; 10] = [
879+
const REGISTERED_SEAL_PROOFS: [RegisteredSealProof; 15] = [
774880
RegisteredSealProof::StackedDrg2KiBV1,
775881
RegisteredSealProof::StackedDrg8MiBV1,
776882
RegisteredSealProof::StackedDrg512MiBV1,
@@ -781,6 +887,11 @@ mod tests {
781887
RegisteredSealProof::StackedDrg512MiBV1_1,
782888
RegisteredSealProof::StackedDrg32GiBV1_1,
783889
RegisteredSealProof::StackedDrg64GiBV1_1,
890+
RegisteredSealProof::StackedDrg2KiBV1_1_Feat_SyntheticPoRep,
891+
RegisteredSealProof::StackedDrg8MiBV1_1_Feat_SyntheticPoRep,
892+
RegisteredSealProof::StackedDrg512MiBV1_1_Feat_SyntheticPoRep,
893+
RegisteredSealProof::StackedDrg32GiBV1_1_Feat_SyntheticPoRep,
894+
RegisteredSealProof::StackedDrg64GiBV1_1_Feat_SyntheticPoRep,
784895
];
785896

786897
#[test]
@@ -822,6 +933,21 @@ mod tests {
822933
RegisteredSealProof::StackedDrg64GiBV1_1 => {
823934
"0900000000000000000000000000000000000000000000000000000000000000"
824935
}
936+
RegisteredSealProof::StackedDrg2KiBV1_1_Feat_SyntheticPoRep => {
937+
"0a00000000000000000000000000000000000000000000000000000000000000"
938+
}
939+
RegisteredSealProof::StackedDrg8MiBV1_1_Feat_SyntheticPoRep => {
940+
"0b00000000000000000000000000000000000000000000000000000000000000"
941+
}
942+
RegisteredSealProof::StackedDrg512MiBV1_1_Feat_SyntheticPoRep => {
943+
"0c00000000000000000000000000000000000000000000000000000000000000"
944+
}
945+
RegisteredSealProof::StackedDrg32GiBV1_1_Feat_SyntheticPoRep => {
946+
"0d00000000000000000000000000000000000000000000000000000000000000"
947+
}
948+
RegisteredSealProof::StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
949+
"0e00000000000000000000000000000000000000000000000000000000000000"
950+
}
825951
};
826952
let hex: String = rsp
827953
.porep_id()
@@ -854,7 +980,14 @@ mod tests {
854980
| RegisteredSealProof::StackedDrg8MiBV1_1
855981
| RegisteredSealProof::StackedDrg512MiBV1_1
856982
| RegisteredSealProof::StackedDrg32GiBV1_1
857-
| RegisteredSealProof::StackedDrg64GiBV1_1 => assert!(!is_legacy),
983+
| RegisteredSealProof::StackedDrg64GiBV1_1
984+
| RegisteredSealProof::StackedDrg2KiBV1_1_Feat_SyntheticPoRep
985+
| RegisteredSealProof::StackedDrg8MiBV1_1_Feat_SyntheticPoRep
986+
| RegisteredSealProof::StackedDrg512MiBV1_1_Feat_SyntheticPoRep
987+
| RegisteredSealProof::StackedDrg32GiBV1_1_Feat_SyntheticPoRep
988+
| RegisteredSealProof::StackedDrg64GiBV1_1_Feat_SyntheticPoRep => {
989+
assert!(!is_legacy)
990+
}
858991
}
859992
}
860993
}

0 commit comments

Comments
 (0)