openvm_sdk_config/
deferral.rs1use std::sync::Arc;
2
3use openvm_continuations::CommitBytes;
4use openvm_deferral_circuit::{DeferralExtension, DeferralFn};
5use openvm_verify_stark_circuit::extension::verify_stark_deferral_fn;
6use serde::{Deserialize, Serialize};
7
8#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
9pub enum SupportedDeferral {
10 VerifyStark,
12 Other(String),
17}
18
19#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
24pub struct DeferralCircuitConfig {
25 pub def_type: SupportedDeferral,
27 pub commit: CommitBytes,
29}
30
31#[derive(Clone, Debug, Serialize, Deserialize)]
36pub struct DeferralConfig {
37 pub circuits: Vec<DeferralCircuitConfig>,
39}
40
41impl DeferralConfig {
42 pub fn new(circuits: Vec<DeferralCircuitConfig>) -> Self {
43 Self { circuits }
44 }
45
46 pub fn to_extension(&self) -> DeferralExtension {
47 DeferralExtension {
48 fns: self
49 .circuits
50 .iter()
51 .map(|circuit| circuit.def_type.deferral_fn())
52 .collect(),
53 def_circuit_commits: self
54 .circuits
55 .iter()
56 .map(|circuit| circuit.commit.to_field_le_bytes())
57 .collect(),
58 }
59 }
60}
61
62impl From<DeferralConfig> for DeferralExtension {
63 fn from(config: DeferralConfig) -> Self {
64 config.to_extension()
65 }
66}
67
68impl SupportedDeferral {
69 fn deferral_fn(&self) -> Arc<DeferralFn> {
70 match self {
71 SupportedDeferral::VerifyStark => Arc::new(DeferralFn::new(verify_stark_deferral_fn)),
72 SupportedDeferral::Other(name) => {
73 let name = name.clone();
74 Arc::new(DeferralFn::new(move |_| {
75 panic!(
76 "deferral `{name}`: placeholder DeferralFn from `SupportedDeferral::Other` \
77 was never replaced — set the real DeferralFn in the DeferralExtension \
78 after deserialize"
79 )
80 }))
81 }
82 }
83 }
84}