Skip to content

Commit

Permalink
Implement fauxrep2.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jul 22, 2020
1 parent 9be0a74 commit 7b8ade3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
24 changes: 24 additions & 0 deletions filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,3 +807,27 @@ pub fn fauxrep_aux<
commitment[..].copy_from_slice(&comm_r.into_bytes()[..]);
Ok(commitment)
}

pub fn fauxrep2<R: AsRef<Path>, S: AsRef<Path>, Tree: 'static + MerkleTreeTrait>(
cache_path: R,
existing_p_aux_path: S,
) -> Result<Commitment> {
let mut rng = rand::thread_rng();

let fake_comm_c = <Tree::Hasher as Hasher>::Domain::random(&mut rng);

let (comm_r, p_aux) =
StackedDrg::<Tree, DefaultPieceHasher>::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)
}
1 change: 1 addition & 0 deletions storage-proofs/porep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 28 additions & 0 deletions storage-proofs/porep/src/stacked/vanilla/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<R: AsRef<Path>>(
tree_c_root: <Tree::Hasher as Hasher>::Domain,
existing_p_aux_path: R,
) -> Result<(
<Tree::Hasher as Hasher>::Domain,
PersistentAux<<Tree::Hasher as Hasher>::Domain>,
)> {
let existing_p_aux: PersistentAux<<Tree::Hasher as Hasher>::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: <Tree::Hasher as Hasher>::Domain =
<Tree::Hasher as Hasher>::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)]
Expand Down

0 comments on commit 7b8ade3

Please sign in to comment.