Skip to content

Commit

Permalink
Add FaultySectors error to Fallback PoSt.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Sep 7, 2020
1 parent 1bc4e0d commit ab30c29
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions storage-proofs/core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::any::Any;

use crate::sector::SectorId;
use bellperson::SynthesisError;

pub use anyhow::Result;
Expand Down Expand Up @@ -37,6 +38,8 @@ pub enum Error {
Unclassified(String),
#[error("Missing Private Input {0} for sector {1}")]
MissingPrivateInput(&'static str, u64),
#[error("faulty sectors {:?}", _0)]
FaultySectors(Vec<SectorId>),
}

impl From<Box<dyn Any + Send>> for Error {
Expand Down
2 changes: 0 additions & 2 deletions storage-proofs/core/src/merkle/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ impl<

let proof = self.inner.gen_cached_proof(i, rows_to_discard)?;

debug_assert!(proof.validate::<H::Function>().expect("validate failed"));

MerkleProof::try_from_proof(proof)
}

Expand Down
41 changes: 36 additions & 5 deletions storage-proofs/post/src/fallback/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

use storage_proofs_core::{
error::Result,
error::{Error, Result},
hasher::{Domain, HashFunction, Hasher},
merkle::{MerkleProof, MerkleProofTrait, MerkleTreeTrait, MerkleTreeWrapper},
parameter_cache::ParameterSetMetadata,
Expand Down Expand Up @@ -230,6 +230,11 @@ pub fn generate_leaf_challenge<T: Domain>(
Ok(challenged_range_index)
}

enum ProofOrFault<T> {
Proof(T),
Fault(SectorId),
}

impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree> {
type PublicParams = PublicParams;
type SetupParams = SetupParams;
Expand Down Expand Up @@ -292,6 +297,7 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
);

let mut partition_proofs = Vec::new();
let mut faulty_sectors = Vec::new();

for (j, (pub_sectors_chunk, priv_sectors_chunk)) in pub_inputs
.sectors
Expand Down Expand Up @@ -319,7 +325,8 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
Tree::Arity::to_usize(),
);

let inclusion_proofs = (0..pub_params.challenge_count)
let mut inclusion_proofs = Vec::new();
for proof_or_fault in (0..pub_params.challenge_count)
.into_par_iter()
.map(|n| {
let challenge_index = ((j * num_sectors_per_chunk + i)
Expand All @@ -332,9 +339,28 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
challenge_index,
)?;

tree.gen_cached_proof(challenged_leaf_start as usize, Some(rows_to_discard))
let proof = tree.gen_cached_proof(
challenged_leaf_start as usize,
Some(rows_to_discard),
);
let valid = if let Ok(proof) = &proof {
proof.validate(challenge_index as usize)
} else {
false
};
if valid {
Ok(ProofOrFault::Proof(proof))
} else {
Ok(ProofOrFault::Fault(sector_id))
}
})
.collect::<Result<Vec<_>>>()?;
.collect::<Result<Vec<_>>>()?
{
match proof_or_fault {
ProofOrFault::Proof(proof) => inclusion_proofs.push(proof?),
ProofOrFault::Fault(sector_id) => faulty_sectors.push(sector_id),
}
}

proofs.push(SectorProof {
inclusion_proofs,
Expand All @@ -352,6 +378,11 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
partition_proofs.push(Proof { sectors: proofs });
}

ensure!(
faulty_sectors.is_empty(),
Error::FaultySectors(faulty_sectors)
);

Ok(partition_proofs)
}

Expand Down Expand Up @@ -390,6 +421,7 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
proof.sectors.len(),
num_sectors_per_chunk,
);

for (i, (pub_sector, sector_proof)) in pub_sectors_chunk
.iter()
.zip(proof.sectors.iter())
Expand Down Expand Up @@ -449,7 +481,6 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
}
}
}

Ok(true)
}

Expand Down

0 comments on commit ab30c29

Please sign in to comment.