Skip to content

Commit

Permalink
feat(prover): Added 4844 circuit to verification keys (#1141)
Browse files Browse the repository at this point in the history
## What ❔

* Added support for 4844 circuit to verification key generator

## Why ❔

* 4844 is the new circuit that will be used from the upcoming release.
  • Loading branch information
mm-zk committed Feb 20, 2024
1 parent b567e6c commit 8b0cc4a
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 12 deletions.
32 changes: 32 additions & 0 deletions prover/prover_fri_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,38 @@ impl ProverServiceDataKey {
round: AggregationRound::Scheduler,
}
}

const EIP_4844_CIRCUIT_ID: u8 = 255;

/// Key for 4844 circuit.
// Currently this is a special 'aux' style circuit (as we have just one),
// But from VM 1.5.0 it will change into a 'basic' circuit.
pub fn eip4844() -> Self {
Self {
circuit_id: Self::EIP_4844_CIRCUIT_ID,
round: AggregationRound::BasicCircuits,
}
}
pub fn is_eip4844(&self) -> bool {
self.circuit_id == Self::EIP_4844_CIRCUIT_ID
&& self.round == AggregationRound::BasicCircuits
}

pub fn name(&self) -> String {
if self.is_eip4844() {
return "eip4844".to_string();
}
match self.round {
AggregationRound::BasicCircuits => {
format!("basic_{}", self.circuit_id)
}
AggregationRound::LeafAggregation => {
format!("leaf_{}", self.circuit_id)
}
AggregationRound::NodeAggregation => "node".to_string(),
AggregationRound::Scheduler => "scheduler".to_string(),
}
}
}

