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