Build prover with byte arrays of params

This commit is contained in:
adityapk00 2020-10-14 15:34:49 -07:00 committed by Aditya Kulkarni
parent 4c66a17b93
commit b8aa2d9169
2 changed files with 33 additions and 10 deletions

View File

@ -135,7 +135,10 @@ pub fn load_parameters(
)
}
fn parse_parameters<R: io::Read>(
/// Parse Bls12 keys from bytes as serialized by [`Parameters::write`].
///
/// This function will panic if it encounters unparseable data.
pub fn parse_parameters<R: io::Read>(
spend_fs: R,
output_fs: R,
sprout_fs: Option<R>,

View File

@ -2,6 +2,7 @@
use bellman::groth16::{Parameters, PreparedVerifyingKey};
use bls12_381::Bls12;
use std::path::Path;
use zcash_primitives::{
merkle_tree::MerklePath,
primitives::{Diversifier, PaymentAddress, ProofGenerationKey, Rseed},
@ -11,15 +12,10 @@ use zcash_primitives::{
transaction::components::{Amount, GROTH_PROOF_SIZE},
};
use crate::sapling::SaplingProvingContext;
use crate::{load_parameters, parse_parameters, sapling::SaplingProvingContext};
#[cfg(feature = "local-prover")]
use crate::{default_params_folder, load_parameters, SAPLING_OUTPUT_NAME, SAPLING_SPEND_NAME};
#[cfg(feature = "local-prover")]
use std::path::Path;
#[cfg(feature = "bundled-prover")]
use crate::parse_parameters;
use crate::{default_params_folder, SAPLING_OUTPUT_NAME, SAPLING_SPEND_NAME};
/// An implementation of [`TxProver`] using Sapling Spend and Output parameters from
/// locally-accessible paths.
@ -48,8 +44,6 @@ impl LocalTxProver {
///
/// This function will panic if the paths do not point to valid parameter files with
/// the expected hashes.
#[cfg(feature = "local-prover")]
#[cfg_attr(docsrs, doc(cfg(feature = "local-prover")))]
pub fn new(spend_path: &Path, output_path: &Path) -> Self {
let (spend_params, spend_vk, output_params, _, _) =
load_parameters(spend_path, output_path, None);
@ -60,6 +54,32 @@ impl LocalTxProver {
}
}
/// Creates a `LocalTxProver` using parameters specified as byte arrays.
///
/// # Examples
///
/// ```should_panic
/// use std::path::Path;
/// use zcash_proofs::prover::LocalTxProver;
///
/// let tx_prover = LocalTxProver::from_bytes(&[0u8], &[0u8]);
/// ```
///
/// # Panics
///
/// This function will panic if the byte arrays do not contain valid parameters with
/// the expected hashes.
pub fn from_bytes(spend_param_bytes: &[u8], output_param_bytes: &[u8]) -> Self {
let (spend_params, spend_vk, output_params, _, _) =
parse_parameters(spend_param_bytes, output_param_bytes, None);
LocalTxProver {
spend_params,
spend_vk,
output_params,
}
}
/// Attempts to create a `LocalTxProver` using parameters from the default local
/// location.
///