-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nargo): Consume CommonReferenceString functions & manage caching (…
- Loading branch information
Showing
18 changed files
with
358 additions
and
132 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::{env, path::PathBuf}; | ||
|
||
use acvm::{acir::circuit::Circuit, CommonReferenceString}; | ||
|
||
use super::{create_named_dir, write_to_file}; | ||
|
||
// TODO: pull this from backend. | ||
const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; | ||
const TRANSCRIPT_NAME: &str = "common-reference-string.bin"; | ||
|
||
fn common_reference_string_location() -> PathBuf { | ||
let cache_dir = match env::var("NARGO_BACKEND_CACHE_DIR") { | ||
Ok(cache_dir) => PathBuf::from(cache_dir), | ||
Err(_) => dirs::home_dir().unwrap().join(".nargo").join("backends"), | ||
}; | ||
cache_dir.join(BACKEND_IDENTIFIER).join(TRANSCRIPT_NAME) | ||
} | ||
|
||
pub(crate) fn read_cached_common_reference_string() -> Vec<u8> { | ||
let crs_path = common_reference_string_location(); | ||
|
||
// TODO: Implement checksum | ||
match std::fs::read(crs_path) { | ||
Ok(common_reference_string) => common_reference_string, | ||
Err(_) => vec![], | ||
} | ||
} | ||
|
||
pub(crate) fn update_common_reference_string<B: CommonReferenceString>( | ||
backend: &B, | ||
common_reference_string: &[u8], | ||
circuit: &Circuit, | ||
) -> Result<Vec<u8>, B::Error> { | ||
use tokio::runtime::Builder; | ||
|
||
let runtime = Builder::new_current_thread().enable_all().build().unwrap(); | ||
|
||
// TODO: Implement retries | ||
// If the read data is empty, we don't have a CRS and need to generate one | ||
let fut = if common_reference_string.is_empty() { | ||
backend.generate_common_reference_string(circuit) | ||
} else { | ||
backend.update_common_reference_string(common_reference_string.to_vec(), circuit) | ||
}; | ||
|
||
runtime.block_on(fut) | ||
} | ||
|
||
pub(crate) fn write_cached_common_reference_string(common_reference_string: &[u8]) { | ||
let crs_path = common_reference_string_location(); | ||
|
||
create_named_dir(crs_path.parent().unwrap(), "crs"); | ||
|
||
write_to_file(common_reference_string, &crs_path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.