-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feat/build all casper circuits #271
base: main
Are you sure you want to change the base?
Changes from all commits
136be82
6b94349
85c0c8c
a919fd9
5249649
3f8b60d
371c3e1
b76839c
2142ab6
ce12d9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
pub mod biguint; | ||
pub mod build_balance_inner_level_circuit; | ||
pub mod build_commitment_mapper_first_level_circuit; | ||
pub mod build_commitment_mapper_inner_level_circuit; | ||
pub mod build_final_circuit; | ||
pub mod build_validator_balance_circuit; | ||
pub mod generator_serializer; | ||
pub mod hash_tree_root; | ||
pub mod hash_tree_root_poseidon; | ||
pub mod is_active_validator; | ||
pub mod is_valid_merkle_branch; | ||
pub mod sha256; | ||
pub mod targets_serialization; | ||
pub mod utils; | ||
pub mod validator_balance_circuit; | ||
pub mod validator_commitment_mapper; | ||
pub mod validator_hash_tree_root; | ||
pub mod validator_hash_tree_root_poseidon; | ||
pub mod build_balance_inner_level_circuit; | ||
pub mod is_active_validator; | ||
pub mod build_final_circuit; | ||
pub mod targets_serialization; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use casper_finality_proofs::test_engine::wrappers::{ | ||
compute_shuffled_index::wrapper_mainnet::MAINNET_CIRCUIT as circuit_mainnet, | ||
compute_shuffled_index::wrapper_minimal::MINIMAL_CIRCUIT as circuit_minimal, | ||
wrapper_weigh_justification_and_finalization::CIRCUIT as circuit_weigh_justification_and_finalization, | ||
}; | ||
use clap::Parser; | ||
use once_cell::sync::Lazy; | ||
use plonky2x::{ | ||
backend::circuit::{DefaultParameters, GateRegistry, HintRegistry}, | ||
frontend::builder::CircuitBuilder, | ||
}; | ||
use std::env::args; | ||
use strum::{Display, EnumIter, EnumString, IntoEnumIterator}; | ||
#[derive(Debug, Eq, Hash, PartialEq, Copy, Clone, EnumString, Display, EnumIter)] | ||
#[allow(non_camel_case_types)] | ||
enum Circuits { | ||
compute_shuffled_index_mainnet, | ||
compute_shuffled_index_minimal, | ||
weigh_justification_and_finalization, | ||
all, | ||
} | ||
|
||
impl Circuits { | ||
fn from_str(circuit_as_str: &str) -> Option<Circuits> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EnumString already creates this function for you so this implementation is redundant. Moreover, you can provide casing in it to match the Pascal case of the enum corectly |
||
match circuit_as_str { | ||
"compute_shuffled_index_mainnet" => Some(Circuits::compute_shuffled_index_mainnet), | ||
"compute_shuffled_index_minimal" => Some(Circuits::compute_shuffled_index_minimal), | ||
"weigh_justification_and_finalization" => { | ||
Some(Circuits::weigh_justification_and_finalization) | ||
} | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
enum OneOrAllCircuits { | ||
OneCircuit(Box<dyn Fn() -> () + Send + Sync>), | ||
AllCircuits(Vec<Box<dyn Fn() -> () + Send + Sync>>), | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
struct CommandLineCircuit { | ||
/// Enter name of circuit | ||
#[clap(value_delimiter = ' ', num_args = 0..)] | ||
name: Circuits, | ||
} | ||
|
||
fn build_circuit(circuit: Circuits) -> OneOrAllCircuits { | ||
match circuit { | ||
Circuits::compute_shuffled_index_mainnet => OneOrAllCircuits::OneCircuit(Box::new(|| { | ||
Lazy::force(&circuit_mainnet); | ||
})), | ||
Circuits::compute_shuffled_index_minimal => OneOrAllCircuits::OneCircuit(Box::new(|| { | ||
Lazy::force(&circuit_minimal); | ||
})), | ||
Circuits::weigh_justification_and_finalization => { | ||
OneOrAllCircuits::OneCircuit(Box::new(|| { | ||
Lazy::force(&circuit_weigh_justification_and_finalization); | ||
})) | ||
} | ||
Comment on lines
+48
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return type of build_circuit is never used so it can be removed. Then OneOrAllCircuits becomes obsolete and the Box::new expression can be removed. Simply match the enum value and Lazy::force in the body of the matched value |
||
Circuits::all => OneOrAllCircuits::AllCircuits(vec![ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is never called |
||
Box::new(|| { | ||
Lazy::force(&circuit_mainnet); | ||
}), | ||
Box::new(|| { | ||
Lazy::force(&circuit_minimal); | ||
}), | ||
Box::new(|| { | ||
Lazy::force(&circuit_weigh_justification_and_finalization); | ||
}), | ||
]), | ||
} | ||
} | ||
|
||
fn main() { | ||
type L = DefaultParameters; | ||
const D: usize = 2; | ||
let builder = CircuitBuilder::<DefaultParameters, D>::new(); | ||
|
||
let circuit = builder.build(); | ||
let hint_serializer = HintRegistry::<L, D>::new(); | ||
let gate_serializer = GateRegistry::<L, D>::new(); | ||
let command_line_circuit: CommandLineCircuit = CommandLineCircuit::parse(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename CommandLineCircuit to CommandLineOptions |
||
let command_line_arguments: Vec<String> = args().skip(1).collect(); | ||
|
||
if command_line_circuit.name != Circuits::all { | ||
Comment on lines
+83
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are only using command_line_circuit to check if it's all and are not using it to determine which circuits you should build. You could just as well check if args()[1] is "all" |
||
for (_, arg) in command_line_arguments.iter().enumerate() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enumerate is useless if you are not using the index |
||
let arg_as_circuit = Circuits::from_str(&arg); | ||
build_circuit(arg_as_circuit.unwrap()); | ||
let path = format!("build/{}", arg_as_circuit.unwrap().to_string()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handle the None case |
||
circuit.save(&path, &gate_serializer, &hint_serializer); | ||
} | ||
} else { | ||
for _circuit in Circuits::iter() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove underscore |
||
if _circuit != Circuits::all { | ||
build_circuit(_circuit); | ||
let path = format!("build/{}", _circuit.to_string()); | ||
circuit.save(&path, &gate_serializer, &hint_serializer); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod circuit; | ||
|
||
mod helpers; | ||
mod helpers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename these to Pascal case