rust: Load Orchard circuit parameters at startup

This commit is contained in:
Jack Grigg 2021-06-21 13:16:34 +01:00
parent 785803382a
commit 9ad5b75b30
4 changed files with 24 additions and 12 deletions

12
Cargo.lock generated
View File

@ -473,7 +473,7 @@ checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
[[package]]
name = "equihash"
version = "0.1.0"
source = "git+https://github.com/zcash/librustzcash.git?rev=fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13#fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13"
source = "git+https://github.com/zcash/librustzcash.git?rev=02052526925fba9389f1428d6df254d4dec967e6#02052526925fba9389f1428d6df254d4dec967e6"
dependencies = [
"blake2b_simd",
"byteorder",
@ -1030,7 +1030,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "orchard"
version = "0.0.0"
source = "git+https://github.com/zcash/orchard.git?rev=f7c64e0437040d831e61711cd9e5695b001cb5cb#f7c64e0437040d831e61711cd9e5695b001cb5cb"
source = "git+https://github.com/zcash/orchard.git?rev=93a7f1db228479228f768e9d86dd5868e4c2ff1e#93a7f1db228479228f768e9d86dd5868e4c2ff1e"
dependencies = [
"aes",
"arrayvec 0.7.0",
@ -1677,7 +1677,7 @@ dependencies = [
[[package]]
name = "zcash_history"
version = "0.2.0"
source = "git+https://github.com/zcash/librustzcash.git?rev=fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13#fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13"
source = "git+https://github.com/zcash/librustzcash.git?rev=02052526925fba9389f1428d6df254d4dec967e6#02052526925fba9389f1428d6df254d4dec967e6"
dependencies = [
"bigint",
"blake2b_simd",
@ -1687,7 +1687,7 @@ dependencies = [
[[package]]
name = "zcash_note_encryption"
version = "0.0.0"
source = "git+https://github.com/zcash/librustzcash.git?rev=fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13#fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13"
source = "git+https://github.com/zcash/librustzcash.git?rev=02052526925fba9389f1428d6df254d4dec967e6#02052526925fba9389f1428d6df254d4dec967e6"
dependencies = [
"blake2b_simd",
"byteorder",
@ -1701,7 +1701,7 @@ dependencies = [
[[package]]
name = "zcash_primitives"
version = "0.5.0"
source = "git+https://github.com/zcash/librustzcash.git?rev=fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13#fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13"
source = "git+https://github.com/zcash/librustzcash.git?rev=02052526925fba9389f1428d6df254d4dec967e6#02052526925fba9389f1428d6df254d4dec967e6"
dependencies = [
"aes",
"bitvec",
@ -1731,7 +1731,7 @@ dependencies = [
[[package]]
name = "zcash_proofs"
version = "0.5.0"
source = "git+https://github.com/zcash/librustzcash.git?rev=fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13#fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13"
source = "git+https://github.com/zcash/librustzcash.git?rev=02052526925fba9389f1428d6df254d4dec967e6#02052526925fba9389f1428d6df254d4dec967e6"
dependencies = [
"bellman",
"blake2b_simd",

View File

@ -61,8 +61,8 @@ codegen-units = 1
[patch.crates-io]
ed25519-zebra = { git = "https://github.com/ZcashFoundation/ed25519-zebra.git", rev = "d3512400227a362d08367088ffaa9bd4142a69c7" }
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "d04b532368d05b505e622f8cac4c0693574fbd93" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "f7c64e0437040d831e61711cd9e5695b001cb5cb" }
zcash_history = { git = "https://github.com/zcash/librustzcash.git", rev = "fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash.git", rev = "fe4b63c8fe7300ebc9cd7a1242867525ccfe1e13" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "93a7f1db228479228f768e9d86dd5868e4c2ff1e" }
zcash_history = { git = "https://github.com/zcash/librustzcash.git", rev = "02052526925fba9389f1428d6df254d4dec967e6" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "02052526925fba9389f1428d6df254d4dec967e6" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "02052526925fba9389f1428d6df254d4dec967e6" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash.git", rev = "02052526925fba9389f1428d6df254d4dec967e6" }

View File

@ -737,7 +737,7 @@ static void ZC_LoadParams(
gettimeofday(&tv_end, 0);
elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000);
LogPrintf("Loaded Sapling parameters in %fs seconds.\n", elapsed);
LogPrintf("Loaded proof system parameters in %fs seconds.\n", elapsed);
}
bool AppInitServers(boost::thread_group& threadGroup)

View File

@ -25,6 +25,7 @@ use bls12_381::Bls12;
use group::{cofactor::CofactorGroup, GroupEncoding};
use libc::{c_uchar, size_t};
use rand_core::{OsRng, RngCore};
use tracing::info;
use std::fs::File;
use std::io::BufReader;
use std::path::{Path, PathBuf};
@ -84,6 +85,9 @@ static mut SAPLING_SPEND_PARAMS: Option<Parameters<Bls12>> = None;
static mut SAPLING_OUTPUT_PARAMS: Option<Parameters<Bls12>> = None;
static mut SPROUT_GROTH16_PARAMS_PATH: Option<PathBuf> = None;
static mut ORCHARD_PK: Option<orchard::circuit::ProvingKey> = None;
static mut ORCHARD_VK: Option<orchard::circuit::VerifyingKey> = None;
/// Converts CtOption<t> into Option<T>
fn de_ct<T>(ct: CtOption<T>) -> Option<T> {
if ct.is_some().into() {
@ -155,6 +159,11 @@ pub extern "C" fn librustzcash_init_zksnark_params(
// Load params
let params = load_parameters(spend_path, output_path, sprout_path);
// Generate Orchard parameters.
info!(target: "main", "Loading Orchard parameters");
let orchard_pk = orchard::circuit::ProvingKey::build();
let orchard_vk = orchard::circuit::VerifyingKey::build();
// Caller is responsible for calling this function once, so
// these global mutations are safe.
unsafe {
@ -165,6 +174,9 @@ pub extern "C" fn librustzcash_init_zksnark_params(
SAPLING_SPEND_VK = Some(params.spend_vk);
SAPLING_OUTPUT_VK = Some(params.output_vk);
SPROUT_GROTH16_VK = params.sprout_vk;
ORCHARD_PK = Some(orchard_pk);
ORCHARD_VK = Some(orchard_vk);
}
}