#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ScalarKind {
#[default]
Unsigned,
Signed,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Value {
MScalar {
size_in_bits: usize,
},
MFloat {
size_in_bits: usize,
},
MBool,
Scalar {
size_in_bits: usize,
kind: ScalarKind,
},
Float {
size_in_bits: usize,
},
Bool,
Ciphertext {
size_in_bits: usize,
},
ArcisX25519Pubkey,
Point,
Array(Vec<Value>),
Tuple(Vec<Value>),
Struct(Vec<Value>),
}
impl Value {
pub fn size_in_scalars(&self) -> usize {
match self {
Self::MScalar { .. } => 1,
Self::MFloat { .. } => 1,
Self::Scalar { .. } => 1,
Self::Float { .. } => 1,
Self::MBool { .. } => 1,
Self::Bool { .. } => 1,
Self::Ciphertext { .. } => 1,
Self::ArcisX25519Pubkey => 1,
Self::Point => 1,
Self::Array(c) | Self::Tuple(c) | Self::Struct(c) => {
c.iter().fold(0, |acc, x| acc + x.size_in_scalars())
}
}
}
pub fn flatten(&self) -> Vec<Value> {
match self {
Self::Array(c) | Self::Tuple(c) | Self::Struct(c) => {
let mut v = Vec::new();
for a in c {
v.extend(a.flatten());
}
v
}
_ => vec![self.clone()],
}
}
}
#[derive(Debug, serde::Serialize)]
pub struct CircuitInterface {
pub name: String,
pub inputs: Vec<Value>,
pub outputs: Vec<Value>,
}
impl CircuitInterface {
pub fn new(name: String, inputs: Vec<Value>, outputs: Vec<Value>) -> Self {
Self {
name,
inputs,
outputs,
}
}
pub fn serialize(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(self)
}
pub fn from_json(input: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(input)
}
}