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