iden3/circom

adding new primes

nickz-t3 opened this issue · 0 comments

Hi, I tried to add a prime (PR here).

  1. Better to refactor the code and make the primes an enum types. Then we can use the match statement everywhere we use primes without the "_" in the end. Then adding new primes would feel like a breeze.
  2. Is there a generator for cpp and wasm code_elements? How to launch it? shall we add it to build.rs? it would work well with enum
  3. why is there even a choice here
@@ -850,14 +851,15 @@ pub fn generate_fr_cpp_file(c_folder: &PathBuf, prime: &String) -> std::io::Resu
    let file_name = file_path.to_str().unwrap();
    let mut c_file = BufWriter::new(File::create(file_name).unwrap());
    let mut code = "".to_string();
    let file = match prime.as_ref() {
        "bn128" => include_str!("bn128/fr.cpp"),
        "bls12381" => include_str!("bls12381/fr.cpp"),
        "goldilocks" => include_str!("goldilocks/fr.cpp"),
        "grumpkin" => include_str!("grumpkin/fr.cpp"),
        "pallas" => include_str!("pallas/fr.cpp"),
        "secq256k1" => include_str!("secq256k1/fr.cpp"),
        "vesta" => include_str!("vesta/fr.cpp"),        
        _ => unreachable!(),
    };
    for line in file.lines() {
@@ -893,15 +895,16 @@ pub fn generate_fr_asm_file(c_folder: &PathBuf, prime: &String) -> std::io::Resu
    let file_name = file_path.to_str().unwrap();
    let mut c_file = BufWriter::new(File::create(file_name).unwrap());
    let mut code = "".to_string();
    let file = match prime.as_ref() {
        "bn128" => include_str!("bn128/fr.asm"),
        "bls12381" => include_str!("bls12381/fr.asm"),
        "goldilocks" => include_str!("goldilocks/fr.asm"),
        "grumpkin" => include_str!("grumpkin/fr.asm"),
        "pallas" => include_str!("pallas/fr.asm"),
        "secq256k1" => include_str!("secq256k1/fr.asm"),
        "vesta" => include_str!("vesta/fr.asm"),
        _ => unreachable!(),
    };    

aren't these files all same?