2022-08-21 10:36:53 +00:00
|
|
|
use std::{
|
|
|
|
io::Write,
|
|
|
|
path::Path,
|
2022-08-21 10:48:59 +00:00
|
|
|
fs::{File, DirBuilder, remove_file},
|
2022-08-21 10:36:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
use dalek_ff_group::EdwardsPoint;
|
|
|
|
|
|
|
|
use monero_generators::bulletproofs_generators;
|
|
|
|
|
|
|
|
fn serialize(generators_string: &mut String, points: &[EdwardsPoint]) {
|
|
|
|
for generator in points {
|
|
|
|
generators_string.extend(
|
|
|
|
format!(
|
|
|
|
"
|
|
|
|
dalek_ff_group::EdwardsPoint(
|
|
|
|
curve25519_dalek::edwards::CompressedEdwardsY({:?}).decompress().unwrap()
|
|
|
|
),
|
|
|
|
",
|
|
|
|
generator.compress().to_bytes()
|
|
|
|
)
|
|
|
|
.chars(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn generators(prefix: &'static str, path: &str) {
|
|
|
|
let generators = bulletproofs_generators(prefix.as_bytes());
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
let mut G_str = "".to_string();
|
|
|
|
serialize(&mut G_str, &generators.G);
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
let mut H_str = "".to_string();
|
|
|
|
serialize(&mut H_str, &generators.H);
|
|
|
|
|
2022-08-21 10:48:59 +00:00
|
|
|
DirBuilder::new().recursive(true).create(".generators").unwrap();
|
2022-08-21 10:36:53 +00:00
|
|
|
let path = Path::new(".generators").join(path);
|
|
|
|
let _ = remove_file(&path);
|
|
|
|
File::create(&path)
|
|
|
|
.unwrap()
|
|
|
|
.write_all(
|
|
|
|
format!(
|
|
|
|
"
|
|
|
|
lazy_static! {{
|
2022-08-21 15:06:17 +00:00
|
|
|
pub static ref GENERATORS: Generators = Generators {{
|
2022-08-21 10:36:53 +00:00
|
|
|
G: [
|
|
|
|
{}
|
|
|
|
],
|
|
|
|
H: [
|
|
|
|
{}
|
|
|
|
],
|
|
|
|
}};
|
|
|
|
}}
|
|
|
|
",
|
|
|
|
G_str, H_str,
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// For some reason, filtering off .generators does not work. This prevents re-building overall
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
|
|
|
|
generators("bulletproof", "generators.rs");
|
|
|
|
generators("bulletproof_plus", "generators_plus.rs");
|
|
|
|
}
|