From 7af37015409eb7dcf3415faed4309e88c91b038c Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 23 Oct 2023 10:48:01 +1000 Subject: [PATCH] Build sapling parameters into zebrad --- Cargo.lock | 51 +++++++++++++++++++ zebra-consensus/Cargo.toml | 2 + .../src/primitives/groth16/params.rs | 28 +++++++--- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6d76e909d8..74fe1369616 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4916,6 +4916,56 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "wagyu-zcash-parameters" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955763984e7d1e7bfb1d796c6ec303913a288c138774fa67a86cdf4f2adad08b" +dependencies = [ + "wagyu-zcash-parameters-1", + "wagyu-zcash-parameters-2", + "wagyu-zcash-parameters-3", + "wagyu-zcash-parameters-4", + "wagyu-zcash-parameters-5", + "wagyu-zcash-parameters-6", +] + +[[package]] +name = "wagyu-zcash-parameters-1" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30f179c3951340a68e6ae2d00add39ed72263fd99f6693b399b1ae0ea4dca6f1" + +[[package]] +name = "wagyu-zcash-parameters-2" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e08a39cf68902082af6fb8129cbfe5f100c731cf1e4c49a81e456146249fb21" + +[[package]] +name = "wagyu-zcash-parameters-3" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f1ae3f133131bfb34ee27c0749fe79c310a766a3370ce676908a7e3d3987512" + +[[package]] +name = "wagyu-zcash-parameters-4" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "049f697efaa5fcded7e43f8095c359325b7f92371e147530397917dd6d32b23c" + +[[package]] +name = "wagyu-zcash-parameters-5" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80adeea7cd72a33e72e4093f17c211df54b221cc047ad6c3a64ac3a8542617a8" + +[[package]] +name = "wagyu-zcash-parameters-6" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad468482ce2ea9fc0bbe80c729f628b2f729fa2ec10c7d95b0b60fd7f4658c9" + [[package]] name = "wait-timeout" version = "0.2.0" @@ -5516,6 +5566,7 @@ dependencies = [ "tracing-error", "tracing-futures", "tracing-subscriber", + "wagyu-zcash-parameters", "zcash_proofs", "zebra-chain", "zebra-node-services", diff --git a/zebra-consensus/Cargo.toml b/zebra-consensus/Cargo.toml index f674e18777c..da183bc74cf 100644 --- a/zebra-consensus/Cargo.toml +++ b/zebra-consensus/Cargo.toml @@ -60,7 +60,9 @@ tracing-futures = "0.2.5" orchard = "0.6.0" +# TODO: remove local-prover and download-params when sprout is built into the binary zcash_proofs = { version = "0.13.0-rc.1", features = ["local-prover", "multicore", "download-params"] } +wagyu-zcash-parameters = "0.1.0" tower-fallback = { path = "../tower-fallback/", version = "0.2.41-beta.6" } tower-batch-control = { path = "../tower-batch-control/", version = "0.2.41-beta.6" } diff --git a/zebra-consensus/src/primitives/groth16/params.rs b/zebra-consensus/src/primitives/groth16/params.rs index 52fb20b7595..7055712dfc4 100644 --- a/zebra-consensus/src/primitives/groth16/params.rs +++ b/zebra-consensus/src/primitives/groth16/params.rs @@ -76,31 +76,43 @@ impl Groth16Parameters { let sapling_output_path = params_directory.join(zcash_proofs::SAPLING_OUTPUT_NAME); let sprout_path = params_directory.join(zcash_proofs::SPROUT_NAME); + // TODO: remove sapling download when sprout is also built into the binary. Groth16Parameters::download_sapling_parameters(&sapling_spend_path, &sapling_output_path); Groth16Parameters::download_sprout_parameters(&sprout_path); - // TODO: if loading fails, log a message including `failure_hint` + // TODO: remove file load when sprout is also built into the binary. tracing::info!("checking and loading Zcash Sapling and Sprout parameters"); - let parameters = zcash_proofs::load_parameters( + let file_parameters = zcash_proofs::load_parameters( &sapling_spend_path, &sapling_output_path, Some(&sprout_path), ); + let (sapling_spend_bytes, sapling_output_bytes) = + wagyu_zcash_parameters::load_sapling_parameters(); + + // TODO: add sprout bytes here + let bin_parameters = zcash_proofs::parse_parameters( + sapling_spend_bytes.as_slice(), + sapling_output_bytes.as_slice(), + None, + ); + let sapling = SaplingParameters { - spend: parameters.spend_params, - spend_prepared_verifying_key: parameters.spend_vk, - output: parameters.output_params, - output_prepared_verifying_key: parameters.output_vk, + spend: bin_parameters.spend_params, + spend_prepared_verifying_key: bin_parameters.spend_vk, + output: bin_parameters.output_params, + output_prepared_verifying_key: bin_parameters.output_vk, }; + // TODO: remove sprout extract when sprout is also built into the binary. let sprout = SproutParameters { - joinsplit_prepared_verifying_key: parameters + joinsplit_prepared_verifying_key: file_parameters .sprout_vk .expect("unreachable code: sprout loader panics on failure"), }; - tracing::info!("Zcash Sapling and Sprout parameters downloaded and/or verified"); + tracing::info!("Zcash Sapling and Sprout parameters loaded and verified"); Groth16Parameters { sapling, sprout } }