diff --git a/filecoin-proofs/src/api/seal.rs b/filecoin-proofs/src/api/seal.rs index 9b9efecb2..d464a1547 100644 --- a/filecoin-proofs/src/api/seal.rs +++ b/filecoin-proofs/src/api/seal.rs @@ -807,3 +807,27 @@ pub fn fauxrep_aux< commitment[..].copy_from_slice(&comm_r.into_bytes()[..]); Ok(commitment) } + +pub fn fauxrep2, S: AsRef, Tree: 'static + MerkleTreeTrait>( + cache_path: R, + existing_p_aux_path: S, +) -> Result { + let mut rng = rand::thread_rng(); + + let fake_comm_c = ::Domain::random(&mut rng); + + let (comm_r, p_aux) = + StackedDrg::::fake_comm_r(fake_comm_c, existing_p_aux_path)?; + + let p_aux_path = cache_path.as_ref().join(CacheKey::PAux.to_string()); + let mut f_p_aux = File::create(&p_aux_path) + .with_context(|| format!("could not create file p_aux={:?}", p_aux_path))?; + let p_aux_bytes = serialize(&p_aux)?; + f_p_aux + .write_all(&p_aux_bytes) + .with_context(|| format!("could not write to file p_aux={:?}", p_aux_path))?; + + let mut commitment = [0u8; 32]; + commitment[..].copy_from_slice(&comm_r.into_bytes()[..]); + Ok(commitment) +} diff --git a/storage-proofs/porep/Cargo.toml b/storage-proofs/porep/Cargo.toml index fa0bace7c..38bc3f1ed 100644 --- a/storage-proofs/porep/Cargo.toml +++ b/storage-proofs/porep/Cargo.toml @@ -31,6 +31,7 @@ once_cell = "1.3.1" neptune = { version = "1.0.1", features = ["gpu"] } num_cpus = "1.10.1" hex = "0.4.2" +bincode = "1.1.2" byteorder = "1.3.4" [dev-dependencies] diff --git a/storage-proofs/porep/src/stacked/vanilla/proof.rs b/storage-proofs/porep/src/stacked/vanilla/proof.rs index 71f3b8364..38b5d2570 100644 --- a/storage-proofs/porep/src/stacked/vanilla/proof.rs +++ b/storage-proofs/porep/src/stacked/vanilla/proof.rs @@ -4,6 +4,7 @@ use std::marker::PhantomData; use std::path::{Path, PathBuf}; use std::sync::{mpsc, Arc, RwLock}; +use bincode::deserialize; use generic_array::typenum::{self, Unsigned}; use log::{info, trace}; use merkletree::merkle::{ @@ -1328,6 +1329,33 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr Ok((comm_r, p_aux)) } + + pub fn fake_comm_r>( + tree_c_root: ::Domain, + existing_p_aux_path: R, + ) -> Result<( + ::Domain, + PersistentAux<::Domain>, + )> { + let existing_p_aux: PersistentAux<::Domain> = { + let p_aux_bytes = std::fs::read(&existing_p_aux_path)?; + + deserialize(&p_aux_bytes) + }?; + + let existing_comm_r_last = existing_p_aux.comm_r_last; + + // comm_r = H(comm_c || comm_r_last) + let comm_r: ::Domain = + ::Function::hash2(&tree_c_root, &existing_comm_r_last); + + let p_aux = PersistentAux { + comm_c: tree_c_root, + comm_r_last: existing_comm_r_last, + }; + + Ok((comm_r, p_aux)) + } } #[cfg(test)]