@@ -13,7 +13,7 @@ pub struct Input {
1313 pub out_c_code : PathBuf ,
1414 pub out_c_dat : PathBuf ,
1515 pub out_sym : PathBuf ,
16- pub field : & ' static str ,
16+ // pub field: &'static str,
1717 pub c_flag : bool ,
1818 pub wasm_flag : bool ,
1919 pub wat_flag : bool ,
@@ -29,10 +29,10 @@ pub struct Input {
2929 pub inspect_constraints_flag : bool ,
3030 pub no_rounds : usize ,
3131 pub flag_verbose : bool ,
32+ pub prime : String ,
3233}
3334
34- const P_0 : & ' static str =
35- "21888242871839275222246405745257275088548364400416034343698204186575808495617" ;
35+
3636const R1CS : & ' static str = "r1cs" ;
3737const WAT : & ' static str = "wat" ;
3838const WASM : & ' static str = "wasm" ;
@@ -42,6 +42,7 @@ const DAT: &'static str = "dat";
4242const SYM : & ' static str = "sym" ;
4343const JSON : & ' static str = "json" ;
4444
45+
4546impl Input {
4647 pub fn new ( ) -> Result < Input , ( ) > {
4748 use input_processing:: SimplificationStyle ;
@@ -53,15 +54,15 @@ impl Input {
5354 let output_js_path = Input :: build_folder ( & output_path, & file_name, JS ) ;
5455 let o_style = input_processing:: get_simplification_style ( & matches) ?;
5556 Result :: Ok ( Input {
56- field : P_0 ,
57+ // field: P_BN128 ,
5758 input_program : input,
5859 out_r1cs : Input :: build_output ( & output_path, & file_name, R1CS ) ,
5960 out_wat_code : Input :: build_output ( & output_js_path, & file_name, WAT ) ,
6061 out_wasm_code : Input :: build_output ( & output_js_path, & file_name, WASM ) ,
61- out_js_folder : output_js_path. clone ( ) ,
62- out_wasm_name : file_name. clone ( ) ,
63- out_c_folder : output_c_path. clone ( ) ,
64- out_c_run_name : file_name. clone ( ) ,
62+ out_js_folder : output_js_path. clone ( ) ,
63+ out_wasm_name : file_name. clone ( ) ,
64+ out_c_folder : output_c_path. clone ( ) ,
65+ out_c_run_name : file_name. clone ( ) ,
6566 out_c_code : Input :: build_output ( & output_c_path, & file_name, CPP ) ,
6667 out_c_dat : Input :: build_output ( & output_c_path, & file_name, DAT ) ,
6768 out_sym : Input :: build_output ( & output_path, & file_name, SYM ) ,
@@ -84,15 +85,16 @@ impl Input {
8485 reduced_simplification_flag : o_style == SimplificationStyle :: O1 ,
8586 parallel_simplification_flag : input_processing:: get_parallel_simplification ( & matches) ,
8687 inspect_constraints_flag : input_processing:: get_inspect_constraints ( & matches) ,
87- flag_verbose : input_processing:: get_flag_verbose ( & matches)
88+ flag_verbose : input_processing:: get_flag_verbose ( & matches) ,
89+ prime : input_processing:: get_prime ( & matches) ?,
8890 } )
8991 }
9092
9193 fn build_folder ( output_path : & PathBuf , filename : & str , ext : & str ) -> PathBuf {
9294 let mut file = output_path. clone ( ) ;
93- let folder_name = format ! ( "{}_{}" , filename, ext) ;
94- file. push ( folder_name) ;
95- file
95+ let folder_name = format ! ( "{}_{}" , filename, ext) ;
96+ file. push ( folder_name) ;
97+ file
9698 }
9799
98100 fn build_output ( output_path : & PathBuf , filename : & str , ext : & str ) -> PathBuf {
@@ -184,6 +186,9 @@ impl Input {
184186 pub fn no_rounds ( & self ) -> usize {
185187 self . no_rounds
186188 }
189+ pub fn prime ( & self ) -> String {
190+ self . prime . clone ( )
191+ }
187192}
188193mod input_processing {
189194 use ansi_term:: Colour ;
@@ -279,6 +284,26 @@ mod input_processing {
279284 matches. is_present ( "flag_verbose" )
280285 }
281286
287+ pub fn get_prime ( matches : & ArgMatches ) -> Result < String , ( ) > {
288+
289+ match matches. is_present ( "prime" ) {
290+ true =>
291+ {
292+ let prime_value = matches. value_of ( "prime" ) . unwrap ( ) ;
293+ if prime_value == "bn128"
294+ || prime_value == "bls12381"
295+ || prime_value == "goldilocks" {
296+ Ok ( String :: from ( matches. value_of ( "prime" ) . unwrap ( ) ) )
297+ }
298+ else {
299+ Result :: Err ( eprintln ! ( "{}" , Colour :: Red . paint( "invalid prime number" ) ) )
300+ }
301+ }
302+
303+ false => Ok ( String :: from ( "bn128" ) ) ,
304+ }
305+ }
306+
282307 pub fn view ( ) -> ArgMatches < ' static > {
283308 App :: new ( "circom compiler" )
284309 . version ( VERSION )
@@ -397,6 +422,14 @@ mod input_processing {
397422 . takes_value ( false )
398423 . help ( "Shows logs during compilation" ) ,
399424 )
425+ . arg (
426+ Arg :: with_name ( "prime" )
427+ . short ( "prime" )
428+ . long ( "prime" )
429+ . takes_value ( true )
430+ . default_value ( "bn128" )
431+ . help ( "To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks)" ) ,
432+ )
400433 . get_matches ( )
401434 }
402435}
0 commit comments