mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-25 05:36:50 +03:00
672: Feature/515 eliminate const vars r=collinc97 a=gluax Resolves #515. Removes const keyword from statements. Also resolves #514. Still allows const y in function declaration of args. 673: feature/671-primefield-refactor r=collinc97 a=gluax Resolves #671. Refactor "Field + PrimeField" -> "PrimeField" and all tests still pass. Co-authored-by: gluaxspeed <jonathan.t.pavlik@gmail.com> Co-authored-by: gluax <jonathan.t.pavlik@gmail.com> Co-authored-by: Collin Chin <collin.chin@berkeley.edu>
This commit is contained in:
commit
c62af038c5
@ -28,6 +28,7 @@ use crate::{
|
||||
Type,
|
||||
Variable,
|
||||
};
|
||||
use leo_ast::{AstError, DeprecatedError};
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
@ -89,8 +90,10 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
||||
}
|
||||
|
||||
for (variable, type_) in statement.variable_names.iter().zip(output_types.into_iter()) {
|
||||
if statement.declaration_type == leo_ast::Declare::Const && variable.mutable {
|
||||
return Err(AsgConvertError::illegal_ast_structure("cannot have const mut"));
|
||||
if statement.declaration_type == leo_ast::Declare::Const {
|
||||
return Err(AsgConvertError::AstError(AstError::DeprecatedError(
|
||||
DeprecatedError::const_statement(&statement.span),
|
||||
)));
|
||||
}
|
||||
variables.push(&*scope.alloc_variable(RefCell::new(InnerVariable {
|
||||
id: uuid::Uuid::new_v4(),
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Multidimensional array syntax in leo
|
||||
function main() {
|
||||
const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
let a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Multidimensional array syntax in leo
|
||||
function main() {
|
||||
const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
let a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
let b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
let b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
let b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
|
||||
let b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering)
|
||||
let b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [u8; (2, 3)] = [[0; 3]; 2]; // initializer
|
||||
let b: [u8; (2, 3)] = [[0; 3]; 2]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
let b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering)
|
||||
let b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [u8; (2, 3)] = [0; (2, 3)]; // initializer
|
||||
let b: [u8; (2, 3)] = [0; (2, 3)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order)
|
||||
let b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order)
|
||||
}
|
@ -3,6 +3,6 @@ function foo() -> field {
|
||||
}
|
||||
|
||||
function main() {
|
||||
const myGlobal = 42field;
|
||||
let myGlobal = 42field;
|
||||
let err = foo();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// Constant variables are immutable by default.
|
||||
// Let variables are immutable by default.
|
||||
function main() {
|
||||
const a = 1u32;
|
||||
let a = 1u32;
|
||||
a = 0;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
// Adding the `mut` keyword to a constant variable is illegal
|
||||
function main() {
|
||||
const mut a = 1u32;
|
||||
}
|
@ -30,12 +30,6 @@ fn test_const_fail() {
|
||||
load_asg(&new_context(), program_string).err().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_const_mut_fail() {
|
||||
let program_string = include_str!("const_mut.leo");
|
||||
load_asg(&new_context(), program_string).err().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array() {
|
||||
let program_string = include_str!("array.leo");
|
||||
|
3
asg/tests/fail/statements/const_declaration_fail.leo
Normal file
3
asg/tests/fail/statements/const_declaration_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
const x = 1u32;
|
||||
}
|
@ -23,3 +23,9 @@ fn test_num_returns_fail() {
|
||||
let program_string = include_str!("num_returns_fail.leo");
|
||||
load_asg(&new_context(), program_string).err().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_const_declaration_fail() {
|
||||
let program_string = include_str!("const_declaration_fail.leo");
|
||||
load_asg(&new_context(), program_string).err().unwrap();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
|
||||
let a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
|
||||
|
||||
const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
|
||||
let b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
// Multidimensional array syntax in leo
|
||||
function main() {
|
||||
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
|
||||
let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
|
||||
|
||||
const b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
let b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
// Multidimensional array syntax in leo
|
||||
function main() {
|
||||
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
|
||||
let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
|
||||
|
||||
const b: [u32; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
let b: [u32; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
function main(a: [[u8; 2]; 3]) {
|
||||
const b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
function main(a: [[[u8; 2]; 3]; 4]) {
|
||||
const b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
let b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
|
||||
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer
|
||||
let b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
function main() {
|
||||
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
|
||||
|
||||
const b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer
|
||||
let b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer
|
||||
let b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
function main() {
|
||||
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
|
||||
|
||||
const b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer
|
||||
let b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
let b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
function main() {
|
||||
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
|
||||
|
||||
const b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer
|
||||
let b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [u8; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
let b: [u8; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
function main() {
|
||||
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
|
||||
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
|
||||
|
||||
const b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer
|
||||
let b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
// !(true && (false || true))
|
||||
function main() {
|
||||
const a = true;
|
||||
const b = false || a;
|
||||
const c = !(true && b);
|
||||
let a = true;
|
||||
let b = false || a;
|
||||
let c = !(true && b);
|
||||
|
||||
console.assert(c == false);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
const point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group;
|
||||
let point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group;
|
||||
}
|
@ -12,15 +12,15 @@ import bar.( // imports directory import
|
||||
import car.Car; // imports directory import
|
||||
|
||||
function main() {
|
||||
const point = Point { x: 1u32, y: 1u32 };
|
||||
const foo = foo();
|
||||
let point = Point { x: 1u32, y: 1u32 };
|
||||
let foo = foo();
|
||||
|
||||
const bar = Bar { r: 1u32 };
|
||||
const baz = Baz { z: 1u32 };
|
||||
const bazzar = Bazzar { a: 1u32 };
|
||||
const bat = Bat { t: 1u32 };
|
||||
let bar = Bar { r: 1u32 };
|
||||
let baz = Baz { z: 1u32 };
|
||||
let bazzar = Bazzar { a: 1u32 };
|
||||
let bat = Bat { t: 1u32 };
|
||||
|
||||
const car = Car { c: 1u32 };
|
||||
let car = Car { c: 1u32 };
|
||||
|
||||
console.assert(car.c == 1u32);
|
||||
}
|
@ -6,14 +6,14 @@ import bar.bat.bat.*; // imports directory import
|
||||
import car.*; // imports directory import
|
||||
|
||||
function main() {
|
||||
const point = Point { x: 1u32, y: 1u32 };
|
||||
const foo = foo();
|
||||
let point = Point { x: 1u32, y: 1u32 };
|
||||
let foo = foo();
|
||||
|
||||
const bar = Bar { r: 1u32 };
|
||||
const bat = Bat { t: 1u32 };
|
||||
const baz = Baz { z: 1u32 };
|
||||
let bar = Bar { r: 1u32 };
|
||||
let bat = Bat { t: 1u32 };
|
||||
let baz = Baz { z: 1u32 };
|
||||
|
||||
const car = Car { c: 1u32 };
|
||||
let car = Car { c: 1u32 };
|
||||
|
||||
console.assert(car.c == 1u32);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
function main(a: bool, b: bool) {
|
||||
let c = if a ? true : false;
|
||||
|
||||
const d = c == b;
|
||||
let d = c == b;
|
||||
}
|
@ -61,3 +61,10 @@ impl<'ast> TryFrom<AnnotationName<'ast>> for DeprecatedError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DeprecatedError {
|
||||
pub fn const_statement(span: &Span) -> Self {
|
||||
let message = "const _ = ... is deprecated. Did you mean let?".to_string();
|
||||
Self::new_from_span(message, span.clone())
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ use leo_state::verify_local_data_commitment;
|
||||
use snarkvm_dpc::{base_dpc::instantiated::Components, SystemParameters};
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
|
||||
};
|
||||
|
||||
@ -57,7 +57,7 @@ pub fn thread_leaked_context() -> AsgContext<'static> {
|
||||
|
||||
/// Stores information to compile a Leo program.
|
||||
#[derive(Clone)]
|
||||
pub struct Compiler<'a, F: Field + PrimeField, G: GroupType<F>> {
|
||||
pub struct Compiler<'a, F: PrimeField, G: GroupType<F>> {
|
||||
program_name: String,
|
||||
main_file_path: PathBuf,
|
||||
output_directory: PathBuf,
|
||||
@ -69,7 +69,7 @@ pub struct Compiler<'a, F: Field + PrimeField, G: GroupType<F>> {
|
||||
_group: PhantomData<G>,
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
///
|
||||
/// Returns a new Leo program compiler.
|
||||
///
|
||||
@ -277,7 +277,7 @@ impl<'a, F: Field + PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<'a, F, G> {
|
||||
///
|
||||
/// Synthesizes the circuit with program input.
|
||||
///
|
||||
|
@ -26,11 +26,11 @@ use crate::{
|
||||
use leo_asg::{Expression, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn evaluate_console_assert<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -20,11 +20,11 @@ use crate::{errors::ConsoleError, program::ConstrainedProgram, statement::get_in
|
||||
use leo_asg::{ConsoleFunction, ConsoleStatement};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn evaluate_console_function_call<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ConsoleError, program::ConstrainedProgram, GroupType};
|
||||
use leo_asg::FormattedString;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn format<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -23,12 +23,12 @@ use leo_input::LeoInputParser;
|
||||
use leo_package::inputs::InputPairs;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::r1cs::{ConstraintSystem, TestConstraintSystem},
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
pub fn generate_constraints<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn generate_constraints<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
asg: &Asg<'a>,
|
||||
input: &Input,
|
||||
@ -50,7 +50,7 @@ pub fn generate_constraints<'a, F: Field + PrimeField, G: GroupType<F>, CS: Cons
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_test_constraints<'a, F: Field + PrimeField, G: GroupType<F>>(
|
||||
pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType<F>>(
|
||||
asg: &Asg<'a>,
|
||||
input: InputPairs,
|
||||
main_file_path: &Path,
|
||||
|
@ -19,9 +19,9 @@
|
||||
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Variable;
|
||||
|
||||
use snarkvm_models::curves::{Field, PrimeField};
|
||||
use snarkvm_models::curves::PrimeField;
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn store_definition(&mut self, variable: &Variable, value: ConstrainedValue<'a, F, G>) {
|
||||
let variable = variable.borrow();
|
||||
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_ast::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn enforce_add<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_add<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_ast::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn enforce_div<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_div<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_ast::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn enforce_mul<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_mul<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_ast::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn enforce_negate<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_negate<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
value: ConstrainedValue<'a, F, G>,
|
||||
span: &Span,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_ast::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn enforce_pow<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_pow<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_ast::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn enforce_sub<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_sub<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{Expression, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_array_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -21,12 +21,9 @@ use std::cell::Cell;
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{Expression, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Enforce array expressions
|
||||
pub fn enforce_array<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{Expression, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub(crate) fn enforce_index<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -19,14 +19,11 @@
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Expression;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
type ConstrainedValuePair<'a, T, U> = (ConstrainedValue<'a, T, U>, ConstrainedValue<'a, T, U>);
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_binary_expression<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{CircuitAccessExpression, Node};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_circuit_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -24,12 +24,9 @@ use crate::{
|
||||
};
|
||||
use leo_asg::{CircuitInitExpression, CircuitMember, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn enforce_circuit<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -20,11 +20,11 @@ use crate::{errors::ExpressionError, program::ConstrainedProgram, value::Constra
|
||||
use leo_asg::{Expression, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::select::CondSelectGadget},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Enforce ternary conditional expression
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_conditional_expression<CS: ConstraintSystem<F>>(
|
||||
|
@ -30,11 +30,11 @@ use crate::{
|
||||
use leo_asg::{expression::*, ConstValue, Expression, Node};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub(crate) fn enforce_expression<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -20,12 +20,9 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, CoreCircuit, G
|
||||
|
||||
use crate::errors::ExpressionError;
|
||||
use leo_asg::{Expression, Function, Span};
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Call a default core circuit function with arguments
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_core_circuit_call_expression<CS: ConstraintSystem<F>, C: CoreCircuit<'a, F, G>>(
|
||||
|
@ -21,12 +21,9 @@ use std::cell::Cell;
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{Expression, Function, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_function_call_expression<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -20,11 +20,11 @@ use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
pub fn enforce_and<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_and<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,9 +19,9 @@
|
||||
use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
|
||||
use snarkvm_models::curves::{Field, PrimeField};
|
||||
use snarkvm_models::curves::PrimeField;
|
||||
|
||||
pub fn evaluate_not<'a, F: Field + PrimeField, G: GroupType<F>>(
|
||||
pub fn evaluate_not<'a, F: PrimeField, G: GroupType<F>>(
|
||||
value: ConstrainedValue<'a, F, G>,
|
||||
span: &Span,
|
||||
) -> Result<ConstrainedValue<'a, F, G>, BooleanError> {
|
||||
|
@ -20,11 +20,11 @@ use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
pub fn enforce_or<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_or<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -20,14 +20,14 @@ use crate::{enforce_and, errors::ExpressionError, value::ConstrainedValue, Group
|
||||
use leo_asg::Span;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::{boolean::Boolean, eq::EvaluateEqGadget},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn evaluate_eq<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_eq<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -20,12 +20,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
use leo_gadgets::bits::ComparatorGadget;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn evaluate_ge<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_ge<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -20,12 +20,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
use leo_gadgets::bits::ComparatorGadget;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn evaluate_gt<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_gt<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -20,12 +20,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
use leo_gadgets::bits::ComparatorGadget;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn evaluate_le<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_le<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -20,12 +20,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Span;
|
||||
use leo_gadgets::bits::comparator::EvaluateLtGadget;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub fn evaluate_lt<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_lt<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<'a, F, G>,
|
||||
right: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{Expression, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_tuple_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -21,12 +21,9 @@ use std::cell::Cell;
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::Expression;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Enforce tuple expressions
|
||||
pub fn enforce_tuple<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -19,9 +19,9 @@
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::VariableRef;
|
||||
|
||||
use snarkvm_models::curves::{Field, PrimeField};
|
||||
use snarkvm_models::curves::PrimeField;
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Enforce a variable expression by getting the resolved value
|
||||
pub fn evaluate_ref(&mut self, variable_ref: &VariableRef) -> Result<ConstrainedValue<'a, F, G>, ExpressionError> {
|
||||
// Evaluate the identifier name in the current function scope
|
||||
|
@ -22,11 +22,11 @@ use leo_asg::{Expression, Function, FunctionQualifier};
|
||||
use std::cell::Cell;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub(crate) fn enforce_function<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -21,12 +21,9 @@ use crate::{errors::FunctionError, program::ConstrainedProgram, value::Constrain
|
||||
use leo_asg::Type;
|
||||
use leo_ast::{InputValue, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn allocate_array<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -18,17 +18,14 @@ use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram,
|
||||
use leo_asg::{Circuit, CircuitMember, Type};
|
||||
use leo_ast::{Identifier, Input, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub const RECORD_VARIABLE_NAME: &str = "record";
|
||||
pub const REGISTERS_VARIABLE_NAME: &str = "registers";
|
||||
pub const STATE_VARIABLE_NAME: &str = "state";
|
||||
pub const STATE_LEAF_VARIABLE_NAME: &str = "state_leaf";
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn allocate_input_keyword<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -18,14 +18,11 @@ use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram,
|
||||
use leo_asg::{AsgConvertError, Circuit, CircuitMember};
|
||||
use leo_ast::{Identifier, InputValue, Parameter};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn allocate_input_section<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -32,12 +32,9 @@ use crate::{
|
||||
|
||||
use leo_asg::Type;
|
||||
use leo_ast::{InputValue, Span};
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn allocate_main_function_input<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -21,12 +21,9 @@ use crate::{errors::FunctionError, program::ConstrainedProgram, value::Constrain
|
||||
use leo_asg::Type;
|
||||
use leo_ast::{InputValue, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn allocate_tuple<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -22,12 +22,9 @@ use leo_asg::{Expression, Function, FunctionQualifier};
|
||||
use leo_ast::Input;
|
||||
use std::cell::Cell;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn enforce_main_function<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -34,12 +34,9 @@ use leo_asg::{
|
||||
Variable,
|
||||
};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
fn prepare_mut_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -27,14 +27,14 @@ use crate::{
|
||||
use leo_asg::{Span, Type};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::{boolean::Boolean, select::CondSelectGadget},
|
||||
},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
///
|
||||
/// Returns a conditionally selected result from the given possible function returns and
|
||||
/// given function return type.
|
||||
|
@ -18,7 +18,7 @@ use crate::{errors::OutputBytesError, ConstrainedValue, GroupType, REGISTERS_VAR
|
||||
use leo_asg::Program;
|
||||
use leo_ast::{Parameter, Registers, Span};
|
||||
|
||||
use snarkvm_models::curves::{Field, PrimeField};
|
||||
use snarkvm_models::curves::PrimeField;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -31,7 +31,7 @@ impl OutputBytes {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn new_from_constrained_value<'a, F: Field + PrimeField, G: GroupType<F>>(
|
||||
pub fn new_from_constrained_value<'a, F: PrimeField, G: GroupType<F>>(
|
||||
program: &Program<'a>,
|
||||
registers: &Registers,
|
||||
value: ConstrainedValue<'a, F, G>,
|
||||
|
@ -19,7 +19,7 @@ use crate::{errors::ExpressionError, ConstrainedValue, GroupType, Integer};
|
||||
use leo_asg::{Function, Span};
|
||||
use snarkvm_gadgets::algorithms::prf::Blake2sGadget;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
algorithms::PRFGadget,
|
||||
r1cs::ConstraintSystem,
|
||||
@ -29,7 +29,7 @@ use snarkvm_models::{
|
||||
|
||||
pub struct Blake2s;
|
||||
|
||||
fn unwrap_argument<F: Field + PrimeField, G: GroupType<F>>(arg: ConstrainedValue<F, G>) -> Vec<UInt8> {
|
||||
fn unwrap_argument<F: PrimeField, G: GroupType<F>>(arg: ConstrainedValue<F, G>) -> Vec<UInt8> {
|
||||
if let ConstrainedValue::Array(args) = arg {
|
||||
assert_eq!(args.len(), 32); // asg enforced
|
||||
args.into_iter()
|
||||
@ -46,7 +46,7 @@ fn unwrap_argument<F: Field + PrimeField, G: GroupType<F>>(arg: ConstrainedValue
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> CoreCircuit<'a, F, G> for Blake2s {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> CoreCircuit<'a, F, G> for Blake2s {
|
||||
fn call_function<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
cs: &mut CS,
|
||||
|
@ -19,12 +19,9 @@ pub use blake2s::*;
|
||||
|
||||
use crate::{errors::ExpressionError, ConstrainedValue, GroupType};
|
||||
use leo_asg::{Function, Span};
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub trait CoreCircuit<'a, F: Field + PrimeField, G: GroupType<F>>: Send + Sync {
|
||||
pub trait CoreCircuit<'a, F: PrimeField, G: GroupType<F>>: Send + Sync {
|
||||
fn call_function<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
cs: &mut CS,
|
||||
@ -35,7 +32,7 @@ pub trait CoreCircuit<'a, F: Field + PrimeField, G: GroupType<F>>: Send + Sync {
|
||||
) -> Result<ConstrainedValue<'a, F, G>, ExpressionError>;
|
||||
}
|
||||
|
||||
pub fn resolve_core_circuit<'a, F: Field + PrimeField, G: GroupType<F>>(name: &str) -> impl CoreCircuit<'a, F, G> {
|
||||
pub fn resolve_core_circuit<'a, F: PrimeField, G: GroupType<F>>(name: &str) -> impl CoreCircuit<'a, F, G> {
|
||||
match name {
|
||||
"blake2s" => Blake2s,
|
||||
_ => unimplemented!("invalid core circuit: {}", name),
|
||||
|
@ -19,17 +19,17 @@
|
||||
use crate::{value::ConstrainedValue, GroupType};
|
||||
|
||||
use leo_asg::Program;
|
||||
use snarkvm_models::curves::{Field, PrimeField};
|
||||
use snarkvm_models::curves::PrimeField;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct ConstrainedProgram<'a, F: Field + PrimeField, G: GroupType<F>> {
|
||||
pub struct ConstrainedProgram<'a, F: PrimeField, G: GroupType<F>> {
|
||||
pub asg: Program<'a>,
|
||||
identifiers: IndexMap<Uuid, ConstrainedValue<'a, F, G>>,
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn new(asg: Program<'a>) -> Self {
|
||||
Self {
|
||||
asg,
|
||||
|
@ -20,14 +20,14 @@ use crate::{arithmetic::*, errors::StatementError, program::ConstrainedProgram,
|
||||
use leo_asg::{AssignOperation, AssignStatement, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::{boolean::Boolean, select::CondSelectGadget},
|
||||
},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_assign_statement<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -19,10 +19,7 @@
|
||||
use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::{AssignAccess, AssignStatement, Identifier, Span};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub(crate) enum ResolvedAssigneeAccess {
|
||||
ArrayRange(Option<usize>, Option<usize>),
|
||||
@ -31,7 +28,7 @@ pub(crate) enum ResolvedAssigneeAccess {
|
||||
Member(Identifier),
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn resolve_assign<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -20,11 +20,11 @@ use crate::{program::ConstrainedProgram, GroupType, IndicatorAndConstrainedValue
|
||||
use leo_asg::BlockStatement;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Evaluates a branch of one or more statements and returns a result in
|
||||
/// the given scope.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
@ -27,7 +27,7 @@ use crate::{
|
||||
use leo_asg::ConditionalStatement;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
@ -38,7 +38,7 @@ fn indicator_to_string(indicator: &Boolean) -> String {
|
||||
.unwrap_or_else(|| "[input]".to_string())
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
/// Enforces a conditional statement with one or more branches.
|
||||
/// Due to R1CS constraints, we must evaluate every branch to properly construct the circuit.
|
||||
/// At program execution, we will pass an `indicator` bit down to all child statements within each branch.
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::StatementError, program::ConstrainedProgram, ConstrainedValue, GroupType};
|
||||
use leo_asg::{DefinitionStatement, Span, Variable};
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
fn enforce_multiple_definition(
|
||||
&mut self,
|
||||
variable_names: &[&'a Variable<'a>],
|
||||
|
@ -27,14 +27,14 @@ use crate::{
|
||||
use leo_asg::IterationStatement;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::{boolean::Boolean, uint::UInt32},
|
||||
},
|
||||
};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn enforce_iteration_statement<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
|
@ -19,12 +19,9 @@
|
||||
use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_asg::ReturnStatement;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn enforce_return_statement<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -20,14 +20,14 @@ use crate::{errors::StatementError, program::ConstrainedProgram, value::Constrai
|
||||
use leo_asg::Statement;
|
||||
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
pub type StatementResult<T> = Result<T, StatementError>;
|
||||
pub type IndicatorAndConstrainedValue<'a, T, U> = (Boolean, ConstrainedValue<'a, T, U>);
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
///
|
||||
/// Enforce a program statement.
|
||||
/// Returns a Vector of (indicator, value) tuples.
|
||||
|
@ -20,7 +20,7 @@ use leo_ast::{InputValue, Span};
|
||||
use snarkvm_dpc::base_dpc::instantiated::Components;
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::{Assignment, ConstraintSystem},
|
||||
utilities::{
|
||||
@ -63,7 +63,7 @@ impl Address {
|
||||
self.bytes.iter().all(|byte| byte.is_constant())
|
||||
}
|
||||
|
||||
pub(crate) fn from_input<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
input_value: Option<InputValue>,
|
||||
@ -105,7 +105,7 @@ impl Address {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> AllocGadget<String, F> for Address {
|
||||
impl<F: PrimeField> AllocGadget<String, F> for Address {
|
||||
fn alloc<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>, CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
value_gen: Fn,
|
||||
@ -143,7 +143,7 @@ impl<F: Field + PrimeField> AllocGadget<String, F> for Address {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> EvaluateEqGadget<F> for Address {
|
||||
impl<F: PrimeField> EvaluateEqGadget<F> for Address {
|
||||
fn evaluate_equal<CS: ConstraintSystem<F>>(&self, mut cs: CS, other: &Self) -> Result<Boolean, SynthesisError> {
|
||||
if self.is_constant() && other.is_constant() {
|
||||
Ok(Boolean::Constant(self.eq(other)))
|
||||
@ -178,7 +178,7 @@ fn cond_equal_helper(first: &Address, second: &Address, cond: bool) -> Result<()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> ConditionalEqGadget<F> for Address {
|
||||
impl<F: PrimeField> ConditionalEqGadget<F> for Address {
|
||||
fn conditional_enforce_equal<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
mut cs: CS,
|
||||
@ -208,7 +208,7 @@ fn cond_select_helper(first: &Address, second: &Address, cond: bool) -> Address
|
||||
if cond { first.clone() } else { second.clone() }
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> CondSelectGadget<F> for Address {
|
||||
impl<F: PrimeField> CondSelectGadget<F> for Address {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
|
@ -21,14 +21,14 @@ use leo_ast::{InputValue, Span};
|
||||
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::{alloc::AllocGadget, boolean::Boolean},
|
||||
},
|
||||
};
|
||||
|
||||
pub(crate) fn allocate_bool<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn allocate_bool<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
option: Option<bool>,
|
||||
@ -41,7 +41,7 @@ pub(crate) fn allocate_bool<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
.map_err(|_| BooleanError::missing_boolean(format!("{}: bool", name), span.to_owned()))
|
||||
}
|
||||
|
||||
pub(crate) fn bool_from_input<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
input_value: Option<InputValue>,
|
||||
|
@ -21,7 +21,7 @@ use leo_ast::Span;
|
||||
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
curves::{FieldGadget, FpGadget},
|
||||
r1cs::ConstraintSystem,
|
||||
@ -40,12 +40,12 @@ use snarkvm_models::{
|
||||
use std::{borrow::Borrow, cmp::Ordering};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum FieldType<F: Field + PrimeField> {
|
||||
pub enum FieldType<F: PrimeField> {
|
||||
Constant(F),
|
||||
Allocated(FpGadget<F>),
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> FieldType<F> {
|
||||
impl<F: PrimeField> FieldType<F> {
|
||||
pub fn get_value(&self) -> Option<F> {
|
||||
match self {
|
||||
FieldType::Constant(field) => Some(*field),
|
||||
@ -201,7 +201,7 @@ impl<F: Field + PrimeField> FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> AllocGadget<String, F> for FieldType<F> {
|
||||
impl<F: PrimeField> AllocGadget<String, F> for FieldType<F> {
|
||||
fn alloc<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>, CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
value_gen: Fn,
|
||||
@ -221,7 +221,7 @@ impl<F: Field + PrimeField> AllocGadget<String, F> for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> PartialEq for FieldType<F> {
|
||||
impl<F: PrimeField> PartialEq for FieldType<F> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let self_value = self.get_value();
|
||||
let other_value = other.get_value();
|
||||
@ -230,9 +230,9 @@ impl<F: Field + PrimeField> PartialEq for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Eq for FieldType<F> {}
|
||||
impl<F: PrimeField> Eq for FieldType<F> {}
|
||||
|
||||
impl<F: Field + PrimeField> PartialOrd for FieldType<F> {
|
||||
impl<F: PrimeField> PartialOrd for FieldType<F> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
let self_value = self.get_value();
|
||||
let other_value = other.get_value();
|
||||
@ -241,7 +241,7 @@ impl<F: Field + PrimeField> PartialOrd for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> EvaluateEqGadget<F> for FieldType<F> {
|
||||
impl<F: PrimeField> EvaluateEqGadget<F> for FieldType<F> {
|
||||
fn evaluate_equal<CS: ConstraintSystem<F>>(&self, mut _cs: CS, other: &Self) -> Result<Boolean, SynthesisError> {
|
||||
match (self, other) {
|
||||
(FieldType::Constant(first), FieldType::Constant(second)) => Ok(Boolean::constant(first.eq(second))),
|
||||
@ -257,9 +257,9 @@ impl<F: Field + PrimeField> EvaluateEqGadget<F> for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> EqGadget<F> for FieldType<F> {}
|
||||
impl<F: PrimeField> EqGadget<F> for FieldType<F> {}
|
||||
|
||||
impl<F: Field + PrimeField> ConditionalEqGadget<F> for FieldType<F> {
|
||||
impl<F: PrimeField> ConditionalEqGadget<F> for FieldType<F> {
|
||||
fn conditional_enforce_equal<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
mut cs: CS,
|
||||
@ -293,7 +293,7 @@ impl<F: Field + PrimeField> ConditionalEqGadget<F> for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> CondSelectGadget<F> for FieldType<F> {
|
||||
impl<F: PrimeField> CondSelectGadget<F> for FieldType<F> {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
@ -316,7 +316,7 @@ impl<F: Field + PrimeField> CondSelectGadget<F> for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> ToBitsGadget<F> for FieldType<F> {
|
||||
impl<F: PrimeField> ToBitsGadget<F> for FieldType<F> {
|
||||
fn to_bits<CS: ConstraintSystem<F>>(&self, mut cs: CS) -> Result<Vec<Boolean>, SynthesisError> {
|
||||
let self_gadget = self.allocated(&mut cs)?;
|
||||
self_gadget.to_bits(cs)
|
||||
@ -328,7 +328,7 @@ impl<F: Field + PrimeField> ToBitsGadget<F> for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> ToBytesGadget<F> for FieldType<F> {
|
||||
impl<F: PrimeField> ToBytesGadget<F> for FieldType<F> {
|
||||
fn to_bytes<CS: ConstraintSystem<F>>(&self, mut cs: CS) -> Result<Vec<UInt8>, SynthesisError> {
|
||||
let self_gadget = self.allocated(&mut cs)?;
|
||||
self_gadget.to_bytes(cs)
|
||||
@ -340,7 +340,7 @@ impl<F: Field + PrimeField> ToBytesGadget<F> for FieldType<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> std::fmt::Display for FieldType<F> {
|
||||
impl<F: PrimeField> std::fmt::Display for FieldType<F> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self.get_value().ok_or(std::fmt::Error))
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ use leo_ast::{InputValue, Span};
|
||||
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::alloc::AllocGadget},
|
||||
};
|
||||
|
||||
pub(crate) fn allocate_field<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn allocate_field<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
option: Option<String>,
|
||||
@ -38,7 +38,7 @@ pub(crate) fn allocate_field<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
.map_err(|_| FieldError::missing_field(format!("{}: field", name), span.to_owned()))
|
||||
}
|
||||
|
||||
pub(crate) fn field_from_input<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn field_from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
input_value: Option<InputValue>,
|
||||
|
@ -21,12 +21,9 @@ use leo_asg::{GroupValue, Span};
|
||||
use leo_ast::InputValue;
|
||||
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
|
||||
|
||||
pub(crate) fn allocate_group<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn allocate_group<F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
option: Option<GroupValue>,
|
||||
@ -39,7 +36,7 @@ pub(crate) fn allocate_group<F: Field + PrimeField, G: GroupType<F>, CS: Constra
|
||||
.map_err(|_| GroupError::missing_group(format!("{}: group", name), span.to_owned()))
|
||||
}
|
||||
|
||||
pub(crate) fn group_from_input<'a, F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
input_value: Option<InputValue>,
|
||||
|
@ -298,7 +298,7 @@ impl Integer {
|
||||
Self::allocate_type(cs, integer_type, name, option, span)
|
||||
}
|
||||
|
||||
pub fn negate<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn negate<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
span: &Span,
|
||||
@ -312,7 +312,7 @@ impl Integer {
|
||||
result.ok_or_else(|| IntegerError::negate_operation(span.to_owned()))
|
||||
}
|
||||
|
||||
pub fn add<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn add<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
other: Self,
|
||||
@ -328,7 +328,7 @@ impl Integer {
|
||||
result.ok_or_else(|| IntegerError::binary_operation("+".to_string(), span.to_owned()))
|
||||
}
|
||||
|
||||
pub fn sub<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn sub<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
other: Self,
|
||||
@ -344,7 +344,7 @@ impl Integer {
|
||||
result.ok_or_else(|| IntegerError::binary_operation("-".to_string(), span.to_owned()))
|
||||
}
|
||||
|
||||
pub fn mul<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn mul<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
other: Self,
|
||||
@ -360,7 +360,7 @@ impl Integer {
|
||||
result.ok_or_else(|| IntegerError::binary_operation("*".to_string(), span.to_owned()))
|
||||
}
|
||||
|
||||
pub fn div<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn div<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
other: Self,
|
||||
@ -376,7 +376,7 @@ impl Integer {
|
||||
result.ok_or_else(|| IntegerError::binary_operation("÷".to_string(), span.to_owned()))
|
||||
}
|
||||
|
||||
pub fn pow<F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn pow<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
other: Self,
|
||||
@ -393,7 +393,7 @@ impl Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> EvaluateEqGadget<F> for Integer {
|
||||
impl<F: PrimeField> EvaluateEqGadget<F> for Integer {
|
||||
fn evaluate_equal<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Boolean, SynthesisError> {
|
||||
let a = self;
|
||||
let b = other;
|
||||
@ -404,7 +404,7 @@ impl<F: Field + PrimeField> EvaluateEqGadget<F> for Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> EvaluateLtGadget<F> for Integer {
|
||||
impl<F: PrimeField> EvaluateLtGadget<F> for Integer {
|
||||
fn less_than<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Boolean, SynthesisError> {
|
||||
let a = self;
|
||||
let b = other;
|
||||
@ -414,11 +414,11 @@ impl<F: Field + PrimeField> EvaluateLtGadget<F> for Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> ComparatorGadget<F> for Integer {}
|
||||
impl<F: PrimeField> ComparatorGadget<F> for Integer {}
|
||||
|
||||
impl<F: Field + PrimeField> EqGadget<F> for Integer {}
|
||||
impl<F: PrimeField> EqGadget<F> for Integer {}
|
||||
|
||||
impl<F: Field + PrimeField> ConditionalEqGadget<F> for Integer {
|
||||
impl<F: PrimeField> ConditionalEqGadget<F> for Integer {
|
||||
fn conditional_enforce_equal<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
cs: CS,
|
||||
@ -438,7 +438,7 @@ impl<F: Field + PrimeField> ConditionalEqGadget<F> for Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> CondSelectGadget<F> for Integer {
|
||||
impl<F: PrimeField> CondSelectGadget<F> for Integer {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
cond: &Boolean,
|
||||
|
@ -21,7 +21,7 @@ use leo_asg::{Circuit, Identifier, Span, Type};
|
||||
|
||||
use snarkvm_errors::gadgets::SynthesisError;
|
||||
use snarkvm_models::{
|
||||
curves::{Field, PrimeField},
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::{boolean::Boolean, eq::ConditionalEqGadget, select::CondSelectGadget},
|
||||
@ -30,13 +30,10 @@ use snarkvm_models::{
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct ConstrainedCircuitMember<'a, F: Field + PrimeField, G: GroupType<F>>(
|
||||
pub Identifier,
|
||||
pub ConstrainedValue<'a, F, G>,
|
||||
);
|
||||
pub struct ConstrainedCircuitMember<'a, F: PrimeField, G: GroupType<F>>(pub Identifier, pub ConstrainedValue<'a, F, G>);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum ConstrainedValue<'a, F: Field + PrimeField, G: GroupType<F>> {
|
||||
pub enum ConstrainedValue<'a, F: PrimeField, G: GroupType<F>> {
|
||||
// Data types
|
||||
Address(Address),
|
||||
Boolean(Boolean),
|
||||
@ -54,7 +51,7 @@ pub enum ConstrainedValue<'a, F: Field + PrimeField, G: GroupType<F>> {
|
||||
CircuitExpression(&'a Circuit<'a>, Vec<ConstrainedCircuitMember<'a, F, G>>),
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedValue<'a, F, G> {
|
||||
pub(crate) fn to_type(&self, span: &Span) -> Result<Type<'a>, ValueError> {
|
||||
Ok(match self {
|
||||
// Data types
|
||||
@ -85,7 +82,7 @@ impl<'a, F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<'a, F, G> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<'a, F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
// Data types
|
||||
@ -132,13 +129,13 @@ impl<'a, F: Field + PrimeField, G: GroupType<F>> fmt::Display for ConstrainedVal
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> fmt::Debug for ConstrainedValue<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> fmt::Debug for ConstrainedValue<'a, F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> ConditionalEqGadget<F> for ConstrainedValue<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConditionalEqGadget<F> for ConstrainedValue<'a, F, G> {
|
||||
fn conditional_enforce_equal<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
mut cs: CS,
|
||||
@ -182,7 +179,7 @@ impl<'a, F: Field + PrimeField, G: GroupType<F>> ConditionalEqGadget<F> for Cons
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> CondSelectGadget<F> for ConstrainedValue<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> CondSelectGadget<F> for ConstrainedValue<'a, F, G> {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
@ -259,7 +256,7 @@ impl<'a, F: Field + PrimeField, G: GroupType<F>> CondSelectGadget<F> for Constra
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field + PrimeField, G: GroupType<F>> CondSelectGadget<F> for ConstrainedCircuitMember<'a, F, G> {
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> CondSelectGadget<F> for ConstrainedCircuitMember<'a, F, G> {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
cond: &Boolean,
|
||||
|
@ -1,7 +1,7 @@
|
||||
function main() {
|
||||
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
|
||||
let a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
|
||||
|
||||
const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
|
||||
let b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user