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, spend_fs: R,
output_fs: R, output_fs: R,
sprout_fs: Option<R>, sprout_fs: Option<R>,

View File

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