-
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): Add setup keys step to prover init (#2811)
## What ❔ Add setup keys step to prover init
- Loading branch information
1 parent
b8d4424
commit 0a9e096
Showing
10 changed files
with
214 additions
and
126 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
zk_toolbox/crates/zk_inception/src/commands/prover/args/compressor_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,22 @@ | ||
use clap::Parser; | ||
use common::Prompt; | ||
|
||
use crate::messages::MSG_SETUP_COMPRESSOR_KEY_PATH_PROMPT; | ||
|
||
#[derive(Debug, Clone, Parser, Default)] | ||
pub struct CompressorKeysArgs { | ||
#[clap(long)] | ||
pub path: Option<String>, | ||
} | ||
|
||
impl CompressorKeysArgs { | ||
pub fn fill_values_with_prompt(self, default: &str) -> CompressorKeysArgs { | ||
let path = self.path.unwrap_or_else(|| { | ||
Prompt::new(MSG_SETUP_COMPRESSOR_KEY_PATH_PROMPT) | ||
.default(default) | ||
.ask() | ||
}); | ||
|
||
CompressorKeysArgs { path: Some(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
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 compressor_keys; | ||
pub mod init; | ||
pub mod init_bellman_cuda; | ||
pub mod run; | ||
|
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
73 changes: 73 additions & 0 deletions
73
zk_toolbox/crates/zk_inception/src/commands/prover/compressor_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,73 @@ | ||
use anyhow::Context; | ||
use common::{ | ||
check_prerequisites, cmd::Cmd, config::global_config, spinner::Spinner, WGET_PREREQUISITES, | ||
}; | ||
use config::{EcosystemConfig, GeneralConfig}; | ||
use xshell::{cmd, Shell}; | ||
|
||
use super::{args::compressor_keys::CompressorKeysArgs, utils::get_link_to_prover}; | ||
use crate::messages::{ | ||
MSG_CHAIN_NOT_FOUND_ERR, MSG_DOWNLOADING_SETUP_COMPRESSOR_KEY_SPINNER, | ||
MSG_PROOF_COMPRESSOR_CONFIG_NOT_FOUND_ERR, MSG_SETUP_KEY_PATH_ERROR, | ||
}; | ||
|
||
pub(crate) async fn run(shell: &Shell, args: CompressorKeysArgs) -> anyhow::Result<()> { | ||
let ecosystem_config = EcosystemConfig::from_file(shell)?; | ||
let chain_config = ecosystem_config | ||
.load_chain(global_config().chain_name.clone()) | ||
.context(MSG_CHAIN_NOT_FOUND_ERR)?; | ||
let mut general_config = chain_config.get_general_config()?; | ||
|
||
let default_path = get_default_compressor_keys_path(&ecosystem_config)?; | ||
let args = args.fill_values_with_prompt(&default_path); | ||
|
||
download_compressor_key( | ||
shell, | ||
&mut general_config, | ||
&args.path.context(MSG_SETUP_KEY_PATH_ERROR)?, | ||
)?; | ||
|
||
chain_config.save_general_config(&general_config)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn download_compressor_key( | ||
shell: &Shell, | ||
general_config: &mut GeneralConfig, | ||
path: &str, | ||
) -> anyhow::Result<()> { | ||
check_prerequisites(shell, &WGET_PREREQUISITES, false); | ||
let spinner = Spinner::new(MSG_DOWNLOADING_SETUP_COMPRESSOR_KEY_SPINNER); | ||
let mut compressor_config: zksync_config::configs::FriProofCompressorConfig = general_config | ||
.proof_compressor_config | ||
.as_ref() | ||
.expect(MSG_PROOF_COMPRESSOR_CONFIG_NOT_FOUND_ERR) | ||
.clone(); | ||
compressor_config.universal_setup_path = path.to_string(); | ||
general_config.proof_compressor_config = Some(compressor_config.clone()); | ||
|
||
let url = compressor_config.universal_setup_download_url; | ||
let path = std::path::Path::new(path); | ||
let parent = path.parent().expect(MSG_SETUP_KEY_PATH_ERROR); | ||
let file_name = path.file_name().expect(MSG_SETUP_KEY_PATH_ERROR); | ||
|
||
Cmd::new(cmd!(shell, "wget {url} -P {parent}")).run()?; | ||
|
||
if file_name != "setup_2^24.key" { | ||
Cmd::new(cmd!(shell, "mv {parent}/setup_2^24.key {path}")).run()?; | ||
} | ||
|
||
spinner.finish(); | ||
Ok(()) | ||
} | ||
|
||
pub fn get_default_compressor_keys_path( | ||
ecosystem_config: &EcosystemConfig, | ||
) -> anyhow::Result<String> { | ||
let link_to_prover = get_link_to_prover(ecosystem_config); | ||
let path = link_to_prover.join("keys/setup/setup_2^24.key"); | ||
let string = path.to_str().unwrap(); | ||
|
||
Ok(String::from(string)) | ||
} |
Oops, something went wrong.