subspace_proof_of_space/
lib.rs1#![no_std]
3#![expect(incomplete_features, reason = "generic_const_exprs")]
4#![warn(rust_2018_idioms, missing_debug_implementations, missing_docs)]
5#![feature(const_trait_impl, generic_const_exprs, step_trait)]
6#![cfg_attr(feature = "alloc", feature(get_mut_unchecked, maybe_uninit_fill))]
7#![cfg_attr(any(feature = "alloc", test), feature(portable_simd))]
8#![cfg_attr(feature = "parallel", feature(exact_size_is_empty, sync_unsafe_cell))]
9
10pub mod chia;
11#[cfg(feature = "alloc")]
12pub mod chia_v2;
13pub mod chiapos;
14#[cfg(feature = "alloc")]
15pub mod pos_table;
16pub mod shim;
17
18#[cfg(feature = "alloc")]
19pub use pos_table::{PosTable, PosTableGenerator};
20
21#[cfg(feature = "alloc")]
22extern crate alloc;
23
24#[cfg(feature = "alloc")]
25use core::fmt;
26use subspace_core_primitives::pos::{PosProof, PosSeed};
27use subspace_core_primitives::solutions::SolutionPotVerifier;
28
29#[derive(Debug, Clone, Copy)]
31pub enum PosTableType {
32 Chia,
34 Shim,
36}
37
38#[cfg(feature = "alloc")]
42pub trait TableGenerator<T: Table>:
43 fmt::Debug + Default + Clone + Send + Sync + Sized + 'static
44{
45 fn generate(&self, seed: &PosSeed) -> T;
49
50 #[cfg(feature = "parallel")]
55 fn generate_parallel(&self, seed: &PosSeed) -> T {
56 self.generate(seed)
57 }
58}
59
60pub trait Table: SolutionPotVerifier + Sized + Send + Sync + 'static {
62 const TABLE_TYPE: PosTableType;
64 #[cfg(feature = "alloc")]
66 type Generator: TableGenerator<Self>;
67
68 #[cfg(feature = "alloc")]
70 fn find_proof(&self, challenge_index: u32) -> Option<PosProof>;
71
72 fn is_proof_valid(seed: &PosSeed, challenge_index: u32, proof: &PosProof) -> bool;
74
75 #[cfg(feature = "alloc")]
77 fn generator() -> Self::Generator {
78 Self::Generator::default()
79 }
80
81 #[cfg(feature = "alloc")]
84 fn generator_for(_is_post_cutover: bool) -> Self::Generator {
85 Self::generator()
86 }
87}