Skip to content
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:input file for cli #18

Merged
merged 9 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ Cargo.lock
*.pdb
.DS_Store

/*.json

# Local
.env
13 changes: 1 addition & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/target/debug/circom",
"args": [],
"miDebuggerPath": "/usr/bin/lldb",
"cwd": "${workspaceFolder}"
},

{
"type": "lldb",
"request": "launch",
Expand All @@ -29,7 +18,7 @@
"kind": "bin"
}
},
"args": [],
"args": ["${workspaceFolder}/src/assets/circuit.circom"],
"cwd": "${workspaceFolder}"
},
]
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ mpz-circuits = { git = "https://github.com/privacy-scaling-explorations/mpz", p
[[bin]]
name="circom"
path="./src/main.rs"

6 changes: 3 additions & 3 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ impl ArithmeticCircuit {
let serialized = serde_json::to_string(&self).unwrap();

// Prints serialized = {"x":1,"y":2}
println!("serialized = {}", serialized);
println!("{}", serialized);

// Convert the JSON string back to a Point.
let deserialized: ArithmeticCircuit = serde_json::from_str(&serialized).unwrap();
// let deserialized: ArithmeticCircuit = serde_json::from_str(&serialized).unwrap();

// Prints deserialized = Point { x: 1, y: 2 }
println!("deserialized = {:#?}", deserialized);
// println!("deserialized = {:#?}", deserialized);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub fn execute_project(
pub struct Input {
pub input_program: PathBuf,
pub out_r1cs: PathBuf,
pub out_mpc: PathBuf,
pub out_json_constraints: PathBuf,
pub out_wat_code: PathBuf,
pub out_wasm_code: PathBuf,
Expand Down Expand Up @@ -153,6 +154,7 @@ impl Default for Input {
input_program,
out_r1cs: PathBuf::from("./assets/tmp"),
out_json_constraints: PathBuf::from("./assets/tmp"),
out_mpc: PathBuf::from("./assets/tmp"),
out_wat_code: PathBuf::from("./assets/tmp"),
out_wasm_code: PathBuf::from("./assets/tmp"),
out_wasm_name: String::from("./assets/tmp"),
Expand Down Expand Up @@ -198,6 +200,7 @@ impl Input {
Result::Ok(Input {
//field: P_BN128,
input_program: input,
out_mpc: Input::build_output(&output_path, &file_name, JSON),
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),
Expand Down Expand Up @@ -347,7 +350,7 @@ impl Input {
}

pub fn get_input(matches: &ArgMatches) -> Result<PathBuf, ()> {
println!("{:?}", matches.value_of("input"));
// println!("{:?}", matches.value_of("input"));
let route = Path::new(matches.value_of("input").unwrap()).to_path_buf();
if route.is_file() {
Result::Ok(route)
Expand Down
24 changes: 20 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use circom_2_arithc::program::parse_circom;
use std::fs::File;

use circom_2_arithc::{compiler::Input, program::parse_circom};
use dotenv::dotenv;
use env_logger::{init_from_env, Env};
use std::io::Write;

fn main() {
fn main() -> Result<(), ()> {
dotenv().ok();
init_from_env(Env::default().filter_or("LOG_LEVEL", "info"));

parse_circom().unwrap()
let input = Input::new()?;
match parse_circom(&input) {
Err(err) => {
println!("Error {}", err);
Ok(())
},
Ok(cir) => {
let output_name = input.out_mpc;
let mut data_file = File::create(output_name).expect("Creation file failed!");
data_file
.write_all(serde_json::to_string(&cir).unwrap().as_bytes())
.expect("Write file failed!");
Ok(())
}
}
}
Loading
Loading