Skip to content

Commit b879b6f

Browse files
feat(zkstack): Generating keys for compressor (#4301)
## What ❔ Added zkstack feature to generate keys for compressor <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ There is no functionality in zkstack to generate keys for compressor. <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- The `Why` has to be clear to non-Matter Labs entities running their own ZK Chain --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Is this a breaking change? - [ ] Yes - [ ] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## 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 `zkstack dev fmt` and `zkstack dev lint`.
1 parent 0463de4 commit b879b6f

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

zkstack_cli/crates/config/src/general.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ impl GeneralConfigPatch {
211211
.get("proof_compressor.universal_setup_download_url")
212212
}
213213

214+
pub fn proof_compressor_setup_path(&self) -> anyhow::Result<PathBuf> {
215+
self.0.base().get("proof_compressor.universal_setup_path")
216+
}
217+
214218
pub fn set_proof_compressor_setup_path(&mut self, path: &Path) -> anyhow::Result<()> {
215219
self.0
216220
.insert_path("proof_compressor.universal_setup_path", path)

zkstack_cli/crates/zkstack/src/commands/prover/setup_keys.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
use anyhow::Ok;
1+
use anyhow::{Context, Ok};
22
use xshell::{cmd, Shell};
33
use zkstack_cli_common::{
44
check_prerequisites, cmd::Cmd, logger, spinner::Spinner, GCLOUD_PREREQUISITE, GPU_PREREQUISITES,
55
};
66
use zkstack_cli_config::{get_link_to_prover, EcosystemConfig};
77

88
use crate::{
9-
commands::prover::args::setup_keys::{Mode, Region, SetupKeysArgs},
10-
messages::{MSG_GENERATING_SK_SPINNER, MSG_SK_GENERATED},
9+
commands::prover::{
10+
args::setup_keys::{Mode, Region, SetupKeysArgs},
11+
compressor_keys::download_compressor_key,
12+
},
13+
messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_GENERATING_SK_SPINNER, MSG_SK_GENERATED},
1114
};
1215

1316
pub(crate) async fn run(args: SetupKeysArgs, shell: &Shell) -> anyhow::Result<()> {
@@ -16,6 +19,27 @@ pub(crate) async fn run(args: SetupKeysArgs, shell: &Shell) -> anyhow::Result<()
1619

1720
if args.mode == Mode::Generate {
1821
check_prerequisites(shell, &GPU_PREREQUISITES, false);
22+
let chain_config = ecosystem_config
23+
.load_current_chain()
24+
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
25+
let mut general_config = chain_config.get_general_config().await?.patched();
26+
let proof_compressor_setup_path = general_config
27+
.proof_compressor_setup_path()
28+
.context("proof_compressor_setup_path")?;
29+
if proof_compressor_setup_path.exists() {
30+
logger::info(format!(
31+
"Initial proof compressor setup already present at {}",
32+
proof_compressor_setup_path.display()
33+
));
34+
} else {
35+
logger::info(format!(
36+
"Initial proof compressor setup not found at {}, downloading",
37+
proof_compressor_setup_path.display()
38+
));
39+
download_compressor_key(shell, &mut general_config, &proof_compressor_setup_path)?;
40+
}
41+
std::env::set_var("COMPACT_CRS_FILE", &proof_compressor_setup_path);
42+
1943
let link_to_prover = get_link_to_prover(&ecosystem_config);
2044
shell.change_dir(&link_to_prover);
2145

@@ -28,6 +52,12 @@ pub(crate) async fn run(args: SetupKeysArgs, shell: &Shell) -> anyhow::Result<()
2852
--path={link_to_prover}/data/keys"
2953
));
3054
cmd.run()?;
55+
let cmd = Cmd::new(cmd!(
56+
shell,
57+
"cargo run --features gpu --release --bin key_generator --
58+
generate-compressor-data"
59+
));
60+
cmd.run()?;
3161
spinner.finish();
3262
logger::outro(MSG_SK_GENERATED);
3363
} else {

0 commit comments

Comments
 (0)