Skip to main content

sp1_sdk/blocking/env/
pk.rs

1#![allow(missing_docs)]
2
3use crate::{ProvingKey, SP1ProvingKey};
4#[cfg(feature = "cuda")]
5use sp1_cuda::CudaProvingKey;
6use sp1_primitives::Elf;
7use sp1_prover::SP1VerifyingKey;
8
9#[derive(Clone)]
10pub enum EnvProvingKey {
11    Cpu {
12        pk: SP1ProvingKey,
13        seal: sealed::Seal,
14    },
15    #[cfg(feature = "cuda")]
16    Cuda {
17        pk: CudaProvingKey,
18        seal: sealed::Seal,
19    },
20    Mock {
21        pk: SP1ProvingKey,
22        seal: sealed::Seal,
23    },
24    Light {
25        pk: SP1ProvingKey,
26        seal: sealed::Seal,
27    },
28    #[cfg(feature = "network")]
29    Network {
30        pk: SP1ProvingKey,
31        seal: sealed::Seal,
32    },
33}
34
35impl EnvProvingKey {
36    pub(crate) const fn cpu(inner: SP1ProvingKey) -> Self {
37        Self::Cpu { pk: inner, seal: sealed::Seal::new() }
38    }
39
40    #[cfg(feature = "cuda")]
41    pub(crate) const fn cuda(inner: CudaProvingKey) -> Self {
42        Self::Cuda { pk: inner, seal: sealed::Seal::new() }
43    }
44
45    pub(crate) const fn mock(inner: SP1ProvingKey) -> Self {
46        Self::Mock { pk: inner, seal: sealed::Seal::new() }
47    }
48
49    pub(crate) const fn light(inner: SP1ProvingKey) -> Self {
50        Self::Light { pk: inner, seal: sealed::Seal::new() }
51    }
52
53    #[cfg(feature = "network")]
54    pub(crate) const fn network(inner: SP1ProvingKey) -> Self {
55        Self::Network { pk: inner, seal: sealed::Seal::new() }
56    }
57}
58
59impl ProvingKey for EnvProvingKey {
60    fn verifying_key(&self) -> &SP1VerifyingKey {
61        #[allow(clippy::match_same_arms)]
62        match self {
63            Self::Cpu { pk, .. } => pk.verifying_key(),
64            #[cfg(feature = "cuda")]
65            Self::Cuda { pk, .. } => pk.verifying_key(),
66            Self::Mock { pk, .. } => pk.verifying_key(),
67            Self::Light { pk, .. } => pk.verifying_key(),
68            #[cfg(feature = "network")]
69            Self::Network { pk, .. } => pk.verifying_key(),
70        }
71    }
72
73    fn elf(&self) -> &Elf {
74        #[allow(clippy::match_same_arms)]
75        match self {
76            Self::Cpu { pk, .. } => pk.elf(),
77            #[cfg(feature = "cuda")]
78            Self::Cuda { pk, .. } => pk.elf(),
79            Self::Mock { pk, .. } => pk.elf(),
80            Self::Light { pk, .. } => pk.elf(),
81            #[cfg(feature = "network")]
82            Self::Network { pk, .. } => pk.elf(),
83        }
84    }
85}
86
87/// A seal for disallowing direct construction of `EnvProver` proving key.
88mod sealed {
89    #[derive(Clone)]
90    pub struct Seal {
91        _private: (),
92    }
93
94    impl Seal {
95        pub(crate) const fn new() -> Self {
96            Self { _private: () }
97        }
98    }
99}