1use {
3 crate::{duplicate_block_proof::DuplicateBlockProofData, error::SlashingError},
4 solana_program::{clock::Slot, pubkey::Pubkey},
5};
6
7const PACKET_DATA_SIZE: usize = 1232;
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum ProofType {
12 InvalidType,
14 DuplicateBlockProof,
17}
18
19impl ProofType {
20 pub const fn proof_account_length(&self) -> usize {
23 match self {
24 Self::InvalidType => panic!("Cannot determine size of invalid proof type"),
25 Self::DuplicateBlockProof => {
26 DuplicateBlockProofData::size_of(PACKET_DATA_SIZE)
28 }
29 }
30 }
31
32 pub fn violation_str(&self) -> &str {
34 match self {
35 Self::InvalidType => "invalid",
36 Self::DuplicateBlockProof => "duplicate block",
37 }
38 }
39}
40
41impl From<ProofType> for u8 {
42 fn from(value: ProofType) -> Self {
43 match value {
44 ProofType::InvalidType => 0,
45 ProofType::DuplicateBlockProof => 1,
46 }
47 }
48}
49
50impl From<u8> for ProofType {
51 fn from(value: u8) -> Self {
52 match value {
53 1 => Self::DuplicateBlockProof,
54 _ => Self::InvalidType,
55 }
56 }
57}
58
59pub trait SlashingProofData<'a> {
62 const PROOF_TYPE: ProofType;
64
65 fn unpack(data: &'a [u8]) -> Result<Self, SlashingError>
67 where
68 Self: Sized;
69
70 fn verify_proof(self, slot: Slot, pubkey: &Pubkey) -> Result<(), SlashingError>;
72}
73
74#[cfg(test)]
75mod tests {
76 use crate::state::PACKET_DATA_SIZE;
77
78 #[test]
79 fn test_packet_size_parity() {
80 assert_eq!(PACKET_DATA_SIZE, solana_sdk::packet::PACKET_DATA_SIZE);
81 }
82}