Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate wasteful PoR public-input conversions. #1267

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions storage-proofs/core/src/gadgets/por.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::convert::TryFrom;
use std::marker::PhantomData;

use anyhow::ensure;
use bellperson::gadgets::boolean::{AllocatedBit, Boolean};
use bellperson::gadgets::{multipack, num};
use bellperson::{Circuit, ConstraintSystem, SynthesisError};
use ff::PrimeField;
use generic_array::typenum::Unsigned;
use paired::bls12_381::{Bls12, Fr};
use paired::bls12_381::{Bls12, Fr, FrRepr};

use crate::compound_proof::{CircuitComponent, CompoundProof};
use crate::error::Result;
Expand Down Expand Up @@ -306,10 +308,19 @@ impl<'a, Tree: 'static + MerkleTreeTrait> CompoundProof<'a, PoR<Tree>, PoRCircui
pub_params: &<PoR<Tree> as ProofScheme<'a>>::PublicParams,
_k: Option<usize>,
) -> Result<Vec<Fr>> {
ensure!(
pub_inputs.challenge < pub_params.leaves,
"Challenge out of range"
);
let mut inputs = Vec::new();
let path_bits = challenge_into_auth_path_bits(pub_inputs.challenge, pub_params.leaves);

inputs.extend(multipack::compute_multipacking::<Bls12>(&path_bits));
// Inputs are (currently, inefficiently) packed with one `Fr` per challenge.
// Boolean/bit auth paths trivially correspond to the challenged node's index within a sector.
// Defensively convert the challenge with `try_from` as a reminder that we must not truncate.
let input_fr = Fr::from_repr(FrRepr::from(
u64::try_from(pub_inputs.challenge).expect("challenge type too wide"),
))?;
inputs.push(input_fr);

if let Some(commitment) = pub_inputs.commitment {
ensure!(!pub_params.private, "Params must be public");
Expand Down