Skip to content

Commit

Permalink
Merge pull request zcash#43 from filecoin-project/chore/clippy-happy
Browse files Browse the repository at this point in the history
Chore/clippy happy
  • Loading branch information
dignifiedquire authored Jun 18, 2018
2 parents 191eb2d + 8b3fec6 commit b4de7e5
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 70 deletions.
12 changes: 6 additions & 6 deletions src/circuit/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ pub fn drgporep<E, CS>(
params: &E::Params,
lambda: usize,
replica_node: Option<&[u8]>,
replica_node_path: Vec<Option<(E::Fr, bool)>>,
replica_node_path: &[Option<(E::Fr, bool)>],
replica_root: Option<E::Fr>,
replica_parents: Vec<Option<&[u8]>>,
replica_parents_paths: Vec<Vec<Option<(E::Fr, bool)>>>,
replica_parents_paths: &[Vec<Option<(E::Fr, bool)>>],
data_node: Option<&[u8]>,
data_node_path: Vec<Option<(E::Fr, bool)>>,
data_root: Option<E::Fr>,
Expand Down Expand Up @@ -80,7 +80,7 @@ where
params,
replica_node,
lambda,
replica_node_path.clone(),
replica_node_path.to_owned(),
replica_root,
)?;

Expand Down Expand Up @@ -247,7 +247,7 @@ mod tests {
.into_iter()
.map(|(_, parent)| Some(parent.data))
.collect();
let replica_parents_paths = proof_nc
let replica_parents_paths: Vec<_> = proof_nc
.replica_parents
.iter()
.map(|(_, parent)| parent.proof.as_options())
Expand All @@ -273,10 +273,10 @@ mod tests {
params,
lambda,
replica_node,
replica_node_path,
&replica_node_path,
replica_root,
replica_parents,
replica_parents_paths,
&replica_parents_paths,
data_node,
data_node_path,
data_root,
Expand Down
4 changes: 2 additions & 2 deletions src/circuit/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mod tests {
use pairing::bls12_381::Bls12;
use rand::{Rng, SeedableRng, XorShiftRng};
use sapling_crypto::circuit::boolean::Boolean;
use util::{bits_into_bytes, bytes_into_boolean_vec};
use util::{bits_to_bytes, bytes_into_boolean_vec};

#[test]
fn test_kdf_input_circut() {
Expand Down Expand Up @@ -72,7 +72,7 @@ mod tests {
});

// convert Vec<Boolean> to Vec<u8>
let actual = bits_into_bytes(
let actual = bits_to_bytes(
out.iter()
.map(|v| v.get_value().unwrap())
.collect::<Vec<bool>>()
Expand Down
6 changes: 3 additions & 3 deletions src/circuit/ppor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct ParallelProofOfRetrievability<'a, E: JubjubEngine> {
pub lambda: usize,

/// The authentication path of the commitment in the tree.
pub auth_paths: Vec<Vec<Option<(E::Fr, bool)>>>,
pub auth_paths: &'a [Vec<Option<(E::Fr, bool)>>],

/// The root of the underyling merkle tree.
pub root: Option<E::Fr>,
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for ParallelProofOfRetrievability<'a, E> {
mod tests {
use super::*;
use circuit::test::*;
use drgraph::{self, proof_into_options};
use drgraph;
use merklepor;
use pairing::bls12_381::*;
use pairing::Field;
Expand Down Expand Up @@ -118,7 +118,7 @@ mod tests {
params,
lambda: pub_params.lambda,
values: values,
auth_paths: auth_paths,
auth_paths: &auth_paths,
root: Some(tree.root().into()),
};

Expand Down
1 change: 0 additions & 1 deletion src/circuit/sloth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ mod tests {
use circuit::test::TestConstraintSystem;
use crypto::sloth;
use pairing::bls12_381::{Bls12, Fr};
use pairing::PrimeField;
use rand::{Rng, SeedableRng, XorShiftRng};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/circuit/xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod tests {
use pairing::bls12_381::Bls12;
use rand::{Rng, SeedableRng, XorShiftRng};
use sapling_crypto::circuit::boolean::Boolean;
use util::{bits_into_bytes, bytes_into_boolean_vec};
use util::{bits_to_bytes, bytes_into_boolean_vec};

#[test]
fn test_xor_input_circut() {
Expand Down Expand Up @@ -64,7 +64,7 @@ mod tests {
assert_eq!(out_bits.len(), data_bits.len(), "invalid output length");

// convert Vec<Boolean> to Vec<u8>
let actual = bits_into_bytes(
let actual = bits_to_bytes(
out_bits
.iter()
.map(|v| v.get_value().unwrap())
Expand All @@ -82,7 +82,7 @@ mod tests {
xor(&mut cs, key_bits.as_slice(), out_bits.as_slice()).unwrap()
};

let roundtrip = bits_into_bytes(
let roundtrip = bits_to_bytes(
roundtrip_bits
.iter()
.map(|v| v.get_value().unwrap())
Expand Down
3 changes: 3 additions & 0 deletions src/drgraph.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))]

use crypto::feistel;
use error::Result;
use hasher::pedersen;
Expand Down Expand Up @@ -143,6 +145,7 @@ pub enum Sampling {

impl Graph {
/// Creates a new graph. If no sampling is passed, it does not contain any edges.
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
pub fn new(nodes: usize, sampling: Option<Sampling>) -> Graph {
match sampling {
Some(Sampling::DR) => dr_sample(nodes),
Expand Down
103 changes: 53 additions & 50 deletions src/layered_drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ impl<'a> Into<DataProof> for drgporep::DataProof<'a> {
pub struct PublicInputs<'a> {
pub prover_id: &'a [u8],
pub challenge: usize,
pub tau: Tau,
pub tau: Vec<porep::Tau>,
}

pub struct PrivateInputs<'a> {
pub replica: &'a [u8],
pub aux: &'a ProverAux,
pub aux: &'a [porep::ProverAux],
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -129,14 +129,18 @@ impl<'a> ProofScheme<'a> for LayeredDrgPoRep {
replica: priv_inputs.replica,
};

let mut proofs = Vec::with_capacity(pub_params.layers);

prove_layers(
&pub_params.drg_porep_public_params,
pub_inputs,
&drg_priv_inputs,
priv_inputs.aux,
pub_params.layers,
Vec::new(),
)
&mut proofs,
)?;

Ok(proofs)
}

fn verify(
Expand Down Expand Up @@ -193,10 +197,10 @@ fn prove_layers(
pp: &drgporep::PublicParams,
pub_inputs: &PublicInputs,
priv_inputs: &drgporep::PrivateInputs,
aux: &ProverAux,
aux: &[porep::ProverAux],
layers: usize,
mut proofs: Vec<Proof>,
) -> Result<Vec<Proof>> {
proofs: &mut Vec<Proof>,
) -> Result<()> {
assert!(layers > 0);

let mut scratch = priv_inputs.replica.to_vec().clone();
Expand All @@ -219,53 +223,52 @@ fn prove_layers(

let pp = &permute(pp);

if layers == 1 {
Ok(proofs)
} else {
prove_layers(pp, pub_inputs, &new_priv_inputs, aux, layers - 1, proofs)
if layers != 1 {
prove_layers(pp, pub_inputs, &new_priv_inputs, aux, layers - 1, proofs)?;
}
}

type Tau = Vec<porep::Tau>;
type ProverAux = Vec<porep::ProverAux>;
Ok(())
}

impl<'a, 'c> PoRep<'a> for LayeredDrgPoRep {
type Tau = Tau;
type ProverAux = ProverAux;
type Tau = Vec<porep::Tau>;
type ProverAux = Vec<porep::ProverAux>;

fn replicate(
pp: &'a PublicParams,
prover_id: &[u8],
data: &mut [u8],
) -> Result<(Self::Tau, Self::ProverAux)> {
let taus = Vec::new();
let auxs = Vec::new();
let mut taus = Vec::with_capacity(pp.layers);
let mut auxs = Vec::with_capacity(pp.layers);

permute_and_replicate_layers(
&pp.drg_porep_public_params,
pp.layers,
prover_id,
data,
taus,
auxs,
)
&mut taus,
&mut auxs,
)?;

Ok((taus, auxs))
}

fn extract_all<'b>(
pp: &'b PublicParams,
prover_id: &'b [u8],
data: &'b [u8],
) -> Result<Vec<u8>> {
let mut d: Vec<u8> = data.to_vec();
let dd = d.as_mut_slice();

Ok(
extract_and_invert_permute_layers(
&pp.drg_porep_public_params,
pp.layers,
prover_id,
dd,
)?.to_vec(),
)
let mut data = data.to_vec();

extract_and_invert_permute_layers(
&pp.drg_porep_public_params,
pp.layers,
prover_id,
&mut data,
)?;

Ok(data)
}

fn extract(
Expand All @@ -283,7 +286,7 @@ fn extract_and_invert_permute_layers<'a>(
layers: usize,
prover_id: &[u8],
data: &'a mut [u8],
) -> Result<&'a [u8]> {
) -> Result<()> {
assert!(layers > 0);

let inverted = &invert_permute(&drgpp);
Expand All @@ -293,32 +296,32 @@ fn extract_and_invert_permute_layers<'a>(
data[i] = *r;
}

if layers == 1 {
Ok(data)
} else {
extract_and_invert_permute_layers(inverted, layers - 1, prover_id, data)
if layers != 1 {
extract_and_invert_permute_layers(inverted, layers - 1, prover_id, data)?;
}

Ok(())
}

fn permute_and_replicate_layers(
drgpp: &drgporep::PublicParams,
layers: usize,
prover_id: &[u8],
data: &mut [u8],
mut taus: Vec<porep::Tau>,
mut auxs: Vec<porep::ProverAux>,
) -> Result<(Vec<porep::Tau>, Vec<porep::ProverAux>)> {
taus: &mut Vec<porep::Tau>,
auxs: &mut Vec<porep::ProverAux>,
) -> Result<()> {
assert!(layers > 0);
let (tau, aux) = DrgPoRep::replicate(&drgpp, prover_id, data).unwrap();

taus.push(tau);
auxs.push(aux);

if layers == 1 {
Ok((taus, auxs))
} else {
permute_and_replicate_layers(&permute(&drgpp), layers - 1, prover_id, data, taus, auxs)
if layers != 1 {
permute_and_replicate_layers(&permute(&drgpp), layers - 1, prover_id, data, taus, auxs)?;
}

Ok(())
}

#[cfg(test)]
Expand All @@ -334,7 +337,7 @@ mod tests {
}

#[test]
fn test_layered_extract_all() {
fn layered_extract_all() {
let lambda = 16;
let prover_id = vec![1u8; 16];
let data = vec![2u8; 16 * 3];
Expand Down Expand Up @@ -414,17 +417,17 @@ mod tests {
}

#[test]
fn test_layered_prove_verify_16_2() {
fn layered_prove_verify_16_2() {
layered_prove_verify(16, 4);
}

#[test]
fn test_layered_prove_verify_16_3() {
fn layered_prove_verify_16_3() {
layered_prove_verify(16, 3);
}

#[test]
fn test_layered_prove_verify_16_10() {
fn layered_prove_verify_16_10() {
layered_prove_verify(16, 10);
}

Expand All @@ -435,12 +438,12 @@ mod tests {
// }

#[test]
fn test_layered_prove_verify_32_3() {
fn layered_prove_verify_32_3() {
layered_prove_verify(32, 3);
}

#[test]
fn test_layered_prove_verify_32_10() {
fn layered_prove_verify_32_10() {
layered_prove_verify(32, 10);
}
}
Loading

0 comments on commit b4de7e5

Please sign in to comment.