Skip to content

Commit

Permalink
feat(prover): Extract keystore into a separate crate (#2797)
Browse files Browse the repository at this point in the history
## What ❔

- Extract `keystore` and some adjacent code from the
`vk_setup_generator_server_fri` into a separate library crate.
- ⚠️ this PR just moves code around. I didn't introduce any changes to
not make review harder than it should be. Changes will come as
follow-ups.

## Why ❔

- `vk_setup_generator_server_fri` served as both binary and library,
which was super confusing.
- Better logical separation of code.
- Prerequisite for further refactoring.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
popzxc authored Sep 4, 2024
1 parent 87b02e3 commit e239260
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 61 deletions.
45 changes: 28 additions & 17 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ zksync_periodic_job = { path = "../core/lib/periodic_job" }
zksync_prover_dal = { path = "crates/lib/prover_dal" }
zksync_prover_fri_types = { path = "crates/lib/prover_fri_types" }
zksync_prover_fri_utils = { path = "crates/lib/prover_fri_utils" }
zksync_prover_keystore = { path = "crates/lib/keystore" }
zksync_vk_setup_data_generator_server_fri = { path = "crates/bin/vk_setup_data_generator_server_fri" }

# for `perf` profiling
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/proof_fri_compressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ zksync_utils.workspace = true
zksync_core_leftovers.workspace = true
zksync_prover_fri_types.workspace = true
zksync_queued_job_processor.workspace = true
zksync_vk_setup_data_generator_server_fri.workspace = true
zksync_prover_keystore.workspace = true
zksync_vlog.workspace = true

circuit_sequencer_api.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/proof_fri_compressor/src/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use zksync_prover_fri_types::{
get_current_pod_name, AuxOutputWitnessWrapper, FriProofWrapper,
};
use zksync_prover_interface::outputs::L1BatchProofForL1;
use zksync_prover_keystore::keystore::Keystore;
use zksync_queued_job_processor::JobProcessor;
use zksync_types::{protocol_version::ProtocolSemanticVersion, L1BatchNumber};
use zksync_vk_setup_data_server_fri::keystore::Keystore;

use crate::metrics::METRICS;

Expand Down
4 changes: 2 additions & 2 deletions prover/crates/bin/prover_fri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ zksync_prover_fri_utils.workspace = true
zksync_core_leftovers.workspace = true
zksync_prover_fri_types.workspace = true
zksync_utils.workspace = true
zksync_vk_setup_data_generator_server_fri.workspace = true
zksync_prover_keystore.workspace = true
shivini = { workspace = true, optional = true, features = [
"circuit_definitions",
"zksync",
Expand All @@ -45,4 +45,4 @@ clap = { workspace = true, features = ["derive"] }

[features]
default = []
gpu = ["shivini", "zksync_vk_setup_data_generator_server_fri/gpu"]
gpu = ["shivini", "zksync_prover_keystore/gpu"]
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub mod gpu_prover {
CircuitWrapper, FriProofWrapper, ProverServiceDataKey, WitnessVectorArtifacts,
};
use zksync_prover_fri_utils::region_fetcher::Zone;
use zksync_prover_keystore::{keystore::Keystore, GoldilocksGpuProverSetupData};
use zksync_queued_job_processor::{async_trait, JobProcessor};
use zksync_types::{
basic_fri_types::CircuitIdRoundTuple, protocol_version::ProtocolSemanticVersion,
prover_dal::SocketAddress,
};
use zksync_vk_setup_data_server_fri::{keystore::Keystore, GoldilocksGpuProverSetupData};

use crate::{
metrics::METRICS,
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/prover_fri/src/prover_job_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use zksync_prover_fri_types::{
CircuitWrapper, FriProofWrapper, ProverJob, ProverServiceDataKey,
};
use zksync_prover_fri_utils::fetch_next_circuit;
use zksync_prover_keystore::{keystore::Keystore, GoldilocksProverSetupData};
use zksync_queued_job_processor::{async_trait, JobProcessor};
use zksync_types::{
basic_fri_types::CircuitIdRoundTuple, protocol_version::ProtocolSemanticVersion,
};
use zksync_vk_setup_data_server_fri::{keystore::Keystore, GoldilocksProverSetupData};

use crate::{
metrics::{CircuitLabels, Layer, METRICS},
Expand Down
4 changes: 2 additions & 2 deletions prover/crates/bin/prover_fri/tests/basic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use zksync_prover_fri::prover_job_processor::Prover;
use zksync_prover_fri_types::{
keys::FriCircuitKey, CircuitWrapper, ProverJob, ProverServiceDataKey,
};
use zksync_types::{basic_fri_types::AggregationRound, L1BatchNumber};
use zksync_vk_setup_data_server_fri::{
use zksync_prover_keystore::{
keystore::Keystore, setup_data_generator::generate_setup_data_common,
};
use zksync_types::{basic_fri_types::AggregationRound, L1BatchNumber};

fn compare_serialized<T: Serialize>(expected: &T, actual: &T) {
let serialized_expected = bincode::serialize(expected).unwrap();
Expand Down
20 changes: 2 additions & 18 deletions prover/crates/bin/vk_setup_data_generator_server_fri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,25 @@ categories.workspace = true
name = "key_generator"
path = "src/main.rs"

[lib]
name = "zksync_vk_setup_data_server_fri"
path = "src/lib.rs"


[dependencies]
zksync_vlog.workspace = true
zksync_types.workspace = true
zksync_utils.workspace = true
zksync_prover_fri_types.workspace = true
zksync_prover_keystore.workspace = true
zkevm_test_harness.workspace = true
circuit_definitions = { workspace = true, features = ["log_tracing"] }
shivini = { workspace = true, optional = true }
zksync_config.workspace = true
zksync_env_config.workspace = true

anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
serde_json.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_derive.workspace = true
itertools.workspace = true
bincode.workspace = true
once_cell.workspace = true
toml_edit.workspace = true
md5.workspace = true
sha3.workspace = true
hex.workspace = true
indicatif.workspace = true

[dev-dependencies]
proptest.workspace = true

[features]
default = []
gpu = ["shivini"]
gpu = ["zksync_prover_keystore/gpu"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Context;
use zksync_vk_setup_data_server_fri::{
commitment_utils::generate_commitments,
keystore::Keystore,
vk_commitment_helper::{get_toml_formatted_value, read_contract_toml, write_contract_toml},
use zksync_prover_keystore::{commitment_utils::generate_commitments, keystore::Keystore};

use crate::vk_commitment_helper::{
get_toml_formatted_value, read_contract_toml, write_contract_toml,
};

pub fn read_and_update_contract_toml(keystore: &Keystore, dryrun: bool) -> anyhow::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ use zksync_prover_fri_types::{
circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType,
ProverServiceDataKey,
};
use zksync_vk_setup_data_server_fri::{
use zksync_prover_keystore::{
commitment_utils::generate_commitments,
keystore::Keystore,
setup_data_generator::{CPUSetupDataGenerator, GPUSetupDataGenerator, SetupDataGenerator},
};

mod commitment_generator;
mod vk_commitment_helper;

#[cfg(test)]
mod tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use zksync_prover_fri_types::{
},
ProverServiceDataKey,
};
use zksync_prover_keystore::keystore::Keystore;
use zksync_types::basic_fri_types::AggregationRound;
use zksync_vk_setup_data_server_fri::keystore::Keystore;

fn all_possible_prover_service_data_key() -> impl Strategy<Value = ProverServiceDataKey> {
let mut keys = Vec::with_capacity(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::{fs, path::PathBuf};

use anyhow::Context as _;
use toml_edit::{Document, Item, Value};

use crate::utils::core_workspace_dir_or_current_dir;
use zksync_prover_keystore::utils::core_workspace_dir_or_current_dir;

pub fn get_toml_formatted_value(string_value: String) -> Item {
let mut value = Value::from(string_value);
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/witness_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ zksync_multivm.workspace = true
zksync_object_store.workspace = true
zksync_types.workspace = true
zksync_utils.workspace = true
zksync_vk_setup_data_generator_server_fri.workspace = true
zksync_prover_keystore.workspace = true
zksync_prover_fri_types.workspace = true
zksync_prover_fri_utils.workspace = true
zksync_core_leftovers.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ use zksync_prover_fri_types::{
FriProofWrapper,
};
use zksync_prover_fri_utils::get_recursive_layer_circuit_id_for_base_layer;
use zksync_prover_keystore::keystore::Keystore;
use zksync_queued_job_processor::JobProcessor;
use zksync_types::{
basic_fri_types::AggregationRound, protocol_version::ProtocolSemanticVersion,
prover_dal::LeafAggregationJobMetadata, L1BatchNumber,
};
use zksync_vk_setup_data_server_fri::keystore::Keystore;

use crate::{
metrics::WITNESS_GENERATOR_METRICS,
Expand Down
5 changes: 4 additions & 1 deletion prover/crates/bin/witness_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use zksync_env_config::object_store::ProverObjectStoreConfig;
use zksync_object_store::ObjectStoreFactory;
use zksync_prover_dal::{ConnectionPool, Prover, ProverDal};
use zksync_prover_fri_types::PROVER_PROTOCOL_SEMANTIC_VERSION;
use zksync_prover_keystore::commitment_utils::get_cached_commitments;
use zksync_queued_job_processor::JobProcessor;
use zksync_types::basic_fri_types::AggregationRound;
use zksync_utils::wait_for_tasks::ManagedTasks;
use zksync_vk_setup_data_server_fri::commitment_utils::get_cached_commitments;
use zksync_vlog::prometheus::PrometheusExporterConfig;
use zksync_witness_generator::{
basic_circuits::BasicWitnessGenerator, leaf_aggregation::LeafAggregationWitnessGenerator,
Expand Down Expand Up @@ -171,7 +171,10 @@ async fn main() -> anyhow::Result<()> {

let witness_generator_task = match round {
AggregationRound::BasicCircuits => {
let start = Instant::now();
let vk_commitments = get_cached_commitments(Some(setup_data_path.clone()));
let end = start.elapsed();
tracing::info!("Calculating commitment took: {:?}", end);
assert_eq!(
vk_commitments,
vk_commitments_in_db,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use zksync_prover_fri_types::{
keys::AggregationsKey,
FriProofWrapper,
};
use zksync_prover_keystore::{keystore::Keystore, utils::get_leaf_vk_params};
use zksync_queued_job_processor::JobProcessor;
use zksync_types::{
basic_fri_types::AggregationRound, protocol_version::ProtocolSemanticVersion,
prover_dal::NodeAggregationJobMetadata, L1BatchNumber,
};
use zksync_vk_setup_data_server_fri::{keystore::Keystore, utils::get_leaf_vk_params};

use crate::{
metrics::WITNESS_GENERATOR_METRICS,
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/witness_generator/src/recursion_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ use zksync_prover_fri_types::{
keys::{ClosedFormInputKey, FriCircuitKey},
CircuitWrapper,
};
use zksync_prover_keystore::{keystore::Keystore, utils::get_leaf_vk_params};
use zksync_queued_job_processor::JobProcessor;
use zksync_types::{
basic_fri_types::AggregationRound, protocol_version::ProtocolSemanticVersion, L1BatchNumber,
};
use zksync_vk_setup_data_server_fri::{keystore::Keystore, utils::get_leaf_vk_params};

use crate::{
metrics::WITNESS_GENERATOR_METRICS,
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/witness_generator/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ use zksync_prover_fri_types::{
keys::FriCircuitKey,
CircuitWrapper, FriProofWrapper,
};
use zksync_prover_keystore::{keystore::Keystore, utils::get_leaf_vk_params};
use zksync_queued_job_processor::JobProcessor;
use zksync_types::{
basic_fri_types::AggregationRound, protocol_version::ProtocolSemanticVersion, L1BatchNumber,
};
use zksync_vk_setup_data_server_fri::{keystore::Keystore, utils::get_leaf_vk_params};

use crate::{metrics::WITNESS_GENERATOR_METRICS, utils::SchedulerPartialInputWrapper};

Expand Down
2 changes: 1 addition & 1 deletion prover/crates/bin/witness_vector_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ zksync_prover_fri_types.workspace = true
zksync_core_leftovers.workspace = true
zksync_queued_job_processor.workspace = true
zksync_vlog.workspace = true
zksync_vk_setup_data_generator_server_fri.workspace = true
zksync_prover_keystore.workspace = true

anyhow.workspace = true
tracing.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use zksync_prover_fri_types::{
use zksync_prover_fri_utils::{
fetch_next_circuit, get_numeric_circuit_id, region_fetcher::Zone, socket_utils::send_assembly,
};
use zksync_prover_keystore::keystore::Keystore;
use zksync_queued_job_processor::JobProcessor;
use zksync_types::{
basic_fri_types::CircuitIdRoundTuple, protocol_version::ProtocolSemanticVersion,
prover_dal::GpuProverInstanceStatus,
};
use zksync_vk_setup_data_server_fri::keystore::Keystore;

use crate::metrics::METRICS;

Expand Down
Loading

0 comments on commit e239260

Please sign in to comment.