jf_vid/precomputable.rs
1// Copyright (c) 2024 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6
7//! Trait for additional functionality in Verifiable Information Retrieval (VID)
8//! for precomputation of specific data that allows for calling
9//! methods using the data to save computation for the callee.
10
11use core::fmt::Debug;
12
13use super::{VidDisperse, VidResult, VidScheme};
14use ark_std::hash::Hash;
15use serde::{de::DeserializeOwned, Serialize};
16/// Allow for precomputation of certain data for [`VidScheme`].
17pub trait Precomputable: VidScheme {
18 /// Precomputed data that can be (re-)used during disperse computation
19 type PrecomputeData: Clone + Debug + Eq + PartialEq + Hash + Sync + Serialize + DeserializeOwned;
20
21 /// Similar to [`VidScheme::commit_only`] but returns additional data that
22 /// can be used as input to `disperse_precompute` for faster dispersal.
23 fn commit_only_precompute<B>(
24 &self,
25 payload: B,
26 ) -> VidResult<(Self::Commit, Self::PrecomputeData)>
27 where
28 B: AsRef<[u8]>;
29
30 /// Similar to [`VidScheme::disperse`] but takes as input additional
31 /// data for more efficient computation and faster disersal.
32 fn disperse_precompute<B>(
33 &self,
34 payload: B,
35 data: &Self::PrecomputeData,
36 ) -> VidResult<VidDisperse<Self>>
37 where
38 B: AsRef<[u8]>;
39}