Skip to content

Commit

Permalink
remove fil-blst dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Oct 5, 2020
1 parent b84f850 commit 468c149
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 135 deletions.
41 changes: 2 additions & 39 deletions filecoin-proofs/src/api/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use storage_proofs::post::fallback;
use storage_proofs::post::fallback::SectorProof;
use storage_proofs::proof::ProofScheme;
use storage_proofs::sector::*;
use storage_proofs::settings;
use storage_proofs::util::default_rows_to_discard;

use crate::api::util::{as_safe_commitment, get_base_tree_leafs, get_base_tree_size};
Expand Down Expand Up @@ -624,25 +623,7 @@ pub fn verify_winning_post<Tree: 'static + MerkleTreeTrait>(
k: None,
};

let use_fil_blst = settings::SETTINGS
.lock()
.expect("use_fil_blst settings lock failure")
.use_fil_blst;

let is_valid = if use_fil_blst {
info!("verify_winning_post: use_fil_blst=true");
let verifying_key_path = post_config.get_cache_verifying_key_path::<Tree>()?;
fallback::FallbackPoStCompound::verify_blst(
&pub_params,
&pub_inputs,
&proof,
proof.len() / 192,
&fallback::ChallengeRequirements {
minimum_challenge_count: post_config.challenge_count * post_config.sector_count,
},
&verifying_key_path,
)?
} else {
let is_valid = {
let verifying_key = get_post_verifying_key::<Tree>(&post_config)?;

let single_proof = MultiProof::new_from_reader(None, &proof[..], &verifying_key)?;
Expand Down Expand Up @@ -1000,25 +981,7 @@ pub fn verify_window_post<Tree: 'static + MerkleTreeTrait>(
k: None,
};

let use_fil_blst = settings::SETTINGS
.lock()
.expect("use_fil_blst settings lock failure")
.use_fil_blst;

let is_valid = if use_fil_blst {
info!("verify_window_post: use_fil_blst=true");
let verifying_key_path = post_config.get_cache_verifying_key_path::<Tree>()?;
fallback::FallbackPoStCompound::verify_blst(
&pub_params,
&pub_inputs,
&proof,
proof.len() / 192,
&fallback::ChallengeRequirements {
minimum_challenge_count: post_config.challenge_count * post_config.sector_count,
},
&verifying_key_path,
)?
} else {
let is_valid = {
let verifying_key = get_post_verifying_key::<Tree>(&post_config)?;
let multi_proof = MultiProof::new_from_reader(partitions, &proof[..], &verifying_key)?;

Expand Down
26 changes: 1 addition & 25 deletions filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use storage_proofs::porep::stacked::{
};
use storage_proofs::proof::ProofScheme;
use storage_proofs::sector::SectorId;
use storage_proofs::settings;
use storage_proofs::util::default_rows_to_discard;

use crate::api::util::{
Expand Down Expand Up @@ -609,30 +608,7 @@ pub fn verify_seal<Tree: 'static + MerkleTreeTrait>(
k: None,
};

let use_fil_blst = settings::SETTINGS
.lock()
.expect("use_fil_blst settings lock failure")
.use_fil_blst;

let result = if use_fil_blst {
info!("verify_seal: use_fil_blst=true");
let verifying_key_path = porep_config.get_cache_verifying_key_path::<Tree>()?;

StackedCompound::verify_blst(
&compound_public_params,
&public_inputs,
&proof_vec,
proof_vec.len() / 192,
&ChallengeRequirements {
minimum_challenges: *POREP_MINIMUM_CHALLENGES
.read()
.expect("POREP_MINIMUM_CHALLENGES poisoned")
.get(&u64::from(SectorSize::from(porep_config)))
.expect("unknown sector size") as usize,
},
&verifying_key_path,
)
} else {
let result = {
let sector_bytes = PaddedBytesAmount::from(porep_config);
let verifying_key = get_stacked_verifying_key::<Tree>(porep_config)?;

Expand Down
3 changes: 0 additions & 3 deletions rust-fil-proofs.config.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@ rows_to_discard = 2
# Window size for pedersen hashing.
pedersen_hash_exp_window_size = 16

# This enables accelerate snark verification
use_fil_blst = false

# This enables multicore SDR replication
use_multicore_sdr = false
1 change: 0 additions & 1 deletion storage-proofs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ neptune = { git = "https://github.com/filecoin-project/neptune", branch = "blst"
cpu-time = { version = "1.0", optional = true }
gperftools = { version = "0.2", optional = true }
num_cpus = "1.10.1"
fil-blst = { git = "https://github.com/filecoin-project/fil-blst", branch = "rustify" }

[dev-dependencies]
proptest = "0.10"
Expand Down
63 changes: 0 additions & 63 deletions storage-proofs/core/src/compound_proof.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::path::Path;

use anyhow::{ensure, Context};
use bellperson::bls::{Bls12, Fr};
use bellperson::{groth16, Circuit};
use fil_blst::{blst::blst_scalar, blst_fr_from_fr, scalar_from_u64, verify_batch_proof};
use log::info;
use rand::{rngs::OsRng, RngCore};
use rayon::prelude::*;
Expand Down Expand Up @@ -162,66 +159,6 @@ where
Ok(res)
}

// verify_blst is equivalent to ProofScheme::verify.
fn verify_blst(
public_params: &PublicParams<'a, S>,
public_inputs: &S::PublicInputs,
proof_vec: &[u8],
num_proofs: usize,
requirements: &S::Requirements,
vk_path: &Path,
) -> Result<bool> {
ensure!(
num_proofs == Self::partition_count(public_params),
"Inconsistent inputs"
);

let vanilla_public_params = &public_params.vanilla_params;

if !<S as ProofScheme>::satisfies_requirements(
&public_params.vanilla_params,
requirements,
num_proofs,
) {
return Ok(false);
}

let inputs: Vec<_> = (0..num_proofs)
.into_par_iter()
.map(|k| Self::generate_public_inputs(public_inputs, vanilla_public_params, Some(k)))
.collect::<Result<_>>()?;

let blst_inputs: Vec<_> = todo!(); /*inputs
.iter()
.flat_map(|pis| pis.iter().map(|pi| blst_fr_from_fr(*pi)))
.collect();*/

// choose random coefficients for combining the proofs
let mut r: Vec<blst_scalar> = Vec::with_capacity(num_proofs);
let mut rng = rand::rngs::OsRng;
for _ in 0..num_proofs {
use rand::Rng;
let t: u128 = rng.gen();

let mut limbs: [u64; 4] = [0, 0, 0, 0];
limbs[1] = (t >> 64) as u64;
limbs[0] = (t & (-1i64 as u128) >> 64) as u64;

r.push(scalar_from_u64(&limbs));
}

let res = verify_batch_proof(
proof_vec,
num_proofs,
&blst_inputs[..],
inputs[0].len(),
&r[..],
128,
vk_path,
);
Ok(res)
}

/// Efficiently verify multiple proofs.
fn batch_verify<'b>(
public_params: &PublicParams<'a, S>,
Expand Down
3 changes: 1 addition & 2 deletions storage-proofs/core/src/multi_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use bellperson::groth16;
use crate::error::Result;
use anyhow::{ensure, Context};
use bellperson::bls::Bls12;
use rayon::prelude::*;
use std::io::{self, Read, Write};
use std::io::{Read, Write};

pub struct MultiProof<'a> {
pub circuit_proofs: Vec<groth16::Proof<Bls12>>,
Expand Down
2 changes: 0 additions & 2 deletions storage-proofs/core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub struct Settings {
pub window_post_synthesis_num_cpus: u32,
pub parameter_cache: String,
pub parent_cache: String,
pub use_fil_blst: bool,
pub use_multicore_sdr: bool,
}

Expand All @@ -52,7 +51,6 @@ impl Default for Settings {
// The name is retained for backwards compatibility.
parameter_cache: "/var/tmp/filecoin-proof-parameters/".to_string(),
parent_cache: cache("filecoin-parents"),
use_fil_blst: false,
use_multicore_sdr: false,
}
}
Expand Down

0 comments on commit 468c149

Please sign in to comment.