|
1 | | -use std::process::Command; |
| 1 | +use std::{env, process::Command}; |
2 | 2 |
|
3 | 3 | use circom_example::{aligned, config::EnvConfig, eth}; |
4 | 4 |
|
5 | 5 | #[tokio::main] |
6 | 6 | async fn main() { |
7 | | - // Adjust the path to your script if it's not in the same directory |
| 7 | + println!("==============================="); |
| 8 | + println!("Starting proof generation..."); |
| 9 | + println!("==============================="); |
| 10 | + |
| 11 | + // Run proof generation script |
8 | 12 | let status = Command::new("bash") |
9 | 13 | .arg("./circuits/generate_proof.sh") |
10 | 14 | .status() |
11 | 15 | .expect("failed to execute process"); |
12 | 16 |
|
13 | 17 | if status.success() { |
14 | | - println!("Script executed successfully!"); |
| 18 | + println!("Proof generation script executed successfully"); |
15 | 19 | } else { |
16 | 20 | println!("Script failed with status: {:?}", status.code()); |
| 21 | + return; |
17 | 22 | } |
18 | 23 |
|
19 | | - let config: EnvConfig = EnvConfig { |
20 | | - eth_rpc_url: "http://localhost:8545".to_string(), |
21 | | - private_key_store_path: "devnet_keystore.json".to_string(), |
22 | | - private_key_store_password: "".to_string(), |
23 | | - fibonacci_contract_address: "".to_string(), |
24 | | - network: aligned_sdk::common::types::Network::Devnet, |
| 24 | + // Handle custom .env file |
| 25 | + let args: Vec<String> = env::args().collect(); |
| 26 | + let custom_env = if args.len() > 1 { |
| 27 | + let env_file = args[1].to_string(); |
| 28 | + println!("Using custom .env file: {env_file}"); |
| 29 | + Some(env_file) |
| 30 | + } else { |
| 31 | + println!("Using default .env file (if present)"); |
| 32 | + None |
25 | 33 | }; |
26 | | - let proof = std::fs::read("circuits/proof.json").expect("proof to be created"); |
27 | | - let vk = |
28 | | - std::fs::read("circuits/verification_key.json").expect("verification key to be created"); |
| 34 | + |
| 35 | + let config: EnvConfig = EnvConfig::new(custom_env); |
| 36 | + |
| 37 | + // Load circuit artifacts |
| 38 | + println!("-------------------------------"); |
| 39 | + println!("Loading circuit artifacts..."); |
| 40 | + println!("-------------------------------"); |
| 41 | + |
| 42 | + let proof = std::fs::read("circuits/proof.json").expect("proof.json should exist"); |
| 43 | + let vk = std::fs::read("circuits/verification_key.json") |
| 44 | + .expect("verification_key.json should exist"); |
29 | 45 | let public_inputs_file = |
30 | | - std::fs::read("circuits/public.json").expect("public inputs to be created"); |
| 46 | + std::fs::read("circuits/public.json").expect("public.json should exist"); |
31 | 47 | let pub_inputs: Vec<String> = |
32 | | - serde_json::from_slice(&public_inputs_file).expect("parse inputs json"); |
| 48 | + serde_json::from_slice(&public_inputs_file).expect("could not parse inputs json"); |
33 | 49 | let decoded_inputs = aligned_sdk::common::utils::encode_circom_pub_inputs(&pub_inputs) |
34 | | - .expect("Inputs to be decoded"); |
| 50 | + .expect("inputs should be decoded"); |
35 | 51 |
|
| 52 | + println!("Submitting proof to Aligned..."); |
36 | 53 | let aligned_verification_data = |
37 | 54 | aligned::submit_proof_to_aligned(config.clone(), proof, vk, decoded_inputs.clone()).await; |
38 | 55 |
|
| 56 | + println!("Updating on-chain contract with proof result..."); |
39 | 57 | let receipt = |
40 | 58 | eth::update_number_on_contract(config, decoded_inputs, aligned_verification_data).await; |
41 | 59 |
|
42 | | - println!("RECEIPT HASH {}", receipt); |
| 60 | + println!("Done. Transaction receipt hash: {}", receipt); |
43 | 61 | } |
0 commit comments