#[derive(serde::Serialize, serde::Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
{
"fixed_parameters": {
"parameters": {
"num_columns_under_copy_permutation": 60,
"num_witness_columns": 0,
"num_constant_columns": 8,
"max_allowed_constraint_degree": 4
},
"lookup_parameters": {
"UseSpecializedColumnsWithTableIdAsConstant": {
"width": 3,
"num_repetitions": 20,
"share_table_id": true
}
},
"domain_size": 1048576,
"total_tables_len": 132096,
"public_inputs_locations": [
[
0,
871888
],
[
1,
871888
],
[
2,
871888
],
[
3,
871888
]
],
"extra_constant_polys_for_selectors": 2,
"table_ids_column_idxes": [
10
],
"quotient_degree": 8,
"selectors_placement": {
"Fork": {
"left": {
"Fork": {
"left": {
"Fork": {
"left": {
"Fork": {
"left": {
"Fork": {
"left": {
"GateOnly": {
"gate_idx": 2,
"num_constants": 2,
"degree": 3,
"needs_selector": true,
"is_lookup": false
}
},
"right": {
"Fork": {
"left": {
"GateOnly": {
"gate_idx": 7,
"num_constants": 0,
"degree": 2,
"needs_selector": true,
"is_lookup": false
}
},
"right": {
"GateOnly": {
"gate_idx": 1,
"num_constants": 0,
"degree": 0,
"needs_selector": true,
"is_lookup": false
}
}
}
}
}
},
"right": {
"GateOnly": {
"gate_idx": 6,
"num_constants": 0,
"degree": 2,
"needs_selector": true,
"is_lookup": false
}
}
}
},
"right": {
"GateOnly": {
"gate_idx": 4,
"num_constants": 0,
"degree": 2,
"needs_selector": true,
"is_lookup": false
}
}
}
},
"right": {
"GateOnly": {
"gate_idx": 5,
"num_constants": 1,
"degree": 2,
"needs_selector": true,
"is_lookup": false
}
}
}
},
"right": {
"Fork": {
"left": {
"GateOnly": {
"gate_idx": 3,
"num_constants": 4,
"degree": 2,
"needs_selector": true,
"is_lookup": false
}
},
"right": {
"GateOnly": {
"gate_idx": 0,
"num_constants": 8,
"degree": 1,
"needs_selector": true,
"is_lookup": false
}
}
}
}
}
},
"fri_lde_factor": 2,
"cap_size": 16
},
"setup_merkle_tree_cap": [
[
15012885272458350464,
12918123785161914480,
13671686572559106862,
458420429559950553
],
[
3855596161956112429,
9367986999640085982,
9576686990164770909,
15736630811802716592
],
[
4429424595585567228,
1726575003907041811,
11808623125777752326,
7960090163308302001
],
[
16198073096358255703,
1773566633554043329,
15852741538281887312,
3672365904403393548
],
[
5014302247141995239,
15298901224361045295,
17058410652708079000,
2451098419087154466
],
[
1883879201519384194,
16513689436046407106,
18106823921911623646,
12195558529156429070
],
[
3553190024094472044,
16085740316966804610,
7469059494943248345,
8466978240947973162
],
[
15733255750285479223,
10035744743646423118,
12893682562633909811,
17018145047346847928
],
[
4190189918857924629,
11079126332194735217,
81863766911265321,
1252088896597638701
],
[
13713450655978854074,
6658527377300991599,
11379765760362527623,
18157417093208935759
],
[
13291575128912167224,
5612545196785048171,
14736834588908638980,
3368626854973932908
],
[
6550473513308471355,
261602743346828260,
3476562827380596578,
16103482668860064473
],
[
3000784508673768350,
1118466443868787057,
13001376126891710198,
5277667505560256643
],
[
1638204738185533106,
2943638319874219165,
37345818451115499,
6602609125606041803
],
[
8835198552893947573,
13366615065126505958,
15913885131147312037,
11776601604937573132
],
[
12125147286940007597,
9198361601962582562,
9157325123238861992,
14770289666410955142
]
]
}
41 changes: 30 additions & 11 deletions prover/vk_setup_data_generator_server_fri/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Context as _;
use circuit_definitions::{
boojum::cs::implementations::setup::FinalizationHintsForProver,
circuit_definitions::{
aux_layer::ZkSyncSnarkWrapperVK,
aux_layer::{EIP4844VerificationKey, ZkSyncSnarkWrapperVK},
base_layer::ZkSyncBaseLayerVerificationKey,
recursion_layer::{ZkSyncRecursionLayerStorageType, ZkSyncRecursionLayerVerificationKey},
},
Expand Down Expand Up @@ -85,16 +85,7 @@ impl Keystore {
key: ProverServiceDataKey,
service_data_type: ProverServiceDataType,
) -> String {
let name = match key.round {
AggregationRound::BasicCircuits => {
format!("basic_{}", key.circuit_id)
}
AggregationRound::LeafAggregation => {
format!("leaf_{}", key.circuit_id)
}
AggregationRound::NodeAggregation => "node".to_string(),
AggregationRound::Scheduler => "scheduler".to_string(),
};
let name = key.name();
match service_data_type {
ProverServiceDataType::VerificationKey => {
format!("{}/verification_{}_key.json", self.basedir, name)
Expand Down Expand Up @@ -163,6 +154,13 @@ impl Keystore {
))
}

pub fn load_4844_verification_key(&self) -> anyhow::Result<EIP4844VerificationKey> {
Self::load_json_from_file(self.get_file_path(
ProverServiceDataKey::eip4844(),
ProverServiceDataType::VerificationKey,
))
}

pub fn save_base_layer_verification_key(
&self,
vk: ZkSyncBaseLayerVerificationKey,
Expand All @@ -187,6 +185,15 @@ impl Keystore {
Self::save_json_pretty(filepath, &vk)
}

pub fn save_4844_verification_key(&self, vk: EIP4844VerificationKey) -> anyhow::Result<()> {
let filepath = self.get_file_path(
ProverServiceDataKey::eip4844(),
ProverServiceDataType::VerificationKey,
);
tracing::info!("saving 4844 verification key to: {}", filepath);
Self::save_json_pretty(filepath, &vk)
}

///
/// Finalization hints
///
Expand Down Expand Up @@ -325,6 +332,7 @@ impl Keystore {
}

pub fn save_keys_from_data_source(&self, source: &dyn SetupDataSource) -> anyhow::Result<()> {
// Base circuits
for base_circuit_type in
(BaseLayerCircuitType::VM as u8)..=(BaseLayerCircuitType::L1MessagesHasher as u8)
{
Expand All @@ -346,6 +354,7 @@ impl Keystore {
self.save_finalization_hints(key, &hint)
.context("save_finalization_hints()")?;
}
// Leaf circuits
for leaf_circuit_type in (ZkSyncRecursionLayerStorageType::LeafLayerCircuitForMainVM as u8)
..=(ZkSyncRecursionLayerStorageType::LeafLayerCircuitForL1MessagesHasher as u8)
{
Expand All @@ -369,6 +378,7 @@ impl Keystore {
self.save_finalization_hints(key, &hint)
.context("save_finalization_hints()")?;
}
// Node
self.save_recursive_layer_verification_key(
source
.get_recursion_layer_node_vk()
Expand All @@ -390,6 +400,7 @@ impl Keystore {
)
.context("save_finalization_hints()")?;

// Scheduler
self.save_recursive_layer_verification_key(
source
.get_recursion_layer_vk(ZkSyncRecursionLayerStorageType::SchedulerCircuit as u8)
Expand All @@ -414,6 +425,14 @@ impl Keystore {
)
.context("save_finalization_hints()")?;

// 4844
self.save_4844_verification_key(
source
.get_eip4844_vk()
.map_err(|err| anyhow::anyhow!("No vk exist for 4844 circuit: {err}"))?,
)
.context("save_4844_verification_key()")?;

Ok(())
}
}
Loading

0 comments on commit 8b0cc4a

Please sign in to comment.