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

Add opaque porep_id as public input and use when constructing replica_id #1144

Merged
merged 1 commit into from
Jun 3, 2020
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
10 changes: 8 additions & 2 deletions fil-proofs-tooling/src/bin/benchy/prodbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ pub fn run(
let mut outputs = ProdbenchOutputs::default();

let sector_size = SectorSize(inputs.sector_size_bytes());
let arbitrary_porep_id = [123; 32];

assert!(inputs.num_sectors > 0, "Missing num_sectors");

let (cfg, repls) = create_replicas::<DefaultOctLCTree>(
sector_size,
inputs.num_sectors as usize,
only_add_piece,
arbitrary_porep_id,
);

if only_add_piece || only_replicate {
Expand Down Expand Up @@ -270,7 +272,6 @@ fn run_measure_circuits(i: &ProdbenchInputs) -> CircuitOutputs {
}

fn measure_porep_circuit(i: &ProdbenchInputs) -> usize {
use storage_proofs::drgraph::new_seed;
use storage_proofs::porep::stacked::{
LayerChallenges, SetupParams, StackedCompound, StackedDrg,
};
Expand All @@ -282,11 +283,12 @@ fn measure_porep_circuit(i: &ProdbenchInputs) -> usize {
let nodes = (i.sector_size_bytes() / 32) as usize;
let layer_challenges = LayerChallenges::new(layers, challenge_count);

let arbitrary_porep_id = [222; 32];
let sp = SetupParams {
nodes,
degree: drg_degree,
expansion_degree,
seed: new_seed(),
porep_id: arbitrary_porep_id,
layer_challenges,
};

Expand Down Expand Up @@ -315,20 +317,24 @@ fn generate_params(i: &ProdbenchInputs) {
"generating params: porep: (size: {:?}, partitions: {:?})",
&sector_size, &partitions
);
let dummy_porep_id = [0; 32];

cache_porep_params(PoRepConfig {
sector_size,
partitions,
porep_id: dummy_porep_id,
});
}

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
6 changes: 5 additions & 1 deletion fil-proofs-tooling/src/bin/benchy/stacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ where
);

let replica_id = H::Domain::random(rng);
let arbitrary_porep_id = [11; 32];
let sp = stacked::SetupParams {
nodes,
degree: BASE_DEGREE,
expansion_degree: EXP_DEGREE,
seed: new_seed(),
porep_id: arbitrary_porep_id,
layer_challenges: layer_challenges.clone(),
};

Expand Down Expand Up @@ -154,11 +155,14 @@ where
replica_path.clone(),
)?;

let arbitrary_porep_id = [88; 32];

let pb = stacked::PublicInputs::<H::Domain, <Sha256Hasher as Hasher>::Domain> {
replica_id,
seed,
tau: Some(tau),
k: Some(0),
porep_id: arbitrary_porep_id,
};

// Convert TemporaryAux to TemporaryAuxCache, which instantiates all
Expand Down
3 changes: 3 additions & 0 deletions fil-proofs-tooling/src/bin/benchy/window_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(

let piece_infos = vec![piece_info];

let arbitrary_porep_id = [99; 32];

// Replicate the staged sector, write the replica file to `sealed_path`.
let porep_config = PoRepConfig {
sector_size: SectorSize(sector_size),
Expand All @@ -112,6 +114,7 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
.get(&(sector_size))
.unwrap(),
),
porep_id: arbitrary_porep_id,
};
let cache_dir = tempfile::tempdir().unwrap();
let sector_id = SectorId::from(SECTOR_ID);
Expand Down
3 changes: 2 additions & 1 deletion fil-proofs-tooling/src/bin/benchy/winning_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
"This benchmark only works with WINNING_POST_SECTOR_COUNT == 1"
));
}
let (sector_id, replica_output) = create_replica::<Tree>(sector_size);
let arbitrary_porep_id = [66; 32];
let (sector_id, replica_output) = create_replica::<Tree>(sector_size, arbitrary_porep_id);

