core_utils/circuit/v1/
ops.rs1use primitives::{
2 algebra::elliptic_curve::{Curve, Point, Scalar},
3 types::PeerNumber,
4};
5use serde::Deserialize;
6
7use crate::circuit::{
8 v1::{
9 constants::{
10 BaseFieldPlaintext,
11 BaseFieldPlaintextBatch,
12 BitPlaintext,
13 BitPlaintextBatch,
14 Mersenne107Plaintext,
15 Mersenne107PlaintextBatch,
16 PointPlaintext,
17 PointPlaintextBatch,
18 ScalarPlaintext,
19 ScalarPlaintextBatch,
20 },
21 errors::OpsConversionError,
22 AlgebraicType,
23 },
24 v2,
25};
26
27pub type FieldPlaintextUnaryOp = v2::FieldPlaintextUnaryOp;
29
30pub type FieldPlaintextBinaryOp = v2::FieldPlaintextBinaryOp;
32
33pub type FieldShareUnaryOp = v2::FieldShareUnaryOp;
35
36pub type FieldShareBinaryOp = v2::FieldShareBinaryOp;
39
40pub type BitShareUnaryOp = v2::BitShareUnaryOp;
42
43pub type BitShareBinaryOp = v2::BitShareBinaryOp;
45
46pub type PointPlaintextUnaryOp = v2::PointPlaintextUnaryOp;
48
49pub type PointPlaintextBinaryOp = v2::PointPlaintextBinaryOp;
51
52pub type PointShareUnaryOp = v2::PointShareUnaryOp;
54
55pub type PointShareBinaryOp = v2::PointShareBinaryOp;
57
58impl TryFrom<FieldPlaintextUnaryOp> for v2::BitPlaintextUnaryOp {
59 type Error = OpsConversionError;
60
61 fn try_from(value: FieldPlaintextUnaryOp) -> Result<Self, Self::Error> {
62 match value {
63 FieldPlaintextUnaryOp::Neg => Ok(Self::Not),
64 _ => Err(OpsConversionError::PlaintextUnaryOpFieldToBit(value)),
65 }
66 }
67}
68
69impl TryFrom<FieldPlaintextBinaryOp> for v2::BitPlaintextBinaryOp {
70 type Error = OpsConversionError;
71
72 fn try_from(value: FieldPlaintextBinaryOp) -> Result<Self, Self::Error> {
73 match value {
74 FieldPlaintextBinaryOp::Mul => Ok(Self::And),
75 FieldPlaintextBinaryOp::Xor => Ok(Self::Xor),
76 FieldPlaintextBinaryOp::Or => Ok(Self::Or),
77 _ => Err(OpsConversionError::PlaintextBinaryOpFieldToBit(value)),
78 }
79 }
80}
81
82#[derive(Deserialize)]
83#[serde(bound(deserialize = "Scalar<C>: Deserialize<'de>, Point<C>: Deserialize<'de>"))]
84#[repr(C)]
85pub enum Input<C: Curve> {
86 SecretPlaintext {
87 inputer: PeerNumber,
88 algebraic_type: AlgebraicType,
89 batched: Batched,
90 },
91 Share {
92 algebraic_type: AlgebraicType,
93 batched: Batched,
94 },
95 RandomShare {
96 algebraic_type: AlgebraicType,
97 batched: Batched,
98 },
99 Scalar(ScalarPlaintext<C>),
100 ScalarBatch(ScalarPlaintextBatch<C>),
101 BaseField(BaseFieldPlaintext<C>),
102 BaseFieldBatch(BaseFieldPlaintextBatch<C>),
103 Mersenne107(Mersenne107Plaintext),
104 Mersenne107Batch(Mersenne107PlaintextBatch),
105 Bit(BitPlaintext),
106 BitBatch(BitPlaintextBatch),
107 Point(PointPlaintext<C>),
108 PointBatch(PointPlaintextBatch<C>),
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)]
113#[repr(C)]
114pub enum Batched {
115 Yes(usize),
116 No,
117}
118
119impl Batched {
120 pub fn count(&self) -> usize {
121 match self {
122 Batched::Yes(count) => *count,
123 Batched::No => 1,
124 }
125 }
126}