-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move and implement constraints as traits for backends
- Loading branch information
Showing
8 changed files
with
884 additions
and
131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod kimchi; | ||
pub mod r1cs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
#[derive(Debug)] | ||
pub struct R1CSBackend { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,107 @@ | ||
use ark_ff::Field; | ||
|
||
use crate::{ | ||
circuit_writer::CircuitWriter, | ||
constants::Span, | ||
helpers::PrettyField, | ||
var::{ConstOrCell, Var}, | ||
}; | ||
|
||
pub mod boolean; | ||
pub mod field; | ||
|
||
pub trait BooleanConstraints<F: Field + PrettyField> { | ||
fn is_valid(&self, f: F) -> bool { | ||
f.is_one() || f.is_zero() | ||
} | ||
|
||
fn check( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
xx: &ConstOrCell<F>, | ||
span: Span, | ||
); | ||
|
||
fn and( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
lhs: &ConstOrCell<F>, | ||
rhs: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn not( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
var: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn or( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
lhs: &ConstOrCell<F>, | ||
rhs: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
} | ||
|
||
pub trait FieldConstraints<F: Field + PrettyField> { | ||
fn add( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
lhs: &ConstOrCell<F>, | ||
rhs: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn sub( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
lhs: &ConstOrCell<F>, | ||
rhs: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn mul( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
lhs: &ConstOrCell<F>, | ||
rhs: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn equal( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
lhs: &Var<F>, | ||
rhs: &Var<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn equal_cells( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
x1: &ConstOrCell<F>, | ||
x2: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn if_else( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
cond: &Var<F>, | ||
then_: &Var<F>, | ||
else_: &Var<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
|
||
fn if_else_inner( | ||
&self, | ||
compiler: &mut CircuitWriter<F>, | ||
cond: &ConstOrCell<F>, | ||
then_: &ConstOrCell<F>, | ||
else_: &ConstOrCell<F>, | ||
span: Span, | ||
) -> Var<F>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters