mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
add implicit module. Edit expression module descriptions
This commit is contained in:
parent
2d9386f685
commit
6a442fc421
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce arithmetic addition in a compiled Leo program.
|
||||
//! Enforces an arithmetic `+` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn enforce_add_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_add<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -26,11 +26,11 @@ pub fn enforce_add_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
enforce_add_expression(cs, val_1, val_2, span)
|
||||
enforce_add(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
enforce_add_expression(cs, val_1, val_2, span)
|
||||
enforce_add(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, val_2) => Err(ExpressionError::incompatible_types(
|
||||
format!("{} + {}", val_1, val_2),
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce arithmetic division in a compiled Leo program.
|
||||
//! Enforces an arithmetic `/` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn enforce_div_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_div<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -23,11 +23,11 @@ pub fn enforce_div_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
enforce_div_expression(cs, val_1, val_2, span)
|
||||
enforce_div(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
enforce_div_expression(cs, val_1, val_2, span)
|
||||
enforce_div(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce arithmetic multiplication in a compiled Leo program.
|
||||
//! Enforces an arithmetic `*` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn enforce_mul_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_mul<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -23,11 +23,11 @@ pub fn enforce_mul_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
enforce_mul_expression(cs, val_1, val_2, span)
|
||||
enforce_mul(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
enforce_mul_expression(cs, val_1, val_2, span)
|
||||
enforce_mul(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce arithmetic exponentiation in a compiled Leo program.
|
||||
//! Enforces an arithmetic `**` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn enforce_pow_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_pow<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -20,11 +20,11 @@ pub fn enforce_pow_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
enforce_pow_expression(cs, val_1, val_2, span)
|
||||
enforce_pow(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
enforce_pow_expression(cs, val_1, val_2, span)
|
||||
enforce_pow(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, val_2) => Err(ExpressionError::incompatible_types(
|
||||
format!("{} ** {}", val_1, val_2,),
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce arithmetic subtraction in a compiled Leo program.
|
||||
//! Enforces an arithmetic `-` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn enforce_sub_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_sub<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -26,11 +26,11 @@ pub fn enforce_sub_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
enforce_sub_expression(cs, val_1, val_2, span)
|
||||
enforce_sub(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
enforce_sub_expression(cs, val_1, val_2, span)
|
||||
enforce_sub(cs, val_1, val_2, span)
|
||||
}
|
||||
(val_1, val_2) => Err(ExpressionError::incompatible_types(
|
||||
format!("{} - {}", val_1, val_2),
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces constraints on array access expressions in a compiled Leo program.
|
||||
//! Enforces array access in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Expression, RangeOrExpression, Span, Type};
|
||||
@ -9,7 +9,7 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
pub fn enforce_array_access_expression<CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_array_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces constraints on array expressions in a compiled Leo program.
|
||||
//! Enforces an array expression in a compiled Leo program.
|
||||
|
||||
use crate::{
|
||||
errors::ExpressionError,
|
||||
@ -15,7 +15,7 @@ use snarkos_models::{
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
/// Enforce array expressions
|
||||
pub fn enforce_array_expression<CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_array<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces constraints on an array index expression in a compiled Leo program.
|
||||
//! Enforces an array index expression in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Expression, IntegerType, Span, Type};
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Methods to enforce array expressions in a compiled Leo program.
|
||||
|
||||
pub mod array;
|
||||
pub use self::array::*;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforce constraints on binary expressions in a compiled Leo program.
|
||||
//! Enforces a binary expression in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Expression, Span, Type};
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Methods to enforce binary expressions in a compiled Leo program.
|
||||
|
||||
pub mod binary;
|
||||
pub use self::binary::*;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforce constraints on one operand in a binary expression in a compiled Leo program.
|
||||
//! Enforces one operand in a binary expression in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Expression, Span, Type};
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces constraints on circuit access expressions in a compiled Leo program.
|
||||
//! Enforces a circuit access expression in a compiled Leo program.
|
||||
|
||||
use crate::{
|
||||
errors::ExpressionError,
|
||||
@ -16,7 +16,7 @@ use snarkos_models::{
|
||||
static SELF_KEYWORD: &'static str = "self";
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
pub fn enforce_circuit_access_expression<CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_circuit_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces constraints on circuit expressions in a compiled Leo program.
|
||||
//! Enforces a circuit expression in a compiled Leo program.
|
||||
|
||||
use crate::{
|
||||
errors::ExpressionError,
|
||||
@ -14,7 +14,7 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
pub fn enforce_circuit_expression<CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_circuit<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Methods to enforce circuit expressions in a compiled Leo program.
|
||||
|
||||
pub mod access;
|
||||
pub use self::access::*;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces constraints on circuit static access expressions in a compiled Leo program.
|
||||
//! Enforces a circuit static access expression in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{CircuitMember, Expression, Identifier, Span, Type};
|
||||
@ -9,7 +9,7 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
pub fn enforce_circuit_static_access_expression<CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_circuit_static_access<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on ternary expressions in a compiled Leo program.
|
||||
//! Enforces a conditional expression in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Expression, Span, Type};
|
@ -1,2 +1,4 @@
|
||||
pub mod ternary;
|
||||
pub use self::ternary::*;
|
||||
//! Methods to enforce conditional expressions in a compiled Leo program.
|
||||
|
||||
pub mod conditional;
|
||||
pub use self::conditional::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on expressions in a compiled Leo program.
|
||||
//! Enforce constraints on an expression in a compiled Leo program.
|
||||
|
||||
use crate::{
|
||||
arithmetic::*,
|
||||
@ -6,13 +6,13 @@ use crate::{
|
||||
logical::*,
|
||||
program::ConstrainedProgram,
|
||||
relational::*,
|
||||
value::{boolean::input::new_bool_constant, ConstrainedValue},
|
||||
value::{boolean::input::new_bool_constant, implicit::*, ConstrainedValue},
|
||||
Address,
|
||||
FieldType,
|
||||
GroupType,
|
||||
Integer,
|
||||
};
|
||||
use leo_types::{Expression, Span, Type};
|
||||
use leo_types::{Expression, Type};
|
||||
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
@ -20,18 +20,6 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
pub(crate) fn enforce_number_implicit(
|
||||
expected_types: &Vec<Type>,
|
||||
value: String,
|
||||
span: Span,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
if expected_types.len() == 1 {
|
||||
return Ok(ConstrainedValue::from_type(value, &expected_types[0], span)?);
|
||||
}
|
||||
|
||||
Ok(ConstrainedValue::Unresolved(value))
|
||||
}
|
||||
|
||||
pub(crate) fn enforce_expression<CS: ConstraintSystem<F>>(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
@ -51,7 +39,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
Expression::Boolean(boolean, span) => Ok(ConstrainedValue::Boolean(new_bool_constant(boolean, span)?)),
|
||||
Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)),
|
||||
Expression::Group(group_affine, span) => Ok(ConstrainedValue::Group(G::constant(group_affine, span)?)),
|
||||
Expression::Implicit(value, span) => Self::enforce_number_implicit(expected_types, value, span),
|
||||
Expression::Implicit(value, span) => Ok(enforce_number_implicit(expected_types, value, span)?),
|
||||
Expression::Integer(type_, integer, span) => {
|
||||
Ok(ConstrainedValue::Integer(Integer::new_constant(&type_, integer, span)?))
|
||||
}
|
||||
@ -68,7 +56,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
enforce_add_expression(cs, resolved_left, resolved_right, span)
|
||||
enforce_add(cs, resolved_left, resolved_right, span)
|
||||
}
|
||||
Expression::Sub(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -81,7 +69,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
enforce_sub_expression(cs, resolved_left, resolved_right, span)
|
||||
enforce_sub(cs, resolved_left, resolved_right, span)
|
||||
}
|
||||
Expression::Mul(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -94,7 +82,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
enforce_mul_expression(cs, resolved_left, resolved_right, span)
|
||||
enforce_mul(cs, resolved_left, resolved_right, span)
|
||||
}
|
||||
Expression::Div(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -107,7 +95,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
enforce_div_expression(cs, resolved_left, resolved_right, span)
|
||||
enforce_div(cs, resolved_left, resolved_right, span)
|
||||
}
|
||||
Expression::Pow(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -120,7 +108,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
enforce_pow_expression(cs, resolved_left, resolved_right, span)
|
||||
enforce_pow(cs, resolved_left, resolved_right, span)
|
||||
}
|
||||
|
||||
// Boolean operations
|
||||
@ -165,7 +153,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
Ok(evaluate_eq_expression(cs, resolved_left, resolved_right, span)?)
|
||||
Ok(evaluate_eq(cs, resolved_left, resolved_right, span)?)
|
||||
}
|
||||
Expression::Ge(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -178,7 +166,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
Ok(evaluate_ge_expression(cs, resolved_left, resolved_right, span)?)
|
||||
Ok(evaluate_ge(cs, resolved_left, resolved_right, span)?)
|
||||
}
|
||||
Expression::Gt(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -191,7 +179,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
Ok(evaluate_gt_expression(cs, resolved_left, resolved_right, span)?)
|
||||
Ok(evaluate_gt(cs, resolved_left, resolved_right, span)?)
|
||||
}
|
||||
Expression::Le(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -204,7 +192,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
Ok(evaluate_le_expression(cs, resolved_left, resolved_right, span)?)
|
||||
Ok(evaluate_le(cs, resolved_left, resolved_right, span)?)
|
||||
}
|
||||
Expression::Lt(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
@ -217,7 +205,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
span.clone(),
|
||||
)?;
|
||||
|
||||
Ok(evaluate_lt_expression(cs, resolved_left, resolved_right, span)?)
|
||||
Ok(evaluate_lt(cs, resolved_left, resolved_right, span)?)
|
||||
}
|
||||
|
||||
// Conditionals
|
||||
@ -234,34 +222,27 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
|
||||
// Arrays
|
||||
Expression::Array(array, span) => {
|
||||
self.enforce_array_expression(cs, file_scope, function_scope, expected_types, array, span)
|
||||
self.enforce_array(cs, file_scope, function_scope, expected_types, array, span)
|
||||
}
|
||||
Expression::ArrayAccess(array, index, span) => self.enforce_array_access_expression(
|
||||
Expression::ArrayAccess(array, index, span) => {
|
||||
self.enforce_array_access(cs, file_scope, function_scope, expected_types, array, *index, span)
|
||||
}
|
||||
|
||||
// Circuits
|
||||
Expression::Circuit(circuit_name, members, span) => {
|
||||
self.enforce_circuit(cs, file_scope, function_scope, circuit_name, members, span)
|
||||
}
|
||||
Expression::CircuitMemberAccess(circuit_variable, circuit_member, span) => self.enforce_circuit_access(
|
||||
cs,
|
||||
file_scope,
|
||||
function_scope,
|
||||
expected_types,
|
||||
array,
|
||||
*index,
|
||||
circuit_variable,
|
||||
circuit_member,
|
||||
span,
|
||||
),
|
||||
|
||||
// Circuits
|
||||
Expression::Circuit(circuit_name, members, span) => {
|
||||
self.enforce_circuit_expression(cs, file_scope, function_scope, circuit_name, members, span)
|
||||
}
|
||||
Expression::CircuitMemberAccess(circuit_variable, circuit_member, span) => self
|
||||
.enforce_circuit_access_expression(
|
||||
cs,
|
||||
file_scope,
|
||||
function_scope,
|
||||
expected_types,
|
||||
circuit_variable,
|
||||
circuit_member,
|
||||
span,
|
||||
),
|
||||
Expression::CircuitStaticFunctionAccess(circuit_identifier, circuit_member, span) => self
|
||||
.enforce_circuit_static_access_expression(
|
||||
.enforce_circuit_static_access(
|
||||
cs,
|
||||
file_scope,
|
||||
function_scope,
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforce constraints on a function call expression in a compiled Leo program.
|
||||
//! Enforce a function call expression in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Expression, Span, Type};
|
||||
|
@ -1,2 +1,4 @@
|
||||
//! Methods to enforce function call expressions in a compiled Leo program.
|
||||
|
||||
pub mod function;
|
||||
pub use self::function::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on expressions in a compiled Leo program.
|
||||
//! Enforces an identifier expression in a compiled Leo program.
|
||||
|
||||
use crate::{
|
||||
errors::ExpressionError,
|
||||
|
@ -1,2 +1,4 @@
|
||||
//! Methods to enforce identifier expressions in a compiled Leo program.
|
||||
|
||||
pub mod identifier;
|
||||
pub use self::identifier::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on boolean operations in a resolved Leo program.
|
||||
//! Enforces a logical `&&` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on boolean operations in a resolved Leo program.
|
||||
//! Enforces a logical `!` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on boolean operations in a resolved Leo program.
|
||||
//! Enforces a logical `||` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on `==` comparison expressions in a compiled Leo program.
|
||||
//! Enforces a relational `==` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::eq::EvaluateEqGadget},
|
||||
};
|
||||
|
||||
pub fn evaluate_eq_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_eq<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -33,11 +33,11 @@ pub fn evaluate_eq_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
return evaluate_eq_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_eq(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
return evaluate_eq_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_eq(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on `>=` comparison expressions in a compiled Leo program.
|
||||
//! Enforces a relational `>=` operator in a resolved Leo program.
|
||||
|
||||
use crate::{comparator::ComparatorGadget, errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn evaluate_ge_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_ge<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -24,11 +24,11 @@ pub fn evaluate_ge_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
return evaluate_ge_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_ge(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
return evaluate_ge_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_ge(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on `>` comparison expressions in a compiled Leo program.
|
||||
//! Enforces a relational `>` operator in a resolved Leo program.
|
||||
|
||||
use crate::{comparator::ComparatorGadget, errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn evaluate_gt_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_gt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -24,11 +24,11 @@ pub fn evaluate_gt_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
return evaluate_gt_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_gt(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
return evaluate_gt_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_gt(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on `<=` comparison expressions in a compiled Leo program.
|
||||
//! Enforces a relational `<=` operator in a resolved Leo program.
|
||||
|
||||
use crate::{comparator::ComparatorGadget, errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn evaluate_le_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_le<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -24,11 +24,11 @@ pub fn evaluate_le_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
return evaluate_le_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_le(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
return evaluate_le_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_le(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Methods to enforce constraints on `<` comparison expressions in a compiled Leo program.
|
||||
//! Enforces a relational `<` operator in a resolved Leo program.
|
||||
|
||||
use crate::{comparator::EvaluateLtGadget, errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn evaluate_lt_expression<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn evaluate_lt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
@ -24,11 +24,11 @@ pub fn evaluate_lt_expression<F: Field + PrimeField, G: GroupType<F>, CS: Constr
|
||||
}
|
||||
(ConstrainedValue::Unresolved(string), val_2) => {
|
||||
let val_1 = ConstrainedValue::from_other(string, &val_2, span.clone())?;
|
||||
return evaluate_lt_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_lt(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, ConstrainedValue::Unresolved(string)) => {
|
||||
let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?;
|
||||
return evaluate_lt_expression(&mut unique_namespace, val_1, val_2, span);
|
||||
return evaluate_lt(&mut unique_namespace, val_1, val_2, span);
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::incompatible_types(
|
||||
|
18
compiler/src/value/implicit/implicit.rs
Normal file
18
compiler/src/value/implicit/implicit.rs
Normal file
@ -0,0 +1,18 @@
|
||||
//! Enforces constraints on an implicit number in a compiled Leo program.
|
||||
|
||||
use crate::{errors::ValueError, value::ConstrainedValue, GroupType};
|
||||
use leo_types::{Span, Type};
|
||||
|
||||
use snarkos_models::curves::{Field, PrimeField};
|
||||
|
||||
pub fn enforce_number_implicit<F: Field + PrimeField, G: GroupType<F>>(
|
||||
expected_types: &Vec<Type>,
|
||||
value: String,
|
||||
span: Span,
|
||||
) -> Result<ConstrainedValue<F, G>, ValueError> {
|
||||
if expected_types.len() == 1 {
|
||||
return Ok(ConstrainedValue::from_type(value, &expected_types[0], span)?);
|
||||
}
|
||||
|
||||
Ok(ConstrainedValue::Unresolved(value))
|
||||
}
|
2
compiler/src/value/implicit/mod.rs
Normal file
2
compiler/src/value/implicit/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod implicit;
|
||||
pub use self::implicit::*;
|
@ -13,6 +13,9 @@ pub use self::field::*;
|
||||
pub mod group;
|
||||
pub use self::group::*;
|
||||
|
||||
pub mod implicit;
|
||||
pub use self::implicit::*;
|
||||
|
||||
pub mod integer;
|
||||
pub use self::integer::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user