Hush mods to librustzcash
This commit is contained in:
@@ -181,6 +181,8 @@ pub extern "system" fn librustzcash_init_zksnark_params(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We ignore the values of sprout_path/sprout_hash but keep
|
||||||
|
// same function signature for convenience
|
||||||
fn init_zksnark_params(
|
fn init_zksnark_params(
|
||||||
spend_path: &Path,
|
spend_path: &Path,
|
||||||
spend_hash: *const c_char,
|
spend_hash: *const c_char,
|
||||||
@@ -205,7 +207,8 @@ fn init_zksnark_params(
|
|||||||
.expect("hash should be a valid string");
|
.expect("hash should be a valid string");
|
||||||
|
|
||||||
// Load params
|
// Load params
|
||||||
let (spend_params, spend_vk, output_params, output_vk, sprout_vk) = load_parameters(
|
//let (spend_params, spend_vk, output_params, output_vk, sprout_vk) = load_parameters(
|
||||||
|
let (spend_params, spend_vk, output_params, output_vk) = load_parameters(
|
||||||
spend_path,
|
spend_path,
|
||||||
spend_hash,
|
spend_hash,
|
||||||
output_path,
|
output_path,
|
||||||
@@ -223,7 +226,7 @@ fn init_zksnark_params(
|
|||||||
|
|
||||||
SAPLING_SPEND_VK = Some(spend_vk);
|
SAPLING_SPEND_VK = Some(spend_vk);
|
||||||
SAPLING_OUTPUT_VK = Some(output_vk);
|
SAPLING_OUTPUT_VK = Some(output_vk);
|
||||||
SPROUT_GROTH16_VK = Some(sprout_vk.unwrap());
|
//SPROUT_GROTH16_VK = Some(sprout_vk.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +867,7 @@ pub extern "system" fn librustzcash_sprout_prove(
|
|||||||
)
|
)
|
||||||
.expect("couldn't load Sprout groth16 parameters file");
|
.expect("couldn't load Sprout groth16 parameters file");
|
||||||
|
|
||||||
let mut sprout_fs = BufReader::with_capacity(1024 * 1024, sprout_fs);
|
//let mut sprout_fs = BufReader::with_capacity(1024 * 1024, sprout_fs);
|
||||||
|
|
||||||
let params = Parameters::<Bls12>::read(&mut sprout_fs, false)
|
let params = Parameters::<Bls12>::read(&mut sprout_fs, false)
|
||||||
.expect("couldn't deserialize Sprout JoinSplit parameters file");
|
.expect("couldn't deserialize Sprout JoinSplit parameters file");
|
||||||
|
|||||||
@@ -32,14 +32,12 @@ pub fn load_parameters(
|
|||||||
// Load from each of the paths
|
// Load from each of the paths
|
||||||
let spend_fs = File::open(spend_path).expect("couldn't load Sapling spend parameters file");
|
let spend_fs = File::open(spend_path).expect("couldn't load Sapling spend parameters file");
|
||||||
let output_fs = File::open(output_path).expect("couldn't load Sapling output parameters file");
|
let output_fs = File::open(output_path).expect("couldn't load Sapling output parameters file");
|
||||||
let sprout_fs =
|
//let sprout_fs = sprout_path.map(|p| File::open(p).expect("couldn't load Sprout groth16 parameters file"));
|
||||||
sprout_path.map(|p| File::open(p).expect("couldn't load Sprout groth16 parameters file"));
|
|
||||||
|
|
||||||
let mut spend_fs = hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, spend_fs));
|
let mut spend_fs = hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, spend_fs));
|
||||||
let mut output_fs =
|
let mut output_fs =
|
||||||
hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, output_fs));
|
hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, output_fs));
|
||||||
let mut sprout_fs =
|
//let mut sprout_fs = sprout_fs.map(|fs| hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, fs)));
|
||||||
sprout_fs.map(|fs| hashreader::HashReader::new(BufReader::with_capacity(1024 * 1024, fs)));
|
|
||||||
|
|
||||||
// Deserialize params
|
// Deserialize params
|
||||||
let spend_params = Parameters::<Bls12>::read(&mut spend_fs, false)
|
let spend_params = Parameters::<Bls12>::read(&mut spend_fs, false)
|
||||||
@@ -50,10 +48,10 @@ pub fn load_parameters(
|
|||||||
// We only deserialize the verifying key for the Sprout parameters, which
|
// We only deserialize the verifying key for the Sprout parameters, which
|
||||||
// appears at the beginning of the parameter file. The rest is loaded
|
// appears at the beginning of the parameter file. The rest is loaded
|
||||||
// during proving time.
|
// during proving time.
|
||||||
let sprout_vk = sprout_fs.as_mut().map(|mut fs| {
|
//let sprout_vk = sprout_fs.as_mut().map(|mut fs| {
|
||||||
VerifyingKey::<Bls12>::read(&mut fs)
|
// VerifyingKey::<Bls12>::read(&mut fs)
|
||||||
.expect("couldn't deserialize Sprout Groth16 verifying key")
|
// .expect("couldn't deserialize Sprout Groth16 verifying key")
|
||||||
});
|
//});
|
||||||
|
|
||||||
// There is extra stuff (the transcript) at the end of the parameter file which is
|
// There is extra stuff (the transcript) at the end of the parameter file which is
|
||||||
// used to verify the parameter validity, but we're not interested in that. We do
|
// used to verify the parameter validity, but we're not interested in that. We do
|
||||||
@@ -64,10 +62,10 @@ pub fn load_parameters(
|
|||||||
.expect("couldn't finish reading Sapling spend parameter file");
|
.expect("couldn't finish reading Sapling spend parameter file");
|
||||||
io::copy(&mut output_fs, &mut sink)
|
io::copy(&mut output_fs, &mut sink)
|
||||||
.expect("couldn't finish reading Sapling output parameter file");
|
.expect("couldn't finish reading Sapling output parameter file");
|
||||||
if let Some(mut sprout_fs) = sprout_fs.as_mut() {
|
//if let Some(mut sprout_fs) = sprout_fs.as_mut() {
|
||||||
io::copy(&mut sprout_fs, &mut sink)
|
// io::copy(&mut sprout_fs, &mut sink)
|
||||||
.expect("couldn't finish reading Sprout groth16 parameter file");
|
// .expect("couldn't finish reading Sprout groth16 parameter file");
|
||||||
}
|
//}
|
||||||
|
|
||||||
if spend_fs.into_hash() != spend_hash {
|
if spend_fs.into_hash() != spend_hash {
|
||||||
panic!("Sapling spend parameter file is not correct, please clean your `~/.zcash-params/` and re-run `fetch-params`.");
|
panic!("Sapling spend parameter file is not correct, please clean your `~/.zcash-params/` and re-run `fetch-params`.");
|
||||||
@@ -77,14 +75,15 @@ pub fn load_parameters(
|
|||||||
panic!("Sapling output parameter file is not correct, please clean your `~/.zcash-params/` and re-run `fetch-params`.");
|
panic!("Sapling output parameter file is not correct, please clean your `~/.zcash-params/` and re-run `fetch-params`.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if sprout_fs.map(|fs| fs.into_hash()) != sprout_hash.map(|h| h.to_owned()) {
|
//if sprout_fs.map(|fs| fs.into_hash()) != sprout_hash.map(|h| h.to_owned()) {
|
||||||
panic!("Sprout groth16 parameter file is not correct, please clean your `~/.zcash-params/` and re-run `fetch-params`.");
|
// panic!("Sprout groth16 parameter file is not correct, please clean your `~/.zcash-params/` and re-run `fetch-params`.");
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Prepare verifying keys
|
// Prepare verifying keys
|
||||||
let spend_vk = prepare_verifying_key(&spend_params.vk);
|
let spend_vk = prepare_verifying_key(&spend_params.vk);
|
||||||
let output_vk = prepare_verifying_key(&output_params.vk);
|
let output_vk = prepare_verifying_key(&output_params.vk);
|
||||||
let sprout_vk = sprout_vk.map(|vk| prepare_verifying_key(&vk));
|
//let sprout_vk = sprout_vk.map(|vk| prepare_verifying_key(&vk));
|
||||||
|
|
||||||
(spend_params, spend_vk, output_params, output_vk, sprout_vk)
|
//(spend_params, spend_vk, output_params, output_vk, sprout_vk)
|
||||||
|
(spend_params, spend_vk, output_params, output_vk)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user