From 42571a28bb8e14acc7f2cfd503f9c62fbfc6c631 Mon Sep 17 00:00:00 2001 From: nemo Date: Mon, 25 Oct 2021 16:48:06 -0400 Subject: [PATCH] feat: add new partition post API calls (#66) * feat: add new partition post API calls * fix: inner methods should not be exposed as public * feat: update rust-toolchain from 1.51.0 to 1.54.0 * fix: update dependencies to the latest releases --- Cargo.toml | 12 +++---- rust-toolchain | 2 +- src/lib.rs | 4 +-- src/post.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 97 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c75acfe..f15041a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,15 +10,15 @@ readme = "README.md" [dependencies] anyhow = "1.0.26" -bellperson = { version = "0.17", default-features = false } +bellperson = { version = "0.18", default-features = false } bincode = "1.1.2" blstrs = "0.4.0" serde = "1.0.104" -filecoin-proofs-v1 = { package = "filecoin-proofs", version = "~10.0", default-features = false } -filecoin-hashers = { version = "~5.0", default-features = false, features = ["poseidon", "sha256"] } -fr32 = { version = "~3.0", default-features = false } -storage-proofs-core = { version = "~10.0", default-features = false } -storage-proofs-porep = { version = "~10.0", default-features = false } +filecoin-proofs-v1 = { package = "filecoin-proofs", version = "~10.1", default-features = false } +filecoin-hashers = { version = "~5.1", default-features = false, features = ["poseidon", "sha256"] } +fr32 = { version = "~3.1", default-features = false } +storage-proofs-core = { version = "~10.1", default-features = false } +storage-proofs-porep = { version = "~10.1", default-features = false } [features] default = ["opencl"] diff --git a/rust-toolchain b/rust-toolchain index ba0a7191..b7921ae8 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.51.0 +1.54.0 diff --git a/src/lib.rs b/src/lib.rs index eb8ef01e..74029d77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,8 @@ pub use crate::registry::{RegisteredAggregationProof, RegisteredPoStProof, Regis pub use crate::types::{PrivateReplicaInfo, PublicReplicaInfo}; pub use filecoin_proofs_v1::types::{ - AggregateSnarkProof, ChallengeSeed, Commitment, PaddedBytesAmount, PieceInfo, PoStType, - ProverId, Ticket, UnpaddedByteIndex, UnpaddedBytesAmount, + AggregateSnarkProof, ChallengeSeed, Commitment, PaddedBytesAmount, PartitionSnarkProof, + PieceInfo, PoStType, ProverId, Ticket, UnpaddedByteIndex, UnpaddedBytesAmount, }; pub use filecoin_proofs_v1::{FallbackPoStSectorProof, SnarkProof, VanillaProof}; pub use fr32; diff --git a/src/post.rs b/src/post.rs index b4af0fa5..92483323 100644 --- a/src/post.rs +++ b/src/post.rs @@ -5,8 +5,8 @@ use filecoin_proofs_v1::with_shape; use crate::types::VanillaProofBytes; use crate::{ - ChallengeSeed, FallbackPoStSectorProof, MerkleTreeTrait, PoStType, PrivateReplicaInfo, - ProverId, PublicReplicaInfo, RegisteredPoStProof, SectorId, SnarkProof, + ChallengeSeed, FallbackPoStSectorProof, MerkleTreeTrait, PartitionSnarkProof, PoStType, + PrivateReplicaInfo, ProverId, PublicReplicaInfo, RegisteredPoStProof, SectorId, SnarkProof, }; pub fn generate_winning_post_sector_challenge( @@ -493,3 +493,89 @@ fn verify_window_post_inner( Ok(valid_v1) } + +pub fn get_num_partition_for_fallback_post( + registered_post_proof_v1: RegisteredPoStProof, + num_sectors: usize, +) -> Result { + ensure!( + registered_post_proof_v1.typ() == PoStType::Window, + "invalid post type provided" + ); + ensure!( + registered_post_proof_v1.major_version() == 1, + "only V1 supported" + ); + + Ok(filecoin_proofs_v1::get_num_partition_for_fallback_post( + ®istered_post_proof_v1.as_v1_config(), + num_sectors, + )) +} + +pub fn merge_window_post_partition_proofs( + registered_post_proof_v1: RegisteredPoStProof, + proofs: Vec, +) -> Result { + ensure!( + registered_post_proof_v1.typ() == PoStType::Window, + "invalid post type provided" + ); + ensure!( + registered_post_proof_v1.major_version() == 1, + "only V1 supported" + ); + + filecoin_proofs_v1::merge_window_post_partition_proofs(proofs) +} + +fn generate_single_window_post_with_vanilla_inner( + registered_post_proof_v1: RegisteredPoStProof, + randomness: &ChallengeSeed, + prover_id: ProverId, + vanilla_proofs: &[VanillaProofBytes], + partition_index: usize, +) -> Result { + let fallback_post_sector_proofs: Vec> = vanilla_proofs + .iter() + .map(|proof_bytes| { + let proof: FallbackPoStSectorProof = bincode::deserialize(proof_bytes)?; + Ok(proof) + }) + .collect::>()?; + + filecoin_proofs_v1::generate_single_window_post_with_vanilla( + ®istered_post_proof_v1.as_v1_config(), + randomness, + prover_id, + fallback_post_sector_proofs, + partition_index, + ) +} + +pub fn generate_single_window_post_with_vanilla( + registered_post_proof_v1: RegisteredPoStProof, + randomness: &ChallengeSeed, + prover_id: ProverId, + vanilla_proofs: &[VanillaProofBytes], + partition_index: usize, +) -> Result { + ensure!( + registered_post_proof_v1.typ() == PoStType::Window, + "invalid post type provided" + ); + ensure!( + registered_post_proof_v1.major_version() == 1, + "only V1 supported" + ); + + with_shape!( + u64::from(registered_post_proof_v1.sector_size()), + generate_single_window_post_with_vanilla_inner, + registered_post_proof_v1, + randomness, + prover_id, + vanilla_proofs, + partition_index, + ) +}