1//! Loading and checking correctness of Groth16 Sapling and Sprout parameters.
23use bellman::groth16;
4use bls12_381::Bls12;
56mod parse_parameters;
78use parse_parameters::parse_sapling_parameters;
910lazy_static::lazy_static! {
11/// Groth16 Zero-Knowledge Proof parameters for the Sapling and Sprout circuits.
12 ///
13 /// This static is accessed when Zebra needs to use these parameters for verification.
14 ///
15 /// # Panics
16 ///
17 /// If the parameter data in the `zebrad` binary is invalid.
18pub static ref GROTH16_PARAMETERS: Groth16Parameters = Groth16Parameters::new();
19}
2021/// Groth16 Zero-Knowledge Proof parameters for the Sapling and Sprout circuits.
22pub struct Groth16Parameters {
23/// The Sapling circuit Groth16 parameters.
24pub sapling: SaplingParameters,
2526/// The Sprout circuit Groth16 spend parameter.
27pub sprout: SproutParameters,
28}
2930/// Groth16 Zero-Knowledge Proof spend and output parameters for the Sapling circuit.
31pub struct SaplingParameters {
32pub spend: groth16::Parameters<Bls12>,
33pub spend_prepared_verifying_key: groth16::PreparedVerifyingKey<Bls12>,
3435pub output: groth16::Parameters<Bls12>,
36pub output_prepared_verifying_key: groth16::PreparedVerifyingKey<Bls12>,
37}
3839/// Groth16 Zero-Knowledge Proof spend parameters for the Sprout circuit.
40///
41/// Adding value to the Sprout pool was disabled by the Canopy network upgrade.
42pub struct SproutParameters {
43pub joinsplit_prepared_verifying_key: groth16::PreparedVerifyingKey<Bls12>,
44}
4546impl Groth16Parameters {
47/// Loads the Sprout and Sapling Groth16 parameters from the `zebrad` binary, and checks that
48 /// the data is valid.
49 ///
50 /// # Panics
51 ///
52 /// If the parameter data in the `zebrad` binary is invalid.
53fn new() -> Groth16Parameters {
54tracing::info!("checking and loading Zcash Sapling and Sprout parameters");
5556let (sapling_spend_bytes, sapling_output_bytes) =
57 wagyu_zcash_parameters::load_sapling_parameters();
58let sprout_vk_bytes = include_bytes!("sprout-groth16.vk");
5960let sapling = parse_sapling_parameters(
61 sapling_spend_bytes.as_slice(),
62 sapling_output_bytes.as_slice(),
63 );
6465let sprout_vk = groth16::VerifyingKey::<Bls12>::read(&sprout_vk_bytes[..])
66 .expect("should be able to parse Sprout verification key");
67let sprout_vk = groth16::prepare_verifying_key(&sprout_vk);
6869let sprout = SproutParameters {
70 joinsplit_prepared_verifying_key: sprout_vk,
71 };
7273tracing::info!("Zcash Sapling and Sprout parameters loaded and verified");
7475 Groth16Parameters { sapling, sprout }
76 }
7778/// Returns a hint that helps users recover from parameter loading failures.
79pub fn failure_hint() -> String {
80"Hint: re-run `zebrad` or re-install it from a trusted source".to_string()
81 }
82}