-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): Ease requirements, add option to download setup keys (
#2784) ## What ❔ Make some of the prerequisites in prover subcommand optional(checks are enforced only when the prerequisite is needed) Add option to download setup keys instead of generating ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`.
- Loading branch information
1 parent
35e4cae
commit 4a4d87e
Showing
13 changed files
with
188 additions
and
60 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod init; | ||
pub mod init_bellman_cuda; | ||
pub mod run; | ||
pub mod setup_keys; |
53 changes: 53 additions & 0 deletions
53
zk_toolbox/crates/zk_inception/src/commands/prover/args/setup_keys.rs
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,53 @@ | ||
use clap::{Parser, ValueEnum}; | ||
use common::PromptSelect; | ||
use strum::{EnumIter, IntoEnumIterator}; | ||
|
||
use crate::messages::{MSG_SETUP_KEYS_DOWNLOAD_HELP, MSG_SETUP_KEYS_REGION_PROMPT}; | ||
|
||
#[derive(Debug, Clone, Parser, Default)] | ||
pub struct SetupKeysArgs { | ||
#[clap(long)] | ||
pub region: Option<Region>, | ||
#[clap(long)] | ||
pub mode: Option<Mode>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct SetupKeysArgsFinal { | ||
pub region: Option<Region>, | ||
pub mode: Mode, | ||
} | ||
|
||
#[derive(Debug, Clone, ValueEnum, strum::EnumString, EnumIter, PartialEq, Eq, strum::Display)] | ||
pub enum Mode { | ||
Download, | ||
Generate, | ||
} | ||
|
||
#[derive(Debug, Clone, ValueEnum, strum::EnumString, EnumIter, PartialEq, Eq, strum::Display)] | ||
pub enum Region { | ||
Us, | ||
Europe, | ||
Asia, | ||
} | ||
|
||
impl SetupKeysArgs { | ||
pub fn fill_values_with_prompt(self) -> SetupKeysArgsFinal { | ||
let mode = self | ||
.mode | ||
.unwrap_or_else(|| PromptSelect::new(MSG_SETUP_KEYS_DOWNLOAD_HELP, Mode::iter()).ask()); | ||
|
||
if mode == Mode::Download { | ||
let region = self.region.unwrap_or_else(|| { | ||
PromptSelect::new(MSG_SETUP_KEYS_REGION_PROMPT, Region::iter()).ask() | ||
}); | ||
|
||
SetupKeysArgsFinal { | ||
region: Some(region), | ||
mode, | ||
} | ||
} else { | ||
SetupKeysArgsFinal { region: None, mode } | ||
} | ||
} | ||
} |
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
29 changes: 0 additions & 29 deletions
29
zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs
This file was deleted.
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
83 changes: 83 additions & 0 deletions
83
zk_toolbox/crates/zk_inception/src/commands/prover/setup_keys.rs
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,83 @@ | ||
use anyhow::Ok; | ||
use common::{ | ||
check_prerequisites, cmd::Cmd, logger, spinner::Spinner, GCLOUD_PREREQUISITES, | ||
GPU_PREREQUISITES, | ||
}; | ||
use config::EcosystemConfig; | ||
use xshell::{cmd, Shell}; | ||
|
||
use super::utils::get_link_to_prover; | ||
use crate::{ | ||
commands::prover::args::setup_keys::{Mode, Region, SetupKeysArgs}, | ||
messages::{MSG_GENERATING_SK_SPINNER, MSG_SK_GENERATED}, | ||
}; | ||
|
||
pub(crate) async fn run(args: SetupKeysArgs, shell: &Shell) -> anyhow::Result<()> { | ||
let args = args.fill_values_with_prompt(); | ||
let ecosystem_config = EcosystemConfig::from_file(shell)?; | ||
|
||
if args.mode == Mode::Generate { | ||
check_prerequisites(shell, &GPU_PREREQUISITES, false); | ||
let link_to_prover = get_link_to_prover(&ecosystem_config); | ||
shell.change_dir(&link_to_prover); | ||
|
||
let spinner = Spinner::new(MSG_GENERATING_SK_SPINNER); | ||
let cmd = Cmd::new(cmd!( | ||
shell, | ||
"cargo run --features gpu --release --bin key_generator -- | ||
generate-sk-gpu all --recompute-if-missing | ||
--setup-path=data/keys | ||
--path={link_to_prover}/data/keys" | ||
)); | ||
cmd.run()?; | ||
spinner.finish(); | ||
logger::outro(MSG_SK_GENERATED); | ||
} else { | ||
check_prerequisites(shell, &GCLOUD_PREREQUISITES, false); | ||
|
||
let link_to_setup_keys = get_link_to_prover(&ecosystem_config).join("data/keys"); | ||
let path_to_keys_buckets = | ||
get_link_to_prover(&ecosystem_config).join("setup-data-gpu-keys.json"); | ||
|
||
let region = args.region.expect("Region is not provided"); | ||
|
||
let file = shell | ||
.read_file(path_to_keys_buckets) | ||
.expect("Could not find commitments file in zksync-era"); | ||
let json: serde_json::Value = | ||
serde_json::from_str(&file).expect("Could not parse commitments.json"); | ||
|
||
let bucket = &match region { | ||
Region::Us => json | ||
.get("us") | ||
.expect("Could not find link to US bucket") | ||
.to_string(), | ||
Region::Europe => json | ||
.get("europe") | ||
.expect("Could not find link to Europe bucket") | ||
.to_string(), | ||
Region::Asia => json | ||
.get("asia") | ||
.expect("Could not find link to Asia bucket") | ||
.to_string(), | ||
}; | ||
|
||
let len = bucket.len() - 2usize; | ||
let bucket = &bucket[1..len]; | ||
|
||
let spinner = Spinner::new(&format!( | ||
"Downloading keys from bucket: {} to {:?}", | ||
bucket, link_to_setup_keys | ||
)); | ||
|
||
let cmd = Cmd::new(cmd!( | ||
shell, | ||
"gsutil -m rsync -r {bucket} {link_to_setup_keys}" | ||
)); | ||
cmd.run()?; | ||
spinner.finish(); | ||
logger::outro("Keys are downloaded"); | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.