-
Notifications
You must be signed in to change notification settings - Fork 387
feat(nargo): Consume CommonReferenceString functions & manage caching #1348
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da2525d
feat(nargo): Only download as much CRS as you need
phated b6b2c6c
update references
phated 7439e39
code review
phated 2ac6352
Merge branch 'master' into phated/ref-string
TomAFrench 2cf7e16
Merge branch 'phated/acvm-0.12.0' into phated/ref-string
TomAFrench 4e66b82
split crs utilities into 3 functions to isolate read and write ops
phated ecc8806
change env var to include nargo name
phated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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], | ||
|
phated marked this conversation as resolved.
|
||
| 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) | ||
| }; | ||
|
TomAFrench marked this conversation as resolved.
|
||
|
|
||
| runtime.block_on(fut) | ||
| } | ||
|
|
||
| pub(crate) fn write_cached_common_reference_string(common_reference_string: &[u8]) { | ||
|
phated marked this conversation as resolved.
|
||
| 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.