Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prover): Add file based config support for vk-setup-data-generator-server-fri #2371

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions prover/vk_setup_data_generator_server_fri/src/commitment_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{str::FromStr, sync::Mutex};

use anyhow::Context as _;
use hex::ToHex;
Expand All @@ -22,9 +22,14 @@ use crate::{
VkCommitments,
};

static KEYSTORE: Lazy<Mutex<Option<Keystore>>> = Lazy::new(|| Mutex::new(None));

lazy_static! {
// TODO: do not initialize a static const with data read in runtime.
static ref COMMITMENTS: Lazy<L1VerifierConfig> = Lazy::new(|| { circuit_commitments(&Keystore::default()).unwrap() });
static ref COMMITMENTS: Lazy<L1VerifierConfig> = Lazy::new(|| {
let keystore = KEYSTORE.lock().unwrap().clone().unwrap_or_default();
circuit_commitments(&keystore).unwrap()
});
}

fn circuit_commitments(keystore: &Keystore) -> anyhow::Result<L1VerifierConfig> {
Expand Down Expand Up @@ -97,14 +102,19 @@ pub fn generate_commitments(keystore: &Keystore) -> anyhow::Result<VkCommitments
Ok(result)
}

pub fn get_cached_commitments() -> L1VerifierConfig {
pub fn get_cached_commitments(setup_data_path: Option<String>) -> L1VerifierConfig {
if let Some(setup_data_path) = setup_data_path {
let keystore = Keystore::new_with_setup_data_path(setup_data_path);
let mut keystore_lock = KEYSTORE.lock().unwrap();
*keystore_lock = Some(keystore);
}
tracing::info!("Using cached commitments {:?}", **COMMITMENTS);
**COMMITMENTS
}

#[test]
fn test_get_cached_commitments() {
let commitments = get_cached_commitments();
let commitments = get_cached_commitments(None);
assert_eq!(
H256::zero(),
commitments.params.recursion_circuits_set_vks_hash
Expand Down
9 changes: 9 additions & 0 deletions prover/vk_setup_data_generator_server_fri/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum ProverServiceDataType {
/// There are 2 types:
/// - small verification, finalization keys (used only during verification)
/// - large setup keys, used during proving.
#[derive(Clone)]
pub struct Keystore {
/// Directory to store all the small keys.
basedir: PathBuf,
Expand Down Expand Up @@ -80,13 +81,21 @@ impl Keystore {
setup_data_path: Some(setup_data_path),
}
}

pub fn new_with_optional_setup_path(basedir: PathBuf, setup_data_path: Option<String>) -> Self {
Keystore {
basedir,
setup_data_path,
}
}

pub fn new_with_setup_data_path(setup_data_path: String) -> Self {
Keystore {
basedir: get_base_path(),
setup_data_path: Some(setup_data_path),
}
}

pub fn get_base_path(&self) -> &PathBuf {
&self.basedir
}
Expand Down
11 changes: 6 additions & 5 deletions prover/witness_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ async fn main() -> anyhow::Result<()> {
let started_at = Instant::now();
let use_push_gateway = opt.batch_size.is_some();

let prover_config = general_config.prover_config.context("prover config")?;
let object_store_config = ProverObjectStoreConfig(
general_config
.prover_config
.context("prover config")?
prover_config
.prover_object_store
.context("object store")?,
.context("object store")?
.clone(),
);
let store_factory = ObjectStoreFactory::new(object_store_config.0);
let config = general_config
Expand Down Expand Up @@ -202,7 +202,8 @@ async fn main() -> anyhow::Result<()> {

let witness_generator_task = match round {
AggregationRound::BasicCircuits => {
let vk_commitments = get_cached_commitments();
let setup_data_path = prover_config.setup_data_path.clone();
let vk_commitments = get_cached_commitments(Some(setup_data_path));
assert_eq!(
vk_commitments,
vk_commitments_in_db,
Expand Down
Loading