Skip to main content

primitives/correlated_randomness/
mod.rs

1use std::fmt::Debug;
2
3use serde::{de::DeserializeOwned, Serialize};
4use wincode::{SchemaRead, SchemaWrite};
5
6use crate::{
7    sharing::{Reconstructible, Verifiable},
8    types::Batched,
9};
10
11pub mod bundler;
12pub mod generator;
13pub mod stream;
14pub mod types;
15
16pub use types::{dabits, powpairs, singlets, triples};
17
18/// A marker trait for input-independent correlated randomness types that can be
19/// consumed in the (input-dependent) online phase to speed it up.
20/// Includes verification and random generation capabilities.
21pub trait Correlation:
22    'static
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    + Verifiable
35{
36}
37
38impl<
39        T: 'static
40            + Debug
41            + Sized
42            + Send
43            + Sync
44            + Clone
45            + PartialEq
46            + Serialize
47            + DeserializeOwned
48            + Verifiable
49            + for<'a> wincode::SchemaRead<'a, Dst = T>
50            + wincode::SchemaWrite<Src = T>,
51    > Correlation for T
52{
53}
54
55/// A marker trait for input-independent types that can be generated in batches, i.e. for which it
56/// is more efficient to generate/request/verify multiple elements at once rather than one at a
57/// time.
58pub trait CorrelatedBatch: Correlation + Batched<Item: Correlation> {}
59impl<T: Correlation + Batched<Item: Correlation>> CorrelatedBatch for T {}