Merge pull request #251 from str4d/bundled-prover
zcash_proofs: Add LocalProver::bundled
This commit is contained in:
commit
a224d826fa
|
@ -20,6 +20,7 @@ ff = { version = "0.6", path = "../ff" }
|
||||||
minreq = { version = "2", features = ["https"], optional = true }
|
minreq = { version = "2", features = ["https"], optional = true }
|
||||||
pairing = { version = "0.16", path = "../pairing" }
|
pairing = { version = "0.16", path = "../pairing" }
|
||||||
rand_core = "0.5.1"
|
rand_core = "0.5.1"
|
||||||
|
wagyu-zcash-parameters = { version = "0.2", optional = true }
|
||||||
zcash_primitives = { version = "0.2", path = "../zcash_primitives" }
|
zcash_primitives = { version = "0.2", path = "../zcash_primitives" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -27,6 +28,7 @@ rand_xorshift = "0.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["local-prover", "multicore"]
|
default = ["local-prover", "multicore"]
|
||||||
|
bundled-prover = ["wagyu-zcash-parameters"]
|
||||||
download-params = ["minreq"]
|
download-params = ["minreq"]
|
||||||
local-prover = ["directories"]
|
local-prover = ["directories"]
|
||||||
multicore = ["bellman/multicore"]
|
multicore = ["bellman/multicore"]
|
||||||
|
|
|
@ -22,11 +22,13 @@ mod hashreader;
|
||||||
pub mod sapling;
|
pub mod sapling;
|
||||||
pub mod sprout;
|
pub mod sprout;
|
||||||
|
|
||||||
#[cfg(feature = "local-prover")]
|
#[cfg(any(feature = "local-prover", feature = "bundled-prover"))]
|
||||||
pub mod prover;
|
pub mod prover;
|
||||||
|
|
||||||
// Circuit names
|
// Circuit names
|
||||||
|
#[cfg(feature = "local-prover")]
|
||||||
const SAPLING_SPEND_NAME: &str = "sapling-spend.params";
|
const SAPLING_SPEND_NAME: &str = "sapling-spend.params";
|
||||||
|
#[cfg(feature = "local-prover")]
|
||||||
const SAPLING_OUTPUT_NAME: &str = "sapling-output.params";
|
const SAPLING_OUTPUT_NAME: &str = "sapling-output.params";
|
||||||
|
|
||||||
// Circuit hashes
|
// Circuit hashes
|
||||||
|
@ -118,11 +120,27 @@ pub fn load_parameters(
|
||||||
let sprout_fs =
|
let sprout_fs =
|
||||||
sprout_path.map(|p| File::open(p).expect("couldn't load Sprout groth16 parameters file"));
|
sprout_path.map(|p| File::open(p).expect("couldn't load Sprout groth16 parameters file"));
|
||||||
|
|
||||||
let mut spend_fs = hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, spend_fs));
|
parse_parameters(
|
||||||
let mut output_fs =
|
BufReader::with_capacity(1024 * 1024, spend_fs),
|
||||||
hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, output_fs));
|
BufReader::with_capacity(1024 * 1024, output_fs),
|
||||||
let mut sprout_fs =
|
sprout_fs.map(|fs| BufReader::with_capacity(1024 * 1024, fs)),
|
||||||
sprout_fs.map(|fs| hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, fs)));
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_parameters<R: io::Read>(
|
||||||
|
spend_fs: R,
|
||||||
|
output_fs: R,
|
||||||
|
sprout_fs: Option<R>,
|
||||||
|
) -> (
|
||||||
|
Parameters<Bls12>,
|
||||||
|
PreparedVerifyingKey<Bls12>,
|
||||||
|
Parameters<Bls12>,
|
||||||
|
PreparedVerifyingKey<Bls12>,
|
||||||
|
Option<PreparedVerifyingKey<Bls12>>,
|
||||||
|
) {
|
||||||
|
let mut spend_fs = hashreader::HashReader::new(spend_fs);
|
||||||
|
let mut output_fs = hashreader::HashReader::new(output_fs);
|
||||||
|
let mut sprout_fs = sprout_fs.map(|fs| hashreader::HashReader::new(fs));
|
||||||
|
|
||||||
// Deserialize params
|
// Deserialize params
|
||||||
let spend_params = Parameters::<Bls12>::read(&mut spend_fs, false)
|
let spend_params = Parameters::<Bls12>::read(&mut spend_fs, false)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use bellman::groth16::{Parameters, PreparedVerifyingKey};
|
use bellman::groth16::{Parameters, PreparedVerifyingKey};
|
||||||
use pairing::bls12_381::{Bls12, Fr};
|
use pairing::bls12_381::{Bls12, Fr};
|
||||||
use std::path::Path;
|
|
||||||
use zcash_primitives::{
|
use zcash_primitives::{
|
||||||
jubjub::{edwards, fs::Fs, Unknown},
|
jubjub::{edwards, fs::Fs, Unknown},
|
||||||
primitives::{Diversifier, PaymentAddress, ProofGenerationKey},
|
primitives::{Diversifier, PaymentAddress, ProofGenerationKey},
|
||||||
|
@ -16,10 +15,15 @@ use zcash_primitives::{
|
||||||
JUBJUB,
|
JUBJUB,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::sapling::SaplingProvingContext;
|
||||||
default_params_folder, load_parameters, sapling::SaplingProvingContext, SAPLING_OUTPUT_NAME,
|
|
||||||
SAPLING_SPEND_NAME,
|
#[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;
|
||||||
|
|
||||||
/// 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,6 +52,7 @@ 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")]
|
||||||
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);
|
||||||
|
@ -79,6 +84,7 @@ impl LocalTxProver {
|
||||||
///
|
///
|
||||||
/// This function will panic if the parameters in the default local location do not
|
/// This function will panic if the parameters in the default local location do not
|
||||||
/// have the expected hashes.
|
/// have the expected hashes.
|
||||||
|
#[cfg(feature = "local-prover")]
|
||||||
pub fn with_default_location() -> Option<Self> {
|
pub fn with_default_location() -> Option<Self> {
|
||||||
let params_dir = default_params_folder()?;
|
let params_dir = default_params_folder()?;
|
||||||
let (spend_path, output_path) = if params_dir.exists() {
|
let (spend_path, output_path) = if params_dir.exists() {
|
||||||
|
@ -95,6 +101,23 @@ impl LocalTxProver {
|
||||||
|
|
||||||
Some(LocalTxProver::new(&spend_path, &output_path))
|
Some(LocalTxProver::new(&spend_path, &output_path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a `LocalTxProver` using Sapling parameters bundled inside the binary.
|
||||||
|
///
|
||||||
|
/// This requires the `bundled-prover` feature, which will increase the binary size by
|
||||||
|
/// around 50 MiB.
|
||||||
|
#[cfg(feature = "bundled-prover")]
|
||||||
|
pub fn bundled() -> Self {
|
||||||
|
let (spend_buf, output_buf) = wagyu_zcash_parameters::load_sapling_parameters();
|
||||||
|
let (spend_params, spend_vk, output_params, _, _) =
|
||||||
|
parse_parameters(&spend_buf[..], &output_buf[..], None);
|
||||||
|
|
||||||
|
LocalTxProver {
|
||||||
|
spend_params,
|
||||||
|
spend_vk,
|
||||||
|
output_params,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TxProver for LocalTxProver {
|
impl TxProver for LocalTxProver {
|
||||||
|
|
Loading…
Reference in New Issue