Skip to content

Commit

Permalink
add a hacky way to generate FFLONK setup data
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Oct 10, 2024
1 parent ebd5c7c commit 295990c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions prover/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ zksync_prover_keystore.workspace = true
zksync_utils.workspace = true
zkevm_test_harness.workspace = true
circuit_definitions = { workspace = true, features = ["log_tracing"] }
proof-compression-gpu.workspace = true

anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
toml_edit.workspace = true
indicatif.workspace = true
bincode.workspace = true
serde_json.workspace = true

[dev-dependencies]
proptest.workspace = true
Expand Down
38 changes: 37 additions & 1 deletion prover/crates/bin/vk_setup_data_generator_server_fri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
use std::{collections::HashMap, path::PathBuf};

use anyhow::Context as _;
use circuit_definitions::{
circuit_definitions::aux_layer::{ZkSyncCompressionProof, ZkSyncCompressionVerificationKey},
snark_wrapper::franklin_crypto,
};
use clap::{Parser, Subcommand};
use commitment_generator::read_and_update_contract_toml;
use indicatif::{ProgressBar, ProgressStyle};
use proof_compression_gpu::{CompressionInput, CompressionMode};
use tracing::level_filters::LevelFilter;
use zkevm_test_harness::{
compute_setups::{
Expand All @@ -21,7 +26,7 @@ use zkevm_test_harness::{
};
use zksync_prover_fri_types::{
circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType,
ProverServiceDataKey,
FriProofWrapper, ProverServiceDataKey,
};
use zksync_prover_keystore::{
keystore::Keystore,
Expand Down Expand Up @@ -182,6 +187,12 @@ enum Command {
#[arg(long)]
path: Option<String>,
},
/// Generates setup keys (used by the FFLONK prover).
#[command(name = "generate-sk-fflonk")]
GenerateFflonkSetupKeys {
#[arg(long)]
path: Option<String>,
},
}

fn print_stats(digests: HashMap<String, String>) -> anyhow::Result<()> {
Expand Down Expand Up @@ -236,6 +247,27 @@ fn generate_setup_keys(
Ok(())
}

fn generate_fflonk_setup_keys(keystore: &Keystore) -> anyhow::Result<()> {
let mut setup_data = None;
let worker = franklin_crypto::boojum::worker::Worker::new();
let proof_bytes = std::fs::read("data/compression_proof.bin").unwrap();
let proof: ZkSyncCompressionProof = bincode::deserialize(&proof_bytes).unwrap();
let vk_bytes = std::fs::read("data/compression_vk.json").unwrap();
let vk: ZkSyncCompressionVerificationKey = serde_json::from_slice(&vk_bytes).unwrap();
let input = CompressionInput::CompressionWrapper(Some(proof), vk, CompressionMode::Five);
proof_compression_gpu::prove_compression_wrapper_circuit(
input.into_compression_wrapper_circuit(),
&mut setup_data,
&worker,
);
if let Some(setup_data) = setup_data {
keystore.save_setup_data_for_fflonk(setup_data)?;
} else {
unreachable!("Proof compression was supposed to produce setup data but did not")
};
Ok(())
}

fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
Expand Down Expand Up @@ -280,5 +312,9 @@ fn main() -> anyhow::Result<()> {
};
generate_setup_keys(&generator, &options)
}
Command::GenerateFflonkSetupKeys { path } => {
let keystore = keystore_from_optional_path(path, None);
generate_fflonk_setup_keys(&keystore)
}
}
}
17 changes: 16 additions & 1 deletion prover/crates/lib/keystore/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ use anyhow::Context as _;
use circuit_definitions::{
boojum::cs::implementations::setup::FinalizationHintsForProver,
circuit_definitions::{
aux_layer::ZkSyncSnarkWrapperVK,
aux_layer::{compression_modes::CompressionTreeHasherForWrapper, ZkSyncSnarkWrapperVK},
base_layer::ZkSyncBaseLayerVerificationKey,
recursion_layer::{ZkSyncRecursionLayerStorageType, ZkSyncRecursionLayerVerificationKey},
},
zkevm_circuits::scheduler::aux::BaseLayerCircuitType,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use shivini::cs::GpuProverSetupData;
use zkevm_test_harness::data_source::{in_memory_data_source::InMemoryDataSource, SetupDataSource};
use zksync_basic_types::basic_fri_types::AggregationRound;
use zksync_prover_fri_types::ProverServiceDataKey;
Expand Down Expand Up @@ -513,4 +514,18 @@ impl Keystore {
}
Ok(mapping)
}

pub fn save_setup_data_for_fflonk(
&self,
setup_data: GpuProverSetupData<CompressionTreeHasherForWrapper>,
) -> anyhow::Result<()> {
let filepath = self.basedir.join("compression_wrapper_setup_data.json");
tracing::info!(
"saving FFLONK compression wrapper setup data to: {:?}",
filepath
);
let serialized_setup_data = bincode::serialize(&setup_data)?;
fs::write(filepath.clone(), serialized_setup_data)
.with_context(|| format!("Failed saving setup data at path: {filepath:?}"))
}
}
Binary file added prover/data/compression_proof.bin
Binary file not shown.
1 change: 1 addition & 0 deletions prover/data/compression_vk.json

Large diffs are not rendered by default.

Binary file removed prover/data/compression_wrapper_5_setup_data.bin
Binary file not shown.

0 comments on commit 295990c

Please sign in to comment.