// Store the replica's private and publicly facing info for proving and verifying respectively.
let pub_replica_info = vec![(sector_id, replica_output.public_replica_info)];
Expand Down
3 changes: 2 additions & 1 deletion fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ fn threads_mode(parallel: u8, gpu_stealing: bool) {
let mut senders = Vec::new();
// All thread handles that get terminated
let mut threads: Vec<Option<thread::JoinHandle<_>>> = Vec::new();
let arbitrary_porep_id = [234; 32];

// Create fixtures only once for both threads
let (sector_id, replica_output) = create_replica::<MerkleTree>(SECTOR_SIZE);
let (sector_id, replica_output) = create_replica::<MerkleTree>(SECTOR_SIZE, arbitrary_porep_id);
let priv_replica_info = (sector_id, replica_output.private_replica_info);

// Put each proof into it's own scope (the other one is due to the if statement)
Expand Down
6 changes: 5 additions & 1 deletion fil-proofs-tooling/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ pub fn create_piece(piece_bytes: UnpaddedBytesAmount) -> NamedTempFile {
/// Create a replica for a single sector
pub fn create_replica<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
porep_id: [u8; 32],
) -> (SectorId, PreCommitReplicaOutput<Tree>) {
let (_porep_config, result) = create_replicas::<Tree>(SectorSize(sector_size), 1, false);
let (_porep_config, result) =
create_replicas::<Tree>(SectorSize(sector_size), 1, false, porep_id);
// Extract the sector ID and replica output out of the result
result
.unwrap()
Expand All @@ -79,6 +81,7 @@ pub fn create_replicas<Tree: 'static + MerkleTreeTrait>(
sector_size: SectorSize,
qty_sectors: usize,
only_add: bool,
porep_id: [u8; 32],
) -> (
PoRepConfig,
Option<(
Expand All @@ -99,6 +102,7 @@ pub fn create_replicas<Tree: 'static + MerkleTreeTrait>(
.get(&u64::from(sector_size))
.expect("unknown sector size"),
),
porep_id,
};

let mut out: Vec<(SectorId, PreCommitReplicaOutput<Tree>)> = Default::default();
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
13 changes: 11 additions & 2 deletions filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ where
let comm_d =
as_safe_commitment::<<DefaultPieceHasher as Hasher>::Domain, _>(&comm_d, "comm_d")?;

let replica_id =
generate_replica_id::<Tree::Hasher, _>(&prover_id, sector_id.into(), &ticket, comm_d);
let replica_id = generate_replica_id::<Tree::Hasher, _>(
&prover_id,
sector_id.into(),
&ticket,
comm_d,
&porep_config.porep_id,
);

let mut data = Vec::new();
sealed_sector.read_to_end(&mut data)?;
Expand All @@ -152,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 Expand Up @@ -559,6 +565,7 @@ mod tests {
let out = bytes_into_fr(&not_convertible_to_fr_bytes);
assert!(out.is_err(), "tripwire");

let arbitrary_porep_id = [87; 32];
{
let result = verify_seal::<DefaultOctLCTree>(
PoRepConfig {
Expand All @@ -570,6 +577,7 @@ mod tests {
.get(&SECTOR_SIZE_2_KIB)
.unwrap(),
),
porep_id: arbitrary_porep_id,
},
not_convertible_to_fr_bytes,
convertible_to_fr_bytes,
Expand Down Expand Up @@ -604,6 +612,7 @@ mod tests {
.get(&SECTOR_SIZE_2_KIB)
.unwrap(),
),
porep_id: arbitrary_porep_id,
},
convertible_to_fr_bytes,
not_convertible_to_fr_bytes,
Expand Down
38 changes: 32 additions & 6 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 @@ -149,8 +150,13 @@ where
"pieces and comm_d do not match"
);

let replica_id =
generate_replica_id::<Tree::Hasher, _>(&prover_id, sector_id.into(), &ticket, comm_d);
let replica_id = generate_replica_id::<Tree::Hasher, _>(
&prover_id,
sector_id.into(),
&ticket,
comm_d,
&porep_config.porep_id,
);

let labels = StackedDrg::<Tree, DefaultPieceHasher>::replicate_phase1(
&compound_public_params.vanilla_params,
Expand Down Expand Up @@ -234,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 @@ -327,11 +334,17 @@ pub fn seal_commit_phase1<T: AsRef<Path>, Tree: 'static + MerkleTreeTrait>(
let comm_r_safe = as_safe_commitment(&comm_r, "comm_r")?;
let comm_d_safe = DefaultPieceDomain::try_from_bytes(&comm_d)?;

let replica_id =
generate_replica_id::<Tree::Hasher, _>(&prover_id, sector_id.into(), &ticket, comm_d_safe);
let replica_id = generate_replica_id::<Tree::Hasher, _>(
&prover_id,
sector_id.into(),
&ticket,
comm_d_safe,
&porep_config.porep_id,
);

let public_inputs = stacked::PublicInputs {
replica_id,
porep_id: porep_config.porep_id,
tau: Some(stacked::Tau {
comm_d: comm_d_safe,
comm_r: comm_r_safe,
Expand All @@ -349,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 @@ -411,6 +425,7 @@ pub fn seal_commit_phase2<Tree: 'static + MerkleTreeTrait>(

let public_inputs = stacked::PublicInputs {
replica_id,
porep_id: porep_config.porep_id,
tau: Some(stacked::Tau {
comm_d: comm_d_safe,
comm_r: comm_r_safe,
Expand All @@ -430,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 @@ -517,13 +533,19 @@ pub fn verify_seal<Tree: 'static + MerkleTreeTrait>(
let comm_r: <Tree::Hasher as Hasher>::Domain = as_safe_commitment(&comm_r_in, "comm_r")?;
let comm_d: DefaultPieceDomain = as_safe_commitment(&comm_d_in, "comm_d")?;

let replica_id =
generate_replica_id::<Tree::Hasher, _>(&prover_id, sector_id.into(), &ticket, comm_d);
let replica_id = generate_replica_id::<Tree::Hasher, _>(
&prover_id,
sector_id.into(),
&ticket,
comm_d,
&porep_config.porep_id,
);

let compound_setup_params = compound_proof::SetupParams {
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 All @@ -537,6 +559,7 @@ pub fn verify_seal<Tree: 'static + MerkleTreeTrait>(
let public_inputs =
stacked::PublicInputs::<<Tree::Hasher as Hasher>::Domain, DefaultPieceDomain> {
replica_id,
porep_id: porep_config.porep_id,
tau: Some(Tau { comm_r, comm_d }),
seed,
k: None,
Expand Down Expand Up @@ -628,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 All @@ -650,13 +674,15 @@ pub fn verify_batch_seal<Tree: 'static + MerkleTreeTrait>(
sector_ids[i].into(),
&tickets[i],
comm_d,
&porep_config.porep_id,
);

public_inputs.push(stacked::PublicInputs::<
<Tree::Hasher as Hasher>::Domain,
DefaultPieceDomain,
> {
replica_id,
porep_id: porep_config.porep_id,
tau: Some(Tau { comm_r, comm_d }),
seed: seeds[i],
k: None,
Expand Down
2 changes: 2 additions & 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 Expand Up @@ -216,6 +217,7 @@ fn generate_params_porep(sector_size: u64) {
.get(&sector_size)
.expect("missing sector size"),
),
porep_id: [0; 32],
}
);
}
Expand Down
2 changes: 2 additions & 0 deletions filecoin-proofs/src/bin/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ fn blank_porep_poseidon_circuit<Tree: MerkleTreeTrait>(
let porep_config = PoRepConfig {
sector_size: SectorSize(sector_size),
partitions: PoRepProofPartitions(n_partitions),
porep_id: [0; 32],
};

let setup_params = compound_proof::SetupParams {
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
Loading