Skip to content

Commit c41df24

Browse files
authored
Merge pull request #87 from iden3/new_primes_and_custom_gates_added
New primes and custom gates added
2 parents e0c451b + d472c3f commit c41df24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+35828
-249
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ parser/target/
88
program_structure/target/
99
type_analysis/target/
1010
.idea/
11+
.vscode/
1112
.DS_Store
1213
Cargo.lock

circom/src/execution_user.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use constraint_writers::debug_writer::DebugWriter;
44
use constraint_writers::ConstraintExporter;
55
use program_structure::program_archive::ProgramArchive;
66

7+
78
pub struct ExecutionConfig {
89
pub r1cs: String,
910
pub sym: String,
@@ -18,6 +19,7 @@ pub struct ExecutionConfig {
1819
pub r1cs_flag: bool,
1920
pub json_substitution_flag: bool,
2021
pub json_constraint_flag: bool,
22+
pub prime: String,
2123
}
2224

2325
pub fn execute_project(
@@ -34,6 +36,7 @@ pub fn execute_project(
3436
flag_p: config.flag_p,
3537
flag_verbose: config.flag_verbose,
3638
inspect_constraints: config.inspect_constraints_flag,
39+
prime : config.prime,
3740
};
3841
let (exporter, vcp) = build_circuit(program_archive, build_config)?;
3942
if config.r1cs_flag {

circom/src/input_user.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3636
const R1CS: &'static str = "r1cs";
3737
const WAT: &'static str = "wat";
3838
const WASM: &'static str = "wasm";
@@ -42,6 +42,7 @@ const DAT: &'static str = "dat";
4242
const SYM: &'static str = "sym";
4343
const JSON: &'static str = "json";
4444

45+
4546
impl 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
}
188193
mod 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
}

circom/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn start() -> Result<(), ()> {
3939
sym: user_input.sym_file().to_string(),
4040
r1cs: user_input.r1cs_file().to_string(),
4141
json_constraints: user_input.json_constraints_file().to_string(),
42+
prime: user_input.prime(),
4243
};
4344
let circuit = execution_user::execute_project(program_archive, config)?;
4445
let compilation_config = CompilerConfig {
@@ -47,10 +48,10 @@ fn start() -> Result<(), ()> {
4748
c_flag: user_input.c_flag(),
4849
wasm_flag: user_input.wasm_flag(),
4950
wat_flag: user_input.wat_flag(),
50-
js_folder: user_input.js_folder().to_string(),
51-
wasm_name: user_input.wasm_name().to_string(),
52-
c_folder: user_input.c_folder().to_string(),
53-
c_run_name: user_input.c_run_name().to_string(),
51+
js_folder: user_input.js_folder().to_string(),
52+
wasm_name: user_input.wasm_name().to_string(),
53+
c_folder: user_input.c_folder().to_string(),
54+
c_run_name: user_input.c_run_name().to_string(),
5455
c_file: user_input.c_file().to_string(),
5556
dat_file: user_input.dat_file().to_string(),
5657
wat_file: user_input.wat_file().to_string(),
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)