Skip to content

Commit

Permalink
set default circuit size in dowload SRS script
Browse files Browse the repository at this point in the history
  • Loading branch information
madztheo committed Jul 23, 2024
1 parent 660c10d commit 2ca8bea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ This will download the SRS and package it into the app binary, and you'll be rea
**Why do I need to know the circuit with the highest gate count?**
The SRS is the same for all circuits, so you only need to download it once. But you only need a fraction of it according to the size of the circuit you are using. So instead of downloading the whole SRS, which is over 300MB, you can download the chunk of the SRS that is needed to prove the biggest circuit you plan to use. This way you will have a much smaller SRS file to store (likely less than 50MB).

**Note**: You can still download the SRS without specifying a circuit, just run `./scripts/download-srs.sh` without any argument. This will download the fraction of the SRS needed for a circuit of up to 512k constraints, which should be enough in most cases.

### You don't know which circuits you will use for now and just want to try things out

Then you can skip the process described above and the app will revert to fetching the SRS from Aztec's server. This is the default strategy used in the app. This approach will slow down the proof generation process, especially if you have a slow network connection. Also it is not recommended for production as you should not expect users to have a fast connection at all times and this may severely impact their data plan without them realizing it.
Expand Down
45 changes: 29 additions & 16 deletions scripts/srs_downloader/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
use noir_rs::{
srs::{Srs, localsrs::LocalSrs, netsrs::NetSrs, get_srs},
utils::get_subgroup_size
};
use serde_json::{Result, Value};
use noir_rs::srs::{Srs, localsrs::LocalSrs, netsrs::NetSrs, get_srs};
use serde_json::Value;

fn main() {
// Get the circuit path from the command line
let circuit_path = std::env::args().nth(1).expect("No circuit path provided");
// Read the JSON file into a buffer
let manifest = std::fs::read(circuit_path).expect("Failed to read circuit file");
// Decode the JSON buffer into a JSON object
let manifest_value: Value = serde_json::from_slice(&manifest).expect("Failed to decode JSON");
// Get the bytecode from the JSON object
let bytecode = manifest_value["bytecode"].as_str().expect("Failed to get bytecode");
let circuit_path = std::env::args().nth(1);

println!("Circuit decoded. Downloading SRS...");
let srs: Srs = get_srs(bytecode.to_string(), None);
let local_srs = LocalSrs(srs);
println!("SRS downloaded.");
let local_srs: LocalSrs;

match circuit_path {
Some(path) => {
// Read the JSON file into a buffer
let manifest = std::fs::read(path).expect("Failed to read circuit file");
// Decode the JSON buffer into a JSON object
let manifest_value: Value = serde_json::from_slice(&manifest).expect("Failed to decode JSON");
// Get the bytecode from the JSON object
let bytecode = manifest_value["bytecode"].as_str().expect("Failed to get bytecode");

println!("Circuit decoded. Downloading SRS...");
let srs: Srs = get_srs(bytecode.to_string(), None);
local_srs = LocalSrs(srs);
println!("SRS downloaded.");
},
None => {
println!("No path provided, using default circuit size");
println!("Downloading SRS...");
// Default to 512k constraints, which should be enough for most circuits
// that can work on a mobile device
let srs: Srs = NetSrs::new(512_000).to_srs();
local_srs = LocalSrs(srs);
println!("SRS downloaded.");
}
}

let save_path = "./scripts/srs.local";
local_srs.save(Some(&save_path));
Expand Down

0 comments on commit 2ca8bea

Please sign in to comment.