Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new partition post API calls #66

Merged
merged 6 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ bellperson = { version = "0.17", 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.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", git = "https://github.com/filecoin-project/rust-fil-proofs", branch = "feat-decouple-post-partition", default-features = false }
filecoin-hashers = { git = "https://github.com/filecoin-project/rust-fil-proofs", branch = "feat-decouple-post-partition", default-features = false, features = ["poseidon", "sha256"] }
fr32 = { git = "https://github.com/filecoin-project/rust-fil-proofs", branch = "feat-decouple-post-partition", default-features = false }
storage-proofs-core = { git = "https://github.com/filecoin-project/rust-fil-proofs", branch = "feat-decouple-post-partition", default-features = false }
storage-proofs-porep = { git = "https://github.com/filecoin-project/rust-fil-proofs", branch = "feat-decouple-post-partition", default-features = false }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: Replace all of these deps after proofs is released


[features]
default = ["opencl"]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 88 additions & 2 deletions src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -493,3 +493,89 @@ fn verify_window_post_inner<Tree: 'static + MerkleTreeTrait>(

Ok(valid_v1)
}

pub fn get_num_partition_for_fallback_post(
registered_post_proof_v1: RegisteredPoStProof,
num_sectors: usize,
) -> Result<usize> {
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(
&registered_post_proof_v1.as_v1_config(),
num_sectors,
))
}

pub fn merge_window_post_partition_proofs(
registered_post_proof_v1: RegisteredPoStProof,
proofs: Vec<PartitionSnarkProof>,
) -> Result<SnarkProof> {
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)
}

pub fn generate_single_window_post_with_vanilla_inner<Tree: 'static + MerkleTreeTrait>(
dignifiedquire marked this conversation as resolved.
Show resolved Hide resolved
registered_post_proof_v1: RegisteredPoStProof,
randomness: &ChallengeSeed,
prover_id: ProverId,
vanilla_proofs: &[VanillaProofBytes],
partition_index: usize,
) -> Result<PartitionSnarkProof> {
let fallback_post_sector_proofs: Vec<FallbackPoStSectorProof<Tree>> = vanilla_proofs
.iter()
.map(|proof_bytes| {
let proof: FallbackPoStSectorProof<Tree> = bincode::deserialize(proof_bytes)?;
Ok(proof)
})
.collect::<Result<_>>()?;

filecoin_proofs_v1::generate_single_window_post_with_vanilla(
&registered_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<PartitionSnarkProof> {
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,
)
}