Skip to content

Commit

Permalink
Optimize balance_verification_circuit_data_generation, change maximum…
Browse files Browse the repository at this point in the history
… level to 37, add error messages
  • Loading branch information
monyarm authored and PetarKirov committed Nov 3, 2023
1 parent 46358d4 commit 112e89a
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{fs, marker::PhantomData};

use std::{fs, marker::PhantomData, ops::RangeInclusive, path::Path, process};
use num::clamp;
use anyhow::Result;
use circuits::{
build_balance_inner_level_circuit::build_inner_level_circuit,
Expand Down Expand Up @@ -44,7 +44,7 @@ pub async fn async_main() -> Result<()> {
}),
)
.get_matches();

let level_str = matches.value_of("circuit_level").unwrap();
let level = match matches.value_of("circuit_level").unwrap() {
"all" => None,
x => Some(x.parse::<usize>().unwrap()),
Expand All @@ -59,6 +59,11 @@ pub async fn async_main() -> Result<()> {
_phantom: PhantomData::<PoseidonGoldilocksConfig>,
};

if level != None && level.unwrap() > 37 {
eprintln!("\x1b[31mError: Supplied level {} is larger than the maximum allowed level 38\x1b[0m", level.unwrap());
process::exit(1);
}

if level == None || level == Some(0) {
write_first_level_circuit(
&first_level_data,
Expand All @@ -73,10 +78,10 @@ pub async fn async_main() -> Result<()> {
}

let mut prev_circuit_data = first_level_data;

for i in 1..38 {
let level_range = if level == None { 1..=37 } else { RangeInclusive::new(1,clamp(level.unwrap(),1,37)) };
for i in level_range {
let (targets, data) = build_inner_level_circuit(&prev_circuit_data);

println!("{}", i);
if level == Some(i) || level == None {
let circuit_bytes = data
.to_bytes(&gate_serializer, &generator_serializer)
Expand All @@ -96,6 +101,17 @@ pub async fn async_main() -> Result<()> {
prev_circuit_data = data;
}

let mut exists = false;
for i in 1..=37 {
if Path::new(&format!("{}.plonky2_circuit",i)).exists() || Path::new(&format!("{}.plonky2_targets",i)).exists() {
exists = true;
}
}
if !exists {
eprintln!("\x1b[31mError: No plonky2 output created. Level used was: {}\x1b[0m", level_str);
process::exit(1);
}

Ok(())
}

Expand Down

0 comments on commit 112e89a

Please sign in to comment.