diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index 7faca6c35..7c579bf24 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -12,6 +12,11 @@ use std::fs::File; use std::io::{self, BufReader}; use std::path::Path; +#[cfg(feature = "directories")] +use directories::BaseDirs; +#[cfg(feature = "directories")] +use std::path::PathBuf; + pub mod circuit; mod hashreader; pub mod sapling; @@ -20,6 +25,22 @@ pub mod sprout; #[cfg(feature = "local-prover")] pub mod prover; +// Circuit names +const SAPLING_SPEND_NAME: &str = "sapling-spend.params"; +const SAPLING_OUTPUT_NAME: &str = "sapling-output.params"; + +/// Returns the default folder that the Zcash proving parameters are located in. +#[cfg(feature = "directories")] +fn default_params_folder() -> Option { + BaseDirs::new().map(|base_dirs| { + if cfg!(any(windows, target_os = "macos")) { + base_dirs.data_dir().join("ZcashParams") + } else { + base_dirs.home_dir().join(".zcash-params") + } + }) +} + pub fn load_parameters( spend_path: &Path, output_path: &Path, diff --git a/zcash_proofs/src/prover.rs b/zcash_proofs/src/prover.rs index 3dd665a7d..d1c23aac7 100644 --- a/zcash_proofs/src/prover.rs +++ b/zcash_proofs/src/prover.rs @@ -1,7 +1,6 @@ //! Abstractions over the proving system and parameters for ease of use. use bellman::groth16::{Parameters, PreparedVerifyingKey}; -use directories::BaseDirs; use pairing::bls12_381::{Bls12, Fr}; use std::path::Path; use zcash_primitives::{ @@ -17,7 +16,10 @@ use zcash_primitives::{ JUBJUB, }; -use crate::{load_parameters, sapling::SaplingProvingContext}; +use crate::{ + default_params_folder, load_parameters, sapling::SaplingProvingContext, SAPLING_OUTPUT_NAME, + SAPLING_SPEND_NAME, +}; /// An implementation of [`TxProver`] using Sapling Spend and Output parameters from /// locally-accessible paths. @@ -78,18 +80,11 @@ impl LocalTxProver { /// This function will panic if the parameters in the default local location do not /// have the expected hashes. pub fn with_default_location() -> Option { - let base_dirs = BaseDirs::new()?; - let unix_params_dir = base_dirs.home_dir().join(".zcash-params"); - let win_osx_params_dir = base_dirs.data_dir().join("ZcashParams"); - let (spend_path, output_path) = if unix_params_dir.exists() { + let params_dir = default_params_folder()?; + let (spend_path, output_path) = if params_dir.exists() { ( - unix_params_dir.join("sapling-spend.params"), - unix_params_dir.join("sapling-output.params"), - ) - } else if win_osx_params_dir.exists() { - ( - win_osx_params_dir.join("sapling-spend.params"), - win_osx_params_dir.join("sapling-output.params"), + params_dir.join(SAPLING_SPEND_NAME), + params_dir.join(SAPLING_OUTPUT_NAME), ) } else { return None;