Skip to main content

core_utils/preprocessing/
mod.rs

1use primitives::correlated_randomness::{
2    bundler::Bundler,
3    dabits::DaBit,
4    singlets::Singlet,
5    stream::{Next, NextVec},
6    triples::Triple,
7};
8
9use crate::{circuit::preprocessing::CircuitPreprocessing, config::MpcConfig, errors::AbortError};
10
11pub mod bundler;
12pub mod iterator;
13
14/// Runtime accessors for a preprocessing bundler's per-type stream state. Exposed as a trait so it
15/// remains reachable through the opaque `impl PreprocessingBundler` returned by bundler builders.
16pub trait BundlerPositions {
17    /// The logical position (elements delivered) of every stream, per type. Stays in sync across
18    /// parties; take the per-type maximum to agree on a resync target.
19    fn positions(&self) -> CircuitPreprocessing;
20
21    /// The number of already-generated elements currently buffered in every stream, per type — a
22    /// runtime occupancy metric, unlike [`positions`](Self::positions).
23    fn buffered(&self) -> CircuitPreprocessing;
24
25    /// Advances every stream to its per-type `target`, realigning all parties on the same prefix —
26    /// the recovery primitive for a peer whose [`positions`](Self::positions) fell behind. See
27    /// [`StreamBundler::resync`](crate::preprocessing::bundler::StreamBundler::resync).
28    ///
29    /// Only ever called through the opaque `impl PreprocessingBundler` (never as a `dyn Trait`, and
30    /// never spawned onto another task), so the lack of a `Send` bound on the returned future costs
31    /// nothing here — and requiring one would force a `Sync` bound onto every stream type this
32    /// trait is implemented for.
33    #[allow(async_fn_in_trait)]
34    async fn resync(&self, targets: &CircuitPreprocessing) -> Result<(), AbortError>;
35}
36
37// ---------- Type aliases for preprocessing futures --------------
38
39pub type NextSinglet<F> = Next<Singlet<F>, AbortError>;
40pub type NextTriple<F> = Next<Triple<F>, AbortError>;
41pub type NextDaBit<F> = Next<DaBit<F>, AbortError>;
42
43pub type NextSinglets<F> = NextVec<Singlet<F>, AbortError>;
44pub type NextTriples<F> = NextVec<Triple<F>, AbortError>;
45pub type NextDaBits<F> = NextVec<DaBit<F>, AbortError>;
46
47// ---------- PreprocessingBundler trait alias -------------------
48
49/// Alias for any [`Bundler`] whose iterator is the curve-parameterised
50/// [`iterator::PreprocessingIterator<C>`].
51pub trait PreprocessingBundler<C: MpcConfig>:
52    Bundler<Iterator = iterator::PreprocessingIterator<C>>
53{
54}
55
56impl<C: MpcConfig, T: Bundler<Iterator = iterator::PreprocessingIterator<C>>>
57    PreprocessingBundler<C> for T
58{
59}