arcium-core-utils 0.4.4

Arcium core utils
Documentation
use std::fmt::Debug;

use primitives::{
    algebra::elliptic_curve::Curve,
    sharing::{Reconstructible, VerifiableWith},
};
use serde::{de::DeserializeOwned, Serialize};
use wincode::{SchemaRead, SchemaWrite};

use crate::{circuit::Circuit, preprocessing::iterator::CerberusPreprocessingIterator};

#[cfg(any(test, feature = "dev"))]
pub mod dealer;
pub mod errors;
pub mod iterator;

/// A marker trait for preprocessing types that can be served in the online phase, maybe requiring
/// some associated data to be generated/requested/verified. Includes verification and random
/// generation capabilities.
pub trait Preprocessing:
    Debug
    + Sized
    + Send
    + Sync
    + Clone
    + PartialEq
    + Serialize
    + DeserializeOwned
    + SchemaWrite<Src = Self>
    + for<'a> SchemaRead<'a>
    + Reconstructible
    + VerifiableWith<VerificationData = <Self as Preprocessing>::AssociatedData>
{
    /// The associated data that is used to generate/request/verify this preprocessing type. E.g.,
    /// an exponent for `PowPair`. Can be empty if no additional data is needed.
    type AssociatedData: Send
        + Sync
        + Clone
        + PartialEq
        + Serialize
        + DeserializeOwned
        + SchemaWrite<Src = Self::AssociatedData>
        + for<'a> SchemaRead<'a, Dst = Self::AssociatedData>;
}

impl<
        Data: Send
            + Sync
            + Clone
            + PartialEq
            + Serialize
            + DeserializeOwned
            + SchemaWrite<Src = Data>
            + for<'a> SchemaRead<'a, Dst = Data>,
        T: Debug
            + Sized
            + Send
            + Sync
            + Clone
            + PartialEq
            + Serialize
            + DeserializeOwned
            + VerifiableWith<VerificationData = Data>
            + for<'a> wincode::SchemaRead<'a, Dst = T>
            + wincode::SchemaWrite<Src = T>,
    > Preprocessing for T
{
    type AssociatedData = Data;
}

/// Bundles all preprocessing sources for an MPC protocol session.
///
/// Implementations are responsible for fetching all preprocessing required for a circuit
/// concurrently and packaging the results into a [`CerberusPreprocessingIterator`]. Because
/// each implementation owns its sources as disjoint struct fields, it can issue all network
/// requests in a single `try_join!` and return after a single `await`, rather than making
/// one sequential round-trip per source type.
pub trait PreprocessingBundler<C: Curve>: Send {
    /// Fetches all preprocessing required by `circuit` and returns a ready-to-use iterator.
    ///
    /// Implementations should issue all source requests concurrently (e.g. via
    /// `tokio::try_join!`) so that this resolves after a single network barrier rather
    /// than N sequential ones.
    fn fetch_for(&mut self, circuit: &Circuit<C>) -> CerberusPreprocessingIterator<C>;
}