diff --git a/zcash_proofs/CHANGELOG.md b/zcash_proofs/CHANGELOG.md index a35ba5669..f544343b6 100644 --- a/zcash_proofs/CHANGELOG.md +++ b/zcash_proofs/CHANGELOG.md @@ -6,7 +6,16 @@ and this library adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `zcash_proofs::{SpendParameters, OutputParameters}` + ### Changed +- The new `SpendParameters` and `OutputParameters` types are used in the + following places: + - `zcash_proofs::ZcashParameters::{spend_params, output_params}` fields. + - `zcash_proofs::sapling::prover`: + - `SaplingProvingContext::{spend_proof, output_proof}` (the `proving_key` + arguments). - `zcash_proofs::sapling::prover`: - The `verifying_key` argument `SaplingProvingContext::spend_proof` has been removed. Callers should instead use `SaplingVerifyingContext` to verify diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index 992b3a737..bdd452bd4 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -283,11 +283,17 @@ fn stream_params_downloads_to_disk( Ok(()) } +/// The parameters for the Sapling Spend circuit. +pub struct SpendParameters(Parameters); + +/// The parameters for the Sapling Output circuit. +pub struct OutputParameters(Parameters); + /// Zcash Sprout and Sapling groth16 circuit parameters. pub struct ZcashParameters { - pub spend_params: Parameters, + pub spend_params: SpendParameters, pub spend_vk: PreparedVerifyingKey, - pub output_params: Parameters, + pub output_params: OutputParameters, pub output_vk: PreparedVerifyingKey, pub sprout_vk: Option>, } @@ -429,9 +435,9 @@ pub fn parse_parameters( let sprout_vk = sprout_vk.map(|vk| prepare_verifying_key(&vk)); ZcashParameters { - spend_params, + spend_params: SpendParameters(spend_params), spend_vk, - output_params, + output_params: OutputParameters(output_params), output_vk, sprout_vk, } diff --git a/zcash_proofs/src/prover.rs b/zcash_proofs/src/prover.rs index 40b1240fb..8bbd1abff 100644 --- a/zcash_proofs/src/prover.rs +++ b/zcash_proofs/src/prover.rs @@ -1,6 +1,6 @@ //! Abstractions over the proving system and parameters for ease of use. -use bellman::groth16::{Parameters, PreparedVerifyingKey}; +use bellman::groth16::PreparedVerifyingKey; use bls12_381::Bls12; use std::path::Path; use zcash_primitives::{ @@ -13,7 +13,10 @@ use zcash_primitives::{ transaction::components::{Amount, GROTH_PROOF_SIZE}, }; -use crate::{load_parameters, parse_parameters, sapling::SaplingProvingContext}; +use crate::{ + load_parameters, parse_parameters, sapling::SaplingProvingContext, OutputParameters, + SpendParameters, +}; #[cfg(feature = "local-prover")] use crate::{default_params_folder, SAPLING_OUTPUT_NAME, SAPLING_SPEND_NAME}; @@ -21,12 +24,12 @@ 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. pub struct LocalTxProver { - spend_params: Parameters, + spend_params: SpendParameters, // TODO: Either re-introduce verification-after-proving (once the verifier is // refactored), or remove this. #[allow(unused)] spend_vk: PreparedVerifyingKey, - output_params: Parameters, + output_params: OutputParameters, } impl LocalTxProver { diff --git a/zcash_proofs/src/sapling/prover.rs b/zcash_proofs/src/sapling/prover.rs index 9c31efc9f..435290108 100644 --- a/zcash_proofs/src/sapling/prover.rs +++ b/zcash_proofs/src/sapling/prover.rs @@ -1,4 +1,4 @@ -use bellman::groth16::{create_random_proof, Parameters, Proof}; +use bellman::groth16::{create_random_proof, Proof}; use bls12_381::Bls12; use group::GroupEncoding; use rand_core::OsRng; @@ -13,6 +13,8 @@ use zcash_primitives::{ transaction::components::Amount, }; +use crate::{OutputParameters, SpendParameters}; + /// A context object for creating the Sapling components of a Zcash transaction. pub struct SaplingProvingContext { bsk: TrapdoorSum, @@ -48,7 +50,7 @@ impl SaplingProvingContext { value: u64, anchor: bls12_381::Scalar, merkle_path: MerklePath, - proving_key: &Parameters, + proving_key: &SpendParameters, ) -> Result<(Proof, ValueCommitment, PublicKey), ()> { // Initialize secure RNG let mut rng = OsRng; @@ -96,8 +98,8 @@ impl SaplingProvingContext { }; // Create proof - let proof = - create_random_proof(instance, proving_key, &mut rng).expect("proving should not fail"); + let proof = create_random_proof(instance, &proving_key.0, &mut rng) + .expect("proving should not fail"); // Accumulate the value commitment in the context self.cv_sum += &value_commitment; @@ -114,7 +116,7 @@ impl SaplingProvingContext { payment_address: PaymentAddress, rcm: jubjub::Fr, value: u64, - proving_key: &Parameters, + proving_key: &OutputParameters, ) -> (Proof, ValueCommitment) { // Initialize secure RNG let mut rng = OsRng; @@ -143,8 +145,8 @@ impl SaplingProvingContext { }; // Create proof - let proof = - create_random_proof(instance, proving_key, &mut rng).expect("proving should not fail"); + let proof = create_random_proof(instance, &proving_key.0, &mut rng) + .expect("proving should not fail"); // Accumulate the value commitment in the context. We do this to check internal consistency. self.cv_sum -= &value_commitment; // Outputs subtract from the total.