Skip to content

Commit

Permalink
adding new primes for working with different curves
Browse files Browse the repository at this point in the history
  • Loading branch information
clararod9 committed Jun 3, 2022
1 parent c15805f commit e8e606a
Show file tree
Hide file tree
Showing 61 changed files with 35,040 additions and 141 deletions.
3 changes: 3 additions & 0 deletions circom/src/execution_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use constraint_writers::debug_writer::DebugWriter;
use constraint_writers::ConstraintExporter;
use program_structure::program_archive::ProgramArchive;


pub struct ExecutionConfig {
pub r1cs: String,
pub sym: String,
Expand All @@ -18,6 +19,7 @@ pub struct ExecutionConfig {
pub r1cs_flag: bool,
pub json_substitution_flag: bool,
pub json_constraint_flag: bool,
pub prime: String,
}

pub fn execute_project(
Expand All @@ -34,6 +36,7 @@ pub fn execute_project(
flag_p: config.flag_p,
flag_verbose: config.flag_verbose,
inspect_constraints: config.inspect_constraints_flag,
prime : config.prime,
};
let (exporter, vcp) = build_circuit(program_archive, build_config)?;
if config.r1cs_flag {
Expand Down
57 changes: 45 additions & 12 deletions circom/src/input_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Input {
pub out_c_code: PathBuf,
pub out_c_dat: PathBuf,
pub out_sym: PathBuf,
pub field: &'static str,
//pub field: &'static str,
pub c_flag: bool,
pub wasm_flag: bool,
pub wat_flag: bool,
Expand All @@ -29,10 +29,10 @@ pub struct Input {
pub inspect_constraints_flag: bool,
pub no_rounds: usize,
pub flag_verbose: bool,
pub prime: String,
}

const P_0: &'static str =
"21888242871839275222246405745257275088548364400416034343698204186575808495617";

const R1CS: &'static str = "r1cs";
const WAT: &'static str = "wat";
const WASM: &'static str = "wasm";
Expand All @@ -42,6 +42,7 @@ const DAT: &'static str = "dat";
const SYM: &'static str = "sym";
const JSON: &'static str = "json";


impl Input {
pub fn new() -> Result<Input, ()> {
use input_processing::SimplificationStyle;
Expand All @@ -53,15 +54,15 @@ impl Input {
let output_js_path = Input::build_folder(&output_path, &file_name, JS);
let o_style = input_processing::get_simplification_style(&matches)?;
Result::Ok(Input {
field: P_0,
//field: P_BN128,
input_program: input,
out_r1cs: Input::build_output(&output_path, &file_name, R1CS),
out_wat_code: Input::build_output(&output_js_path, &file_name, WAT),
out_wasm_code: Input::build_output(&output_js_path, &file_name, WASM),
out_js_folder: output_js_path.clone(),
out_wasm_name: file_name.clone(),
out_c_folder: output_c_path.clone(),
out_c_run_name: file_name.clone(),
out_js_folder: output_js_path.clone(),
out_wasm_name: file_name.clone(),
out_c_folder: output_c_path.clone(),
out_c_run_name: file_name.clone(),
out_c_code: Input::build_output(&output_c_path, &file_name, CPP),
out_c_dat: Input::build_output(&output_c_path, &file_name, DAT),
out_sym: Input::build_output(&output_path, &file_name, SYM),
Expand All @@ -84,15 +85,16 @@ impl Input {
reduced_simplification_flag: o_style == SimplificationStyle::O1,
parallel_simplification_flag: input_processing::get_parallel_simplification(&matches),
inspect_constraints_flag: input_processing::get_inspect_constraints(&matches),
flag_verbose: input_processing::get_flag_verbose(&matches)
flag_verbose: input_processing::get_flag_verbose(&matches),
prime: input_processing::get_prime(&matches)?,
})
}

fn build_folder(output_path: &PathBuf, filename: &str, ext: &str) -> PathBuf {
let mut file = output_path.clone();
let folder_name = format!("{}_{}",filename,ext);
file.push(folder_name);
file
let folder_name = format!("{}_{}",filename,ext);
file.push(folder_name);
file
}

fn build_output(output_path: &PathBuf, filename: &str, ext: &str) -> PathBuf {
Expand Down Expand Up @@ -184,6 +186,9 @@ impl Input {
pub fn no_rounds(&self) -> usize {
self.no_rounds
}
pub fn prime(&self) -> String{
self.prime.clone()
}
}
mod input_processing {
use ansi_term::Colour;
Expand Down Expand Up @@ -279,6 +284,26 @@ mod input_processing {
matches.is_present("flag_verbose")
}

pub fn get_prime(matches: &ArgMatches) -> Result<String, ()> {

match matches.is_present("prime"){
true =>
{
let prime_value = matches.value_of("prime").unwrap();
if prime_value == "bn128"
|| prime_value == "bls12381"
|| prime_value == "goldilocks"{
Ok(String::from(matches.value_of("prime").unwrap()))
}
else{
Result::Err(eprintln!("{}", Colour::Red.paint("invalid prime number")))
}
}

false => Ok(String::from("bn128")),
}
}

pub fn view() -> ArgMatches<'static> {
App::new("circom compiler")
.version(VERSION)
Expand Down Expand Up @@ -397,6 +422,14 @@ mod input_processing {
.takes_value(false)
.help("Shows logs during compilation"),
)
.arg (
Arg::with_name("prime")
.short("prime")
.long("prime")
.takes_value(true)
.default_value("bn128")
.help("To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks)"),
)
.get_matches()
}
}
1 change: 1 addition & 0 deletions circom/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn start() -> Result<(), ()> {
sym: user_input.sym_file().to_string(),
r1cs: user_input.r1cs_file().to_string(),
json_constraints: user_input.json_constraints_file().to_string(),
prime: user_input.prime(),
};
let circuit = execution_user::execute_project(program_archive, config)?;
let compilation_config = CompilerConfig {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e8e606a

Please sign in to comment.