Skip to content

Commit

Permalink
feat: add new partition post API calls (#66)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cryptonemo authored Oct 25, 2021
1 parent 383fee3 commit 42571a2
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 11 deletions.
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,
)
}

0 comments on commit 42571a2

Please sign in to comment.