espresso_types/v0/v0_3/
nsproof.rs

1use serde::{Deserialize, Serialize};
2
3/// Re-export the AVID-M namespace proof.
4#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
5pub struct AvidMNsProof(pub(crate) vid::avid_m::proofs::NsProof);
6
7/// The namespace proof for both correct and incorrect encoding.
8#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
9pub enum AvidMNsProofV1 {
10    /// V1 proof for AvidM, contains only correct encoding proof
11    CorrectEncoding(vid::avid_m::proofs::NsProof),
12    /// V1_1 proof for AvidM, contains both correct and incorrect encoding proofs
13    IncorrectEncoding(vid::avid_m::proofs::NsAvidMBadEncodingProof),
14}
15
16impl From<AvidMNsProof> for AvidMNsProofV1 {
17    fn from(proof: AvidMNsProof) -> Self {
18        AvidMNsProofV1::CorrectEncoding(proof.0)
19    }
20}
21
22impl TryFrom<AvidMNsProofV1> for AvidMNsProof {
23    type Error = anyhow::Error;
24
25    fn try_from(proof: AvidMNsProofV1) -> Result<Self, Self::Error> {
26        match proof {
27            AvidMNsProofV1::CorrectEncoding(proof) => Ok(AvidMNsProof(proof)),
28            AvidMNsProofV1::IncorrectEncoding(_) => {
29                Err(anyhow::anyhow!("incorrect encoding proof"))
30            },
31        }
32    }
33}