2022-08-21 10:36:53 +00:00
|
|
|
use std::{
|
|
|
|
io::Write,
|
2022-09-29 06:24:33 +00:00
|
|
|
env,
|
2022-08-21 10:36:53 +00:00
|
|
|
path::Path,
|
2022-09-29 06:24:33 +00:00
|
|
|
fs::{File, 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-09-29 06:24:33 +00:00
|
|
|
let path = Path::new(&env::var("OUT_DIR").unwrap()).join(path);
|
2022-08-21 10:36:53 +00:00
|
|
|
let _ = remove_file(&path);
|
|
|
|
File::create(&path)
|
|
|
|
.unwrap()
|
|
|
|
.write_all(
|
|
|
|
format!(
|
|
|
|
"
|
2023-08-27 19:33:17 +00:00
|
|
|
pub(crate) static GENERATORS_CELL: OnceLock<Generators> = OnceLock::new();
|
2023-06-29 01:16:33 +00:00
|
|
|
pub fn GENERATORS() -> &'static Generators {{
|
|
|
|
GENERATORS_CELL.get_or_init(|| Generators {{
|
2023-09-20 08:31:16 +00:00
|
|
|
G: vec![
|
2023-01-01 09:18:23 +00:00
|
|
|
{G_str}
|
2022-08-21 10:36:53 +00:00
|
|
|
],
|
2023-09-20 08:31:16 +00:00
|
|
|
H: vec![
|
2023-01-01 09:18:23 +00:00
|
|
|
{H_str}
|
2022-08-21 10:36:53 +00:00
|
|
|
],
|
2023-06-29 01:16:33 +00:00
|
|
|
}})
|
2022-08-21 10:36:53 +00:00
|
|
|
}}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.as_bytes(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
|
|
|
|
generators("bulletproof", "generators.rs");
|
|
|
|
generators("bulletproof_plus", "generators_plus.rs");
|
|
|
|
}
|