axiom_query/keygen/
mod.rs

1//! Module with utility functions to generate proving keys and verifying keys for production circuits.
2
3use std::path::Path;
4
5use axiom_eth::{
6    halo2_proofs::plonk::ProvingKey, halo2curves::bn256::G1Affine,
7    utils::build_utils::pinning::aggregation::AggTreeId,
8};
9use enum_dispatch::enum_dispatch;
10use serde::{Deserialize, Serialize};
11
12use self::{
13    agg::{
14        axiom_agg_1::RecursiveAxiomAgg1Intent, axiom_agg_2::RecursiveAxiomAgg2Intent,
15        common::AggTreePinning, single_type::*, subquery_agg::RecursiveSubqueryAggIntent,
16        SupportedAggPinning,
17    },
18    shard::{keccak::ShardIntentKeccak, *},
19};
20
21pub mod agg;
22pub mod shard;
23
24pub type CircuitId = String;
25
26#[derive(Serialize, Deserialize)]
27#[enum_dispatch(ProvingKeySerializer)]
28pub enum SupportedRecursiveIntent {
29    Subquery(SupportedIntentTreeSingleType),
30    VerifyCompute(CircuitIntentVerifyCompute),
31    SubqueryAgg(RecursiveSubqueryAggIntent),
32    Keccak(IntentTreeSingleType<ShardIntentKeccak>),
33    AxiomAgg1(RecursiveAxiomAgg1Intent),
34    AxiomAgg2(RecursiveAxiomAgg2Intent),
35}
36
37/// ** !! IMPORTANT !! **
38/// Enum names are used to deserialize the pinning file. Please be careful if you need renaming.
39#[derive(Serialize, Deserialize, Clone)]
40#[enum_dispatch(AggTreePinning)]
41pub enum SupportedPinning {
42    Shard(SupportedShardPinning),
43    Agg(SupportedAggPinning),
44}
45
46// We only serialize to [SupportedPinning] so the JSON will have the name of the pinning in it.
47/// Trait specific to this crate for keygen since it uses enum_dispatch and must return a pinning in enum [SupportedPinning].
48#[enum_dispatch]
49pub trait ProvingKeySerializer: Sized {
50    /// Recursively creates and serializes proving keys and pinnings.
51    ///
52    /// Computes `circuit_id` as the blake3 hash of the halo2 VerifyingKey written to bytes. Writes proving key to `circuit_id.pk`, verifying key to `circuit_id.vk` and pinning to `circuit_id.json` in the `data_dir` directory.
53    ///
54    /// Returns the `circuit_id, proving_key, pinning`.
55    fn create_and_serialize_proving_key(
56        self,
57        params_dir: &Path,
58        data_dir: &Path,
59    ) -> anyhow::Result<(AggTreeId, ProvingKey<G1Affine>, SupportedPinning)>;
60}