Skip to main content

core_utils/preprocessing/
mod.rs

1use std::fmt::Debug;
2
3use primitives::{
4    algebra::elliptic_curve::Curve,
5    sharing::{Reconstructible, VerifiableWith},
6};
7use serde::{de::DeserializeOwned, Serialize};
8use wincode::{SchemaRead, SchemaWrite};
9
10use crate::{circuit::Circuit, preprocessing::iterator::CerberusPreprocessingIterator};
11
12pub mod batching;
13#[cfg(any(test, feature = "dev"))]
14pub mod dealer;
15pub mod errors;
16pub mod iterator;
17pub mod source;
18
19/// A marker trait for preprocessing types that can be served in the online phase, maybe requiring
20/// some associated data to be generated/requested/verified. Includes verification and random
21/// generation capabilities.
22pub trait Preprocessing:
23    Debug
24    + Sized
25    + Send
26    + Sync
27    + Clone
28    + PartialEq
29    + Serialize
30    + DeserializeOwned
31    + SchemaWrite<Src = Self>
32    + for<'a> SchemaRead<'a>
33    + Reconstructible
34    + VerifiableWith<VerificationData = <Self as Preprocessing>::AssociatedData>
35{
36    /// The associated data that is used to generate/request/verify this preprocessing type. E.g.,
37    /// an exponent for `PowPair`. Can be empty if no additional data is needed.
38    type AssociatedData: Send
39        + Sync
40        + Clone
41        + PartialEq
42        + Serialize
43        + DeserializeOwned
44        + SchemaWrite<Src = Self::AssociatedData>
45        + for<'a> SchemaRead<'a, Dst = Self::AssociatedData>;
46}
47
48impl<
49        Data: Send
50            + Sync
51            + Clone
52            + PartialEq
53            + Serialize
54            + DeserializeOwned
55            + SchemaWrite<Src = Data>
56            + for<'a> SchemaRead<'a, Dst = Data>,
57        T: Debug
58            + Sized
59            + Send
60            + Sync
61            + Clone
62            + PartialEq
63            + Serialize
64            + DeserializeOwned
65            + VerifiableWith<VerificationData = Data>
66            + for<'a> wincode::SchemaRead<'a, Dst = T>
67            + wincode::SchemaWrite<Src = T>,
68    > Preprocessing for T
69{
70    type AssociatedData = Data;
71}
72
73/// Bundles all preprocessing sources for an MPC protocol session.
74///
75/// Implementations are responsible for fetching all preprocessing required for a circuit
76/// concurrently and packaging the results into a [`CerberusPreprocessingIterator`]. Because
77/// each implementation owns its sources as disjoint struct fields, it can issue all network
78/// requests in a single `try_join!` and return after a single `await`, rather than making
79/// one sequential round-trip per source type.
80pub trait PreprocessingBundler<C: Curve>: Send {
81    /// Fetches all preprocessing required by `circuit` and returns a ready-to-use iterator.
82    ///
83    /// Implementations should issue all source requests concurrently (e.g. via
84    /// `tokio::try_join!`) so that this resolves after a single network barrier rather
85    /// than N sequential ones.
86    fn fetch_for(&mut self, circuit: &Circuit<C>) -> CerberusPreprocessingIterator<C>;
87}