espresso_types/v0/
nsproof.rs1use hotshot_query_service::VidCommon;
2use hotshot_types::{data::VidCommitment, vid::avidm::AvidMShare};
3use serde::{Deserialize, Serialize};
4
5use crate::{
6 v0::{NamespaceId, NsIndex, NsPayload, NsTable, Payload, Transaction},
7 v0_1::ADVZNsProof,
8 v0_3::{AvidMNsProof, AvidMNsProofV1},
9};
10
11#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
12pub struct NamespaceProofQueryData {
13 pub proof: Option<NsProof>,
14 pub transactions: Vec<Transaction>,
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
18pub struct ADVZNamespaceProofQueryData {
19 pub proof: Option<ADVZNsProof>,
20 pub transactions: Vec<Transaction>,
21}
22
23#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
25pub enum NsProof {
26 V0(ADVZNsProof),
28 V1(AvidMNsProof),
30 V1_1(AvidMNsProofV1),
32}
33
34impl NsProof {
35 pub fn new(payload: &Payload, index: &NsIndex, common: &VidCommon) -> Option<NsProof> {
36 match common {
37 VidCommon::V0(common) => Some(NsProof::V0(ADVZNsProof::new(payload, index, common)?)),
38 VidCommon::V1(common) => Some(NsProof::V1(AvidMNsProof::new(payload, index, common)?)),
39 }
40 }
41
42 pub fn v1_1_new_with_correct_encoding(
43 payload: &Payload,
44 index: &NsIndex,
45 common: &VidCommon,
46 ) -> Option<NsProof> {
47 match common {
48 VidCommon::V1(common) => Some(NsProof::V1_1(AvidMNsProofV1::new_correct_encoding(
49 payload, index, common,
50 )?)),
51 _ => None,
52 }
53 }
54
55 pub fn v1_1_new_with_incorrect_encoding(
56 shares: &[AvidMShare],
57 ns_table: &NsTable,
58 index: &NsIndex,
59 commit: &VidCommitment,
60 common: &VidCommon,
61 ) -> Option<NsProof> {
62 match common {
63 VidCommon::V1(common) => Some(NsProof::V1_1(AvidMNsProofV1::new_incorrect_encoding(
64 shares, ns_table, index, commit, common,
65 )?)),
66 _ => None,
67 }
68 }
69
70 pub fn verify(
71 &self,
72 ns_table: &NsTable,
73 commit: &VidCommitment,
74 common: &VidCommon,
75 ) -> Option<(Vec<Transaction>, NamespaceId)> {
76 match (self, common) {
77 (Self::V0(proof), VidCommon::V0(common)) => proof.verify(ns_table, commit, common),
78 (Self::V1(proof), VidCommon::V1(common)) => proof.verify(ns_table, commit, common),
79 (Self::V1_1(proof), VidCommon::V1(common)) => proof.verify(ns_table, commit, common),
80 _ => {
81 tracing::error!("Incompatible version of VidCommon and NsProof.");
82 None
83 },
84 }
85 }
86
87 pub fn export_all_txs(&self, ns_id: &NamespaceId) -> Vec<Transaction> {
88 match self {
89 Self::V0(proof) => proof.export_all_txs(ns_id),
90 Self::V1(AvidMNsProof(proof)) | Self::V1_1(AvidMNsProofV1::CorrectEncoding(proof)) => {
91 NsPayload::from_bytes_slice(&proof.ns_payload).export_all_txs(ns_id)
92 },
93 Self::V1_1(AvidMNsProofV1::IncorrectEncoding(_)) => vec![],
94 }
95 }
96}