Skip to content

Commit

Permalink
fix(prover): Use SNARK wrapper VK for picking prover jobs (#142)
Browse files Browse the repository at this point in the history
# What ❔

Prover and Witgen now use snark wrapper VKs to pick their jobs.

## Why ❔

`prover_protocol_versions` table had SNARK wrapper VKs, but prover and
witgens picked jobs based on FRI scheduler VKs.

Since if one changes the other also does, we can use the SNARK one
instead, since it's also used in `eth_sender`.

---------

Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
  • Loading branch information
ly0va and StanislavBreadless authored Oct 5, 2023
1 parent 867f2bf commit 6040e37
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 141 deletions.
5 changes: 3 additions & 2 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
use std::{str::FromStr, time::Duration};
use zksync_config::configs::chain::NetworkConfig;

use zksync_config::{ContractsConfig, ETHSenderConfig};
use zksync_config::{ContractsConfig, ETHClientConfig, ETHSenderConfig};
use zksync_core::{
genesis_init, initialize_components, is_genesis_needed, setup_sigint_handler, Component,
Components,
Expand Down Expand Up @@ -80,7 +80,8 @@ async fn main() -> anyhow::Result<()> {
let network = NetworkConfig::from_env().context("NetworkConfig")?;
let eth_sender = ETHSenderConfig::from_env().context("ETHSenderConfig")?;
let contracts = ContractsConfig::from_env().context("ContractsConfig")?;
genesis_init(&eth_sender, &network, &contracts)
let eth_client = ETHClientConfig::from_env().context("EthClientConfig")?;
genesis_init(&eth_sender, &network, &contracts, &eth_client.web3_url)
.await
.context("genesis_init")?;
if opt.genesis {
Expand Down
5 changes: 5 additions & 0 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ContractsConfig {
pub fri_recursion_node_level_vk_hash: H256,
pub fri_recursion_leaf_level_vk_hash: H256,
pub prover_at_genesis: String,
pub snark_wrapper_vk_hash: H256,
}

impl ContractsConfig {
Expand Down Expand Up @@ -95,6 +96,9 @@ mod tests {
"0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828",
),
prover_at_genesis: "fri".to_string(),
snark_wrapper_vk_hash: hash(
"0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2",
),
}
}

Expand Down Expand Up @@ -129,6 +133,7 @@ CONTRACTS_FRI_RECURSION_SCHEDULER_LEVEL_VK_HASH="0x201d4c7d8e781d51a3bbd451a43a8
CONTRACTS_FRI_RECURSION_NODE_LEVEL_VK_HASH="0x5a3ef282b21e12fe1f4438e5bb158fc5060b160559c5158c6389d62d9fe3d080"
CONTRACTS_FRI_RECURSION_LEAF_LEVEL_VK_HASH="0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828"
CONTRACTS_PROVER_AT_GENESIS="fri"
SNARK_WRAPPER_VK_HASH="0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2"
"#;
lock.set_env(config);

Expand Down
29 changes: 25 additions & 4 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use zksync_dal::{
connection::DbVariant, healthcheck::ConnectionPoolHealthCheck, ConnectionPool, StorageProcessor,
};
use zksync_eth_client::clients::http::QueryClient;
use zksync_eth_client::EthInterface;
use zksync_eth_client::{clients::http::PKSigningClient, BoundEthInterface};
use zksync_health_check::{CheckHealth, HealthStatus, ReactiveHealthCheck};
use zksync_object_store::ObjectStoreFactory;
Expand Down Expand Up @@ -110,6 +111,7 @@ pub async fn genesis_init(
eth_sender: &ETHSenderConfig,
network_config: &NetworkConfig,
contracts_config: &ContractsConfig,
eth_client_url: &str,
) -> anyhow::Result<()> {
let mut storage = StorageProcessor::establish_connection(true)
.await
Expand All @@ -126,15 +128,34 @@ pub async fn genesis_init(
// Later we can change provers using the system upgrades, but for genesis
// we should select one using the environment config.
let first_l1_verifier_config = if contracts_config.prover_at_genesis == "fri" {
L1VerifierConfig {
let l1_verifier_config = L1VerifierConfig {
params: VerifierParams {
recursion_node_level_vk_hash: contracts_config.fri_recursion_node_level_vk_hash,
recursion_leaf_level_vk_hash: contracts_config.fri_recursion_leaf_level_vk_hash,
recursion_circuits_set_vks_hash: zksync_types::H256::zero(),
},
recursion_scheduler_level_vk_hash: contracts_config
.fri_recursion_scheduler_level_vk_hash,
}
recursion_scheduler_level_vk_hash: contracts_config.snark_wrapper_vk_hash,
};

let eth_client = QueryClient::new(eth_client_url)?;
let vk_hash: zksync_types::H256 = eth_client
.call_contract_function(
"verificationKeyHash",
(),
None,
Default::default(),
None,
contracts_config.verifier_addr,
zksync_contracts::verifier_contract(),
)
.await?;

assert_eq!(
vk_hash, l1_verifier_config.recursion_scheduler_level_vk_hash,
"L1 verifier key does not match the one in the config"
);

l1_verifier_config
} else {
L1VerifierConfig {
params: VerifierParams {
Expand Down
3 changes: 2 additions & 1 deletion etc/env/base/contracts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ L2_WETH_TOKEN_IMPL_ADDR="0x5E6D086F5eC079ADFF4FB3774CDf3e8D6a34F7E9"
L2_WETH_TOKEN_PROXY_ADDR="0x5E6D086F5eC079ADFF4FB3774CDf3e8D6a34F7E9"
FRI_RECURSION_LEAF_LEVEL_VK_HASH ="0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828"
FRI_RECURSION_NODE_LEVEL_VK_HASH ="0x5a3ef282b21e12fe1f4438e5bb158fc5060b160559c5158c6389d62d9fe3d080"
FRI_RECURSION_SCHEDULER_LEVEL_VK_HASH ="0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2"
FRI_RECURSION_SCHEDULER_LEVEL_VK_HASH ="0x201d4c7d8e781d51a3bbd451a43a8f45240bb765b565ae6ce69192d918c3563d"
SNARK_WRAPPER_VK_HASH = "0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2"

# Prover that should be used at genesis. 'fri' or 'snark'
PROVER_AT_GENESIS="fri"
Expand Down
Loading

0 comments on commit 6040e37

Please sign in to comment.