ab_proof_of_space/
chia.rs1#[cfg(all(feature = "alloc", test, not(miri)))]
4mod tests;
5
6#[cfg(feature = "alloc")]
7use crate::PosProofs;
8#[cfg(feature = "alloc")]
9use crate::TableGenerator;
10use crate::chiapos::Tables;
11#[cfg(feature = "alloc")]
12use crate::chiapos::TablesCache;
13use crate::{PosTableType, Table};
14use ab_core_primitives::pos::{PosProof, PosSeed};
15use ab_core_primitives::sectors::SBucket;
16#[cfg(feature = "alloc")]
17use alloc::boxed::Box;
18
19const K: u8 = PosProof::K;
20
21#[derive(Debug, Default, Clone)]
25#[cfg(feature = "alloc")]
26pub struct ChiaTableGenerator {
27 tables_cache: TablesCache,
28}
29
30#[cfg(feature = "alloc")]
31impl TableGenerator<ChiaTable> for ChiaTableGenerator {
32 fn create_proofs(&self, seed: &PosSeed) -> Box<PosProofs> {
33 Tables::<K>::create_proofs((*seed).into(), &self.tables_cache).into()
34 }
35
36 #[cfg(feature = "parallel")]
37 fn create_proofs_parallel(&self, seed: &PosSeed) -> Box<PosProofs> {
38 Tables::<K>::create_proofs_parallel((*seed).into(), &self.tables_cache).into()
39 }
40}
41
42#[derive(Debug)]
46pub struct ChiaTable;
47
48impl ab_core_primitives::solutions::SolutionPotVerifier for ChiaTable {
49 fn is_proof_valid(seed: &PosSeed, s_bucket: SBucket, proof: &PosProof) -> bool {
50 Tables::<K>::verify_only_raw(seed, u32::from(s_bucket), proof)
51 }
52}
53
54impl Table for ChiaTable {
55 const TABLE_TYPE: PosTableType = PosTableType::Chia;
56 #[cfg(feature = "alloc")]
57 type Generator = ChiaTableGenerator;
58
59 fn is_proof_valid(seed: &PosSeed, s_bucket: SBucket, proof: &PosProof) -> bool {
60 <Self as ab_core_primitives::solutions::SolutionPotVerifier>::is_proof_valid(
61 seed, s_bucket, proof,
62 )
63 }
64}