1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_core/src/solvers/mod.rs
2020-12-20 20:30:40 +01:00

50 lines
1.1 KiB
Rust

use serde::{Deserialize, Serialize};
use std::fmt;
use zokrates_field::Field;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, Hash, Eq)]
pub enum Solver {
ConditionEq,
Bits(usize),
Div,
Xor,
Or,
ShaAndXorAndXorAnd,
ShaCh,
EuclideanDiv,
}
impl fmt::Display for Solver {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl Solver {
pub fn get_signature(&self) -> (usize, usize) {
match self {
Solver::ConditionEq => (1, 2),
Solver::Bits(bit_width) => (1, *bit_width),
Solver::Div => (2, 1),
Solver::Xor => (2, 1),
Solver::Or => (2, 1),
Solver::ShaAndXorAndXorAnd => (3, 1),
Solver::ShaCh => (3, 1),
Solver::EuclideanDiv => (2, 2),
}
}
}
impl Solver {
pub fn bits(width: usize) -> Self {
Solver::Bits(width)
}
}
pub trait Executable<T: Field>: Signed {
fn execute(&self, inputs: &[T]) -> Result<Vec<T>, String>;
}
pub trait Signed {
fn get_signature(&self) -> (usize, usize);
}