subspace_proof_of_space/
chiapos.rs1mod constants;
4mod table;
5mod tables;
6mod utils;
7
8#[cfg(feature = "alloc")]
9pub use crate::chiapos::table::TablesCache;
10use crate::chiapos::table::{metadata_size_bytes, num_buckets};
11use crate::chiapos::tables::TablesGeneric;
12use crate::chiapos::utils::EvaluatableUsize;
13
14type Seed = [u8; 32];
15#[cfg(any(feature = "full-chiapos", test))]
16type Challenge = [u8; 32];
17#[cfg(any(feature = "full-chiapos", test))]
18type Quality = [u8; 32];
19
20#[derive(Debug)]
22pub struct Tables<const K: u8>(TablesGeneric<K>)
23where
24 EvaluatableUsize<{ metadata_size_bytes(K, 7) }>: Sized,
25 [(); 1 << K]:,
26 [(); num_buckets(K)]:,
27 [(); num_buckets(K) - 1]:;
28
29macro_rules! impl_any {
30 ($($k: expr$(,)? )*) => {
31 $(
32impl Tables<$k> {
33 #[cfg(feature = "alloc")]
36 pub fn create(seed: Seed, cache: &TablesCache) -> Self {
37 Self(TablesGeneric::<$k>::create(
38 seed, cache,
39 ))
40 }
41
42 #[cfg(feature = "parallel")]
45 pub fn create_parallel(seed: Seed, cache: &TablesCache) -> Self {
46 Self(TablesGeneric::<$k>::create_parallel(
47 seed, cache,
48 ))
49 }
50
51 #[cfg(all(feature = "alloc", any(feature = "full-chiapos", test)))]
53 pub fn find_quality<'a>(
54 &'a self,
55 challenge: &'a Challenge,
56 ) -> impl Iterator<Item = Quality> + 'a {
57 self.0.find_quality(challenge)
58 }
59
60 #[cfg(feature = "alloc")]
62 pub fn find_proof<'a>(
63 &'a self,
64 first_challenge_bytes: [u8; 4],
65 ) -> impl Iterator<Item = [u8; 64 * $k / 8]> + 'a {
66 self.0.find_proof(first_challenge_bytes)
67 }
68
69 pub fn verify_only(
71 seed: &Seed,
72 first_challenge_bytes: [u8; 4],
73 proof_of_space: &[u8; 64 * $k as usize / 8],
74 ) -> bool {
75 TablesGeneric::<$k>::verify_only(seed, first_challenge_bytes, proof_of_space)
76 }
77
78 #[cfg(any(feature = "full-chiapos", test))]
82 pub fn verify(
83 seed: &Seed,
84 challenge: &Challenge,
85 proof_of_space: &[u8; 64 * $k as usize / 8],
86 ) -> Option<Quality> {
87 TablesGeneric::<$k>::verify(seed, challenge, proof_of_space)
88 }
89}
90 )*
91 }
92}
93
94#[cfg(feature = "full-chiapos")]
96impl_any!(15, 16, 18, 19, 21, 22, 23, 24, 25);
97#[cfg(any(feature = "full-chiapos", test))]
98impl_any!(17);
99impl_any!(20);