Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/boojum-integration' into lyova-p…
Browse files Browse the repository at this point in the history
…la-581-use-snark-vk-hash-while-picking-prover-jobs
  • Loading branch information
ly0va committed Oct 5, 2023
2 parents 94bb2dc + 867f2bf commit d3c3f9d
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 151 deletions.
4 changes: 3 additions & 1 deletion core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct ContractsConfig {
pub fri_recursion_scheduler_level_vk_hash: H256,
pub fri_recursion_node_level_vk_hash: H256,
pub fri_recursion_leaf_level_vk_hash: H256,
pub prover_at_genesis: String,
}

impl ContractsConfig {
Expand Down Expand Up @@ -93,6 +94,7 @@ mod tests {
fri_recursion_leaf_level_vk_hash: hash(
"0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828",
),
prover_at_genesis: "fri".to_string(),
}
}

Expand Down Expand Up @@ -126,7 +128,7 @@ CONTRACTS_L1_MULTICALL3_ADDR="0xcA11bde05977b3631167028862bE2a173976CA11"
CONTRACTS_FRI_RECURSION_SCHEDULER_LEVEL_VK_HASH="0x201d4c7d8e781d51a3bbd451a43a8f45240bb765b565ae6ce69192d918c3563d"
CONTRACTS_FRI_RECURSION_NODE_LEVEL_VK_HASH="0x5a3ef282b21e12fe1f4438e5bb158fc5060b160559c5158c6389d62d9fe3d080"
CONTRACTS_FRI_RECURSION_LEAF_LEVEL_VK_HASH="0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828"
CONTRACTS_PROVER_AT_GENESIS="fri"
"#;
lock.set_env(config);

Expand Down
2 changes: 2 additions & 0 deletions core/lib/mini_merkle_tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ impl<'a, const LEAF_SIZE: usize> MiniMerkleTree<'a, LEAF_SIZE> {
}

/// Returns the root hash of this tree.
/// # Panics
/// Will panic if the constant below is invalid.
pub fn merkle_root(self) -> H256 {
if self.hashes.is_empty() {
H256::from_str("fef7bd9f889811e59e4076a0174087135f080177302763019adaf531257e3a87")
Expand Down
9 changes: 2 additions & 7 deletions core/lib/types/src/aggregated_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,14 @@ impl L1BatchProofOperation {
assert_eq!(self.l1_batches.len(), 1);

let L1BatchProofForL1 {
aggregation_result_coords,
aggregation_result_coords: _,
scheduler_proof,
} = self.proofs.first().unwrap();

let (_inputs, proof) = serialize_proof(scheduler_proof);

let proof_input = Token::Tuple(vec![
Token::Array(
aggregation_result_coords
.iter()
.map(|bytes| Token::Uint(U256::from_big_endian(bytes)))
.collect(),
),
Token::Array(vec![]),
Token::Array(proof.into_iter().map(Token::Uint).collect()),
]);

Expand Down
7 changes: 6 additions & 1 deletion core/lib/zksync_core/src/eth_watch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,12 @@ fn upgrade_into_log(upgrade: ProtocolUpgrade, eth_block: u64) -> Log {
),
]);

let diamond_upgrade_calldata = vec![0u8; 4]
let execute_upgrade_selector = zksync_contract()
.function("executeUpgrade")
.unwrap()
.short_signature();
let diamond_upgrade_calldata = execute_upgrade_selector
.to_vec()
.into_iter()
.chain(encode(&[diamond_cut]))
.collect();
Expand Down
68 changes: 40 additions & 28 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,46 @@ pub async fn genesis_init(
)
.context("Failed to restore operator address from private key")?;

// We don't need to worry about backward-compatibility with the old verifier here,
// since this is only run during genesis.
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?;
// Select the first prover to be used during genesis.
// 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" {
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.recursion_scheduler_level_vk_hash,
};

assert_eq!(
vk_hash, contracts_config.recursion_scheduler_level_vk_hash,
"L1 verifier key does not match the one in the config"
);
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"
);
} else {
L1VerifierConfig {
params: VerifierParams {
recursion_node_level_vk_hash: contracts_config.recursion_node_level_vk_hash,
recursion_leaf_level_vk_hash: contracts_config.recursion_leaf_level_vk_hash,
recursion_circuits_set_vks_hash: contracts_config.recursion_circuits_set_vks_hash,
},
recursion_scheduler_level_vk_hash: contracts_config.recursion_scheduler_level_vk_hash,
}
};

genesis::ensure_genesis_state(
&mut storage,
Expand All @@ -154,16 +175,7 @@ pub async fn genesis_init(
base_system_contracts: BaseSystemContracts::load_from_disk(),
system_contracts: get_system_smart_contracts(),
first_verifier_address: contracts_config.verifier_addr,
first_l1_verifier_config: L1VerifierConfig {
params: VerifierParams {
recursion_node_level_vk_hash: contracts_config.recursion_node_level_vk_hash,
recursion_leaf_level_vk_hash: contracts_config.recursion_leaf_level_vk_hash,
recursion_circuits_set_vks_hash: contracts_config
.recursion_circuits_set_vks_hash,
},
recursion_scheduler_level_vk_hash: contracts_config
.recursion_scheduler_level_vk_hash,
},
first_l1_verifier_config,
},
)
.await?;
Expand Down
5 changes: 4 additions & 1 deletion etc/env/base/contracts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ 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 ="0x201d4c7d8e781d51a3bbd451a43a8f45240bb765b565ae6ce69192d918c3563d"
FRI_RECURSION_SCHEDULER_LEVEL_VK_HASH ="0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2"

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

[contracts.test]
dummy_verifier=true
Expand Down
4 changes: 3 additions & 1 deletion infrastructure/zk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dotenv": "^8.2.0",
"ethers": "~5.5.0",
"node-fetch": "^2.6.1",
"pg": "^8.11.3",
"tabtab": "^3.0.2",
"zksync-web3": "link:../../sdk/zksync-web3.js"
},
Expand All @@ -25,8 +26,9 @@
"@types/deep-extend": "^0.4.31",
"@types/node": "^14.6.1",
"@types/node-fetch": "^2.5.7",
"@types/pg": "^8.10.3",
"@types/tabtab": "^3.0.1",
"hardhat": "=2.12.4",
"typescript": "^4.3.5"
}
}
}
2 changes: 2 additions & 0 deletions infrastructure/zk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { command as config } from './config';
import { command as clean } from './clean';
import { command as db } from './database';
import { command as verifyUpgrade } from './verify-upgrade';
import { command as status } from './status';
import * as env from './env';

const COMMANDS = [
Expand All @@ -44,6 +45,7 @@ const COMMANDS = [
compiler,
verifyUpgrade,
env.command,
status,
completion(program as Command)
];

Expand Down
Loading

0 comments on commit d3c3f9d

Please sign in to comment.