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 all commits
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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.51.0
1.54.0
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)
}

fn generate_single_window_post_with_vanilla_inner<Tree: 'static + MerkleTreeTrait>(
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,
)
}