use primitives::{
algebra::elliptic_curve::{Curve, Point, Scalar},
types::PeerNumber,
};
use serde::Deserialize;
#[cfg(test)]
use serde::Serialize;
use crate::circuit::{
latest,
old::v1::{
constants::{
BaseFieldPlaintext,
BaseFieldPlaintextBatch,
BitPlaintext,
BitPlaintextBatch,
Mersenne107Plaintext,
Mersenne107PlaintextBatch,
PointPlaintext,
PointPlaintextBatch,
ScalarPlaintext,
ScalarPlaintextBatch,
},
errors::OpsConversionError,
AlgebraicType,
},
};
pub type FieldPlaintextUnaryOp = latest::FieldPlaintextUnaryOp;
pub type FieldPlaintextBinaryOp = latest::FieldPlaintextBinaryOp;
pub type FieldShareUnaryOp = latest::FieldShareUnaryOp;
pub type FieldShareBinaryOp = latest::FieldShareBinaryOp;
pub type BitShareUnaryOp = latest::BitShareUnaryOp;
pub type BitShareBinaryOp = latest::BitShareBinaryOp;
pub type PointPlaintextUnaryOp = latest::PointPlaintextUnaryOp;
pub type PointPlaintextBinaryOp = latest::PointPlaintextBinaryOp;
pub type PointShareUnaryOp = latest::PointShareUnaryOp;
pub type PointShareBinaryOp = latest::PointShareBinaryOp;
impl TryFrom<FieldPlaintextUnaryOp> for latest::BitPlaintextUnaryOp {
type Error = OpsConversionError;
fn try_from(value: FieldPlaintextUnaryOp) -> Result<Self, Self::Error> {
match value {
FieldPlaintextUnaryOp::Neg => Ok(Self::Not),
_ => Err(OpsConversionError::PlaintextUnaryOpFieldToBit(value)),
}
}
}
impl TryFrom<FieldPlaintextBinaryOp> for latest::BitPlaintextBinaryOp {
type Error = OpsConversionError;
fn try_from(value: FieldPlaintextBinaryOp) -> Result<Self, Self::Error> {
match value {
FieldPlaintextBinaryOp::Mul => Ok(Self::And),
FieldPlaintextBinaryOp::Xor => Ok(Self::Xor),
FieldPlaintextBinaryOp::Or => Ok(Self::Or),
_ => Err(OpsConversionError::PlaintextBinaryOpFieldToBit(value)),
}
}
}
#[derive(Deserialize)]
#[cfg_attr(test, derive(Serialize))]
#[serde(bound(
deserialize = "Scalar<C>: Deserialize<'de>, Point<C>: Deserialize<'de>",
serialize = "Scalar<C>: Serialize, Point<C>: Serialize"
))]
#[repr(C)]
pub enum Input<C: Curve> {
SecretPlaintext {
inputer: PeerNumber,
algebraic_type: AlgebraicType,
batched: Batched,
},
Share {
algebraic_type: AlgebraicType,
batched: Batched,
},
RandomShare {
algebraic_type: AlgebraicType,
batched: Batched,
},
Scalar(ScalarPlaintext<C>),
ScalarBatch(ScalarPlaintextBatch<C>),
BaseField(BaseFieldPlaintext<C>),
BaseFieldBatch(BaseFieldPlaintextBatch<C>),
Mersenne107(Mersenne107Plaintext),
Mersenne107Batch(Mersenne107PlaintextBatch),
Bit(BitPlaintext),
BitBatch(BitPlaintextBatch),
Point(PointPlaintext<C>),
PointBatch(PointPlaintextBatch<C>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
#[repr(C)]
pub enum Batched {
Yes(usize),
No,
}
impl Batched {
pub fn count(&self) -> usize {
match self {
Batched::Yes(count) => *count,
Batched::No => 1,
}
}
}