From a5e858c56b591f7ef987ec929f386163be6e8c65 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:52:04 +0300 Subject: [PATCH 01/31] make prover run without core --- zk_toolbox/crates/config/src/secrets.rs | 12 +++ .../src/commands/chain/args/init.rs | 14 ++- .../zk_inception/src/commands/chain/init.rs | 4 +- .../src/commands/prover/args/init.rs | 71 +++++++++++++++- .../zk_inception/src/commands/prover/init.rs | 85 ++++++++++++++++--- .../zk_inception/src/commands/prover/run.rs | 2 +- .../crates/zk_inception/src/messages.rs | 1 + 7 files changed, 173 insertions(+), 16 deletions(-) diff --git a/zk_toolbox/crates/config/src/secrets.rs b/zk_toolbox/crates/config/src/secrets.rs index 5bcad19ad339..f0a39148b034 100644 --- a/zk_toolbox/crates/config/src/secrets.rs +++ b/zk_toolbox/crates/config/src/secrets.rs @@ -26,6 +26,18 @@ pub fn set_databases( Ok(()) } +pub fn set_prover_database( + secrets: &mut SecretsConfig, + prover_db_config: &DatabaseConfig, +) -> anyhow::Result<()> { + let database = secrets + .database + .as_mut() + .context("Databases must be presented")?; + database.prover_url = Some(SensitiveUrl::from(prover_db_config.full_url())); + Ok(()) +} + pub fn set_l1_rpc_url(secrets: &mut SecretsConfig, l1_rpc_url: String) -> anyhow::Result<()> { secrets .l1 diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs index 0700c96c76ec..2df6020561cb 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs @@ -10,8 +10,8 @@ use crate::{ commands::chain::args::genesis::GenesisArgs, defaults::LOCAL_RPC_URL, messages::{ - MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, - MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, + MSG_COPY_CONFIGS_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, + MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, }, }; @@ -28,6 +28,8 @@ pub struct InitArgs { pub deploy_paymaster: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, + #[clap(long)] + pub copy_configs: Option, } impl InitArgs { @@ -52,11 +54,18 @@ impl InitArgs { .ask() }); + let copy_configs = self.copy_configs.unwrap_or_else(|| { + common::PromptConfirm::new(MSG_COPY_CONFIGS_PROMPT) + .default(true) + .ask() + }); + InitArgsFinal { forge_args: self.forge_args, genesis_args: self.genesis_args.fill_values_with_prompt(config), deploy_paymaster, l1_rpc_url, + copy_configs, } } } @@ -67,4 +76,5 @@ pub struct InitArgsFinal { pub genesis_args: GenesisArgsFinal, pub deploy_paymaster: bool, pub l1_rpc_url: String, + pub copy_configs: bool, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index b3b43c75c36a..81d831d83d9d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -58,7 +58,9 @@ pub async fn init( ecosystem_config: &EcosystemConfig, chain_config: &ChainConfig, ) -> anyhow::Result<()> { - copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; + if init_args.copy_configs { + copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; + } let mut genesis_config = chain_config.get_genesis_config()?; update_from_chain_config(&mut genesis_config, chain_config); diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index cef435625716..fbde4d9ae54c 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -1,6 +1,8 @@ use clap::{Parser, ValueEnum}; -use common::{logger, Prompt, PromptConfirm, PromptSelect}; +use common::{db::DatabaseConfig, logger, Prompt, PromptConfirm, PromptSelect}; +use config::ChainConfig; use serde::{Deserialize, Serialize}; +use slugify_rs::slugify; use strum::{EnumIter, IntoEnumIterator}; use xshell::Shell; use zksync_config::configs::fri_prover::CloudConnectionMode; @@ -9,8 +11,10 @@ use super::init_bellman_cuda::InitBellmanCudaArgs; use crate::{ commands::prover::gcs::get_project_ids, consts::{DEFAULT_CREDENTIALS_FILE, DEFAULT_PROOF_STORE_DIR}, + defaults::{generate_db_names, DBNames, DATABASE_PROVER_URL}, messages::{ - MSG_CLOUD_TYPE_PROMPT, MSG_CREATE_GCS_BUCKET_LOCATION_PROMPT, + msg_prover_db_name_prompt, msg_prover_db_url_prompt, MSG_CLOUD_TYPE_PROMPT, + MSG_COPY_CONFIGS_PROMPT, MSG_CREATE_GCS_BUCKET_LOCATION_PROMPT, MSG_CREATE_GCS_BUCKET_NAME_PROMTP, MSG_CREATE_GCS_BUCKET_PROJECT_ID_NO_PROJECTS_PROMPT, MSG_CREATE_GCS_BUCKET_PROJECT_ID_PROMPT, MSG_CREATE_GCS_BUCKET_PROMPT, MSG_DOWNLOAD_SETUP_KEY_PROMPT, MSG_GETTING_PROOF_STORE_CONFIG, @@ -54,6 +58,12 @@ pub struct ProverInitArgs { #[serde(flatten)] pub setup_key_config: SetupKeyConfigTmp, + #[clap(long)] + pub copy_configs: Option, + + #[clap(long)] + pub setup_database: Option, + #[clap(long)] cloud_type: Option, } @@ -160,6 +170,12 @@ pub struct SetupKeyConfig { pub setup_key_path: String, } +#[derive(Debug, Clone)] +pub struct ProverDatabaseConfig { + pub database_config: DatabaseConfig, + pub dont_drop: bool, +} + #[derive(Debug, Clone)] pub struct ProverInitArgsFinal { pub proof_store: ProofStorageConfig, @@ -167,6 +183,8 @@ pub struct ProverInitArgsFinal { pub setup_key_config: SetupKeyConfig, pub bellman_cuda_config: InitBellmanCudaArgs, pub cloud_type: CloudConnectionMode, + pub copy_configs: bool, + pub database_config: Option, } impl ProverInitArgs { @@ -174,12 +192,15 @@ impl ProverInitArgs { &self, shell: &Shell, setup_key_path: &str, + chain_config: &ChainConfig, ) -> anyhow::Result { let proof_store = self.fill_proof_storage_values_with_prompt(shell)?; let public_store = self.fill_public_storage_values_with_prompt(shell)?; let setup_key_config = self.fill_setup_key_values_with_prompt(setup_key_path); let bellman_cuda_config = self.fill_bellman_cuda_values_with_prompt()?; let cloud_type = self.get_cloud_type_with_prompt(); + let copy_configs = self.ask_copy_configs(); + let database_config = self.fill_database_values_with_prompt(chain_config); Ok(ProverInitArgsFinal { proof_store, @@ -187,6 +208,8 @@ impl ProverInitArgs { setup_key_config, bellman_cuda_config, cloud_type, + copy_configs, + database_config, }) } @@ -440,4 +463,48 @@ impl ProverInitArgs { cloud_type.into() } + + fn ask_copy_configs(&self) -> bool { + self.copy_configs + .unwrap_or_else(|| PromptConfirm::new(MSG_COPY_CONFIGS_PROMPT).ask()) + } + + fn fill_database_values_with_prompt( + &self, + config: &ChainConfig, + ) -> Option { + let setup_database = self + .setup_database + .unwrap_or_else(|| PromptConfirm::new("Do you want to setup the database?").ask()); + + if setup_database { + let DBNames { prover_name, .. } = generate_db_names(config); + let chain_name = config.name.clone(); + + let dont_drop = !PromptConfirm::new("Do you want to drop the database?").ask(); + + if PromptConfirm::new("Do you want to use default database?").ask() { + Some(ProverDatabaseConfig { + database_config: DatabaseConfig::new(DATABASE_PROVER_URL.clone(), prover_name), + dont_drop, + }) + } else { + let prover_db_url = Prompt::new(&msg_prover_db_url_prompt(&chain_name)) + .default(DATABASE_PROVER_URL.as_str()) + .ask(); + let prover_db_name = slugify!( + Prompt::new(&msg_prover_db_name_prompt(&chain_name)) + .default(&prover_name) + .ask(), + separator = "_" + ); + Some(ProverDatabaseConfig { + database_config: DatabaseConfig::new(prover_db_url, prover_db_name), + dont_drop, + }) + } + } else { + None + } + } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs index a27e5f1b0bec..dcff77458de1 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs @@ -1,6 +1,19 @@ +use std::path::PathBuf; + use anyhow::Context; -use common::{check_prover_prequisites, cmd::Cmd, logger, spinner::Spinner}; -use config::EcosystemConfig; +use common::{ + check_prover_prequisites, + cmd::Cmd, + config::global_config, + db::{drop_db_if_exists, init_db, migrate_db, DatabaseConfig}, + logger, + spinner::Spinner, + PromptConfirm, +}; +use config::{ + copy_configs, set_databases, set_prover_database, traits::SaveConfigWithBasePath, + EcosystemConfig, +}; use xshell::{cmd, Shell}; use zksync_config::{ configs::{object_store::ObjectStoreMode, GeneralConfig}, @@ -14,28 +27,37 @@ use super::{ utils::get_link_to_prover, }; use crate::{ - consts::PROVER_STORE_MAX_RETRIES, + consts::{PROVER_MIGRATIONS, PROVER_STORE_MAX_RETRIES, SERVER_MIGRATIONS}, messages::{ MSG_CHAIN_NOT_FOUND_ERR, MSG_DOWNLOADING_SETUP_KEY_SPINNER, - MSG_GENERAL_CONFIG_NOT_FOUND_ERR, MSG_PROOF_COMPRESSOR_CONFIG_NOT_FOUND_ERR, - MSG_PROVER_CONFIG_NOT_FOUND_ERR, MSG_PROVER_INITIALIZED, MSG_SETUP_KEY_PATH_ERROR, + MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR, MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR, + MSG_GENERAL_CONFIG_NOT_FOUND_ERR, MSG_INITIALIZING_DATABASES_SPINNER, + MSG_INITIALIZING_PROVER_DATABASE, MSG_INITIALIZING_SERVER_DATABASE, + MSG_PROOF_COMPRESSOR_CONFIG_NOT_FOUND_ERR, MSG_PROVER_CONFIG_NOT_FOUND_ERR, + MSG_PROVER_INITIALIZED, MSG_SETUP_KEY_PATH_ERROR, }, }; pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<()> { - check_prover_prequisites(shell); + //check_prover_prequisites(shell); + let ecosystem_config = EcosystemConfig::from_file(shell)?; + + let setup_key_path = get_default_setup_key_path(&ecosystem_config)?; + let args = args.fill_values_with_prompt(shell, &setup_key_path)?; + let chain_config = ecosystem_config .load_chain(Some(ecosystem_config.default_chain.clone())) .context(MSG_CHAIN_NOT_FOUND_ERR)?; + + if args.copy_configs { + copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; + } + let mut general_config = chain_config .get_general_config() .context(MSG_GENERAL_CONFIG_NOT_FOUND_ERR)?; - let setup_key_path = get_default_setup_key_path(&ecosystem_config)?; - - let args = args.fill_values_with_prompt(shell, &setup_key_path)?; - let proof_object_store_config = get_object_store_config(shell, Some(args.proof_store))?; let public_object_store_config = get_object_store_config(shell, args.public_store)?; @@ -72,6 +94,23 @@ pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<( init_bellman_cuda(shell, args.bellman_cuda_config).await?; + if let Some(prover_db) = &args.database_config { + let spinner = Spinner::new(MSG_INITIALIZING_DATABASES_SPINNER); + + let mut secrets = chain_config.get_secrets_config()?; + set_prover_database(&mut secrets, &prover_db.database_config)?; + secrets.save_with_base_path(shell, &chain_config.configs)?; + initialize_prover_database( + shell, + &prover_db.database_config, + ecosystem_config.link_to_code.clone(), + prover_db.dont_drop, + ) + .await?; + + spinner.finish(); + } + logger::outro(MSG_PROVER_INITIALIZED); Ok(()) } @@ -138,3 +177,29 @@ fn get_object_store_config( Ok(object_store) } + +async fn initialize_prover_database( + shell: &Shell, + prover_db_config: &DatabaseConfig, + link_to_code: PathBuf, + dont_drop: bool, +) -> anyhow::Result<()> { + if global_config().verbose { + logger::debug(MSG_INITIALIZING_PROVER_DATABASE) + } + if !dont_drop { + drop_db_if_exists(prover_db_config) + .await + .context(MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR)?; + init_db(prover_db_config).await?; + } + let path_to_prover_migration = link_to_code.join(PROVER_MIGRATIONS); + migrate_db( + shell, + path_to_prover_migration, + &prover_db_config.full_url(), + ) + .await?; + + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs index 5497db8a21e0..db323719e01a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs @@ -19,7 +19,7 @@ use crate::messages::{ }; pub(crate) async fn run(args: ProverRunArgs, shell: &Shell) -> anyhow::Result<()> { - check_prover_prequisites(shell); + //check_prover_prequisites(shell); let args = args.fill_values_with_prompt()?; let ecosystem_config = EcosystemConfig::from_file(shell)?; let chain = ecosystem_config diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 402ee0718e88..75315f220eb2 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -299,6 +299,7 @@ pub(super) const MSG_BELLMAN_CUDA_ORIGIN_SELECT: &str = pub(super) const MSG_BELLMAN_CUDA_SELECTION_CLONE: &str = "Clone for me (recommended)"; pub(super) const MSG_BELLMAN_CUDA_SELECTION_PATH: &str = "I have the code already"; pub(super) const MSG_CLOUD_TYPE_PROMPT: &str = "Select the cloud connection mode:"; +pub(super) const MSG_COPY_CONFIGS_PROMPT: &str = "Do you want to copy configs from scratch?"; pub(super) const MSG_THREADS_PROMPT: &str = "Provide the number of threads:"; pub(super) fn msg_bucket_created(bucket_name: &str) -> String { From 863e6012748eb19d7a123739e8c9776ed7d8a8dc Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:31:07 +0300 Subject: [PATCH 02/31] fix build --- .../zk_inception/src/commands/ecosystem/init.rs | 1 + .../zk_inception/src/commands/prover/args/init.rs | 13 +++++++------ .../crates/zk_inception/src/commands/prover/init.rs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs index 101d272494a0..428d439b388f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -118,6 +118,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { genesis_args: genesis_args.clone().fill_values_with_prompt(&chain_config), deploy_paymaster: final_ecosystem_args.deploy_paymaster, l1_rpc_url: final_ecosystem_args.ecosystem.l1_rpc_url.clone(), + copy_configs: true, }; chain::init::init( diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index fbde4d9ae54c..74bc4888f8af 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -492,12 +492,13 @@ impl ProverInitArgs { let prover_db_url = Prompt::new(&msg_prover_db_url_prompt(&chain_name)) .default(DATABASE_PROVER_URL.as_str()) .ask(); - let prover_db_name = slugify!( - Prompt::new(&msg_prover_db_name_prompt(&chain_name)) - .default(&prover_name) - .ask(), - separator = "_" - ); + + let prover_db_name: String = Prompt::new(&msg_prover_db_name_prompt(&chain_name)) + .default(&prover_name) + .ask(); + + let prover_db_name = slugify!(&prover_db_name, separator = "_"); + Some(ProverDatabaseConfig { database_config: DatabaseConfig::new(prover_db_url, prover_db_name), dont_drop, diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs index dcff77458de1..7e5855b02a7b 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs @@ -44,11 +44,11 @@ pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<( let ecosystem_config = EcosystemConfig::from_file(shell)?; let setup_key_path = get_default_setup_key_path(&ecosystem_config)?; - let args = args.fill_values_with_prompt(shell, &setup_key_path)?; let chain_config = ecosystem_config .load_chain(Some(ecosystem_config.default_chain.clone())) .context(MSG_CHAIN_NOT_FOUND_ERR)?; + let args = args.fill_values_with_prompt(shell, &setup_key_path, &chain_config)?; if args.copy_configs { copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; From 9c858655c5e0e18e4d42d30ed7a0cdbc1c6ca64a Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:53:15 +0300 Subject: [PATCH 03/31] add docs --- prover/docs/05_proving_batch.md | 126 ++++++++++++++++++ zk_toolbox/crates/zk_inception/README.md | 7 +- .../zk_inception/src/commands/prover/init.rs | 15 +-- .../zk_inception/src/commands/prover/run.rs | 2 +- 4 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 prover/docs/05_proving_batch.md diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md new file mode 100644 index 000000000000..c01a7179e22b --- /dev/null +++ b/prover/docs/05_proving_batch.md @@ -0,0 +1,126 @@ +# Proving a batch + +If you got to this section, then most likely you are wondering how to prove and verify the batch by yourself. After +releases `prover-v15.1.0` and `core-v24.9.0` prover subsystem doesn't need access to core database anymore, which means +you can run only prover subsystem and prove batches without running the whole core system. This guide will help you with +that. + +## Requirements + +First of all, you need to install CUDA drivers, all other things will be dealt with by `zk_inception` tool. For that, +check the following [guide](./02_setup.md)(you can skip bellman-cuda step). + +Now, you can use `zk_inception` tool for setting up the env and running prover subsystem. Check the steps for +installation in [this guide](../../zk_toolbox/README.md). And don't forget to install the prerequisites! + +## Initializing system + +After you have installed the tool, you can run the prover subsystem by running: + +```shell +zk_inception ecosystem create +``` + +The command will create the ecosystem and all the necessary components for the prover subsystem. Now, you need to +initialize the prover subsystem by running: + +```shell +zk_inception prover init +``` + +For the prompts, you need to put `Yes` for copying the configs and setting up the database. + +## Proving the batch + +### Getting data needed for proving + +At this step, we need to get the witness inputs data for the batch you want to prove. Database information now lives in +input file, called `witness_inputs_.bin` generated by different core components). + +- If batch was produced by your system, the file is stored by prover gateway in GCS (or your choice of object storage -- + check config). To access it from GCS (assuming you have access to the bucket), run: + + ```shell + gsutil cp gs://your_bucket/witness_inputs/witness_inputs_.bin + ``` + +- If you want to prove the batch produced by zkSync, you can get the data from the `ExternalProofIntegrationAPI` using + `{address}/proof_generation_data` endpoint. You need to replace `{address}` with the address of the API and provide + the batch number as a query data to get the data for specific batch, otherwise, you will receive latest data for the + batch, that was already proven. + +### Preparing database + +After you have the data, you need to prepare the system to run the batch. So, database needs to know about the batch and +the protocol version it should use. Check the latest protocol version in the codebase by checking const +`PROVER_PROTOCOL_SEMANTIC_VERSION` or run the binary in `prover` workspace: + +```console +cargo run --bin prover_version +``` + +It will give you the latest prover protocol version in a semver format, like `0.24.2`, you need to know only minor and +patch versions. Now, go to the `prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json` and get +`snark_wrapper` value from it. Then, you need to insert the info about protocol version into the database. First, +connect to the database, e.g. locally you can do it like that(for local DB you can find the url in `prover.yaml` or +`general.yaml` files): + +```shell +psql postgres://postgres:notsecurepassword@localhost/prover_local +``` + +And run the following query: + +```shell +INSERT INTO +prover_fri_protocol_versions ( +id, +recursion_scheduler_level_vk_hash, +created_at, +protocol_version_patch +) +VALUES +(, ''::bytea, NOW(), ) +ON CONFLICT (id, protocol_version_patch) DO NOTHING + +``` + +Now, you need to insert the batch into the database. Run the following query: + +```shell +INSERT INTO +witness_inputs_fri ( +l1_batch_number, +witness_inputs_blob_url, +protocol_version, +status, +created_at, +updated_at, +protocol_version_patch +) +VALUES +(, 'witness_inputs_.bin', , 'queued', NOW(), NOW(), ) +ON CONFLICT (l1_batch_number) DO NOTHING +``` + +## Running prover subsystem + +At this step, all the data is prepared and you can run the prover subsystem. To do that, run the following commands: + +```shell +zk_inception prover run --component=prover +zk_inception prover run --component=witness-generator --round=all-rounds +zk_inception prover run --component=witness-vector-generator --threads=10 +zk_inception prover run --component=compressor +``` + +And you are good to go! The prover subsystem will prove the batch and you can check the results in the database. + +## Verifying zkSync batch + +Now, assuming the proof is already generated, you can verify using `ExternalProofIntegrationAPI`. Usually proof is +stored in GCS bucket(for which you can use the same steps as for getting the witness inputs data +[here](#getting-data-needed-for-proving), but locally you can find it in `/artifacts/proofs_fri` directory). Now, simply +send the data to the endpoint `{address}/verify_batch/{batch_number}`. Note, that you need to pass the generated proof +as serialized JSON data when calling the endpoint. API will respond with status 200 if the proof is valid and with the +error message otherwise. diff --git a/zk_toolbox/crates/zk_inception/README.md b/zk_toolbox/crates/zk_inception/README.md index 61fd9ec2e36e..63501cb07cf2 100644 --- a/zk_toolbox/crates/zk_inception/README.md +++ b/zk_toolbox/crates/zk_inception/README.md @@ -269,6 +269,7 @@ Initialize chain, deploying necessary contracts and performing on-chain operatio - `-u`, `--use-default` — Use default database urls and names - `-d`, `--dont-drop` - `--deploy-paymaster ` +- `--copy-configs` - Copy default configs to the chain Possible values: `true`, `false` @@ -418,7 +419,7 @@ Initialize prover - `--project-id ` - `--shall-save-to-public-bucket ` - Possible values: `true`, `false` +Possible values: `true`, `false` - `--public-store-dir ` - `--public-bucket-base-url ` @@ -428,8 +429,10 @@ Initialize prover - `--public-project-id ` - `--bellman-cuda-dir ` - `--download-key ` +- `--setup-database` +- `--copy-configs` - Possible values: `true`, `false` +Possible values: `true`, `false` - `--setup-key-path ` - `--cloud-type ` diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs index 7e5855b02a7b..55f69c7bae76 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs @@ -8,12 +8,8 @@ use common::{ db::{drop_db_if_exists, init_db, migrate_db, DatabaseConfig}, logger, spinner::Spinner, - PromptConfirm, -}; -use config::{ - copy_configs, set_databases, set_prover_database, traits::SaveConfigWithBasePath, - EcosystemConfig, }; +use config::{copy_configs, set_prover_database, traits::SaveConfigWithBasePath, EcosystemConfig}; use xshell::{cmd, Shell}; use zksync_config::{ configs::{object_store::ObjectStoreMode, GeneralConfig}, @@ -27,19 +23,18 @@ use super::{ utils::get_link_to_prover, }; use crate::{ - consts::{PROVER_MIGRATIONS, PROVER_STORE_MAX_RETRIES, SERVER_MIGRATIONS}, + consts::{PROVER_MIGRATIONS, PROVER_STORE_MAX_RETRIES}, messages::{ MSG_CHAIN_NOT_FOUND_ERR, MSG_DOWNLOADING_SETUP_KEY_SPINNER, - MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR, MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR, - MSG_GENERAL_CONFIG_NOT_FOUND_ERR, MSG_INITIALIZING_DATABASES_SPINNER, - MSG_INITIALIZING_PROVER_DATABASE, MSG_INITIALIZING_SERVER_DATABASE, + MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR, MSG_GENERAL_CONFIG_NOT_FOUND_ERR, + MSG_INITIALIZING_DATABASES_SPINNER, MSG_INITIALIZING_PROVER_DATABASE, MSG_PROOF_COMPRESSOR_CONFIG_NOT_FOUND_ERR, MSG_PROVER_CONFIG_NOT_FOUND_ERR, MSG_PROVER_INITIALIZED, MSG_SETUP_KEY_PATH_ERROR, }, }; pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<()> { - //check_prover_prequisites(shell); + check_prover_prequisites(shell); let ecosystem_config = EcosystemConfig::from_file(shell)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs index db323719e01a..5497db8a21e0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs @@ -19,7 +19,7 @@ use crate::messages::{ }; pub(crate) async fn run(args: ProverRunArgs, shell: &Shell) -> anyhow::Result<()> { - //check_prover_prequisites(shell); + check_prover_prequisites(shell); let args = args.fill_values_with_prompt()?; let ecosystem_config = EcosystemConfig::from_file(shell)?; let chain = ecosystem_config From 7529c3faac4cf9afa565ac67458c636279770cd2 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:38:30 +0300 Subject: [PATCH 04/31] fix build, address comments --- .../src/commands/chain/args/init.rs | 10 ----- .../zk_inception/src/commands/chain/init.rs | 4 +- .../src/commands/prover/args/init.rs | 41 ++++++++++++++----- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs index 2df6020561cb..6e2cb1672b08 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs @@ -28,8 +28,6 @@ pub struct InitArgs { pub deploy_paymaster: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, - #[clap(long)] - pub copy_configs: Option, } impl InitArgs { @@ -54,18 +52,11 @@ impl InitArgs { .ask() }); - let copy_configs = self.copy_configs.unwrap_or_else(|| { - common::PromptConfirm::new(MSG_COPY_CONFIGS_PROMPT) - .default(true) - .ask() - }); - InitArgsFinal { forge_args: self.forge_args, genesis_args: self.genesis_args.fill_values_with_prompt(config), deploy_paymaster, l1_rpc_url, - copy_configs, } } } @@ -76,5 +67,4 @@ pub struct InitArgsFinal { pub genesis_args: GenesisArgsFinal, pub deploy_paymaster: bool, pub l1_rpc_url: String, - pub copy_configs: bool, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 81d831d83d9d..b3b43c75c36a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -58,9 +58,7 @@ pub async fn init( ecosystem_config: &EcosystemConfig, chain_config: &ChainConfig, ) -> anyhow::Result<()> { - if init_args.copy_configs { - copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; - } + copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; let mut genesis_config = chain_config.get_genesis_config()?; update_from_chain_config(&mut genesis_config, chain_config); diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index 74bc4888f8af..1455e3993f17 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -4,6 +4,7 @@ use config::ChainConfig; use serde::{Deserialize, Serialize}; use slugify_rs::slugify; use strum::{EnumIter, IntoEnumIterator}; +use url::Url; use xshell::Shell; use zksync_config::configs::fri_prover::CloudConnectionMode; @@ -21,7 +22,7 @@ use crate::{ MSG_GETTING_PUBLIC_STORE_CONFIG, MSG_PROOF_STORE_CONFIG_PROMPT, MSG_PROOF_STORE_DIR_PROMPT, MSG_PROOF_STORE_GCS_BUCKET_BASE_URL_ERR, MSG_PROOF_STORE_GCS_BUCKET_BASE_URL_PROMPT, MSG_PROOF_STORE_GCS_CREDENTIALS_FILE_PROMPT, MSG_SAVE_TO_PUBLIC_BUCKET_PROMPT, - MSG_SETUP_KEY_PATH_PROMPT, + MSG_SETUP_KEY_PATH_PROMPT, MSG_USE_DEFAULT_DATABASES_HELP, }, }; @@ -63,6 +64,14 @@ pub struct ProverInitArgs { #[clap(long)] pub setup_database: Option, + #[clap(long, help = MSG_PROVER_DB_URL_HELP)] + pub prover_db_url: Option, + #[clap(long, help = MSG_PROVER_DB_NAME_HELP)] + pub prover_db_name: Option, + #[clap(long, short, help = MSG_USE_DEFAULT_DATABASES_HELP)] + pub use_default: bool, + #[clap(long, short, action)] + pub dont_drop: bool, #[clap(long)] cloud_type: Option, @@ -475,27 +484,39 @@ impl ProverInitArgs { ) -> Option { let setup_database = self .setup_database + .clone() .unwrap_or_else(|| PromptConfirm::new("Do you want to setup the database?").ask()); if setup_database { let DBNames { prover_name, .. } = generate_db_names(config); let chain_name = config.name.clone(); - let dont_drop = !PromptConfirm::new("Do you want to drop the database?").ask(); + let dont_drop = self + .dont_drop + .clone() + .unwrap_or_else(|| !PromptConfirm::new("Do you want to drop the database?").ask()); - if PromptConfirm::new("Do you want to use default database?").ask() { + if self + .use_default + .clone() + .unwrap_or_else(|| PromptConfirm::new(MSG_USE_DEFAULT_DATABASES_HELP).ask()) + { Some(ProverDatabaseConfig { database_config: DatabaseConfig::new(DATABASE_PROVER_URL.clone(), prover_name), dont_drop, }) } else { - let prover_db_url = Prompt::new(&msg_prover_db_url_prompt(&chain_name)) - .default(DATABASE_PROVER_URL.as_str()) - .ask(); - - let prover_db_name: String = Prompt::new(&msg_prover_db_name_prompt(&chain_name)) - .default(&prover_name) - .ask(); + let prover_db_url = self.prover_db_url.clone().unwrap_or_else(|| { + Prompt::new(&msg_prover_db_url_prompt(&chain_name)) + .default(DATABASE_PROVER_URL.as_str()) + .ask() + }); + + let prover_db_name: String = self.prover_db_name.clone().unwrap_or_else(|| { + Prompt::new(&msg_prover_db_name_prompt(&chain_name)) + .default(&prover_name) + .ask() + }); let prover_db_name = slugify!(&prover_db_name, separator = "_"); From 90781000015fea5ffb185d4d797a22d87cae54a7 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:05:18 +0300 Subject: [PATCH 05/31] fix build --- .../src/commands/chain/args/init.rs | 4 +-- .../src/commands/ecosystem/init.rs | 1 - .../src/commands/prover/args/init.rs | 28 ++++++++++--------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs index 6e2cb1672b08..0700c96c76ec 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs @@ -10,8 +10,8 @@ use crate::{ commands::chain::args::genesis::GenesisArgs, defaults::LOCAL_RPC_URL, messages::{ - MSG_COPY_CONFIGS_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, - MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, + MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, + MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, }, }; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs index 428d439b388f..101d272494a0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -118,7 +118,6 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { genesis_args: genesis_args.clone().fill_values_with_prompt(&chain_config), deploy_paymaster: final_ecosystem_args.deploy_paymaster, l1_rpc_url: final_ecosystem_args.ecosystem.l1_rpc_url.clone(), - copy_configs: true, }; chain::init::init( diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index 1455e3993f17..46cfa7adbd7e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -21,8 +21,9 @@ use crate::{ MSG_DOWNLOAD_SETUP_KEY_PROMPT, MSG_GETTING_PROOF_STORE_CONFIG, MSG_GETTING_PUBLIC_STORE_CONFIG, MSG_PROOF_STORE_CONFIG_PROMPT, MSG_PROOF_STORE_DIR_PROMPT, MSG_PROOF_STORE_GCS_BUCKET_BASE_URL_ERR, MSG_PROOF_STORE_GCS_BUCKET_BASE_URL_PROMPT, - MSG_PROOF_STORE_GCS_CREDENTIALS_FILE_PROMPT, MSG_SAVE_TO_PUBLIC_BUCKET_PROMPT, - MSG_SETUP_KEY_PATH_PROMPT, MSG_USE_DEFAULT_DATABASES_HELP, + MSG_PROOF_STORE_GCS_CREDENTIALS_FILE_PROMPT, MSG_PROVER_DB_NAME_HELP, + MSG_PROVER_DB_URL_HELP, MSG_SAVE_TO_PUBLIC_BUCKET_PROMPT, MSG_SETUP_KEY_PATH_PROMPT, + MSG_USE_DEFAULT_DATABASES_HELP, }, }; @@ -69,9 +70,9 @@ pub struct ProverInitArgs { #[clap(long, help = MSG_PROVER_DB_NAME_HELP)] pub prover_db_name: Option, #[clap(long, short, help = MSG_USE_DEFAULT_DATABASES_HELP)] - pub use_default: bool, + pub use_default: Option, #[clap(long, short, action)] - pub dont_drop: bool, + pub dont_drop: Option, #[clap(long)] cloud_type: Option, @@ -491,16 +492,17 @@ impl ProverInitArgs { let DBNames { prover_name, .. } = generate_db_names(config); let chain_name = config.name.clone(); - let dont_drop = self - .dont_drop - .clone() - .unwrap_or_else(|| !PromptConfirm::new("Do you want to drop the database?").ask()); + let dont_drop = self.dont_drop.clone().unwrap_or_else(|| { + !PromptConfirm::new("Do you want to drop the database?") + .default(true) + .ask() + }); - if self - .use_default - .clone() - .unwrap_or_else(|| PromptConfirm::new(MSG_USE_DEFAULT_DATABASES_HELP).ask()) - { + if self.use_default.clone().unwrap_or_else(|| { + PromptConfirm::new(MSG_USE_DEFAULT_DATABASES_HELP) + .default(true) + .ask() + }) { Some(ProverDatabaseConfig { database_config: DatabaseConfig::new(DATABASE_PROVER_URL.clone(), prover_name), dont_drop, From 6e7be8dedba09f987f4c6d07b126ab349e102f84 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:48:04 +0300 Subject: [PATCH 06/31] add some prover_cli commands --- prover/crates/bin/prover_cli/src/cli.rs | 7 +- .../prover_cli/src/commands/insert_batch.rs | 43 +++++++++++ .../prover_cli/src/commands/insert_version.rs | 52 +++++++++++++ .../crates/bin/prover_cli/src/commands/mod.rs | 2 + prover/crates/bin/witness_generator/README.md | 73 ------------------- prover/docs/05_proving_batch.md | 46 ++++-------- 6 files changed, 118 insertions(+), 105 deletions(-) create mode 100644 prover/crates/bin/prover_cli/src/commands/insert_batch.rs create mode 100644 prover/crates/bin/prover_cli/src/commands/insert_version.rs diff --git a/prover/crates/bin/prover_cli/src/cli.rs b/prover/crates/bin/prover_cli/src/cli.rs index 0c7022cae297..41ef94980056 100644 --- a/prover/crates/bin/prover_cli/src/cli.rs +++ b/prover/crates/bin/prover_cli/src/cli.rs @@ -2,7 +2,8 @@ use clap::{command, Args, Parser, Subcommand}; use zksync_types::url::SensitiveUrl; use crate::commands::{ - config, debug_proof, delete, get_file_info, requeue, restart, stats, status::StatusCommand, + config, debug_proof, delete, get_file_info, insert_batch, insert_version, requeue, restart, + stats, status::StatusCommand, }; pub const VERSION_STRING: &str = env!("CARGO_PKG_VERSION"); @@ -27,6 +28,8 @@ impl ProverCLI { ProverCommand::Restart(args) => restart::run(args).await?, ProverCommand::DebugProof(args) => debug_proof::run(args).await?, ProverCommand::Stats(args) => stats::run(args, self.config).await?, + ProverCommand::InsertVersion(args) => insert_version::run(args, self.config).await?, + ProverCommand::InsertBatch(args) => insert_batch::run(args, self.config).await?, }; Ok(()) } @@ -55,4 +58,6 @@ pub enum ProverCommand { Restart(restart::Args), #[command(about = "Displays L1 Batch proving stats for a given period")] Stats(stats::Options), + InsertVersion(insert_version::Args), + InsertBatch(insert_batch::Args), } diff --git a/prover/crates/bin/prover_cli/src/commands/insert_batch.rs b/prover/crates/bin/prover_cli/src/commands/insert_batch.rs new file mode 100644 index 000000000000..add1474633d7 --- /dev/null +++ b/prover/crates/bin/prover_cli/src/commands/insert_batch.rs @@ -0,0 +1,43 @@ +use anyhow::Context as _; +use clap::Args as ClapArgs; +use zksync_basic_types::{ + protocol_version::{ProtocolSemanticVersion, ProtocolVersionId, VersionPatch}, + L1BatchNumber, +}; +use zksync_db_connection::connection_pool::ConnectionPool; +use zksync_prover_dal::{Prover, ProverDal}; + +use crate::cli::ProverCLIConfig; + +#[derive(ClapArgs)] +pub struct Args { + #[clap(short, long)] + pub number: L1BatchNumber, + #[clap(short, long)] + pub version: u16, + #[clap(short, long)] + pub patch: u32, +} + +pub async fn run(args: Args, config: ProverCLIConfig) -> anyhow::Result<()> { + let connection = ConnectionPool::::singleton(config.db_url) + .build() + .await + .context("failed to build a prover_connection_pool")?; + let mut conn = connection.connection().await.unwrap(); + + let protocol_version = ProtocolVersionId::try_from(args.version) + .map_err(|_| anyhow::anyhow!("Invalid protocol version"))?; + + let protocol_version_patch = VersionPatch(args.patch); + + conn.fri_witness_generator_dal() + .save_witness_inputs( + args.number, + &format!("witness_inputs_{}", args.number.0), + ProtocolSemanticVersion::new(protocol_version, protocol_version_patch), + ) + .await; + + Ok(()) +} diff --git a/prover/crates/bin/prover_cli/src/commands/insert_version.rs b/prover/crates/bin/prover_cli/src/commands/insert_version.rs new file mode 100644 index 000000000000..7f30719a713b --- /dev/null +++ b/prover/crates/bin/prover_cli/src/commands/insert_version.rs @@ -0,0 +1,52 @@ +use std::str::FromStr; + +use anyhow::Context as _; +use clap::Args as ClapArgs; +use zksync_basic_types::{ + protocol_version::{ + L1VerifierConfig, ProtocolSemanticVersion, ProtocolVersionId, VersionPatch, + }, + H256, +}; +use zksync_db_connection::connection_pool::ConnectionPool; +use zksync_prover_dal::{Prover, ProverDal}; + +use crate::cli::ProverCLIConfig; + +#[derive(ClapArgs)] +pub struct Args { + #[clap(short, long)] + pub version: u16, + #[clap(short, long)] + pub patch: u32, + #[clap(short, long)] + pub snark_wrapper: String, +} + +pub async fn run(args: Args, config: ProverCLIConfig) -> anyhow::Result<()> { + let connection = ConnectionPool::::singleton(config.db_url) + .build() + .await + .context("failed to build a prover_connection_pool")?; + let mut conn = connection.connection().await.unwrap(); + + let protocol_version = ProtocolVersionId::try_from(args.version) + .map_err(|_| anyhow::anyhow!("Invalid protocol version"))?; + + let protocol_version_patch = VersionPatch(args.patch); + + let snark_wrapper = H256::from_str(&args.snark_wrapper).unwrap_or_else(|_| { + panic!("Invalid snark wrapper hash"); + }); + + conn.fri_protocol_versions_dal() + .save_prover_protocol_version( + ProtocolSemanticVersion::new(protocol_version, protocol_version_patch), + L1VerifierConfig { + recursion_scheduler_level_vk_hash: snark_wrapper, + }, + ) + .await; + + Ok(()) +} diff --git a/prover/crates/bin/prover_cli/src/commands/mod.rs b/prover/crates/bin/prover_cli/src/commands/mod.rs index d9dde52284b4..bafe229884b9 100644 --- a/prover/crates/bin/prover_cli/src/commands/mod.rs +++ b/prover/crates/bin/prover_cli/src/commands/mod.rs @@ -2,6 +2,8 @@ pub(crate) mod config; pub(crate) mod debug_proof; pub(crate) mod delete; pub(crate) mod get_file_info; +pub(crate) mod insert_batch; +pub(crate) mod insert_version; pub(crate) mod requeue; pub(crate) mod restart; pub(crate) mod stats; diff --git a/prover/crates/bin/witness_generator/README.md b/prover/crates/bin/witness_generator/README.md index a318a4612069..dc476ca44fc3 100644 --- a/prover/crates/bin/witness_generator/README.md +++ b/prover/crates/bin/witness_generator/README.md @@ -50,76 +50,3 @@ One round of prover generation consists of: Note that the very first input table (`witness_inputs`) is populated by the tree (as the input artifact for the `WitnessGeneratorJobType::BasicCircuits` is the merkle proofs) - -## Running BWG for custom batch - -After releases `prover-v15.1.0` and `core-v24.9.0` basic witness generator doesn't need access to core database anymore. -Database information now lives in input file, called `witness_inputs_.bin` generated by different core -components). - -This file is stored by prover gateway in GCS (or your choice of object storage -- check config). To access it from GCS -(assuming you have access to the bucket), run: - -```shell -gsutil cp gs://your_bucket/witness_inputs/witness_inputs_.bin -``` - -Note, that you need to have `gsutil` installed, and you need to have access to the bucket. - -Now, database needs to know about the batch and the protocol version it should use. Check the latest protocol version in -the codebase by checking const `PROVER_PROTOCOL_SEMANTIC_VERSION` or run the binary in `prover` workspace: - -```console -cargo run --bin prover_version -``` - -It will give you the latest prover protocol version in a semver format, like `0.24.2`, you need to know only minor and -patch versions. Now, go to the `prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json` and get -`snark_wrapper` value from it. Then, you need to insert the info about protocol version into the database. First, -connect to the database, e.g. locally you can do it like that: - -```shell -psql postgres://postgres:notsecurepassword@localhost/prover_local -``` - -And run the following query: - -```shell -INSERT INTO -prover_fri_protocol_versions ( -id, -recursion_scheduler_level_vk_hash, -created_at, -protocol_version_patch -) -VALUES -(, ''::bytea, NOW(), ) -ON CONFLICT (id, protocol_version_patch) DO NOTHING - -``` - -Now, you need to insert the batch into the database. Run the following query: - -```shell -INSERT INTO -witness_inputs_fri ( -l1_batch_number, -witness_inputs_blob_url, -protocol_version, -status, -created_at, -updated_at, -protocol_version_patch -) -VALUES -(, 'witness_inputs_.bin', , 'queued', NOW(), NOW(), ) -ON CONFLICT (l1_batch_number) DO NOTHING -``` - -Finally, run the basic witness generator itself: - -```shell -API_PROMETHEUS_LISTENER_PORT=3116 zk f cargo run --release --bin zksync_witness_generator -- --round=basic_circuits -``` - -And you are good to go! diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index c01a7179e22b..506fa433f8fe 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -7,12 +7,15 @@ that. ## Requirements -First of all, you need to install CUDA drivers, all other things will be dealt with by `zk_inception` tool. For that, -check the following [guide](./02_setup.md)(you can skip bellman-cuda step). +First of all, you need to install CUDA drivers, all other things will be dealt with by `zk_inception` and `prover_cli` +tools. For that, check the following [guide](./02_setup.md)(you can skip bellman-cuda step). Now, you can use `zk_inception` tool for setting up the env and running prover subsystem. Check the steps for installation in [this guide](../../zk_toolbox/README.md). And don't forget to install the prerequisites! +Also, to assure that you are working with database securely, you need to use `prover_cli` tool. You can find the guide +for installation [here](../crates/bin/prover_cli/README.md). + ## Initializing system After you have installed the tool, you can run the prover subsystem by running: @@ -62,45 +65,26 @@ cargo run --bin prover_version It will give you the latest prover protocol version in a semver format, like `0.24.2`, you need to know only minor and patch versions. Now, go to the `prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json` and get `snark_wrapper` value from it. Then, you need to insert the info about protocol version into the database. First, -connect to the database, e.g. locally you can do it like that(for local DB you can find the url in `prover.yaml` or -`general.yaml` files): +connect to the database, e.g. locally you can do it like that: + +Now, with the use of `prover_cli` tool, you can insert the data about the batch and protocol version into the database: + +First, let the tool know which database it should connect to((for local DB you can find the url in `secrets.yaml` file): ```shell -psql postgres://postgres:notsecurepassword@localhost/prover_local +pli config --db-url ``` -And run the following query: +Now, insert the information about protocol version in the database: ```shell -INSERT INTO -prover_fri_protocol_versions ( -id, -recursion_scheduler_level_vk_hash, -created_at, -protocol_version_patch -) -VALUES -(, ''::bytea, NOW(), ) -ON CONFLICT (id, protocol_version_patch) DO NOTHING - +pli insert-version --version= --patch= --snark-wrapper= ``` -Now, you need to insert the batch into the database. Run the following query: +And finally, provide the data about the batch: ```shell -INSERT INTO -witness_inputs_fri ( -l1_batch_number, -witness_inputs_blob_url, -protocol_version, -status, -created_at, -updated_at, -protocol_version_patch -) -VALUES -(, 'witness_inputs_.bin', , 'queued', NOW(), NOW(), ) -ON CONFLICT (l1_batch_number) DO NOTHING +pli insert-batch --number= --version= --patch= ``` ## Running prover subsystem From 03832b1d5b982e57e8ce0f72a881381438f7d8d4 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:04:46 +0300 Subject: [PATCH 07/31] address comments --- prover/crates/bin/prover_cli/README.md | 3 +-- prover/docs/05_proving_batch.md | 9 +++++---- .../src/commands/prover/args/init.rs | 16 ++-------------- .../zk_inception/src/commands/prover/init.rs | 2 +- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/prover/crates/bin/prover_cli/README.md b/prover/crates/bin/prover_cli/README.md index 6a9091aef25e..f69a88d7b4f8 100644 --- a/prover/crates/bin/prover_cli/README.md +++ b/prover/crates/bin/prover_cli/README.md @@ -5,8 +5,7 @@ CLI tool for performing maintenance of a ZKsync Prover ## Installation ``` -git clone git@github.com:matter-labs/zksync-era.git -cargo install -p prover_cli +cargo install --git https://github.com/matter-labs/zksync-era.git prover_cli ``` > This should be `cargo install zksync-prover-cli` or something similar ideally. diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 506fa433f8fe..71fed0f32348 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -18,7 +18,8 @@ for installation [here](../crates/bin/prover_cli/README.md). ## Initializing system -After you have installed the tool, you can run the prover subsystem by running: +After you have installed the tool, you can create ecosystem(you need to run only if you are outside of `zksync-era`) by +running: ```shell zk_inception ecosystem create @@ -72,19 +73,19 @@ Now, with the use of `prover_cli` tool, you can insert the data about the batch First, let the tool know which database it should connect to((for local DB you can find the url in `secrets.yaml` file): ```shell -pli config --db-url +prover_cli config --db-url ``` Now, insert the information about protocol version in the database: ```shell -pli insert-version --version= --patch= --snark-wrapper= +prover_cli insert-version --version= --patch= --snark-wrapper= ``` And finally, provide the data about the batch: ```shell -pli insert-batch --number= --version= --patch= +prover_cli insert-batch --number= --version= --patch= ``` ## Running prover subsystem diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index 46cfa7adbd7e..4a502cfa9010 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -60,9 +60,6 @@ pub struct ProverInitArgs { #[serde(flatten)] pub setup_key_config: SetupKeyConfigTmp, - #[clap(long)] - pub copy_configs: Option, - #[clap(long)] pub setup_database: Option, #[clap(long, help = MSG_PROVER_DB_URL_HELP)] @@ -193,7 +190,6 @@ pub struct ProverInitArgsFinal { pub setup_key_config: SetupKeyConfig, pub bellman_cuda_config: InitBellmanCudaArgs, pub cloud_type: CloudConnectionMode, - pub copy_configs: bool, pub database_config: Option, } @@ -209,7 +205,6 @@ impl ProverInitArgs { let setup_key_config = self.fill_setup_key_values_with_prompt(setup_key_path); let bellman_cuda_config = self.fill_bellman_cuda_values_with_prompt()?; let cloud_type = self.get_cloud_type_with_prompt(); - let copy_configs = self.ask_copy_configs(); let database_config = self.fill_database_values_with_prompt(chain_config); Ok(ProverInitArgsFinal { @@ -218,7 +213,6 @@ impl ProverInitArgs { setup_key_config, bellman_cuda_config, cloud_type, - copy_configs, database_config, }) } @@ -474,31 +468,25 @@ impl ProverInitArgs { cloud_type.into() } - fn ask_copy_configs(&self) -> bool { - self.copy_configs - .unwrap_or_else(|| PromptConfirm::new(MSG_COPY_CONFIGS_PROMPT).ask()) - } - fn fill_database_values_with_prompt( &self, config: &ChainConfig, ) -> Option { let setup_database = self .setup_database - .clone() .unwrap_or_else(|| PromptConfirm::new("Do you want to setup the database?").ask()); if setup_database { let DBNames { prover_name, .. } = generate_db_names(config); let chain_name = config.name.clone(); - let dont_drop = self.dont_drop.clone().unwrap_or_else(|| { + let dont_drop = self.dont_drop.unwrap_or_else(|| { !PromptConfirm::new("Do you want to drop the database?") .default(true) .ask() }); - if self.use_default.clone().unwrap_or_else(|| { + if self.use_default.unwrap_or_else(|| { PromptConfirm::new(MSG_USE_DEFAULT_DATABASES_HELP) .default(true) .ask() diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs index 55f69c7bae76..803ef56df832 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs @@ -45,7 +45,7 @@ pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<( .context(MSG_CHAIN_NOT_FOUND_ERR)?; let args = args.fill_values_with_prompt(shell, &setup_key_path, &chain_config)?; - if args.copy_configs { + if chain_config.get_general_config().is_err() || chain_config.get_secrets_config().is_err() { copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; } From dd9bd7a40e6e2d8110324aae3c2169a95c803fce Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:07:54 +0300 Subject: [PATCH 08/31] add protocol-version command, update docs --- prover/docs/05_proving_batch.md | 29 +++++++------ zk_toolbox/crates/zk_inception/README.md | 7 +++- .../src/commands/prover/args/init.rs | 14 +++++-- .../zk_inception/src/commands/prover/mod.rs | 3 ++ .../src/commands/prover/protocol_version.rs | 41 +++++++++++++++++++ .../crates/zk_inception/src/messages.rs | 1 - 6 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 71fed0f32348..5f01dc50808e 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -10,6 +10,10 @@ that. First of all, you need to install CUDA drivers, all other things will be dealt with by `zk_inception` and `prover_cli` tools. For that, check the following [guide](./02_setup.md)(you can skip bellman-cuda step). +Install the prerequisites, which you can find +[here](https://github.com/matter-labs/zksync-era/blob/main/docs/guides/setup-dev.md). Note, that if you are not using +Google VM instance, you also need to install [gcloud](https://cloud.google.com/sdk/docs/install#deb). + Now, you can use `zk_inception` tool for setting up the env and running prover subsystem. Check the steps for installation in [this guide](../../zk_toolbox/README.md). And don't forget to install the prerequisites! @@ -22,18 +26,16 @@ After you have installed the tool, you can create ecosystem(you need to run only running: ```shell -zk_inception ecosystem create +zk_inception ecosystem create --l1-network=localhost --prover-mode=gpu --wallet-creation=localhost --l1-batch-commit-data-generator-mode=rollup --start-containers=true ``` -The command will create the ecosystem and all the necessary components for the prover subsystem. Now, you need to -initialize the prover subsystem by running: +The command will create the ecosystem and all the necessary components for the prover subsystem. You can leave default +values for all the prompts you will see Now, you need to initialize the prover subsystem by running: ```shell -zk_inception prover init +zk_inception prover init --shall-save-to-public-bucket=false --setup-database=true --use-default=true --dont-drop=false ``` -For the prompts, you need to put `Yes` for copying the configs and setting up the database. - ## Proving the batch ### Getting data needed for proving @@ -56,21 +58,18 @@ input file, called `witness_inputs_.bin` generated by different core comp ### Preparing database After you have the data, you need to prepare the system to run the batch. So, database needs to know about the batch and -the protocol version it should use. Check the latest protocol version in the codebase by checking const -`PROVER_PROTOCOL_SEMANTIC_VERSION` or run the binary in `prover` workspace: +the protocol version it should use. You can do that with running -```console -cargo run --bin prover_version +```shell +zk_inception prover protocol-version ``` -It will give you the latest prover protocol version in a semver format, like `0.24.2`, you need to know only minor and -patch versions. Now, go to the `prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json` and get -`snark_wrapper` value from it. Then, you need to insert the info about protocol version into the database. First, -connect to the database, e.g. locally you can do it like that: +This command will provide you with the information about the semantic protocol version(you need to know only minor and +patch versions) and snark wrapper value. Now, with the use of `prover_cli` tool, you can insert the data about the batch and protocol version into the database: -First, let the tool know which database it should connect to((for local DB you can find the url in `secrets.yaml` file): +First, let the tool know which database it should connect to(for local DB you can find the url in `secrets.yaml` file): ```shell prover_cli config --db-url diff --git a/zk_toolbox/crates/zk_inception/README.md b/zk_toolbox/crates/zk_inception/README.md index 63501cb07cf2..f03bc7b35d17 100644 --- a/zk_toolbox/crates/zk_inception/README.md +++ b/zk_toolbox/crates/zk_inception/README.md @@ -430,7 +430,6 @@ Possible values: `true`, `false` - `--bellman-cuda-dir ` - `--download-key ` - `--setup-database` -- `--copy-configs` Possible values: `true`, `false` @@ -445,6 +444,12 @@ Generate setup keys **Usage:** `zk_inception prover generate-sk` +## `zk_inception prover protocol-version` + +Gets information about current protocol version of provers in `zksync-era` and snark wrapper hash. + +**Usage:** `zk_inception prover protocol-version` + ## `zk_inception prover run` Run prover diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index 4a502cfa9010..20bd34259e44 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -15,8 +15,8 @@ use crate::{ defaults::{generate_db_names, DBNames, DATABASE_PROVER_URL}, messages::{ msg_prover_db_name_prompt, msg_prover_db_url_prompt, MSG_CLOUD_TYPE_PROMPT, - MSG_COPY_CONFIGS_PROMPT, MSG_CREATE_GCS_BUCKET_LOCATION_PROMPT, - MSG_CREATE_GCS_BUCKET_NAME_PROMTP, MSG_CREATE_GCS_BUCKET_PROJECT_ID_NO_PROJECTS_PROMPT, + MSG_CREATE_GCS_BUCKET_LOCATION_PROMPT, MSG_CREATE_GCS_BUCKET_NAME_PROMTP, + MSG_CREATE_GCS_BUCKET_PROJECT_ID_NO_PROJECTS_PROMPT, MSG_CREATE_GCS_BUCKET_PROJECT_ID_PROMPT, MSG_CREATE_GCS_BUCKET_PROMPT, MSG_DOWNLOAD_SETUP_KEY_PROMPT, MSG_GETTING_PROOF_STORE_CONFIG, MSG_GETTING_PUBLIC_STORE_CONFIG, MSG_PROOF_STORE_CONFIG_PROMPT, MSG_PROOF_STORE_DIR_PROMPT, @@ -341,7 +341,11 @@ impl ProverInitArgs { .clone() .setup_key_config .download_key - .unwrap_or_else(|| PromptConfirm::new(MSG_DOWNLOAD_SETUP_KEY_PROMPT).ask()); + .unwrap_or_else(|| { + PromptConfirm::new(MSG_DOWNLOAD_SETUP_KEY_PROMPT) + .default(true) + .ask() + }); let setup_key_path = self .clone() .setup_key_config @@ -462,7 +466,9 @@ impl ProverInitArgs { fn get_cloud_type_with_prompt(&self) -> CloudConnectionMode { let cloud_type = self.cloud_type.clone().unwrap_or_else(|| { - PromptSelect::new(MSG_CLOUD_TYPE_PROMPT, InternalCloudConnectionMode::iter()).ask() + PromptSelect::new(MSG_CLOUD_TYPE_PROMPT, InternalCloudConnectionMode::iter()) + .default(InternalCloudConnectionMode::Local) + .ask() }); cloud_type.into() diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs index 31c3a02e3806..dbbd14d7252a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs @@ -7,6 +7,7 @@ mod gcs; mod generate_sk; mod init; mod init_bellman_cuda; +mod protocol_version; mod run; mod utils; @@ -22,6 +23,7 @@ pub enum ProverCommands { /// Initialize bellman-cuda #[command(alias = "cuda")] InitBellmanCuda(Box), + ProtocolVersion, } pub(crate) async fn run(shell: &Shell, args: ProverCommands) -> anyhow::Result<()> { @@ -30,5 +32,6 @@ pub(crate) async fn run(shell: &Shell, args: ProverCommands) -> anyhow::Result<( ProverCommands::GenerateSK => generate_sk::run(shell).await, ProverCommands::Run(args) => run::run(args, shell).await, ProverCommands::InitBellmanCuda(args) => init_bellman_cuda::run(shell, *args).await, + ProverCommands::ProtocolVersion => protocol_version::run(shell).await, } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs new file mode 100644 index 000000000000..da8abad0fab1 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs @@ -0,0 +1,41 @@ +use std::{fs, path::PathBuf}; + +use common::logger; +use config::EcosystemConfig; +use xshell::{cmd, Shell}; + +pub async fn run(shell: &Shell) -> anyhow::Result<()> { + let link_to_code = EcosystemConfig::from_file(shell)?.link_to_code; + + let protocol_version = get_protocol_version(shell, &link_to_code).await?; + let snark_wrapper = get_snark_wrapper(&link_to_code).await?; + + logger::info(format!( + "Current protocol version found in zksync-era: {}, snark_wrapper: {}", + protocol_version, snark_wrapper + )); + + Ok(()) +} + +async fn get_protocol_version(shell: &Shell, link_to_code: &PathBuf) -> anyhow::Result { + let path = link_to_code.join("prover/crates/bin/prover_version/Cargo.toml"); + + let protocol_version = cmd!(shell, "cargo run --manifest-path {path}").read()?; + + Ok(protocol_version) +} + +async fn get_snark_wrapper(link_to_code: &PathBuf) -> anyhow::Result { + let path = link_to_code + .join("prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json"); + let file = fs::File::open(path).expect("Could not find commitments file in zksync-era"); + let json: serde_json::Value = + serde_json::from_reader(file).expect("Could not parse commitments.json"); + + let snark_wrapper = json + .get("snark_wrapper") + .expect("Could not find snark_wrapper in commitments.json"); + + Ok(snark_wrapper.to_string()) +} diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 75315f220eb2..402ee0718e88 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -299,7 +299,6 @@ pub(super) const MSG_BELLMAN_CUDA_ORIGIN_SELECT: &str = pub(super) const MSG_BELLMAN_CUDA_SELECTION_CLONE: &str = "Clone for me (recommended)"; pub(super) const MSG_BELLMAN_CUDA_SELECTION_PATH: &str = "I have the code already"; pub(super) const MSG_CLOUD_TYPE_PROMPT: &str = "Select the cloud connection mode:"; -pub(super) const MSG_COPY_CONFIGS_PROMPT: &str = "Do you want to copy configs from scratch?"; pub(super) const MSG_THREADS_PROMPT: &str = "Provide the number of threads:"; pub(super) fn msg_bucket_created(bucket_name: &str) -> String { From b58d2d57915138315609a1e8d7778b42907093a0 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:20:02 +0300 Subject: [PATCH 09/31] fix build --- .../crates/zk_inception/src/commands/prover/args/init.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index 20bd34259e44..e8c9cf1888d5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -466,9 +466,11 @@ impl ProverInitArgs { fn get_cloud_type_with_prompt(&self) -> CloudConnectionMode { let cloud_type = self.cloud_type.clone().unwrap_or_else(|| { - PromptSelect::new(MSG_CLOUD_TYPE_PROMPT, InternalCloudConnectionMode::iter()) - .default(InternalCloudConnectionMode::Local) - .ask() + PromptSelect::new( + MSG_CLOUD_TYPE_PROMPT, + InternalCloudConnectionMode::iter().rev(), + ) + .ask() }); cloud_type.into() From 752cd011821bce03661904ee46348c0778378beb Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:38:26 +0300 Subject: [PATCH 10/31] update some commands --- prover/docs/05_proving_batch.md | 10 ++++++---- .../src/commands/prover/protocol_version.rs | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 5f01dc50808e..390ceb585e97 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -14,11 +14,11 @@ Install the prerequisites, which you can find [here](https://github.com/matter-labs/zksync-era/blob/main/docs/guides/setup-dev.md). Note, that if you are not using Google VM instance, you also need to install [gcloud](https://cloud.google.com/sdk/docs/install#deb). -Now, you can use `zk_inception` tool for setting up the env and running prover subsystem. Check the steps for -installation in [this guide](../../zk_toolbox/README.md). And don't forget to install the prerequisites! +Now, you can use `zk_inception` and `prover_cli` tools for setting up the env and running prover subsystem. -Also, to assure that you are working with database securely, you need to use `prover_cli` tool. You can find the guide -for installation [here](../crates/bin/prover_cli/README.md). +```shell +cargo install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception zk_supervisor prover_cli --force +``` ## Initializing system @@ -36,6 +36,8 @@ values for all the prompts you will see Now, you need to initialize the prover s zk_inception prover init --shall-save-to-public-bucket=false --setup-database=true --use-default=true --dont-drop=false ``` +For prompts you can leave default values as well. + ## Proving the batch ### Getting data needed for proving diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs index da8abad0fab1..77b083ed1155 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs @@ -20,8 +20,11 @@ pub async fn run(shell: &Shell) -> anyhow::Result<()> { async fn get_protocol_version(shell: &Shell, link_to_code: &PathBuf) -> anyhow::Result { let path = link_to_code.join("prover/crates/bin/prover_version/Cargo.toml"); - - let protocol_version = cmd!(shell, "cargo run --manifest-path {path}").read()?; + let protocol_version = cmd!( + shell, + "cargo +nightly-2024-08-01 run --manifest-path {path}" + ) + .read()?; Ok(protocol_version) } From 9274787190fa82d939d9a5a6275facf25c2dfc59 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:08:18 +0300 Subject: [PATCH 11/31] fix problems with keystore --- .../bin/proof_fri_compressor/src/compressor.rs | 13 +++++++++++-- .../crates/bin/proof_fri_compressor/src/main.rs | 5 +++++ .../prover_fri/src/gpu_prover_job_processor.rs | 5 +++-- .../bin/prover_fri/src/prover_job_processor.rs | 5 +++-- .../witness_generator/src/leaf_aggregation.rs | 16 ++++++++++++---- prover/crates/bin/witness_generator/src/main.rs | 14 ++++++++++---- .../witness_generator/src/node_aggregation.rs | 8 ++++++-- .../bin/witness_generator/src/recursion_tip.rs | 7 ++++++- .../bin/witness_generator/src/scheduler.rs | 17 +++++++++++++---- prover/docs/05_proving_batch.md | 15 +++++---------- 10 files changed, 74 insertions(+), 31 deletions(-) diff --git a/prover/crates/bin/proof_fri_compressor/src/compressor.rs b/prover/crates/bin/proof_fri_compressor/src/compressor.rs index dc5ca939d9b4..c2cd2608398c 100644 --- a/prover/crates/bin/proof_fri_compressor/src/compressor.rs +++ b/prover/crates/bin/proof_fri_compressor/src/compressor.rs @@ -35,6 +35,7 @@ pub struct ProofCompressor { compression_mode: u8, max_attempts: u32, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, } impl ProofCompressor { @@ -44,6 +45,7 @@ impl ProofCompressor { compression_mode: u8, max_attempts: u32, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, ) -> Self { Self { blob_store, @@ -51,6 +53,7 @@ impl ProofCompressor { compression_mode, max_attempts, protocol_version, + setup_data_path, } } @@ -59,8 +62,9 @@ impl ProofCompressor { l1_batch: L1BatchNumber, proof: ZkSyncRecursionLayerProof, _compression_mode: u8, + setup_data_path: String, ) -> anyhow::Result { - let keystore = Keystore::default(); + let keystore = Keystore::new_with_setup_data_path(setup_data_path); let scheduler_vk = keystore .load_recursive_layer_verification_key( ZkSyncRecursionLayerStorageType::SchedulerCircuit as u8, @@ -175,7 +179,12 @@ impl JobProcessor for ProofCompressor { let compression_mode = self.compression_mode; let block_number = *job_id; tokio::task::spawn_blocking(move || { - Self::compress_proof(block_number, job, compression_mode) + Self::compress_proof( + block_number, + job, + compression_mode, + self.setup_data_path.clone(), + ) }) } diff --git a/prover/crates/bin/proof_fri_compressor/src/main.rs b/prover/crates/bin/proof_fri_compressor/src/main.rs index a1a8ac90253e..e2086b228b69 100644 --- a/prover/crates/bin/proof_fri_compressor/src/main.rs +++ b/prover/crates/bin/proof_fri_compressor/src/main.rs @@ -59,6 +59,7 @@ async fn main() -> anyhow::Result<()> { let object_store_config = ProverObjectStoreConfig( general_config .prover_config + .clone() .expect("ProverConfig") .prover_object_store .context("ProverObjectStoreConfig")?, @@ -75,6 +76,10 @@ async fn main() -> anyhow::Result<()> { config.compression_mode, config.max_attempts, protocol_version, + general_config + .prover_config + .expect("ProverConfig doesn't exist") + .setup_data_path, ); let (stop_sender, stop_receiver) = watch::channel(false); diff --git a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs index 4407dbcd8523..dc8594cbdc1b 100644 --- a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs @@ -112,7 +112,8 @@ pub mod gpu_prover { .clone(), SetupLoadMode::FromDisk => { let started_at = Instant::now(); - let keystore = Keystore::default(); + let keystore = + Keystore::new_with_setup_data_path(self.config.setup_data_path.clone()); let artifact: GoldilocksGpuProverSetupData = keystore .load_gpu_setup_data_for_circuit_type(key.clone()) .context("load_gpu_setup_data_for_circuit_type()")?; @@ -347,7 +348,7 @@ pub mod gpu_prover { &config.specialized_group_id, prover_setup_metadata_list ); - let keystore = Keystore::default(); + let keystore = Keystore::new_with_setup_data_path(config.setup_data_path.clone()); for prover_setup_metadata in prover_setup_metadata_list { let key = setup_metadata_to_setup_data_key(&prover_setup_metadata); let setup_data = keystore diff --git a/prover/crates/bin/prover_fri/src/prover_job_processor.rs b/prover/crates/bin/prover_fri/src/prover_job_processor.rs index 09c9d38348ff..2df1b626497f 100644 --- a/prover/crates/bin/prover_fri/src/prover_job_processor.rs +++ b/prover/crates/bin/prover_fri/src/prover_job_processor.rs @@ -85,7 +85,8 @@ impl Prover { .clone(), SetupLoadMode::FromDisk => { let started_at = Instant::now(); - let keystore = Keystore::default(); + let keystore = + Keystore::new_with_setup_data_path(self.config.setup_data_path.clone()); let artifact: GoldilocksProverSetupData = keystore .load_cpu_setup_data_for_circuit_type(key.clone()) .context("get_cpu_setup_data_for_circuit_type()")?; @@ -298,7 +299,7 @@ pub fn load_setup_data_cache(config: &FriProverConfig) -> anyhow::Result, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, } impl LeafAggregationWitnessGenerator { @@ -80,12 +81,14 @@ impl LeafAggregationWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, ) -> Self { Self { config, object_store, prover_connection_pool, protocol_version, + setup_data_path, } } @@ -131,9 +134,13 @@ impl JobProcessor for LeafAggregationWitnessGenerator { tracing::info!("Processing leaf aggregation job {:?}", metadata.id); Ok(Some(( metadata.id, - prepare_leaf_aggregation_job(metadata, &*self.object_store) - .await - .context("prepare_leaf_aggregation_job()")?, + prepare_leaf_aggregation_job( + metadata, + &*self.object_store, + self.setup_data_path.clone(), + ) + .await + .context("prepare_leaf_aggregation_job()")?, ))) } @@ -219,6 +226,7 @@ impl JobProcessor for LeafAggregationWitnessGenerator { pub async fn prepare_leaf_aggregation_job( metadata: LeafAggregationJobMetadata, object_store: &dyn ObjectStore, + setup_data_path: String, ) -> anyhow::Result { let started_at = Instant::now(); let closed_form_input = get_artifacts(&metadata, object_store).await; @@ -227,7 +235,7 @@ pub async fn prepare_leaf_aggregation_job( .observe(started_at.elapsed()); let started_at = Instant::now(); - let keystore = Keystore::default(); + let keystore = Keystore::new_with_setup_data_path(setup_data_path); let base_vk = keystore .load_base_layer_verification_key(metadata.circuit_id) .context("get_base_layer_vk_for_circuit_type()")?; diff --git a/prover/crates/bin/witness_generator/src/main.rs b/prover/crates/bin/witness_generator/src/main.rs index a88dd8726d39..50c955168602 100644 --- a/prover/crates/bin/witness_generator/src/main.rs +++ b/prover/crates/bin/witness_generator/src/main.rs @@ -80,9 +80,10 @@ async fn main() -> anyhow::Result<()> { let store_factory = ObjectStoreFactory::new(object_store_config.0); let config = general_config .witness_generator_config - .context("witness generator config")?; + .context("witness generator config")? + .clone(); - let prometheus_config = general_config.prometheus_config; + let prometheus_config = general_config.prometheus_config.clone(); // If the prometheus listener port is not set in the witness generator config, use the one from the prometheus config. let prometheus_listener_port = if let Some(port) = config.prometheus_listener_port { @@ -158,6 +159,8 @@ async fn main() -> anyhow::Result<()> { let mut tasks = Vec::new(); tasks.push(tokio::spawn(prometheus_task)); + let setup_data_path = prover_config.setup_data_path.clone(); + for round in rounds { tracing::info!( "initializing the {:?} witness generator, batch size: {:?} with protocol_version: {:?}", @@ -168,8 +171,7 @@ async fn main() -> anyhow::Result<()> { let witness_generator_task = match round { AggregationRound::BasicCircuits => { - let setup_data_path = prover_config.setup_data_path.clone(); - let vk_commitments = get_cached_commitments(Some(setup_data_path)); + let vk_commitments = get_cached_commitments(Some(setup_data_path.clone())); assert_eq!( vk_commitments, vk_commitments_in_db, @@ -204,6 +206,7 @@ async fn main() -> anyhow::Result<()> { store_factory.create_store().await?, prover_connection_pool.clone(), protocol_version, + setup_data_path.clone(), ); generator.run(stop_receiver.clone(), opt.batch_size) } @@ -213,6 +216,7 @@ async fn main() -> anyhow::Result<()> { store_factory.create_store().await?, prover_connection_pool.clone(), protocol_version, + setup_data_path.clone(), ); generator.run(stop_receiver.clone(), opt.batch_size) } @@ -222,6 +226,7 @@ async fn main() -> anyhow::Result<()> { store_factory.create_store().await?, prover_connection_pool.clone(), protocol_version, + setup_data_path.clone(), ); generator.run(stop_receiver.clone(), opt.batch_size) } @@ -231,6 +236,7 @@ async fn main() -> anyhow::Result<()> { store_factory.create_store().await?, prover_connection_pool.clone(), protocol_version, + setup_data_path.clone(), ); generator.run(stop_receiver.clone(), opt.batch_size) } diff --git a/prover/crates/bin/witness_generator/src/node_aggregation.rs b/prover/crates/bin/witness_generator/src/node_aggregation.rs index a7dce2a513d8..b6fc6b8f7c65 100644 --- a/prover/crates/bin/witness_generator/src/node_aggregation.rs +++ b/prover/crates/bin/witness_generator/src/node_aggregation.rs @@ -70,6 +70,7 @@ pub struct NodeAggregationWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, } impl NodeAggregationWitnessGenerator { @@ -78,12 +79,14 @@ impl NodeAggregationWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, ) -> Self { Self { config, object_store, prover_connection_pool, protocol_version, + setup_data_path, } } @@ -241,7 +244,7 @@ impl JobProcessor for NodeAggregationWitnessGenerator { tracing::info!("Processing node aggregation job {:?}", metadata.id); Ok(Some(( metadata.id, - prepare_job(metadata, &*self.object_store) + prepare_job(metadata, &*self.object_store, self.setup_data_path.clone()) .await .context("prepare_job()")?, ))) @@ -326,6 +329,7 @@ impl JobProcessor for NodeAggregationWitnessGenerator { pub async fn prepare_job( metadata: NodeAggregationJobMetadata, object_store: &dyn ObjectStore, + setup_data_path: String, ) -> anyhow::Result { let started_at = Instant::now(); let artifacts = get_artifacts(&metadata, object_store).await; @@ -334,7 +338,7 @@ pub async fn prepare_job( .observe(started_at.elapsed()); let started_at = Instant::now(); - let keystore = Keystore::default(); + let keystore = Keystore::new_with_setup_data_path(setup_data_path); let leaf_vk = keystore .load_recursive_layer_verification_key(metadata.circuit_id) .context("get_recursive_layer_vk_for_circuit_type")?; diff --git a/prover/crates/bin/witness_generator/src/recursion_tip.rs b/prover/crates/bin/witness_generator/src/recursion_tip.rs index 2a57ffff85ff..e05a0cc38cf8 100644 --- a/prover/crates/bin/witness_generator/src/recursion_tip.rs +++ b/prover/crates/bin/witness_generator/src/recursion_tip.rs @@ -75,6 +75,7 @@ pub struct RecursionTipWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, } impl RecursionTipWitnessGenerator { @@ -83,12 +84,14 @@ impl RecursionTipWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, ) -> Self { Self { config, object_store, prover_connection_pool, protocol_version, + setup_data_path, } } @@ -172,6 +175,7 @@ impl JobProcessor for RecursionTipWitnessGenerator { l1_batch_number, final_node_proof_job_ids, &*self.object_store, + self.setup_data_path.clone(), ) .await .context("prepare_job()")?, @@ -284,6 +288,7 @@ pub async fn prepare_job( l1_batch_number: L1BatchNumber, final_node_proof_job_ids: Vec<(u8, u32)>, object_store: &dyn ObjectStore, + setup_data_path: String, ) -> anyhow::Result { let started_at = Instant::now(); let recursion_tip_proofs = @@ -291,7 +296,7 @@ pub async fn prepare_job( WITNESS_GENERATOR_METRICS.blob_fetch_time[&AggregationRound::RecursionTip.into()] .observe(started_at.elapsed()); - let keystore = Keystore::default(); + let keystore = Keystore::new_with_setup_data_path(setup_data_path); let node_vk = keystore .load_recursive_layer_verification_key( ZkSyncRecursionLayerStorageType::NodeLayerCircuit as u8, diff --git a/prover/crates/bin/witness_generator/src/scheduler.rs b/prover/crates/bin/witness_generator/src/scheduler.rs index f69d338061e2..c389e037ffa6 100644 --- a/prover/crates/bin/witness_generator/src/scheduler.rs +++ b/prover/crates/bin/witness_generator/src/scheduler.rs @@ -57,6 +57,7 @@ pub struct SchedulerWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, } impl SchedulerWitnessGenerator { @@ -65,12 +66,14 @@ impl SchedulerWitnessGenerator { object_store: Arc, prover_connection_pool: ConnectionPool, protocol_version: ProtocolSemanticVersion, + setup_data_path: String, ) -> Self { Self { config, object_store, prover_connection_pool, protocol_version, + setup_data_path, } } @@ -147,9 +150,14 @@ impl JobProcessor for SchedulerWitnessGenerator { Ok(Some(( l1_batch_number, - prepare_job(l1_batch_number, recursion_tip_job_id, &*self.object_store) - .await - .context("prepare_job()")?, + prepare_job( + l1_batch_number, + recursion_tip_job_id, + &*self.object_store, + self.setup_data_path.clone(), + ) + .await + .context("prepare_job()")?, ))) } @@ -258,6 +266,7 @@ pub async fn prepare_job( l1_batch_number: L1BatchNumber, recursion_tip_job_id: u32, object_store: &dyn ObjectStore, + setup_data_path: String, ) -> anyhow::Result { let started_at = Instant::now(); let wrapper = object_store.get(recursion_tip_job_id).await?; @@ -271,7 +280,7 @@ pub async fn prepare_job( .observe(started_at.elapsed()); let started_at = Instant::now(); - let keystore = Keystore::default(); + let keystore = Keystore::new_with_setup_data_path(setup_data_path); let node_vk = keystore .load_recursive_layer_verification_key( ZkSyncRecursionLayerStorageType::NodeLayerCircuit as u8, diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 390ceb585e97..c8a267c0647c 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -17,7 +17,7 @@ Google VM instance, you also need to install [gcloud](https://cloud.google.com/s Now, you can use `zk_inception` and `prover_cli` tools for setting up the env and running prover subsystem. ```shell -cargo install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception zk_supervisor prover_cli --force +cargo +nightly-2024-08-01 install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception zk_supervisor prover_cli --force ``` ## Initializing system @@ -71,22 +71,17 @@ patch versions) and snark wrapper value. Now, with the use of `prover_cli` tool, you can insert the data about the batch and protocol version into the database: -First, let the tool know which database it should connect to(for local DB you can find the url in `secrets.yaml` file): +First, get the database URL(you can find it in `/chains/configs//secrets.yaml` - it is the +`prover_url` value) Now, insert the information about protocol version in the database: ```shell -prover_cli config --db-url -``` - -Now, insert the information about protocol version in the database: - -```shell -prover_cli insert-version --version= --patch= --snark-wrapper= +prover_cli insert-version --version= --patch= --snark-wrapper= ``` And finally, provide the data about the batch: ```shell -prover_cli insert-batch --number= --version= --patch= +prover_cli insert-batch --number= --version= --patch= ``` ## Running prover subsystem From a655222795fbd72cf0f74656b3efdd68ce15c34e Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:23:30 +0300 Subject: [PATCH 12/31] debug --- prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs index dc8594cbdc1b..8ae63be216d5 100644 --- a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs @@ -114,6 +114,11 @@ pub mod gpu_prover { let started_at = Instant::now(); let keystore = Keystore::new_with_setup_data_path(self.config.setup_data_path.clone()); + tracing::info!( + "Loading setup data for circuit id: {}, setup_data_path {}", + key.circuit_id, + self.config.setup_data_path.clone() + ); let artifact: GoldilocksGpuProverSetupData = keystore .load_gpu_setup_data_for_circuit_type(key.clone()) .context("load_gpu_setup_data_for_circuit_type()")?; From cd811eea80ee886e1532f54f539fd576bb1498fc Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:26:31 +0300 Subject: [PATCH 13/31] debug --- prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs index 8ae63be216d5..c1bdee5ca00d 100644 --- a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs @@ -287,6 +287,9 @@ pub mod gpu_prover { tokio::task::spawn_blocking(move || { let block_number = job.witness_vector_artifacts.prover_job.block_number; let _span = tracing::info_span!("gpu_prove", %block_number).entered(); + if setup_data.is_err() { + tracing::info!("Failed to get setup data for job: {:?}", setup_data); + } Ok(Self::prove(job, setup_data.context("get_setup_data()")?)) }) } From 56d385ba9c02f1b379fdcf75420aaec786788561 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:32:55 +0300 Subject: [PATCH 14/31] fix path of generate-sk --- .../crates/zk_inception/src/commands/prover/generate_sk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs index 1657ab2c99fb..53b00c522d94 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs @@ -19,7 +19,7 @@ pub(crate) async fn run(shell: &Shell) -> anyhow::Result<()> { "cargo run --features gpu --release --bin key_generator -- generate-sk all --recompute-if-missing --setup-path=vk_setup_data_generator_server_fri/data - --path={link_to_prover}/vk_setup_data_generator_server_fri/data" + --path={link_to_prover}/crates/bin/vk_setup_data_generator_server_fri/data" )); cmd.run()?; spinner.finish(); From 32b5bfc5dbf1e965d5defc3d1ddf2a32ca7cb6ee Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:52:56 +0300 Subject: [PATCH 15/31] fix? --- .../crates/zk_inception/src/commands/prover/generate_sk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs index 53b00c522d94..4e69492bd11e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs @@ -18,7 +18,7 @@ pub(crate) async fn run(shell: &Shell) -> anyhow::Result<()> { shell, "cargo run --features gpu --release --bin key_generator -- generate-sk all --recompute-if-missing - --setup-path=vk_setup_data_generator_server_fri/data + --setup-path=crates/bin/vk_setup_data_generator_server_fri/data --path={link_to_prover}/crates/bin/vk_setup_data_generator_server_fri/data" )); cmd.run()?; From d4f7063e784932bfb4b7e496f33e8dc86f5cb940 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:16:11 +0300 Subject: [PATCH 16/31] update docs --- etc/env/file_based/general.yaml | 2 +- .../prover_fri/src/gpu_prover_job_processor.rs | 8 -------- prover/docs/01_gcp_vm.md | 2 +- prover/docs/05_proving_batch.md | 15 ++++++++++++++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/etc/env/file_based/general.yaml b/etc/env/file_based/general.yaml index 9df7358c08cd..b4ef43109332 100644 --- a/etc/env/file_based/general.yaml +++ b/etc/env/file_based/general.yaml @@ -140,7 +140,7 @@ prover: file_backed: file_backed_base_path: artifacts max_retries: 10 - setup_data_path: vk_setup_data_generator_server_fri/data + setup_data_path: crates/bin/vk_setup_data_generator_server_fri/data prometheus_port: 3315 max_attempts: 10 generation_timeout_in_secs: 600 diff --git a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs index c1bdee5ca00d..dc8594cbdc1b 100644 --- a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs @@ -114,11 +114,6 @@ pub mod gpu_prover { let started_at = Instant::now(); let keystore = Keystore::new_with_setup_data_path(self.config.setup_data_path.clone()); - tracing::info!( - "Loading setup data for circuit id: {}, setup_data_path {}", - key.circuit_id, - self.config.setup_data_path.clone() - ); let artifact: GoldilocksGpuProverSetupData = keystore .load_gpu_setup_data_for_circuit_type(key.clone()) .context("load_gpu_setup_data_for_circuit_type()")?; @@ -287,9 +282,6 @@ pub mod gpu_prover { tokio::task::spawn_blocking(move || { let block_number = job.witness_vector_artifacts.prover_job.block_number; let _span = tracing::info_span!("gpu_prove", %block_number).entered(); - if setup_data.is_err() { - tracing::info!("Failed to get setup data for job: {:?}", setup_data); - } Ok(Self::prove(job, setup_data.context("get_setup_data()")?)) }) } diff --git a/prover/docs/01_gcp_vm.md b/prover/docs/01_gcp_vm.md index a541495e978a..2c431eda9572 100644 --- a/prover/docs/01_gcp_vm.md +++ b/prover/docs/01_gcp_vm.md @@ -42,7 +42,7 @@ When you choose the region, set the following options: - Operating system: Ubuntu - Version: Ubuntu 22.04 LTS (x86/64) - Boot disk type: SSD persistent disk - - Size: 300GB + - Size: 500GB Leave the remaining options as is and click on "Create". diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index c8a267c0647c..0cb2dc47b4a0 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -46,7 +46,14 @@ At this step, we need to get the witness inputs data for the batch you want to p input file, called `witness_inputs_.bin` generated by different core components). - If batch was produced by your system, the file is stored by prover gateway in GCS (or your choice of object storage -- - check config). To access it from GCS (assuming you have access to the bucket), run: + check config). At the point of getting it, most likely there is no artifacts directory created. If you have cloned the + zksync-era repo, then it is in the root of ecosystem directory. Create artifacts directory by running: + + ```shell + mkdir -p + ``` + + To access it from GCS (assuming you have access to the bucket), run: ```shell gsutil cp gs://your_bucket/witness_inputs/witness_inputs_.bin @@ -84,6 +91,12 @@ And finally, provide the data about the batch: prover_cli insert-batch --number= --version= --patch= ``` +Also, provers need to know which setup keys they should use. Generate them with: + +```shell +zk_inception prover generate-sk +``` + ## Running prover subsystem At this step, all the data is prepared and you can run the prover subsystem. To do that, run the following commands: From 3b45abaf0d72a644d24461a41926c31129e823c5 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:32:12 +0300 Subject: [PATCH 17/31] fix build, fix lint --- prover/crates/bin/proof_fri_compressor/src/compressor.rs | 8 ++------ .../zk_inception/src/commands/prover/protocol_version.rs | 7 ++++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/prover/crates/bin/proof_fri_compressor/src/compressor.rs b/prover/crates/bin/proof_fri_compressor/src/compressor.rs index c2cd2608398c..4bf4ecbac04e 100644 --- a/prover/crates/bin/proof_fri_compressor/src/compressor.rs +++ b/prover/crates/bin/proof_fri_compressor/src/compressor.rs @@ -178,13 +178,9 @@ impl JobProcessor for ProofCompressor { ) -> JoinHandle> { let compression_mode = self.compression_mode; let block_number = *job_id; + let setup_data_path = self.setup_data_path.clone(); tokio::task::spawn_blocking(move || { - Self::compress_proof( - block_number, - job, - compression_mode, - self.setup_data_path.clone(), - ) + Self::compress_proof(block_number, job, compression_mode, setup_data_path) }) } diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs index 77b083ed1155..e5af38bb5f8e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs @@ -1,4 +1,5 @@ -use std::{fs, path::PathBuf}; +use std::fs; +use std::path::Path; use common::logger; use config::EcosystemConfig; @@ -18,7 +19,7 @@ pub async fn run(shell: &Shell) -> anyhow::Result<()> { Ok(()) } -async fn get_protocol_version(shell: &Shell, link_to_code: &PathBuf) -> anyhow::Result { +async fn get_protocol_version(shell: &Shell, link_to_code: &Path) -> anyhow::Result { let path = link_to_code.join("prover/crates/bin/prover_version/Cargo.toml"); let protocol_version = cmd!( shell, @@ -29,7 +30,7 @@ async fn get_protocol_version(shell: &Shell, link_to_code: &PathBuf) -> anyhow:: Ok(protocol_version) } -async fn get_snark_wrapper(link_to_code: &PathBuf) -> anyhow::Result { +async fn get_snark_wrapper(link_to_code: &Path) -> anyhow::Result { let path = link_to_code .join("prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json"); let file = fs::File::open(path).expect("Could not find commitments file in zksync-era"); From f254d99cb9a445eb85f79aacca1b44679ab6464e Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:32:43 +0300 Subject: [PATCH 18/31] fmt --- .../zk_inception/src/commands/prover/protocol_version.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs index e5af38bb5f8e..00be0aae32b3 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs @@ -1,5 +1,4 @@ -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; use common::logger; use config::EcosystemConfig; From db4b0f9b0129d231f77927452f41609a5518596b Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:35:18 +0300 Subject: [PATCH 19/31] update doc --- prover/docs/05_proving_batch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 0cb2dc47b4a0..5a2158e817a5 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -91,7 +91,7 @@ And finally, provide the data about the batch: prover_cli insert-batch --number= --version= --patch= ``` -Also, provers need to know which setup keys they should use. Generate them with: +Also, provers need to know which setup keys they should use. It may take some time, but you can generate them with: ```shell zk_inception prover generate-sk From 4e3ffb67cb6ba3f6eaadece8d658c50076dc61f9 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:01:42 +0300 Subject: [PATCH 20/31] fix test --- .../bin/witness_generator/tests/basic_test.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/prover/crates/bin/witness_generator/tests/basic_test.rs b/prover/crates/bin/witness_generator/tests/basic_test.rs index f8a21179adb7..b034ab57d82c 100644 --- a/prover/crates/bin/witness_generator/tests/basic_test.rs +++ b/prover/crates/bin/witness_generator/tests/basic_test.rs @@ -50,9 +50,13 @@ async fn test_leaf_witness_gen() { .await .unwrap(); - let job = prepare_leaf_aggregation_job(leaf_aggregation_job_metadata, &*object_store) - .await - .unwrap(); + let job = prepare_leaf_aggregation_job( + leaf_aggregation_job_metadata, + &*object_store, + "crates/bin/vk_setup_data_generator/data".to_string(), + ) + .await + .unwrap(); let artifacts = LeafAggregationWitnessGenerator::process_job_impl( job, @@ -139,9 +143,13 @@ async fn test_node_witness_gen() { prover_job_ids_for_proofs: vec![5211320], }; - let job = node_aggregation::prepare_job(node_aggregation_job_metadata, &*object_store) - .await - .unwrap(); + let job = node_aggregation::prepare_job( + node_aggregation_job_metadata, + &*object_store, + "crates/bin/vk_setup_data_generator/data".to_string(), + ) + .await + .unwrap(); let artifacts = NodeAggregationWitnessGenerator::process_job_impl( job, From 374118b2f03c68c5a0d672d06492c2f83a275c09 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:17:51 +0300 Subject: [PATCH 21/31] fix generate-sk --- .../crates/zk_inception/src/commands/prover/generate_sk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs index 4e69492bd11e..7f678470d178 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/generate_sk.rs @@ -17,7 +17,7 @@ pub(crate) async fn run(shell: &Shell) -> anyhow::Result<()> { let cmd = Cmd::new(cmd!( shell, "cargo run --features gpu --release --bin key_generator -- - generate-sk all --recompute-if-missing + generate-sk-gpu all --recompute-if-missing --setup-path=crates/bin/vk_setup_data_generator_server_fri/data --path={link_to_prover}/crates/bin/vk_setup_data_generator_server_fri/data" )); From 25567e4d1f1e5324c0d17aaa5e9b3eae8dd194f5 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:41:10 +0300 Subject: [PATCH 22/31] add pjm to prover components --- .../src/commands/prover/args/run.rs | 2 ++ .../zk_inception/src/commands/prover/run.rs | 18 +++++++++++++++--- zk_toolbox/crates/zk_inception/src/messages.rs | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs index c2d5cef26ad4..6bdd62c1d488 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs @@ -28,6 +28,8 @@ pub enum ProverComponent { Prover, #[strum(to_string = "Compressor")] Compressor, + #[strum(to_string = "ProverJobMonitor")] + ProverJobMonitor, } #[derive(Debug, Clone, Parser, Default)] diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs index 5497db8a21e0..661ba7de9560 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs @@ -13,9 +13,10 @@ use super::{ use crate::messages::{ MSG_BELLMAN_CUDA_DIR_ERR, MSG_CHAIN_NOT_FOUND_ERR, MSG_MISSING_COMPONENT_ERR, MSG_RUNNING_COMPRESSOR, MSG_RUNNING_COMPRESSOR_ERR, MSG_RUNNING_PROVER, MSG_RUNNING_PROVER_ERR, - MSG_RUNNING_PROVER_GATEWAY, MSG_RUNNING_PROVER_GATEWAY_ERR, MSG_RUNNING_WITNESS_GENERATOR, - MSG_RUNNING_WITNESS_GENERATOR_ERR, MSG_RUNNING_WITNESS_VECTOR_GENERATOR, - MSG_RUNNING_WITNESS_VECTOR_GENERATOR_ERR, MSG_WITNESS_GENERATOR_ROUND_ERR, + MSG_RUNNING_PROVER_GATEWAY, MSG_RUNNING_PROVER_GATEWAY_ERR, MSG_RUNNING_PROVER_JOB_MONITOR, + MSG_RUNNING_WITNESS_GENERATOR, MSG_RUNNING_WITNESS_GENERATOR_ERR, + MSG_RUNNING_WITNESS_VECTOR_GENERATOR, MSG_RUNNING_WITNESS_VECTOR_GENERATOR_ERR, + MSG_WITNESS_GENERATOR_ROUND_ERR, }; pub(crate) async fn run(args: ProverRunArgs, shell: &Shell) -> anyhow::Result<()> { @@ -39,6 +40,7 @@ pub(crate) async fn run(args: ProverRunArgs, shell: &Shell) -> anyhow::Result<() } Some(ProverComponent::Prover) => run_prover(shell, &chain)?, Some(ProverComponent::Compressor) => run_compressor(shell, &chain, &ecosystem_config)?, + Some(ProverComponent::ProverJobMonitor) => run_prover_job_monitor(shell, &chain)?, None => anyhow::bail!(MSG_MISSING_COMPONENT_ERR), } @@ -127,3 +129,13 @@ fn run_compressor( cmd = cmd.with_force_run(); cmd.run().context(MSG_RUNNING_COMPRESSOR_ERR) } + +fn run_prover_job_monitor(shell: &Shell, chain: &ChainConfig) -> anyhow::Result<()> { + logger::info(MSG_RUNNING_PROVER_JOB_MONITOR); + let config_path = chain.path_to_general_config(); + let secrets_path = chain.path_to_secrets_config(); + + let mut cmd = Cmd::new(cmd!(shell, "cargo run --release --bin prover_job_monitor -- --config-path={config_path} --secrets-path={secrets_path}")); + cmd = cmd.with_force_run(); + cmd.run().context(MSG_RUNNING_PROVER_JOB_MONITOR) +} diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index f0e46aaf4869..1ec2b006452f 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -259,6 +259,7 @@ pub(super) const MSG_GENERATING_SK_SPINNER: &str = "Generating setup keys..."; pub(super) const MSG_SK_GENERATED: &str = "Setup keys generated successfully"; pub(super) const MSG_MISSING_COMPONENT_ERR: &str = "Missing component"; pub(super) const MSG_RUNNING_PROVER_GATEWAY: &str = "Running gateway"; +pub(super) const MSG_RUNNING_PROVER_JOB_MONITOR: &str = "Running prover job monitor"; pub(super) const MSG_RUNNING_WITNESS_GENERATOR: &str = "Running witness generator"; pub(super) const MSG_RUNNING_WITNESS_VECTOR_GENERATOR: &str = "Running witness vector generator"; pub(super) const MSG_RUNNING_PROVER: &str = "Running prover"; From b2c3639c00f1178cc8b716bffd3bc7e020494dfe Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:46:35 +0300 Subject: [PATCH 23/31] fix name --- zk_toolbox/crates/zk_inception/src/commands/prover/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs index 661ba7de9560..056723836662 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs @@ -135,7 +135,7 @@ fn run_prover_job_monitor(shell: &Shell, chain: &ChainConfig) -> anyhow::Result< let config_path = chain.path_to_general_config(); let secrets_path = chain.path_to_secrets_config(); - let mut cmd = Cmd::new(cmd!(shell, "cargo run --release --bin prover_job_monitor -- --config-path={config_path} --secrets-path={secrets_path}")); + let mut cmd = Cmd::new(cmd!(shell, "cargo run --release --bin zksync_prover_job_monitor -- --config-path={config_path} --secrets-path={secrets_path}")); cmd = cmd.with_force_run(); cmd.run().context(MSG_RUNNING_PROVER_JOB_MONITOR) } From c412a32591be3df66b66d5dc338524e4d228c6c3 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:53:05 +0300 Subject: [PATCH 24/31] add pjm to doc --- prover/docs/05_proving_batch.md | 1 + 1 file changed, 1 insertion(+) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 5a2158e817a5..e7a6f4b1062c 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -106,6 +106,7 @@ zk_inception prover run --component=prover zk_inception prover run --component=witness-generator --round=all-rounds zk_inception prover run --component=witness-vector-generator --threads=10 zk_inception prover run --component=compressor +zk_inception prover run --component=prover-job-monitor ``` And you are good to go! The prover subsystem will prove the batch and you can check the results in the database. From 8e153755ede46dd878538f67075ddb8512d2c8a6 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:21:36 +0300 Subject: [PATCH 25/31] update docs --- prover/docs/01_gcp_vm.md | 2 +- prover/docs/05_proving_batch.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/prover/docs/01_gcp_vm.md b/prover/docs/01_gcp_vm.md index 2c431eda9572..a541495e978a 100644 --- a/prover/docs/01_gcp_vm.md +++ b/prover/docs/01_gcp_vm.md @@ -42,7 +42,7 @@ When you choose the region, set the following options: - Operating system: Ubuntu - Version: Ubuntu 22.04 LTS (x86/64) - Boot disk type: SSD persistent disk - - Size: 500GB + - Size: 300GB Leave the remaining options as is and click on "Create". diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index e7a6f4b1062c..9bf2cfba17b1 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -7,6 +7,13 @@ that. ## Requirements +### Hardware + +Setup for running the whole process should be the same as described [here](./01_gcp_vm.md), except you need 48 GB of +GPU, which requires an NVIDIA A100 80GB GPU. + +### Prerequisites + First of all, you need to install CUDA drivers, all other things will be dealt with by `zk_inception` and `prover_cli` tools. For that, check the following [guide](./02_setup.md)(you can skip bellman-cuda step). From e8c861796a967c5cc24aa60f647ed8beade09a0f Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:25:25 +0300 Subject: [PATCH 26/31] update docs --- zk_toolbox/crates/zk_inception/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/README.md b/zk_toolbox/crates/zk_inception/README.md index 7f1d3d64d856..0d7c0521fb8f 100644 --- a/zk_toolbox/crates/zk_inception/README.md +++ b/zk_toolbox/crates/zk_inception/README.md @@ -271,7 +271,6 @@ Initialize chain, deploying necessary contracts and performing on-chain operatio - `-u`, `--use-default` — Use default database urls and names - `-d`, `--dont-drop` - `--deploy-paymaster ` -- `--copy-configs` - Copy default configs to the chain Possible values: `true`, `false` @@ -440,6 +439,10 @@ Possible values: `true`, `false` - `--bellman-cuda-dir ` - `--download-key ` - `--setup-database` +- `--use-default` - use default database +- `--dont-drop` - don't drop database +- `--prover-db-url` - URL of database to use +- `--prover-db-name` - Name of database to use Possible values: `true`, `false` From 6ad0f21f4fe8aad54265d3f3118cdd6f99d888f6 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:59:44 +0300 Subject: [PATCH 27/31] address comments --- prover/docs/05_proving_batch.md | 20 +++++++++++++++--- zk_toolbox/Cargo.lock | 1 + .../zk_inception/src/commands/prover/mod.rs | 3 --- zk_toolbox/crates/zk_supervisor/Cargo.toml | 1 + .../crates/zk_supervisor/src/commands/mod.rs | 1 + .../src/commands}/protocol_version.rs | 21 ++++++++----------- zk_toolbox/crates/zk_supervisor/src/main.rs | 9 +++++--- .../crates/zk_supervisor/src/messages.rs | 1 + 8 files changed, 36 insertions(+), 21 deletions(-) rename zk_toolbox/crates/{zk_inception/src/commands/prover => zk_supervisor/src/commands}/protocol_version.rs (59%) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 9bf2cfba17b1..5d0e54bef9c7 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -69,7 +69,14 @@ input file, called `witness_inputs_.bin` generated by different core comp - If you want to prove the batch produced by zkSync, you can get the data from the `ExternalProofIntegrationAPI` using `{address}/proof_generation_data` endpoint. You need to replace `{address}` with the address of the API and provide the batch number as a query data to get the data for specific batch, otherwise, you will receive latest data for the - batch, that was already proven. + batch, that was already proven. Example: + ```shell + curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d 'null' + ``` + or + ```shell + curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d '1000' + ``` ### Preparing database @@ -80,12 +87,19 @@ the protocol version it should use. You can do that with running zk_inception prover protocol-version ``` +Example output: + +```shell +Current protocol version found in zksync-era: 0.24.2, snark_wrapper: "0x14f97b81e54b35fe673d8708cc1a19e1ea5b5e348e12d31e39824ed4f42bbca2" +``` + This command will provide you with the information about the semantic protocol version(you need to know only minor and -patch versions) and snark wrapper value. +patch versions) and snark wrapper value. In the example, `MINOR_VERSION` is 24, `PATCH_VERSION` is 2, and +`SNARK_WRAPPER` is `0x14f97b81e54b35fe673d8708cc1a19e1ea5b5e348e12d31e39824ed4f42bbca2`. Now, with the use of `prover_cli` tool, you can insert the data about the batch and protocol version into the database: -First, get the database URL(you can find it in `/chains/configs//secrets.yaml` - it is the +First, get the database URL(you can find it in `/chains//configs/secrets.yaml` - it is the `prover_url` value) Now, insert the information about protocol version in the database: ```shell diff --git a/zk_toolbox/Cargo.lock b/zk_toolbox/Cargo.lock index c76556272e82..7682b92a4f2d 100644 --- a/zk_toolbox/Cargo.lock +++ b/zk_toolbox/Cargo.lock @@ -6298,6 +6298,7 @@ dependencies = [ "futures", "human-panic", "serde", + "serde_json", "strum", "tokio", "url", diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs index dbbd14d7252a..31c3a02e3806 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs @@ -7,7 +7,6 @@ mod gcs; mod generate_sk; mod init; mod init_bellman_cuda; -mod protocol_version; mod run; mod utils; @@ -23,7 +22,6 @@ pub enum ProverCommands { /// Initialize bellman-cuda #[command(alias = "cuda")] InitBellmanCuda(Box), - ProtocolVersion, } pub(crate) async fn run(shell: &Shell, args: ProverCommands) -> anyhow::Result<()> { @@ -32,6 +30,5 @@ pub(crate) async fn run(shell: &Shell, args: ProverCommands) -> anyhow::Result<( ProverCommands::GenerateSK => generate_sk::run(shell).await, ProverCommands::Run(args) => run::run(args, shell).await, ProverCommands::InitBellmanCuda(args) => init_bellman_cuda::run(shell, *args).await, - ProverCommands::ProtocolVersion => protocol_version::run(shell).await, } } diff --git a/zk_toolbox/crates/zk_supervisor/Cargo.toml b/zk_toolbox/crates/zk_supervisor/Cargo.toml index e1225de96d32..e24c88f3ec25 100644 --- a/zk_toolbox/crates/zk_supervisor/Cargo.toml +++ b/zk_toolbox/crates/zk_supervisor/Cargo.toml @@ -23,3 +23,4 @@ xshell.workspace = true serde.workspace = true clap-markdown.workspace = true futures.workspace = true +serde_json.workspace = true diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs index 99a8fa5e0a5f..f3113e95cc93 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs @@ -3,5 +3,6 @@ pub mod database; pub mod fmt; pub mod lint; pub(crate) mod lint_utils; +pub mod protocol_version; pub mod snapshot; pub mod test; diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs b/zk_toolbox/crates/zk_supervisor/src/commands/protocol_version.rs similarity index 59% rename from zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs rename to zk_toolbox/crates/zk_supervisor/src/commands/protocol_version.rs index 00be0aae32b3..479f796294fa 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/protocol_version.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/protocol_version.rs @@ -6,9 +6,10 @@ use xshell::{cmd, Shell}; pub async fn run(shell: &Shell) -> anyhow::Result<()> { let link_to_code = EcosystemConfig::from_file(shell)?.link_to_code; + let link_to_prover = link_to_code.join("prover"); - let protocol_version = get_protocol_version(shell, &link_to_code).await?; - let snark_wrapper = get_snark_wrapper(&link_to_code).await?; + let protocol_version = get_protocol_version(shell, &link_to_prover).await?; + let snark_wrapper = get_snark_wrapper(&link_to_prover).await?; logger::info(format!( "Current protocol version found in zksync-era: {}, snark_wrapper: {}", @@ -18,20 +19,16 @@ pub async fn run(shell: &Shell) -> anyhow::Result<()> { Ok(()) } -async fn get_protocol_version(shell: &Shell, link_to_code: &Path) -> anyhow::Result { - let path = link_to_code.join("prover/crates/bin/prover_version/Cargo.toml"); - let protocol_version = cmd!( - shell, - "cargo +nightly-2024-08-01 run --manifest-path {path}" - ) - .read()?; +async fn get_protocol_version(shell: &Shell, link_to_prover: &Path) -> anyhow::Result { + shell.change_dir(link_to_prover); + let protocol_version = cmd!(shell, "cargo run --release --bin prover_version").read()?; Ok(protocol_version) } -async fn get_snark_wrapper(link_to_code: &Path) -> anyhow::Result { - let path = link_to_code - .join("prover/crates/bin/vk_setup_data_generator_server_fri/data/commitments.json"); +async fn get_snark_wrapper(link_to_prover: &Path) -> anyhow::Result { + let path = + link_to_prover.join("crates/bin/vk_setup_data_generator_server_fri/data/commitments.json"); let file = fs::File::open(path).expect("Could not find commitments file in zksync-era"); let json: serde_json::Value = serde_json::from_reader(file).expect("Could not parse commitments.json"); diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 965def9263aa..168b542f289d 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -10,9 +10,9 @@ use common::{ }; use config::EcosystemConfig; use messages::{ - msg_global_chain_does_not_exist, MSG_SUBCOMMAND_CLEAN, MSG_SUBCOMMAND_DATABASE_ABOUT, - MSG_SUBCOMMAND_FMT_ABOUT, MSG_SUBCOMMAND_LINT_ABOUT, MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, - MSG_SUBCOMMAND_TESTS_ABOUT, + msg_global_chain_does_not_exist, MSG_PROTOCOL_VERSION_ABOUT, MSG_SUBCOMMAND_CLEAN, + MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, MSG_SUBCOMMAND_LINT_ABOUT, + MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, }; use xshell::Shell; @@ -47,6 +47,8 @@ enum SupervisorSubcommands { Fmt(FmtArgs), #[command(hide = true)] Markdown, + #[command(about = MSG_PROTOCOL_VERSION_ABOUT)] + ProtocolVersion, } #[derive(Parser, Debug)] @@ -103,6 +105,7 @@ async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { } SupervisorSubcommands::Lint(args) => commands::lint::run(shell, args)?, SupervisorSubcommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, + SupervisorSubcommands::ProtocolVersion => commands::protocol_version::run(shell).await?, } Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index df0cf0c311df..adf0f49d453e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -8,6 +8,7 @@ pub(super) fn msg_global_chain_does_not_exist(chain: &str, available_chains: &st } // Subcommands help +pub(super) const MSG_PROTOCOL_VERSION_ABOUT: &str = "Protocol version used by provers"; pub(super) const MSG_SUBCOMMAND_DATABASE_ABOUT: &str = "Database related commands"; pub(super) const MSG_SUBCOMMAND_TESTS_ABOUT: &str = "Run tests"; pub(super) const MSG_SUBCOMMAND_CLEAN: &str = "Clean artifacts"; From fda7e4d6f016a5688f2e6f4072d3b87d0c5b2504 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:03:30 +0300 Subject: [PATCH 28/31] update docs --- zk_toolbox/crates/zk_inception/README.md | 6 ------ zk_toolbox/crates/zk_supervisor/README.md | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/README.md b/zk_toolbox/crates/zk_inception/README.md index 0d7c0521fb8f..8b6368ce8c24 100644 --- a/zk_toolbox/crates/zk_inception/README.md +++ b/zk_toolbox/crates/zk_inception/README.md @@ -457,12 +457,6 @@ Generate setup keys **Usage:** `zk_inception prover generate-sk` -## `zk_inception prover protocol-version` - -Gets information about current protocol version of provers in `zksync-era` and snark wrapper hash. - -**Usage:** `zk_inception prover protocol-version` - ## `zk_inception prover run` Run prover diff --git a/zk_toolbox/crates/zk_supervisor/README.md b/zk_toolbox/crates/zk_supervisor/README.md index 4648fe6cb366..9357af096ee8 100644 --- a/zk_toolbox/crates/zk_supervisor/README.md +++ b/zk_toolbox/crates/zk_supervisor/README.md @@ -5,6 +5,7 @@ This document contains the help content for the `zk_supervisor` command-line pro **Command Overview:** - [`zk_supervisor`↴](#zk_supervisor) +- [`zk_supervisor protocol-version`↴](#zk_supervisor-protocol-version) - [`zk_supervisor database`↴](#zk_supervisor-database) - [`zk_supervisor database check-sqlx-data`↴](#zk_supervisor-database-check-sqlx-data) - [`zk_supervisor database drop`↴](#zk_supervisor-database-drop) @@ -44,6 +45,12 @@ ZK Toolbox is a set of tools for working with zk stack. - `--chain ` — Chain to use - `--ignore-prerequisites` — Ignores prerequisites checks +## `zk_supervisor protocol-version` + +Gets information about current protocol version of provers in `zksync-era` and snark wrapper hash. + +**Usage:** `zk_supervisor protocol-version` + ## `zk_supervisor database` Database related commands From 1dc3c35035cee38cf39b9a75679968afcd979630 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:33:11 +0300 Subject: [PATCH 29/31] fix lint --- prover/docs/05_proving_batch.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 5d0e54bef9c7..44d52a566b54 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -70,12 +70,15 @@ input file, called `witness_inputs_.bin` generated by different core comp `{address}/proof_generation_data` endpoint. You need to replace `{address}` with the address of the API and provide the batch number as a query data to get the data for specific batch, otherwise, you will receive latest data for the batch, that was already proven. Example: + ```shell - curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d 'null' + curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d 'null' ``` + or + ```shell - curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d '1000' + curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d '1000' ``` ### Preparing database From ecedbe3767a313d36c3a37b2b680e4b48d4fcc74 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:34:06 +0300 Subject: [PATCH 30/31] fmt --- prover/docs/05_proving_batch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 44d52a566b54..659e1e0e81e8 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -74,7 +74,7 @@ input file, called `witness_inputs_.bin` generated by different core comp ```shell curl -H "Content-Type: application/json" -X POST {address}/proof_generation_data -d 'null' ``` - + or ```shell From eae98182a68fb61e37f621303a3a0d43dd2d9974 Mon Sep 17 00:00:00 2001 From: Lech <88630083+Artemka374@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:13:27 +0300 Subject: [PATCH 31/31] rename to prover-version --- prover/docs/05_proving_batch.md | 2 +- zk_toolbox/crates/zk_supervisor/README.md | 6 +++--- zk_toolbox/crates/zk_supervisor/src/commands/mod.rs | 2 +- .../commands/{protocol_version.rs => prover_version.rs} | 0 zk_toolbox/crates/zk_supervisor/src/main.rs | 8 ++++---- zk_toolbox/crates/zk_supervisor/src/messages.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename zk_toolbox/crates/zk_supervisor/src/commands/{protocol_version.rs => prover_version.rs} (100%) diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index 659e1e0e81e8..441a8225f866 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -87,7 +87,7 @@ After you have the data, you need to prepare the system to run the batch. So, da the protocol version it should use. You can do that with running ```shell -zk_inception prover protocol-version +zk_supervisor prover-version ``` Example output: diff --git a/zk_toolbox/crates/zk_supervisor/README.md b/zk_toolbox/crates/zk_supervisor/README.md index 9357af096ee8..1f880cdcb30a 100644 --- a/zk_toolbox/crates/zk_supervisor/README.md +++ b/zk_toolbox/crates/zk_supervisor/README.md @@ -5,7 +5,7 @@ This document contains the help content for the `zk_supervisor` command-line pro **Command Overview:** - [`zk_supervisor`↴](#zk_supervisor) -- [`zk_supervisor protocol-version`↴](#zk_supervisor-protocol-version) +- [`zk_supervisor prover-version`↴](#zk_supervisor-prover-version) - [`zk_supervisor database`↴](#zk_supervisor-database) - [`zk_supervisor database check-sqlx-data`↴](#zk_supervisor-database-check-sqlx-data) - [`zk_supervisor database drop`↴](#zk_supervisor-database-drop) @@ -45,11 +45,11 @@ ZK Toolbox is a set of tools for working with zk stack. - `--chain ` — Chain to use - `--ignore-prerequisites` — Ignores prerequisites checks -## `zk_supervisor protocol-version` +## `zk_supervisor prover-version` Gets information about current protocol version of provers in `zksync-era` and snark wrapper hash. -**Usage:** `zk_supervisor protocol-version` +**Usage:** `zk_supervisor prover-version` ## `zk_supervisor database` diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs index f3113e95cc93..181ce50c2134 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs @@ -3,6 +3,6 @@ pub mod database; pub mod fmt; pub mod lint; pub(crate) mod lint_utils; -pub mod protocol_version; +pub mod prover_version; pub mod snapshot; pub mod test; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/protocol_version.rs b/zk_toolbox/crates/zk_supervisor/src/commands/prover_version.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/protocol_version.rs rename to zk_toolbox/crates/zk_supervisor/src/commands/prover_version.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 168b542f289d..9a1c1ad74bcd 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -10,7 +10,7 @@ use common::{ }; use config::EcosystemConfig; use messages::{ - msg_global_chain_does_not_exist, MSG_PROTOCOL_VERSION_ABOUT, MSG_SUBCOMMAND_CLEAN, + msg_global_chain_does_not_exist, MSG_PROVER_VERSION_ABOUT, MSG_SUBCOMMAND_CLEAN, MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, MSG_SUBCOMMAND_LINT_ABOUT, MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, }; @@ -47,8 +47,8 @@ enum SupervisorSubcommands { Fmt(FmtArgs), #[command(hide = true)] Markdown, - #[command(about = MSG_PROTOCOL_VERSION_ABOUT)] - ProtocolVersion, + #[command(about = MSG_PROVER_VERSION_ABOUT)] + ProverVersion, } #[derive(Parser, Debug)] @@ -105,7 +105,7 @@ async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { } SupervisorSubcommands::Lint(args) => commands::lint::run(shell, args)?, SupervisorSubcommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, - SupervisorSubcommands::ProtocolVersion => commands::protocol_version::run(shell).await?, + SupervisorSubcommands::ProverVersion => commands::prover_version::run(shell).await?, } Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index adf0f49d453e..de25be281328 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -8,7 +8,7 @@ pub(super) fn msg_global_chain_does_not_exist(chain: &str, available_chains: &st } // Subcommands help -pub(super) const MSG_PROTOCOL_VERSION_ABOUT: &str = "Protocol version used by provers"; +pub(super) const MSG_PROVER_VERSION_ABOUT: &str = "Protocol version used by provers"; pub(super) const MSG_SUBCOMMAND_DATABASE_ABOUT: &str = "Database related commands"; pub(super) const MSG_SUBCOMMAND_TESTS_ABOUT: &str = "Run tests"; pub(super) const MSG_SUBCOMMAND_CLEAN: &str = "Clean artifacts";