arcium-core-utils 0.8.0

Arcium core utils
Documentation
use primitives::correlated_randomness::{
    bundler::Bundler,
    dabits::DaBit,
    singlets::Singlet,
    stream::{Next, NextVec},
    triples::Triple,
};

use crate::{circuit::preprocessing::CircuitPreprocessing, config::MpcConfig, errors::AbortError};

pub mod bundler;
pub mod iterator;

/// Runtime accessors for a preprocessing bundler's per-type stream state. Exposed as a trait so it
/// remains reachable through the opaque `impl PreprocessingBundler` returned by bundler builders.
pub trait BundlerPositions {
    /// The logical position (elements delivered) of every stream, per type. Stays in sync across
    /// parties; take the per-type maximum to agree on a resync target.
    fn positions(&self) -> CircuitPreprocessing;

    /// The number of already-generated elements currently buffered in every stream, per type — a
    /// runtime occupancy metric, unlike [`positions`](Self::positions).
    fn buffered(&self) -> CircuitPreprocessing;

    /// Advances every stream to its per-type `target`, realigning all parties on the same prefix —
    /// the recovery primitive for a peer whose [`positions`](Self::positions) fell behind. See
    /// [`StreamBundler::resync`](crate::preprocessing::bundler::StreamBundler::resync).
    ///
    /// Only ever called through the opaque `impl PreprocessingBundler` (never as a `dyn Trait`, and
    /// never spawned onto another task), so the lack of a `Send` bound on the returned future costs
    /// nothing here — and requiring one would force a `Sync` bound onto every stream type this
    /// trait is implemented for.
    #[allow(async_fn_in_trait)]
    async fn resync(&self, targets: &CircuitPreprocessing) -> Result<(), AbortError>;
}

// ---------- Type aliases for preprocessing futures --------------

pub type NextSinglet<F> = Next<Singlet<F>, AbortError>;
pub type NextTriple<F> = Next<Triple<F>, AbortError>;
pub type NextDaBit<F> = Next<DaBit<F>, AbortError>;

pub type NextSinglets<F> = NextVec<Singlet<F>, AbortError>;
pub type NextTriples<F> = NextVec<Triple<F>, AbortError>;
pub type NextDaBits<F> = NextVec<DaBit<F>, AbortError>;

// ---------- PreprocessingBundler trait alias -------------------

/// Alias for any [`Bundler`] whose iterator is the curve-parameterised
/// [`iterator::PreprocessingIterator<C>`].
pub trait PreprocessingBundler<C: MpcConfig>:
    Bundler<Iterator = iterator::PreprocessingIterator<C>>
{
}

impl<C: MpcConfig, T: Bundler<Iterator = iterator::PreprocessingIterator<C>>>
    PreprocessingBundler<C> for T
{
}