Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize balance_verification_circuit_data_generation, change maximum… #260

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -21,11 +21,11 @@ fn write_to_file(file_path: &str, data: &[u8]) -> Result<()> {
Ok(())
}

fn main() -> Result<()> {
fn main() -> Result<(),String> {
future::block_on(async_main())
}

pub async fn async_main() -> Result<()> {
pub async fn async_main() -> Result<(),String> {
let matches = App::new("")
.arg(
Arg::with_name("circuit_level")
Expand All @@ -44,8 +44,8 @@ pub async fn async_main() -> Result<()> {
}),
)
.get_matches();

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

if level != None && level.unwrap() > 37 {
return Err(String::from(format!("Supplied level {} is larger than the maximum allowed level 37",level.unwrap())));
}

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

let mut prev_circuit_data = first_level_data;

for i in 1..38 {
let max_level = if level == None {37} else {clamp(level.unwrap(),1,37)};
for i in 1..=max_level {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for clamp. Just use unwrap_or(37)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clamp is in case a value greater than 37 is supplied

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is greater than 37, the program returns a few lines above, so the clamp is obsolete

let (targets, data) = build_inner_level_circuit(&prev_circuit_data);

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

let mut exists = false;
for i in 1..=max_level {
if Path::new(&format!("{}.plonky2_circuit",i)).exists() || Path::new(&format!("{}.plonky2_targets",i)).exists() {
exists = true;
break;
monyarm marked this conversation as resolved.
Show resolved Hide resolved
}
}
if !exists {
return Err(String::from(format!("No plonky2 output created. Level used was: {}", level_str)));
}

Ok(())
}

Expand Down
Loading