Skip to content

Commit

Permalink
Use porep_id to create drg_seed.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jun 3, 2020
1 parent a96a793 commit 5cb4331
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions fil-proofs-tooling/src/bin/benchy/prodbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,11 @@ fn cache_porep_params(porep_config: PoRepConfig) {
use filecoin_proofs::parameters::public_params;
use storage_proofs::porep::stacked::{StackedCompound, StackedDrg};

let dummy_porep_id = [0; 32];
let public_params = public_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
dummy_porep_id,
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ merkletree = "0.20.0"
bincode = "1.1.2"
anyhow = "1.0.23"
rand_xorshift = "0.2.0"
sha2 = { version = "0.8.3", package = "sha2ni" }
typenum = "1.11.2"
bitintr = "0.3.0"
gperftools = { version = "0.2", optional = true }
Expand Down
1 change: 1 addition & 0 deletions filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ where
let pp = public_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?;

let offset_padded: PaddedBytesAmount = UnpaddedBytesAmount::from(offset).into();
Expand Down
6 changes: 6 additions & 0 deletions filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ where
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?,
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
priority: false,
Expand Down Expand Up @@ -239,6 +240,7 @@ where
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?,
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
priority: false,
Expand Down Expand Up @@ -360,6 +362,7 @@ pub fn seal_commit_phase1<T: AsRef<Path>, Tree: 'static + MerkleTreeTrait>(
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?,
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
priority: false,
Expand Down Expand Up @@ -442,6 +445,7 @@ pub fn seal_commit_phase2<Tree: 'static + MerkleTreeTrait>(
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?,
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
priority: false,
Expand Down Expand Up @@ -541,6 +545,7 @@ pub fn verify_seal<Tree: 'static + MerkleTreeTrait>(
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?,
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
priority: false,
Expand Down Expand Up @@ -646,6 +651,7 @@ pub fn verify_batch_seal<Tree: 'static + MerkleTreeTrait>(
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?,
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
priority: false,
Expand Down
1 change: 1 addition & 0 deletions filecoin-proofs/src/bin/paramcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn cache_porep_params<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig
let public_params = public_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions filecoin-proofs/src/bin/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ fn blank_porep_poseidon_circuit<Tree: MerkleTreeTrait>(
vanilla_params: setup_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)
.unwrap(),
partitions: Some(usize::from(PoRepProofPartitions::from(porep_config))),
Expand Down
2 changes: 2 additions & 0 deletions filecoin-proofs/src/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn get_stacked_params<Tree: 'static + MerkleTreeTrait>(
let public_params = public_params::<Tree>(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?;

let parameters_generator = || {
Expand Down Expand Up @@ -151,6 +152,7 @@ pub fn get_stacked_verifying_key<Tree: 'static + MerkleTreeTrait>(
let public_params = public_params(
PaddedBytesAmount::from(porep_config),
usize::from(PoRepProofPartitions::from(porep_config)),
porep_config.porep_id,
)?;

let vk_generator = || {
Expand Down
28 changes: 23 additions & 5 deletions filecoin-proofs/src/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use anyhow::{ensure, Result};
use sha2::{Digest, Sha256};
use storage_proofs::porep::stacked::{self, LayerChallenges, StackedDrg};
use storage_proofs::post::fallback;
use storage_proofs::proof::ProofScheme;

use crate::constants::*;
use crate::types::{MerkleTreeTrait, PaddedBytesAmount, PoStConfig};

const DRG_SEED: [u8; 28] = [
const DRG_NONCE: [u8; 32] = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27,
]; // Arbitrary, need a theory for how to vary this over time.
26, 27, 28, 30, 30, 31,
];

type WinningPostSetupParams = fallback::SetupParams;
pub type WinningPostPublicParams = fallback::PublicParams;
Expand All @@ -20,8 +21,13 @@ pub type WindowPostPublicParams = fallback::PublicParams;
pub fn public_params<Tree: 'static + MerkleTreeTrait>(
sector_bytes: PaddedBytesAmount,
partitions: usize,
porep_id: [u8; 32],
) -> Result<stacked::PublicParams<Tree>> {
StackedDrg::<Tree, DefaultPieceHasher>::setup(&setup_params(sector_bytes, partitions)?)
StackedDrg::<Tree, DefaultPieceHasher>::setup(&setup_params(
sector_bytes,
partitions,
porep_id,
)?)
}

pub fn winning_post_public_params<Tree: 'static + MerkleTreeTrait>(
Expand Down Expand Up @@ -68,9 +74,19 @@ pub fn window_post_setup_params(post_config: &PoStConfig) -> WindowPostSetupPara
}
}

fn drg_seed_from_porep_id(porep_id: [u8; 32]) -> [u8; 28] {
let mut drg_seed = [0; 28];

let hash = Sha256::new().chain(porep_id).chain(DRG_NONCE).result();

drg_seed.copy_from_slice(&hash[..28]);
drg_seed
}

pub fn setup_params(
sector_bytes: PaddedBytesAmount,
partitions: usize,
porep_id: [u8; 32],
) -> Result<stacked::SetupParams> {
let layer_challenges = select_challenges(
partitions,
Expand All @@ -97,11 +113,13 @@ pub fn setup_params(
let degree = DRG_DEGREE;
let expansion_degree = EXP_DEGREE;

let drg_seed = drg_seed_from_porep_id(porep_id);

Ok(stacked::SetupParams {
nodes,
degree,
expansion_degree,
seed: DRG_SEED,
seed: drg_seed,
layer_challenges,
})
}
Expand Down
1 change: 1 addition & 0 deletions filecoin-proofs/src/types/porep_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl PoRepConfig {
let params = crate::parameters::public_params::<Tree>(
self.sector_size.into(),
self.partitions.into(),
self.porep_id,
)?;

Ok(
Expand Down

0 comments on commit 5cb4331

Please sign in to comment.