From 19f6e64c480a2c6695ae14c53f9e28542ca258d4 Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 29 May 2020 15:55:57 -0700 Subject: [PATCH] remove snarkos group trait from compiler --- benchmark/src/main.rs | 18 +- compiler/src/compiler.rs | 20 +- compiler/src/constraints/boolean.rs | 28 +-- compiler/src/constraints/expression.rs | 170 ++++++++-------- compiler/src/constraints/field_element.rs | 20 +- compiler/src/constraints/function.rs | 42 ++-- compiler/src/constraints/group.rs | 1 + compiler/src/constraints/group_element.rs | 67 ------ compiler/src/constraints/import.rs | 6 +- compiler/src/constraints/integer/integer.rs | 22 +- compiler/src/constraints/integer/uint128.rs | 6 +- compiler/src/constraints/integer/uint16.rs | 6 +- compiler/src/constraints/integer/uint32.rs | 6 +- compiler/src/constraints/integer/uint64.rs | 6 +- compiler/src/constraints/integer/uint8.rs | 6 +- compiler/src/constraints/mod.rs | 14 +- compiler/src/constraints/program.rs | 14 +- compiler/src/constraints/statement.rs | 68 +++---- compiler/src/constraints/value.rs | 52 +++-- compiler/src/errors/constraints/function.rs | 12 +- .../{group_element.rs => group.rs} | 6 +- compiler/src/errors/constraints/mod.rs | 4 +- compiler/src/imports.rs | 22 +- compiler/src/types.rs | 178 ++++++++-------- compiler/src/types_display.rs | 46 ++--- compiler/src/types_from.rs | 191 +++++++----------- compiler/tests/array/mod.rs | 27 ++- compiler/tests/boolean/mod.rs | 22 +- compiler/tests/circuit/mod.rs | 62 +++--- compiler/tests/field_element/mod.rs | 14 +- compiler/tests/function/mod.rs | 15 +- compiler/tests/group/mod.rs | 1 + .../tests/{group_element => group}/zero.leo | 0 compiler/tests/group_element/mod.rs | 23 --- compiler/tests/integer/u32/mod.rs | 30 +-- compiler/tests/mod.rs | 15 +- compiler/tests/mutability/mod.rs | 12 +- leo/commands/build.rs | 9 +- leo/commands/deploy.rs | 2 +- leo/commands/load.rs | 2 +- leo/commands/prove.rs | 7 +- leo/commands/publish.rs | 2 +- leo/commands/run.rs | 2 +- leo/commands/setup.rs | 21 +- leo/commands/unload.rs | 2 +- leo/files/checksum.rs | 10 +- leo/files/proof.rs | 8 +- leo/files/proving_key.rs | 5 +- leo/files/verification_key.rs | 11 +- 49 files changed, 595 insertions(+), 738 deletions(-) create mode 100644 compiler/src/constraints/group.rs delete mode 100644 compiler/src/constraints/group_element.rs rename compiler/src/errors/constraints/{group_element.rs => group.rs} (68%) create mode 100644 compiler/tests/group/mod.rs rename compiler/tests/{group_element => group}/zero.leo (100%) delete mode 100644 compiler/tests/group_element/mod.rs diff --git a/benchmark/src/main.rs b/benchmark/src/main.rs index 5376982218..04508b5295 100644 --- a/benchmark/src/main.rs +++ b/benchmark/src/main.rs @@ -6,9 +6,7 @@ use snarkos_algorithms::snark::{ create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, }; use snarkos_curves::bls12_377::{Bls12_377, Fr}; -use snarkos_curves::edwards_bls12::EdwardsProjective; use snarkos_errors::gadgets::SynthesisError; -use snarkos_models::curves::Group; use snarkos_models::{ curves::{Field, PrimeField}, gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}, @@ -20,19 +18,17 @@ use std::{ }; #[derive(Clone)] -pub struct Benchmark { - program: Program, - parameters: Vec>>, - _group: PhantomData, +pub struct Benchmark { + program: Program, + parameters: Vec>>, _engine: PhantomData, } -impl Benchmark { +impl Benchmark { pub fn new() -> Self { Self { program: Program::new(), parameters: vec![], - _group: PhantomData, _engine: PhantomData, } } @@ -48,7 +44,7 @@ impl Benchmark { let syntax_tree = ast::File::from_pest(&mut file).expect("infallible"); // Build a leo program from the syntax tree - self.program = Program::::from(syntax_tree, "simple".into()); + self.program = Program::::from(syntax_tree, "simple".into()); self.parameters = vec![None; self.program.num_parameters]; println!(" compiled: {:#?}\n", self.program); @@ -57,7 +53,7 @@ impl Benchmark { } } -impl ConstraintSynthesizer for Benchmark { +impl ConstraintSynthesizer for Benchmark { fn generate_constraints>( self, cs: &mut CS, @@ -81,7 +77,7 @@ fn main() { let start = Instant::now(); // Load and compile program - let mut program = Benchmark::::new(); + let mut program = Benchmark::::new(); program.evaluate_program().unwrap(); // Generate proof parameters diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index fddae78cbd..8a49d84460 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -9,7 +9,7 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}, }; @@ -18,16 +18,16 @@ use sha2::{Digest, Sha256}; use std::{fs, marker::PhantomData, path::PathBuf}; #[derive(Clone)] -pub struct Compiler { +pub struct Compiler { package_name: String, main_file_path: PathBuf, - program: Program, - program_inputs: Vec>>, - output: Option>, + program: Program, + program_inputs: Vec>>, + output: Option>, _engine: PhantomData, } -impl Compiler { +impl Compiler { pub fn init(package_name: String, main_file_path: PathBuf) -> Result { let mut program = Self { package_name, @@ -44,7 +44,7 @@ impl Compiler { Ok(program) } - pub fn set_inputs(&mut self, program_inputs: Vec>>) { + pub fn set_inputs(&mut self, program_inputs: Vec>>) { self.program_inputs = program_inputs; } @@ -64,7 +64,7 @@ impl Compiler { pub fn compile_constraints>( self, cs: &mut CS, - ) -> Result, CompilerError> { + ) -> Result, CompilerError> { generate_constraints(cs, self.program, self.program_inputs) } @@ -98,7 +98,7 @@ impl Compiler { // Build program from abstract syntax tree let package_name = self.package_name.clone(); - self.program = Program::::from(syntax_tree, package_name); + self.program = Program::::from(syntax_tree, package_name); self.program_inputs = vec![None; self.program.num_parameters]; log::debug!("Program parsing complete\n{:#?}", self.program); @@ -107,7 +107,7 @@ impl Compiler { } } -impl ConstraintSynthesizer for Compiler { +impl ConstraintSynthesizer for Compiler { fn generate_constraints>( self, cs: &mut CS, diff --git a/compiler/src/constraints/boolean.rs b/compiler/src/constraints/boolean.rs index ee9dfe27e8..692074ee43 100644 --- a/compiler/src/constraints/boolean.rs +++ b/compiler/src/constraints/boolean.rs @@ -8,21 +8,21 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn bool_from_input( &mut self, cs: &mut CS, name: String, private: bool, - input_value: Option>, - ) -> Result, BooleanError> { + input_value: Option>, + ) -> Result, BooleanError> { // Check that the input value is the correct type let bool_value = match input_value { Some(input) => { @@ -49,13 +49,13 @@ impl> ConstrainedProgra Ok(ConstrainedValue::Boolean(number)) } - pub(crate) fn get_boolean_constant(bool: Boolean) -> ConstrainedValue { + pub(crate) fn get_boolean_constant(bool: Boolean) -> ConstrainedValue { ConstrainedValue::Boolean(bool) } pub(crate) fn evaluate_not( - value: ConstrainedValue, - ) -> Result, BooleanError> { + value: ConstrainedValue, + ) -> Result, BooleanError> { match value { ConstrainedValue::Boolean(boolean) => Ok(ConstrainedValue::Boolean(boolean.not())), value => Err(BooleanError::CannotEvaluate(format!("!{}", value))), @@ -65,9 +65,9 @@ impl> ConstrainedProgra pub(crate) fn enforce_or( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, BooleanError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, BooleanError> { match (left, right) { (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) => Ok( ConstrainedValue::Boolean(Boolean::or(cs, &left_bool, &right_bool)?), @@ -82,9 +82,9 @@ impl> ConstrainedProgra pub(crate) fn enforce_and( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, BooleanError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, BooleanError> { match (left, right) { (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) => Ok( ConstrainedValue::Boolean(Boolean::and(cs, &left_bool, &right_bool)?), @@ -96,7 +96,7 @@ impl> ConstrainedProgra } } - pub(crate) fn boolean_eq(left: Boolean, right: Boolean) -> ConstrainedValue { + pub(crate) fn boolean_eq(left: Boolean, right: Boolean) -> ConstrainedValue { ConstrainedValue::Boolean(Boolean::Constant(left.eq(&right))) } diff --git a/compiler/src/constraints/expression.rs b/compiler/src/constraints/expression.rs index d52c07be1c..902dda0380 100644 --- a/compiler/src/constraints/expression.rs +++ b/compiler/src/constraints/expression.rs @@ -12,22 +12,22 @@ use crate::{ }; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{boolean::Boolean, select::CondSelectGadget}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { /// Enforce a variable expression by getting the resolved value pub(crate) fn evaluate_identifier( &mut self, file_scope: String, function_scope: String, - expected_types: &Vec>, - unresolved_identifier: Identifier, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + unresolved_identifier: Identifier, + ) -> Result, ExpressionError> { // Evaluate the identifier name in the current function scope let variable_name = new_scope(function_scope, unresolved_identifier.to_string()); let identifier_name = new_scope(file_scope, unresolved_identifier.to_string()); @@ -53,9 +53,9 @@ impl> ConstrainedProgra fn enforce_add_expression( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { Ok(Self::enforce_integer_add(cs, num_1, num_2)?) @@ -63,9 +63,9 @@ impl> ConstrainedProgra (ConstrainedValue::FieldElement(fe_1), ConstrainedValue::FieldElement(fe_2)) => { Ok(self.enforce_field_add(cs, fe_1, fe_2)?) } - (ConstrainedValue::GroupElement(ge_1), ConstrainedValue::GroupElement(ge_2)) => { - Ok(Self::evaluate_group_add(ge_1, ge_2)) - } + // (ConstrainedValue::Group(ge_1), ConstrainedValue::Group(ge_2)) => { + // Ok(Self::evaluate_group_add(ge_1, ge_2)) + // } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2)?; self.enforce_add_expression(cs, val_1, val_2) @@ -84,9 +84,9 @@ impl> ConstrainedProgra fn enforce_sub_expression( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { Ok(Self::enforce_integer_sub(cs, num_1, num_2)?) @@ -94,9 +94,9 @@ impl> ConstrainedProgra (ConstrainedValue::FieldElement(fe_1), ConstrainedValue::FieldElement(fe_2)) => { Ok(self.enforce_field_sub(cs, fe_1, fe_2)?) } - (ConstrainedValue::GroupElement(ge_1), ConstrainedValue::GroupElement(ge_2)) => { - Ok(Self::evaluate_group_sub(ge_1, ge_2)) - } + // (ConstrainedValue::Group(ge_1), ConstrainedValue::Group(ge_2)) => { + // Ok(Self::evaluate_group_sub(ge_1, ge_2)) + // } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2)?; self.enforce_sub_expression(cs, val_1, val_2) @@ -115,9 +115,9 @@ impl> ConstrainedProgra fn enforce_mul_expression( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { Ok(Self::enforce_integer_mul(cs, num_1, num_2)?) @@ -148,9 +148,9 @@ impl> ConstrainedProgra fn enforce_div_expression( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { Ok(Self::enforce_integer_div(cs, num_1, num_2)?) @@ -177,9 +177,9 @@ impl> ConstrainedProgra fn enforce_pow_expression( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { Ok(Self::enforce_integer_pow(cs, num_1, num_2)?) @@ -208,9 +208,9 @@ impl> ConstrainedProgra /// Evaluate Boolean operations fn evaluate_eq_expression( &mut self, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { (ConstrainedValue::Boolean(bool_1), ConstrainedValue::Boolean(bool_2)) => { Ok(Self::boolean_eq(bool_1, bool_2)) @@ -221,9 +221,9 @@ impl> ConstrainedProgra // (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => { // Self::field_eq(fe_1, fe_2) // } - (ConstrainedValue::GroupElement(ge_1), ConstrainedValue::GroupElement(ge_2)) => { - Ok(Self::evaluate_group_eq(ge_1, ge_2)) - } + // (ConstrainedValue::Group(ge_1), ConstrainedValue::Group(ge_2)) => { + // Ok(Self::evaluate_group_eq(ge_1, ge_2)) + // } (ConstrainedValue::Unresolved(string), val_2) => { let val_1 = ConstrainedValue::from_other(string, &val_2)?; self.evaluate_eq_expression(val_1, val_2) @@ -241,9 +241,9 @@ impl> ConstrainedProgra fn evaluate_geq_expression( &mut self, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { // (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => { // Self::field_geq(fe_1, fe_2) @@ -265,9 +265,9 @@ impl> ConstrainedProgra fn evaluate_gt_expression( &mut self, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { // (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => { // Self::field_gt(fe_1, fe_2) @@ -289,9 +289,9 @@ impl> ConstrainedProgra fn evaluate_leq_expression( &mut self, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { // (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => { // Self::field_leq(fe_1, fe_2) @@ -313,9 +313,9 @@ impl> ConstrainedProgra fn evaluate_lt_expression( &mut self, - left: ConstrainedValue, - right: ConstrainedValue, - ) -> Result, ExpressionError> { + left: ConstrainedValue, + right: ConstrainedValue, + ) -> Result, ExpressionError> { match (left, right) { // (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => { // Self::field_lt(fe_1, fe_2) @@ -341,11 +341,11 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - first: Expression, - second: Expression, - third: Expression, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + first: Expression, + second: Expression, + third: Expression, + ) -> Result, ExpressionError> { let resolved_first = match self.enforce_expression( cs, file_scope.clone(), @@ -392,9 +392,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - array: Vec>>, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + array: Vec>>, + ) -> Result, ExpressionError> { // Check explicit array type dimension if given let mut expected_types = expected_types.clone(); let expected_dimensions = vec![]; @@ -456,7 +456,7 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - index: Expression, + index: Expression, ) -> Result { let expected_types = vec![Type::IntegerType(IntegerType::U32)]; match self.enforce_branch( @@ -476,10 +476,10 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - array: Box>, - index: RangeOrExpression, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + array: Box>, + index: RangeOrExpression, + ) -> Result, ExpressionError> { let array = match self.enforce_branch( cs, file_scope.clone(), @@ -517,9 +517,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - identifier: Identifier, - members: Vec>, - ) -> Result, ExpressionError> { + identifier: Identifier, + members: Vec>, + ) -> Result, ExpressionError> { let mut program_identifier = new_scope(file_scope.clone(), identifier.to_string()); if identifier.is_self() { @@ -591,10 +591,10 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - circuit_identifier: Box>, - circuit_member: Identifier, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + circuit_identifier: Box>, + circuit_member: Identifier, + ) -> Result, ExpressionError> { let (circuit_name, members) = match self.enforce_branch( cs, file_scope.clone(), @@ -652,10 +652,10 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - circuit_identifier: Box>, - circuit_member: Identifier, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + circuit_identifier: Box>, + circuit_member: Identifier, + ) -> Result, ExpressionError> { // Get defined circuit let circuit = match self.enforce_expression( cs, @@ -706,10 +706,10 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - function: Box>, - arguments: Vec>, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + function: Box>, + arguments: Vec>, + ) -> Result, ExpressionError> { let function_value = self.enforce_expression( cs, file_scope.clone(), @@ -745,9 +745,9 @@ impl> ConstrainedProgra } pub(crate) fn enforce_number_implicit( - expected_types: &Vec>, + expected_types: &Vec>, value: String, - ) -> Result, ExpressionError> { + ) -> Result, ExpressionError> { if expected_types.len() == 1 { return Ok(ConstrainedValue::from_type(value, &expected_types[0])?); } @@ -763,9 +763,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - expression: Expression, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + expression: Expression, + ) -> Result, ExpressionError> { let mut branch = self.enforce_expression(cs, file_scope, function_scope, expected_types, expression)?; @@ -780,10 +780,10 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - left: Expression, - right: Expression, - ) -> Result<(ConstrainedValue, ConstrainedValue), ExpressionError> { + expected_types: &Vec>, + left: Expression, + right: Expression, + ) -> Result<(ConstrainedValue, ConstrainedValue), ExpressionError> { let resolved_left = self.enforce_branch( cs, file_scope.clone(), @@ -807,9 +807,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expected_types: &Vec>, - expression: Expression, - ) -> Result, ExpressionError> { + expected_types: &Vec>, + expression: Expression, + ) -> Result, ExpressionError> { match expression { // Variables Expression::Identifier(unresolved_variable) => self.evaluate_identifier( @@ -822,7 +822,7 @@ impl> ConstrainedProgra // Values Expression::Integer(integer) => Ok(Self::get_integer_constant(integer)), Expression::FieldElement(fe) => Ok(Self::get_field_element_constant(fe)), - Expression::GroupElement(gr) => Ok(ConstrainedValue::GroupElement(gr)), + Expression::Group(gr) => Ok(ConstrainedValue::Group(gr)), Expression::Boolean(bool) => Ok(Self::get_boolean_constant(bool)), Expression::Implicit(value) => Self::enforce_number_implicit(expected_types, value), diff --git a/compiler/src/constraints/field_element.rs b/compiler/src/constraints/field_element.rs index db0c24879f..9e030970dc 100644 --- a/compiler/src/constraints/field_element.rs +++ b/compiler/src/constraints/field_element.rs @@ -8,18 +8,18 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::r1cs::{ConstraintSystem, LinearCombination, Variable as R1CSVariable}, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn field_element_from_input( &mut self, cs: &mut CS, name: String, private: bool, - input_value: Option>, - ) -> Result, FieldElementError> { + input_value: Option>, + ) -> Result, FieldElementError> { // Check that the parameter value is the correct type let field_option = match input_value { Some(input) => { @@ -51,7 +51,7 @@ impl> ConstrainedProgra ))) } - pub(crate) fn get_field_element_constant(fe: FieldElement) -> ConstrainedValue { + pub(crate) fn get_field_element_constant(fe: FieldElement) -> ConstrainedValue { ConstrainedValue::FieldElement(fe) } @@ -124,7 +124,7 @@ impl> ConstrainedProgra cs: &mut CS, fe_1: FieldElement, fe_2: FieldElement, - ) -> Result, FieldElementError> { + ) -> Result, FieldElementError> { Ok(match (fe_1, fe_2) { // if both constants, then return a constant result (FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => { @@ -201,7 +201,7 @@ impl> ConstrainedProgra cs: &mut CS, fe_1: FieldElement, fe_2: FieldElement, - ) -> Result, FieldElementError> { + ) -> Result, FieldElementError> { Ok(match (fe_1, fe_2) { // if both constants, then return a constant result (FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => { @@ -278,7 +278,7 @@ impl> ConstrainedProgra cs: &mut CS, fe_1: FieldElement, fe_2: FieldElement, - ) -> Result, FieldElementError> { + ) -> Result, FieldElementError> { Ok(match (fe_1, fe_2) { // if both constants, then return a constant result (FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => { @@ -355,7 +355,7 @@ impl> ConstrainedProgra cs: &mut CS, fe_1: FieldElement, fe_2: FieldElement, - ) -> Result, FieldElementError> { + ) -> Result, FieldElementError> { Ok(match (fe_1, fe_2) { // if both constants, then return a constant result (FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => { @@ -443,7 +443,7 @@ impl> ConstrainedProgra cs: &mut CS, fe_1: FieldElement, num: Integer, - ) -> Result, FieldElementError> { + ) -> Result, FieldElementError> { Ok(match fe_1 { // if both constants, then return a constant result FieldElement::Constant(fe_1_constant) => ConstrainedValue::FieldElement( diff --git a/compiler/src/constraints/function.rs b/compiler/src/constraints/function.rs index 77a4fa88ba..0ee9e2b611 100644 --- a/compiler/src/constraints/function.rs +++ b/compiler/src/constraints/function.rs @@ -8,11 +8,11 @@ use crate::{ }; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::r1cs::ConstraintSystem, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { fn check_arguments_length(expected: usize, actual: usize) -> Result<(), FunctionError> { // Make sure we are given the correct number of arguments if expected != actual { @@ -28,9 +28,9 @@ impl> ConstrainedProgra scope: String, caller_scope: String, function_name: String, - expected_types: Vec>, - input: Expression, - ) -> Result, FunctionError> { + expected_types: Vec>, + input: Expression, + ) -> Result, FunctionError> { // Evaluate the function input value as pass by value from the caller or // evaluate as an expression in the current function scope match input { @@ -55,9 +55,9 @@ impl> ConstrainedProgra cs: &mut CS, scope: String, caller_scope: String, - function: Function, - inputs: Vec>, - ) -> Result, FunctionError> { + function: Function, + inputs: Vec>, + ) -> Result, FunctionError> { let function_name = new_scope(scope.clone(), function.get_name()); // Make sure we are given the correct number of inputs @@ -116,10 +116,10 @@ impl> ConstrainedProgra cs: &mut CS, name: String, private: bool, - array_type: Type, + array_type: Type, array_dimensions: Vec, - input_value: Option>, - ) -> Result, FunctionError> { + input_value: Option>, + ) -> Result, FunctionError> { let expected_length = array_dimensions[0]; let mut array_value = vec![]; @@ -168,11 +168,11 @@ impl> ConstrainedProgra fn allocate_main_function_input( &mut self, cs: &mut CS, - _type: Type, + _type: Type, name: String, private: bool, - input_value: Option>, - ) -> Result, FunctionError> { + input_value: Option>, + ) -> Result, FunctionError> { match _type { Type::IntegerType(integer_type) => { Ok(self.integer_from_parameter(cs, integer_type, name, private, input_value)?) @@ -180,9 +180,9 @@ impl> ConstrainedProgra Type::FieldElement => { Ok(self.field_element_from_input(cs, name, private, input_value)?) } - Type::GroupElement => { - Ok(self.group_element_from_input(cs, name, private, input_value)?) - } + // Type::Group => { + // Ok(self.group_element_from_input(cs, name, private, input_value)?) + // } Type::Boolean => Ok(self.bool_from_input(cs, name, private, input_value)?), Type::Array(_type, dimensions) => { self.allocate_array(cs, name, private, *_type, dimensions, input_value) @@ -195,9 +195,9 @@ impl> ConstrainedProgra &mut self, cs: &mut CS, scope: String, - function: Function, - inputs: Vec>>, - ) -> Result, FunctionError> { + function: Function, + inputs: Vec>>, + ) -> Result, FunctionError> { let function_name = new_scope(scope.clone(), function.get_name()); // Make sure we are given the correct number of inputs @@ -231,7 +231,7 @@ impl> ConstrainedProgra pub(crate) fn resolve_definitions( &mut self, cs: &mut CS, - program: Program, + program: Program, ) -> Result<(), ImportError> { let program_name = program.name.clone(); diff --git a/compiler/src/constraints/group.rs b/compiler/src/constraints/group.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/compiler/src/constraints/group.rs @@ -0,0 +1 @@ + diff --git a/compiler/src/constraints/group_element.rs b/compiler/src/constraints/group_element.rs deleted file mode 100644 index 14097ce67b..0000000000 --- a/compiler/src/constraints/group_element.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::errors::GroupElementError; -use crate::{ConstrainedProgram, ConstrainedValue, InputValue}; - -use snarkos_models::{ - curves::{Field, Group, PrimeField}, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; - -impl> ConstrainedProgram { - pub(crate) fn group_element_from_input( - &mut self, - _cs: &mut CS, - _name: String, - _private: bool, - input_value: Option>, - ) -> Result, GroupElementError> { - // Check that the parameter value is the correct type - // let group_option = match input_value { - // Some(input) => { - // if let InputValue::Group(group) = input { - // Some(group) - // } else { - // return Err(GroupElementError::InvalidGroup(input.to_string())); - // } - // } - // None => None, - // }; - // - // // Check visibility of parameter - // let group_value = if private { - // cs.alloc( - // || name, - // || group_option.ok_or(SynthesisError::AssignmentMissing), - // )? - // } else { - // cs.alloc_input( - // || name, - // || group_option.ok_or(SynthesisError::AssignmentMissing), - // )? - // }; - // - // Ok(ConstrainedValue::GroupElement()) - - // TODO: use group gadget to allocate groups - if let Some(InputValue::Group(group)) = input_value { - return Ok(ConstrainedValue::GroupElement(group)); - } - - Ok(ConstrainedValue::GroupElement(G::default())) - } - - pub fn evaluate_group_eq(group_element_1: G, group_element_2: G) -> ConstrainedValue { - ConstrainedValue::Boolean(Boolean::constant(group_element_1.eq(&group_element_2))) - } - - pub fn evaluate_group_add(group_element_1: G, group_element_2: G) -> ConstrainedValue { - ConstrainedValue::GroupElement(group_element_1.add(&group_element_2)) - } - - pub fn evaluate_group_sub(group_element_1: G, group_element_2: G) -> ConstrainedValue { - ConstrainedValue::GroupElement(group_element_1.sub(&group_element_2)) - } - // - // pub fn evaluate_group_mul(group_element: G, scalar_field: G::ScalarField) -> ConstrainedValue { - // ConstrainedValue::GroupElement(group_element.mul(&scalar_field)) - // } -} diff --git a/compiler/src/constraints/import.rs b/compiler/src/constraints/import.rs index 8cdef1374b..a75bde4e17 100644 --- a/compiler/src/constraints/import.rs +++ b/compiler/src/constraints/import.rs @@ -9,18 +9,18 @@ use crate::{ use from_pest::FromPest; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::r1cs::ConstraintSystem, }; use std::env::current_dir; use std::fs; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub fn enforce_import( &mut self, cs: &mut CS, scope: String, - import: Import, + import: Import, ) -> Result<(), ImportError> { let path = current_dir().map_err(|error| ImportError::DirectoryError(error))?; diff --git a/compiler/src/constraints/integer/integer.rs b/compiler/src/constraints/integer/integer.rs index edd47807b3..d41bccab3a 100644 --- a/compiler/src/constraints/integer/integer.rs +++ b/compiler/src/constraints/integer/integer.rs @@ -9,7 +9,7 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{ @@ -73,15 +73,15 @@ impl CondSelectGadget for Integer { } } -impl> ConstrainedProgram { - pub(crate) fn get_integer_constant(integer: Integer) -> ConstrainedValue { +impl> ConstrainedProgram { + pub(crate) fn get_integer_constant(integer: Integer) -> ConstrainedValue { ConstrainedValue::Integer(integer) } pub(crate) fn evaluate_integer_eq( left: Integer, right: Integer, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { Ok(ConstrainedValue::Boolean(Boolean::Constant( match (left, right) { (Integer::U8(left_u8), Integer::U8(right_u8)) => left_u8.eq(&right_u8), @@ -105,8 +105,8 @@ impl> ConstrainedProgra integer_type: IntegerType, name: String, private: bool, - integer_value: Option>, - ) -> Result, IntegerError> { + integer_value: Option>, + ) -> Result, IntegerError> { // Check that the input value is the correct type let integer_option = match integer_value { Some(input) => { @@ -162,7 +162,7 @@ impl> ConstrainedProgra cs: &mut CS, left: Integer, right: Integer, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { Ok(ConstrainedValue::Integer(match (left, right) { (Integer::U8(left_u8), Integer::U8(right_u8)) => { Integer::U8(Self::enforce_u8_add(cs, left_u8, right_u8)?) @@ -188,7 +188,7 @@ impl> ConstrainedProgra cs: &mut CS, left: Integer, right: Integer, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { Ok(ConstrainedValue::Integer(match (left, right) { (Integer::U8(left_u8), Integer::U8(right_u8)) => { Integer::U8(Self::enforce_u8_sub(cs, left_u8, right_u8)?) @@ -214,7 +214,7 @@ impl> ConstrainedProgra cs: &mut CS, left: Integer, right: Integer, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { Ok(ConstrainedValue::Integer(match (left, right) { (Integer::U8(left_u8), Integer::U8(right_u8)) => { Integer::U8(Self::enforce_u8_mul(cs, left_u8, right_u8)?) @@ -240,7 +240,7 @@ impl> ConstrainedProgra cs: &mut CS, left: Integer, right: Integer, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { Ok(ConstrainedValue::Integer(match (left, right) { (Integer::U8(left_u8), Integer::U8(right_u8)) => { Integer::U8(Self::enforce_u8_div(cs, left_u8, right_u8)?) @@ -266,7 +266,7 @@ impl> ConstrainedProgra cs: &mut CS, left: Integer, right: Integer, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { Ok(ConstrainedValue::Integer(match (left, right) { (Integer::U8(left_u8), Integer::U8(right_u8)) => { Integer::U8(Self::enforce_u8_pow(cs, left_u8, right_u8)?) diff --git a/compiler/src/constraints/integer/uint128.rs b/compiler/src/constraints/integer/uint128.rs index b8e6244525..24465ea8c5 100644 --- a/compiler/src/constraints/integer/uint128.rs +++ b/compiler/src/constraints/integer/uint128.rs @@ -8,21 +8,21 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{alloc::AllocGadget, eq::EqGadget, uint128::UInt128}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn u128_from_input( &mut self, cs: &mut CS, name: String, private: bool, integer_option: Option, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { // Type cast to u128 in rust. // If this fails should we return our own error? let u128_option = integer_option.map(|integer| integer as u128); diff --git a/compiler/src/constraints/integer/uint16.rs b/compiler/src/constraints/integer/uint16.rs index 92d047a24e..a4f8f80fd5 100644 --- a/compiler/src/constraints/integer/uint16.rs +++ b/compiler/src/constraints/integer/uint16.rs @@ -8,21 +8,21 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{alloc::AllocGadget, eq::EqGadget, uint16::UInt16}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn u16_from_input( &mut self, cs: &mut CS, name: String, private: bool, integer_option: Option, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { // Type cast to u16 in rust. // If this fails should we return our own error? let u16_option = integer_option.map(|integer| integer as u16); diff --git a/compiler/src/constraints/integer/uint32.rs b/compiler/src/constraints/integer/uint32.rs index 409aec5805..db7f33b8a8 100644 --- a/compiler/src/constraints/integer/uint32.rs +++ b/compiler/src/constraints/integer/uint32.rs @@ -8,21 +8,21 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{alloc::AllocGadget, eq::EqGadget, uint32::UInt32}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn u32_from_input( &mut self, cs: &mut CS, name: String, private: bool, integer_option: Option, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { // Type cast to integers.u32 in rust. // If this fails should we return our own error? let u32_option = integer_option.map(|integer| integer as u32); diff --git a/compiler/src/constraints/integer/uint64.rs b/compiler/src/constraints/integer/uint64.rs index 05b2af8ab6..bf135247e9 100644 --- a/compiler/src/constraints/integer/uint64.rs +++ b/compiler/src/constraints/integer/uint64.rs @@ -8,21 +8,21 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{alloc::AllocGadget, eq::EqGadget, uint64::UInt64}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn u64_from_input( &mut self, cs: &mut CS, name: String, private: bool, integer_option: Option, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { // Type cast to u64 in rust. // If this fails should we return our own error? let u64_option = integer_option.map(|integer| integer as u64); diff --git a/compiler/src/constraints/integer/uint8.rs b/compiler/src/constraints/integer/uint8.rs index 5cc7818f53..c8224f8733 100644 --- a/compiler/src/constraints/integer/uint8.rs +++ b/compiler/src/constraints/integer/uint8.rs @@ -8,21 +8,21 @@ use crate::{ use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{ r1cs::ConstraintSystem, utilities::{alloc::AllocGadget, eq::EqGadget, uint8::UInt8}, }, }; -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub(crate) fn u8_from_input( &mut self, cs: &mut CS, name: String, private: bool, integer_option: Option, - ) -> Result, IntegerError> { + ) -> Result, IntegerError> { // Type cast to u8 in rust. // If this fails should we return our own error? let u8_option = integer_option.map(|integer| integer as u8); diff --git a/compiler/src/constraints/mod.rs b/compiler/src/constraints/mod.rs index 65a1ab2fa5..0da1c126dc 100644 --- a/compiler/src/constraints/mod.rs +++ b/compiler/src/constraints/mod.rs @@ -18,8 +18,8 @@ pub use integer::*; pub mod field_element; pub use field_element::*; -pub mod group_element; -pub use group_element::*; +pub mod group; +pub use group::*; pub mod program; pub use program::*; @@ -36,15 +36,15 @@ use crate::{ }; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::r1cs::ConstraintSystem, }; -pub fn generate_constraints>( +pub fn generate_constraints>( cs: &mut CS, - program: Program, - parameters: Vec>>, -) -> Result, CompilerError> { + program: Program, + parameters: Vec>>, +) -> Result, CompilerError> { let mut resolved_program = ConstrainedProgram::new(); let program_name = program.get_name(); let main_function_name = new_scope(program_name.clone(), "main".into()); diff --git a/compiler/src/constraints/program.rs b/compiler/src/constraints/program.rs index 009f96c8be..57b270121d 100644 --- a/compiler/src/constraints/program.rs +++ b/compiler/src/constraints/program.rs @@ -3,13 +3,13 @@ use crate::constraints::ConstrainedValue; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::r1cs::ConstraintSystem, }; use std::{collections::HashMap, marker::PhantomData}; -pub struct ConstrainedProgram> { - pub identifiers: HashMap>, +pub struct ConstrainedProgram> { + pub identifiers: HashMap>, pub _cs: PhantomData, } @@ -17,7 +17,7 @@ pub fn new_scope(outer: String, inner: String) -> String { format!("{}_{}", outer, inner) } -impl> ConstrainedProgram { +impl> ConstrainedProgram { pub fn new() -> Self { Self { identifiers: HashMap::new(), @@ -25,15 +25,15 @@ impl> ConstrainedProgra } } - pub(crate) fn store(&mut self, name: String, value: ConstrainedValue) { + pub(crate) fn store(&mut self, name: String, value: ConstrainedValue) { self.identifiers.insert(name, value); } - pub(crate) fn get(&self, name: &String) -> Option<&ConstrainedValue> { + pub(crate) fn get(&self, name: &String) -> Option<&ConstrainedValue> { self.identifiers.get(name) } - pub(crate) fn get_mut(&mut self, name: &String) -> Option<&mut ConstrainedValue> { + pub(crate) fn get_mut(&mut self, name: &String) -> Option<&mut ConstrainedValue> { self.identifiers.get_mut(name) } } diff --git a/compiler/src/constraints/statement.rs b/compiler/src/constraints/statement.rs index 9da2b5730f..dc9c0de0ed 100644 --- a/compiler/src/constraints/statement.rs +++ b/compiler/src/constraints/statement.rs @@ -12,12 +12,12 @@ use crate::{ }; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean, utilities::uint32::UInt32}, }; -impl> ConstrainedProgram { - fn resolve_assignee(&mut self, scope: String, assignee: Assignee) -> String { +impl> ConstrainedProgram { + fn resolve_assignee(&mut self, scope: String, assignee: Assignee) -> String { match assignee { Assignee::Identifier(name) => new_scope(scope, name.to_string()), Assignee::Array(array, _index) => self.resolve_assignee(scope, *array), @@ -30,7 +30,7 @@ impl> ConstrainedProgra fn get_mutable_assignee( &mut self, name: String, - ) -> Result<&mut ConstrainedValue, StatementError> { + ) -> Result<&mut ConstrainedValue, StatementError> { // Check that assignee exists and is mutable Ok(match self.get_mut(&name) { Some(value) => match value { @@ -47,8 +47,8 @@ impl> ConstrainedProgra file_scope: String, function_scope: String, name: String, - range_or_expression: RangeOrExpression, - new_value: ConstrainedValue, + range_or_expression: RangeOrExpression, + new_value: ConstrainedValue, ) -> Result<(), StatementError> { // Resolve index so we know if we are assigning to a single value or a range of values match range_or_expression { @@ -91,8 +91,8 @@ impl> ConstrainedProgra fn mutute_circuit_field( &mut self, circuit_name: String, - object_name: Identifier, - new_value: ConstrainedValue, + object_name: Identifier, + new_value: ConstrainedValue, ) -> Result<(), StatementError> { match self.get_mutable_assignee(circuit_name)? { ConstrainedValue::CircuitExpression(_variable, members) => { @@ -129,8 +129,8 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - assignee: Assignee, - expression: Expression, + assignee: Assignee, + expression: Expression, ) -> Result<(), StatementError> { // Get the name of the variable we are assigning to let variable_name = self.resolve_assignee(function_scope.clone(), assignee.clone()); @@ -170,8 +170,8 @@ impl> ConstrainedProgra fn store_definition( &mut self, function_scope: String, - variable: Variable, - mut value: ConstrainedValue, + variable: Variable, + mut value: ConstrainedValue, ) -> Result<(), StatementError> { // Store with given mutability if variable.mutable { @@ -190,8 +190,8 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - variable: Variable, - expression: Expression, + variable: Variable, + expression: Expression, ) -> Result<(), StatementError> { let mut expected_types = vec![]; if let Some(ref _type) = variable._type { @@ -213,8 +213,8 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - variables: Vec>, - function: Expression, + variables: Vec>, + function: Expression, ) -> Result<(), StatementError> { let mut expected_types = vec![]; for variable in variables.iter() { @@ -256,9 +256,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - expressions: Vec>, - return_types: Vec>, - ) -> Result, StatementError> { + expressions: Vec>, + return_types: Vec>, + ) -> Result, StatementError> { // Make sure we return the correct number of values if return_types.len() != expressions.len() { return Err(StatementError::InvalidNumberOfReturns( @@ -289,9 +289,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - statements: Vec>, - return_types: Vec>, - ) -> Result>, StatementError> { + statements: Vec>, + return_types: Vec>, + ) -> Result>, StatementError> { let mut res = None; // Evaluate statements and possibly return early for statement in statements.iter() { @@ -315,9 +315,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - statement: ConditionalStatement, - return_types: Vec>, - ) -> Result>, StatementError> { + statement: ConditionalStatement, + return_types: Vec>, + ) -> Result>, StatementError> { let expected_types = vec![Type::Boolean]; let condition = match self.enforce_expression( cs, @@ -367,12 +367,12 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - index: Identifier, + index: Identifier, start: Integer, stop: Integer, - statements: Vec>, - return_types: Vec>, - ) -> Result>, StatementError> { + statements: Vec>, + return_types: Vec>, + ) -> Result>, StatementError> { let mut res = None; for i in start.to_usize()..stop.to_usize() { @@ -403,8 +403,8 @@ impl> ConstrainedProgra fn enforce_assert_eq_statement( &mut self, cs: &mut CS, - left: ConstrainedValue, - right: ConstrainedValue, + left: ConstrainedValue, + right: ConstrainedValue, ) -> Result<(), StatementError> { Ok(match (left, right) { (ConstrainedValue::Boolean(bool_1), ConstrainedValue::Boolean(bool_2)) => { @@ -440,9 +440,9 @@ impl> ConstrainedProgra cs: &mut CS, file_scope: String, function_scope: String, - statement: Statement, - return_types: Vec>, - ) -> Result>, StatementError> { + statement: Statement, + return_types: Vec>, + ) -> Result>, StatementError> { let mut res = None; match statement { Statement::Return(expressions) => { diff --git a/compiler/src/constraints/value.rs b/compiler/src/constraints/value.rs index a31878ad67..c21af4a19b 100644 --- a/compiler/src/constraints/value.rs +++ b/compiler/src/constraints/value.rs @@ -6,7 +6,7 @@ use crate::{ }; use snarkos_models::{ - curves::{Field, Group, PrimeField}, + curves::{Field, PrimeField}, gadgets::utilities::{ boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64, uint8::UInt8, @@ -15,42 +15,42 @@ use snarkos_models::{ use std::fmt; #[derive(Clone, PartialEq, Eq)] -pub struct ConstrainedCircuitMember( - pub Identifier, - pub ConstrainedValue, +pub struct ConstrainedCircuitMember( + pub Identifier, + pub ConstrainedValue, ); #[derive(Clone, PartialEq, Eq)] -pub enum ConstrainedValue { +pub enum ConstrainedValue { Integer(Integer), FieldElement(FieldElement), - GroupElement(G), + Group(String), Boolean(Boolean), - Array(Vec>), + Array(Vec>), - CircuitDefinition(Circuit), - CircuitExpression(Identifier, Vec>), + CircuitDefinition(Circuit), + CircuitExpression(Identifier, Vec>), - Function(Option>, Function), // (optional circuit identifier, function definition) - Return(Vec>), + Function(Option>, Function), // (optional circuit identifier, function definition) + Return(Vec>), - Mutable(Box>), - Static(Box>), + Mutable(Box>), + Static(Box>), Unresolved(String), } -impl ConstrainedValue { +impl ConstrainedValue { pub(crate) fn from_other( value: String, - other: &ConstrainedValue, + other: &ConstrainedValue, ) -> Result { let other_type = other.to_type(); ConstrainedValue::from_type(value, &other_type) } - pub(crate) fn from_type(value: String, _type: &Type) -> Result { + pub(crate) fn from_type(value: String, _type: &Type) -> Result { match _type { Type::IntegerType(integer_type) => Ok(ConstrainedValue::Integer(match integer_type { IntegerType::U8 => Integer::U8(UInt8::constant(value.parse::()?)), @@ -62,13 +62,7 @@ impl ConstrainedValue { Type::FieldElement => Ok(ConstrainedValue::FieldElement(FieldElement::Constant( F::from_str(&value).unwrap_or_default(), ))), - Type::GroupElement => Ok(ConstrainedValue::GroupElement({ - use std::str::FromStr; - - let scalar = G::ScalarField::from_str(&value).unwrap_or_default(); - let point = G::default().mul(&scalar); - point - })), + Type::Group => Ok(ConstrainedValue::Group(value)), Type::Boolean => Ok(ConstrainedValue::Boolean(Boolean::Constant( value.parse::()?, ))), @@ -77,17 +71,17 @@ impl ConstrainedValue { } } - pub(crate) fn to_type(&self) -> Type { + pub(crate) fn to_type(&self) -> Type { match self { ConstrainedValue::Integer(integer) => Type::IntegerType(integer.get_type()), ConstrainedValue::FieldElement(_field) => Type::FieldElement, - ConstrainedValue::GroupElement(_group) => Type::GroupElement, + ConstrainedValue::Group(_group) => Type::Group, ConstrainedValue::Boolean(_bool) => Type::Boolean, _ => unimplemented!("to type only implemented for primitives"), } } - pub(crate) fn resolve_type(&mut self, types: &Vec>) -> Result<(), ValueError> { + pub(crate) fn resolve_type(&mut self, types: &Vec>) -> Result<(), ValueError> { if let ConstrainedValue::Unresolved(ref string) = self { if !types.is_empty() { *self = ConstrainedValue::from_type(string.clone(), &types[0])? @@ -104,12 +98,12 @@ impl ConstrainedValue { } } -impl fmt::Display for ConstrainedValue { +impl fmt::Display for ConstrainedValue { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ConstrainedValue::Integer(ref value) => write!(f, "{}", value), ConstrainedValue::FieldElement(ref value) => write!(f, "{}", value), - ConstrainedValue::GroupElement(ref value) => write!(f, "{}", value), + ConstrainedValue::Group(ref value) => write!(f, "{}", value), ConstrainedValue::Boolean(ref value) => write!(f, "{}", value.get_value().unwrap()), ConstrainedValue::Array(ref array) => { write!(f, "[")?; @@ -154,7 +148,7 @@ impl fmt::Display for ConstrainedValue { } } -impl fmt::Debug for ConstrainedValue { +impl fmt::Debug for ConstrainedValue { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self) } diff --git a/compiler/src/errors/constraints/function.rs b/compiler/src/errors/constraints/function.rs index 98280e64b1..21278a5eb8 100644 --- a/compiler/src/errors/constraints/function.rs +++ b/compiler/src/errors/constraints/function.rs @@ -1,6 +1,6 @@ use crate::errors::{ - BooleanError, ExpressionError, FieldElementError, GroupElementError, IntegerError, - StatementError, ValueError, + BooleanError, ExpressionError, FieldElementError, GroupError, IntegerError, StatementError, + ValueError, }; #[derive(Debug, Error)] @@ -30,7 +30,7 @@ pub enum FunctionError { FieldElementError(FieldElementError), #[error("{}", _0)] - GroupElementError(GroupElementError), + GroupError(GroupError), #[error("{}", _0)] BooleanError(BooleanError), @@ -60,9 +60,9 @@ impl From for FunctionError { } } -impl From for FunctionError { - fn from(error: GroupElementError) -> Self { - FunctionError::GroupElementError(error) +impl From for FunctionError { + fn from(error: GroupError) -> Self { + FunctionError::GroupError(error) } } diff --git a/compiler/src/errors/constraints/group_element.rs b/compiler/src/errors/constraints/group.rs similarity index 68% rename from compiler/src/errors/constraints/group_element.rs rename to compiler/src/errors/constraints/group.rs index 424ee2f86f..238938d8d0 100644 --- a/compiler/src/errors/constraints/group_element.rs +++ b/compiler/src/errors/constraints/group.rs @@ -1,7 +1,7 @@ use snarkos_errors::gadgets::SynthesisError; #[derive(Debug, Error)] -pub enum GroupElementError { +pub enum GroupError { #[error("Expected group element parameter, got {}", _0)] InvalidGroup(String), @@ -9,8 +9,8 @@ pub enum GroupElementError { SynthesisError(SynthesisError), } -impl From for GroupElementError { +impl From for GroupError { fn from(error: SynthesisError) -> Self { - GroupElementError::SynthesisError(error) + GroupError::SynthesisError(error) } } diff --git a/compiler/src/errors/constraints/mod.rs b/compiler/src/errors/constraints/mod.rs index 527f4cb0c5..2a826c241f 100644 --- a/compiler/src/errors/constraints/mod.rs +++ b/compiler/src/errors/constraints/mod.rs @@ -18,8 +18,8 @@ pub use integer::*; pub mod field_element; pub use field_element::*; -pub mod group_element; -pub use group_element::*; +pub mod group; +pub use group::*; pub mod value; pub use value::*; diff --git a/compiler/src/imports.rs b/compiler/src/imports.rs index 2da523f872..d863f76eec 100644 --- a/compiler/src/imports.rs +++ b/compiler/src/imports.rs @@ -2,23 +2,23 @@ use crate::Identifier; -use snarkos_models::curves::{Field, Group, PrimeField}; +use snarkos_models::curves::{Field, PrimeField}; use std::fmt; #[derive(Clone)] -pub struct ImportSymbol { - pub symbol: Identifier, - pub alias: Option>, +pub struct ImportSymbol { + pub symbol: Identifier, + pub alias: Option>, } #[derive(Clone)] -pub struct Import { +pub struct Import { pub path_string: String, - pub symbols: Vec>, + pub symbols: Vec>, } -impl Import { - pub fn new(source: String, symbols: Vec>) -> Import { +impl Import { + pub fn new(source: String, symbols: Vec>) -> Import { Import { path_string: source, symbols, @@ -51,7 +51,7 @@ impl Import { } } -impl fmt::Display for ImportSymbol { +impl fmt::Display for ImportSymbol { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.alias.is_some() { write!(f, "\t{} as {}", self.symbol, self.alias.as_ref().unwrap()) @@ -61,13 +61,13 @@ impl fmt::Display for ImportSymbol { } } -impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for Import { +impl<'ast, F: Field + PrimeField> fmt::Display for Import { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.format(f) } } -impl<'ast, F: Field + PrimeField, G: Group> fmt::Debug for Import { +impl<'ast, F: Field + PrimeField> fmt::Debug for Import { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.format(f) } diff --git a/compiler/src/types.rs b/compiler/src/types.rs index be79c3efa5..7bad68fd3c 100644 --- a/compiler/src/types.rs +++ b/compiler/src/types.rs @@ -3,7 +3,7 @@ use crate::Import; -use snarkos_models::curves::{Field, Group, PrimeField}; +use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::gadgets::{ r1cs::Variable as R1CSVariable, utilities::{ @@ -16,17 +16,15 @@ use std::marker::PhantomData; /// An identifier in the constrained program. #[derive(Clone, PartialEq, Eq, Hash)] -pub struct Identifier { +pub struct Identifier { pub name: String, - pub(crate) _group: PhantomData, pub(crate) _engine: PhantomData, } -impl Identifier { +impl Identifier { pub fn new(name: String) -> Self { Self { name, - _group: PhantomData::, _engine: PhantomData::, } } @@ -38,10 +36,10 @@ impl Identifier { /// A variable that is assigned to a value in the constrained program #[derive(Clone, PartialEq, Eq)] -pub struct Variable { - pub identifier: Identifier, +pub struct Variable { + pub identifier: Identifier, pub mutable: bool, - pub _type: Option>, + pub _type: Option>, } /// An integer type enum wrapping the integer value. Used only in expressions. @@ -63,74 +61,70 @@ pub enum FieldElement { /// Range or expression enum #[derive(Debug, Clone, PartialEq, Eq)] -pub enum RangeOrExpression { +pub enum RangeOrExpression { Range(Option, Option), - Expression(Expression), + Expression(Expression), } /// Spread or expression #[derive(Debug, Clone, PartialEq, Eq)] -pub enum SpreadOrExpression { - Spread(Expression), - Expression(Expression), +pub enum SpreadOrExpression { + Spread(Expression), + Expression(Expression), } /// Expression that evaluates to a value #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Expression { +pub enum Expression { // Identifier - Identifier(Identifier), + Identifier(Identifier), // Values Integer(Integer), FieldElement(FieldElement), - GroupElement(G), + Group(String), Boolean(Boolean), Implicit(String), // Number operations - Add(Box>, Box>), - Sub(Box>, Box>), - Mul(Box>, Box>), - Div(Box>, Box>), - Pow(Box>, Box>), + Add(Box>, Box>), + Sub(Box>, Box>), + Mul(Box>, Box>), + Div(Box>, Box>), + Pow(Box>, Box>), // Boolean operations - Not(Box>), - Or(Box>, Box>), - And(Box>, Box>), - Eq(Box>, Box>), - Geq(Box>, Box>), - Gt(Box>, Box>), - Leq(Box>, Box>), - Lt(Box>, Box>), + Not(Box>), + Or(Box>, Box>), + And(Box>, Box>), + Eq(Box>, Box>), + Geq(Box>, Box>), + Gt(Box>, Box>), + Leq(Box>, Box>), + Lt(Box>, Box>), // Conditionals - IfElse( - Box>, - Box>, - Box>, - ), + IfElse(Box>, Box>, Box>), // Arrays - Array(Vec>>), - ArrayAccess(Box>, Box>), // (array name, range) + Array(Vec>>), + ArrayAccess(Box>, Box>), // (array name, range) // Circuits - Circuit(Identifier, Vec>), - CircuitMemberAccess(Box>, Identifier), // (declared circuit name, circuit member name) - CircuitStaticFunctionAccess(Box>, Identifier), // (defined circuit name, circuit static member name) + Circuit(Identifier, Vec>), + CircuitMemberAccess(Box>, Identifier), // (declared circuit name, circuit member name) + CircuitStaticFunctionAccess(Box>, Identifier), // (defined circuit name, circuit static member name) // Functions - FunctionCall(Box>, Vec>), + FunctionCall(Box>, Vec>), } /// Definition assignee: v, arr[0..2], Point p.x #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Assignee { - Identifier(Identifier), - Array(Box>, RangeOrExpression), - CircuitField(Box>, Identifier), // (circuit name, circuit field name) +pub enum Assignee { + Identifier(Identifier), + Array(Box>, RangeOrExpression), + CircuitField(Box>, Identifier), // (circuit name, circuit field name) } /// Explicit integer type @@ -145,17 +139,17 @@ pub enum IntegerType { /// Explicit type used for defining a variable or expression type #[derive(Clone, Debug, PartialEq, Eq)] -pub enum Type { +pub enum Type { IntegerType(IntegerType), FieldElement, - GroupElement, + Group, Boolean, - Array(Box>, Vec), - Circuit(Identifier), + Array(Box>, Vec), + Circuit(Identifier), SelfType, } -impl Type { +impl Type { pub fn outer_dimension(&self, dimensions: &Vec) -> Self { let _type = self.clone(); @@ -184,79 +178,79 @@ impl Type { } #[derive(Clone, PartialEq, Eq)] -pub enum ConditionalNestedOrEnd { - Nested(Box>), - End(Vec>), +pub enum ConditionalNestedOrEnd { + Nested(Box>), + End(Vec>), } #[derive(Clone, PartialEq, Eq)] -pub struct ConditionalStatement { - pub condition: Expression, - pub statements: Vec>, - pub next: Option>, +pub struct ConditionalStatement { + pub condition: Expression, + pub statements: Vec>, + pub next: Option>, } /// Program statement that defines some action (or expression) to be carried out. #[derive(Clone, PartialEq, Eq)] -pub enum Statement { - Return(Vec>), - Definition(Variable, Expression), - Assign(Assignee, Expression), - MultipleAssign(Vec>, Expression), - Conditional(ConditionalStatement), - For(Identifier, Integer, Integer, Vec>), - AssertEq(Expression, Expression), - Expression(Expression), +pub enum Statement { + Return(Vec>), + Definition(Variable, Expression), + Assign(Assignee, Expression), + MultipleAssign(Vec>, Expression), + Conditional(ConditionalStatement), + For(Identifier, Integer, Integer, Vec>), + AssertEq(Expression, Expression), + Expression(Expression), } /// Circuits #[derive(Clone, Debug, PartialEq, Eq)] -pub struct CircuitFieldDefinition { - pub identifier: Identifier, - pub expression: Expression, +pub struct CircuitFieldDefinition { + pub identifier: Identifier, + pub expression: Expression, } #[derive(Clone, PartialEq, Eq)] -pub enum CircuitMember { - CircuitField(Identifier, Type), - CircuitFunction(bool, Function), +pub enum CircuitMember { + CircuitField(Identifier, Type), + CircuitFunction(bool, Function), } #[derive(Clone, PartialEq, Eq)] -pub struct Circuit { - pub identifier: Identifier, - pub members: Vec>, +pub struct Circuit { + pub identifier: Identifier, + pub members: Vec>, } /// Function parameters #[derive(Clone, PartialEq, Eq)] -pub struct InputModel { - pub identifier: Identifier, +pub struct InputModel { + pub identifier: Identifier, pub mutable: bool, pub private: bool, - pub _type: Type, + pub _type: Type, } #[derive(Clone, PartialEq, Eq)] -pub enum InputValue { +pub enum InputValue { Integer(usize), Field(F), - Group(G), + Group(String), Boolean(bool), - Array(Vec>), + Array(Vec>), } #[derive(Clone, PartialEq, Eq)] -pub struct Function { - pub function_name: Identifier, - pub inputs: Vec>, - pub returns: Vec>, - pub statements: Vec>, +pub struct Function { + pub function_name: Identifier, + pub inputs: Vec>, + pub returns: Vec>, + pub statements: Vec>, } -impl Function { +impl Function { pub fn get_name(&self) -> String { self.function_name.name.clone() } @@ -264,15 +258,15 @@ impl Function { /// A simple program with statement expressions, program arguments and program returns. #[derive(Debug, Clone)] -pub struct Program { - pub name: Identifier, +pub struct Program { + pub name: Identifier, pub num_parameters: usize, - pub imports: Vec>, - pub circuits: HashMap, Circuit>, - pub functions: HashMap, Function>, + pub imports: Vec>, + pub circuits: HashMap, Circuit>, + pub functions: HashMap, Function>, } -impl<'ast, F: Field + PrimeField, G: Group> Program { +impl<'ast, F: Field + PrimeField> Program { pub fn new() -> Self { Self { name: Identifier::new("".into()), diff --git a/compiler/src/types_display.rs b/compiler/src/types_display.rs index e777b11052..62c3e99817 100644 --- a/compiler/src/types_display.rs +++ b/compiler/src/types_display.rs @@ -6,21 +6,21 @@ use crate::{ RangeOrExpression, SpreadOrExpression, Statement, Type, Variable, }; -use snarkos_models::curves::{Field, Group, PrimeField}; +use snarkos_models::curves::{Field, PrimeField}; use std::fmt; -impl fmt::Display for Identifier { +impl fmt::Display for Identifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) } } -impl fmt::Debug for Identifier { +impl fmt::Debug for Identifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) } } -impl fmt::Display for Variable { +impl fmt::Display for Variable { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.mutable { write!(f, "mut ")?; @@ -69,7 +69,7 @@ impl fmt::Debug for FieldElement { } } -impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for RangeOrExpression { +impl<'ast, F: Field + PrimeField> fmt::Display for RangeOrExpression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { RangeOrExpression::Range(ref from, ref to) => write!( @@ -87,7 +87,7 @@ impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for RangeOrExpression fmt::Display for SpreadOrExpression { +impl fmt::Display for SpreadOrExpression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { SpreadOrExpression::Spread(ref spread) => write!(f, "...{}", spread), @@ -96,7 +96,7 @@ impl fmt::Display for SpreadOrExpression } } -impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for Expression { +impl<'ast, F: Field + PrimeField> fmt::Display for Expression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { // Variables @@ -105,7 +105,7 @@ impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for Expression { // Values Expression::Integer(ref integer) => write!(f, "{}", integer), Expression::FieldElement(ref field) => write!(f, "{}", field), - Expression::GroupElement(ref group) => write!(f, "{}", group), + Expression::Group(ref group) => write!(f, "{}", group), Expression::Boolean(ref bool) => write!(f, "{}", bool.get_value().unwrap()), Expression::Implicit(ref value) => write!(f, "{}", value), @@ -177,7 +177,7 @@ impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for Expression { } } -impl fmt::Display for Assignee { +impl fmt::Display for Assignee { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Assignee::Identifier(ref variable) => write!(f, "{}", variable), @@ -189,7 +189,7 @@ impl fmt::Display for Assignee { } } -impl fmt::Display for ConditionalNestedOrEnd { +impl fmt::Display for ConditionalNestedOrEnd { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ConditionalNestedOrEnd::Nested(ref nested) => write!(f, "else {}", nested), @@ -204,7 +204,7 @@ impl fmt::Display for ConditionalNestedOrEnd fmt::Display for ConditionalStatement { +impl fmt::Display for ConditionalStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "if ({}) {{\n", self.condition)?; for statement in self.statements.iter() { @@ -217,7 +217,7 @@ impl fmt::Display for ConditionalStatement fmt::Display for Statement { +impl fmt::Display for Statement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Statement::Return(ref statements) => { @@ -274,12 +274,12 @@ impl fmt::Display for IntegerType { } } -impl fmt::Display for Type { +impl fmt::Display for Type { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type), Type::FieldElement => write!(f, "field"), - Type::GroupElement => write!(f, "group"), + Type::Group => write!(f, "group"), Type::Boolean => write!(f, "bool"), Type::Circuit(ref variable) => write!(f, "{}", variable), Type::SelfType => write!(f, "Self"), @@ -294,7 +294,7 @@ impl fmt::Display for Type { } } -impl fmt::Display for CircuitMember { +impl fmt::Display for CircuitMember { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { CircuitMember::CircuitField(ref identifier, ref _type) => { @@ -310,7 +310,7 @@ impl fmt::Display for CircuitMember { } } -impl Circuit { +impl Circuit { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "circuit {} {{ \n", self.identifier)?; for field in self.members.iter() { @@ -320,19 +320,19 @@ impl Circuit { } } -// impl fmt::Display for Circuit {// uncomment when we no longer print out Program +// impl fmt::Display for Circuit {// uncomment when we no longer print out Program // fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // self.format(f) // } // } -impl fmt::Debug for Circuit { +impl fmt::Debug for Circuit { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.format(f) } } -impl fmt::Display for InputModel { +impl fmt::Display for InputModel { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // mut var: private bool if self.mutable { @@ -348,7 +348,7 @@ impl fmt::Display for InputModel { } } -impl fmt::Display for InputValue { +impl fmt::Display for InputValue { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { InputValue::Integer(ref integer) => write!(f, "{}", integer), @@ -369,7 +369,7 @@ impl fmt::Display for InputValue { } } -impl Function { +impl Function { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "function {}", self.function_name)?; let parameters = self @@ -400,13 +400,13 @@ impl Function { } } -impl fmt::Display for Function { +impl fmt::Display for Function { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.format(f) } } -impl fmt::Debug for Function { +impl fmt::Debug for Function { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.format(f) } diff --git a/compiler/src/types_from.rs b/compiler/src/types_from.rs index 99ba73e41d..137c97cbbd 100644 --- a/compiler/src/types_from.rs +++ b/compiler/src/types_from.rs @@ -2,7 +2,7 @@ use crate::{ast, types, Import, ImportSymbol}; -use snarkos_models::curves::{Field, Group, PrimeField}; +use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::gadgets::utilities::{ boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64, uint8::UInt8, @@ -11,17 +11,13 @@ use std::collections::HashMap; /// pest ast -> types::Identifier -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Identifier -{ +impl<'ast, F: Field + PrimeField> From> for types::Identifier { fn from(identifier: ast::Identifier<'ast>) -> Self { types::Identifier::new(identifier.value) } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(identifier: ast::Identifier<'ast>) -> Self { types::Expression::Identifier(types::Identifier::from(identifier)) } @@ -29,7 +25,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> /// pest ast -> types::Variable -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Variable { +impl<'ast, F: Field + PrimeField> From> for types::Variable { fn from(variable: ast::Variable<'ast>) -> Self { types::Variable { identifier: types::Identifier::from(variable.identifier), @@ -72,32 +68,21 @@ impl<'ast> types::Integer { } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Expression { +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(field: ast::Integer<'ast>) -> Self { types::Expression::Integer(types::Integer::from(field.number, field._type)) } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::RangeOrExpression +impl<'ast, F: Field + PrimeField> From> + for types::RangeOrExpression { fn from(range_or_expression: ast::RangeOrExpression<'ast>) -> Self { match range_or_expression { ast::RangeOrExpression::Range(range) => { let from = range .from - .map(|from| match types::Expression::::from(from.0) { - types::Expression::Integer(number) => number, - types::Expression::Implicit(string) => { - types::Integer::from_implicit(string) - } - expression => { - unimplemented!("Range bounds should be integers, found {}", expression) - } - }); - let to = range - .to - .map(|to| match types::Expression::::from(to.0) { + .map(|from| match types::Expression::::from(from.0) { types::Expression::Integer(number) => number, types::Expression::Implicit(string) => { types::Integer::from_implicit(string) @@ -106,6 +91,13 @@ impl<'ast, F: Field + PrimeField, G: Group> From> unimplemented!("Range bounds should be integers, found {}", expression) } }); + let to = range.to.map(|to| match types::Expression::::from(to.0) { + types::Expression::Integer(number) => number, + types::Expression::Implicit(string) => types::Integer::from_implicit(string), + expression => { + unimplemented!("Range bounds should be integers, found {}", expression) + } + }); types::RangeOrExpression::Range(from, to) } @@ -118,7 +110,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> /// pest ast -> types::Field -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Expression { +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(field: ast::Field<'ast>) -> Self { types::Expression::FieldElement(types::FieldElement::Constant( F::from_str(&field.number.value).unwrap_or_default(), @@ -128,20 +120,15 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types::Ex /// pest ast -> types::Group -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Expression { +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(group: ast::Group<'ast>) -> Self { - use std::str::FromStr; - - let scalar = G::ScalarField::from_str(&group.number.value).unwrap_or_default(); - let point = G::default().mul(&scalar); - - types::Expression::GroupElement(point) + types::Expression::Group(group.number.value) } } /// pest ast -> types::Boolean -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Expression { +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(boolean: ast::Boolean<'ast>) -> Self { types::Expression::Boolean(Boolean::Constant( boolean @@ -154,9 +141,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types:: /// pest ast -> types::NumberImplicit -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(number: ast::NumberImplicit<'ast>) -> Self { types::Expression::Implicit(number.number.value) } @@ -164,7 +149,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> /// pest ast -> types::Expression -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Expression { +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(value: ast::Value<'ast>) -> Self { match value { ast::Value::Integer(num) => types::Expression::from(num), @@ -176,16 +161,14 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types::Ex } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(expression: ast::NotExpression<'ast>) -> Self { types::Expression::Not(Box::new(types::Expression::from(*expression.expression))) } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::SpreadOrExpression +impl<'ast, F: Field + PrimeField> From> + for types::SpreadOrExpression { fn from(s_or_e: ast::SpreadOrExpression<'ast>) -> Self { match s_or_e { @@ -199,9 +182,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(expression: ast::BinaryExpression<'ast>) -> Self { match expression.operation { // Boolean operations @@ -261,9 +242,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(expression: ast::TernaryExpression<'ast>) -> Self { types::Expression::IfElse( Box::new(types::Expression::from(*expression.first)), @@ -273,9 +252,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(array: ast::ArrayInlineExpression<'ast>) -> Self { types::Expression::Array( array @@ -286,19 +263,19 @@ impl<'ast, F: Field + PrimeField, G: Group> From From> - for types::Expression +impl<'ast, F: Field + PrimeField> From> + for types::Expression { fn from(array: ast::ArrayInitializerExpression<'ast>) -> Self { - let count = types::Expression::::get_count(array.count); + let count = types::Expression::::get_count(array.count); let expression = Box::new(types::SpreadOrExpression::from(*array.expression)); types::Expression::Array(vec![expression; count]) } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::CircuitFieldDefinition +impl<'ast, F: Field + PrimeField> From> + for types::CircuitFieldDefinition { fn from(member: ast::CircuitField<'ast>) -> Self { types::CircuitFieldDefinition { @@ -308,8 +285,8 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression +impl<'ast, F: Field + PrimeField> From> + for types::Expression { fn from(expression: ast::CircuitInlineExpression<'ast>) -> Self { let variable = types::Identifier::from(expression.identifier); @@ -317,15 +294,13 @@ impl<'ast, F: Field + PrimeField, G: Group> From>>(); + .collect::>>(); types::Expression::Circuit(variable, members) } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(expression: ast::PostfixExpression<'ast>) -> Self { let variable = types::Expression::Identifier(types::Identifier::from(expression.identifier)); @@ -369,9 +344,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Expression -{ +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(expression: ast::Expression<'ast>) -> Self { match expression { ast::Expression::Value(value) => types::Expression::from(value), @@ -387,7 +360,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> types::Expression { +impl<'ast, F: Field + PrimeField> types::Expression { fn get_count(count: ast::Value<'ast>) -> usize { match count { ast::Value::Integer(integer) => integer @@ -406,7 +379,7 @@ impl<'ast, F: Field + PrimeField, G: Group> types::Expression { } // ast::Assignee -> types::Expression for operator assign statements -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Expression { +impl<'ast, F: Field + PrimeField> From> for types::Expression { fn from(assignee: ast::Assignee<'ast>) -> Self { let variable = types::Expression::Identifier(types::Identifier::from(assignee.identifier)); @@ -431,13 +404,13 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types: /// pest ast -> types::Assignee -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Assignee { +impl<'ast, F: Field + PrimeField> From> for types::Assignee { fn from(variable: ast::Identifier<'ast>) -> Self { types::Assignee::Identifier(types::Identifier::from(variable)) } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Assignee { +impl<'ast, F: Field + PrimeField> From> for types::Assignee { fn from(assignee: ast::Assignee<'ast>) -> Self { let variable = types::Assignee::from(assignee.identifier); @@ -460,9 +433,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types: /// pest ast -> types::Statement -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement -{ +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::ReturnStatement<'ast>) -> Self { types::Statement::Return( statement @@ -474,9 +445,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement -{ +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::DefinitionStatement<'ast>) -> Self { types::Statement::Definition( types::Variable::from(statement.variable), @@ -485,9 +454,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement -{ +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::AssignStatement<'ast>) -> Self { match statement.assign { ast::OperationAssign::Assign(ref _assign) => types::Statement::Assign( @@ -543,8 +510,8 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement +impl<'ast, F: Field + PrimeField> From> + for types::Statement { fn from(statement: ast::MultipleAssignmentStatement<'ast>) -> Self { let variables = statement @@ -567,8 +534,8 @@ impl<'ast, F: Field + PrimeField, G: Group> From From> - for types::ConditionalNestedOrEnd +impl<'ast, F: Field + PrimeField> From> + for types::ConditionalNestedOrEnd { fn from(statement: ast::ConditionalNestedOrEnd<'ast>) -> Self { match statement { @@ -585,8 +552,8 @@ impl<'ast, F: Field + PrimeField, G: Group> From From> - for types::ConditionalStatement +impl<'ast, F: Field + PrimeField> From> + for types::ConditionalStatement { fn from(statement: ast::ConditionalStatement<'ast>) -> Self { types::ConditionalStatement { @@ -604,16 +571,14 @@ impl<'ast, F: Field + PrimeField, G: Group> From } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement -{ +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::ForStatement<'ast>) -> Self { - let from = match types::Expression::::from(statement.start) { + let from = match types::Expression::::from(statement.start) { types::Expression::Integer(number) => number, types::Expression::Implicit(string) => types::Integer::from_implicit(string), expression => unimplemented!("Range bounds should be integers, found {}", expression), }; - let to = match types::Expression::::from(statement.stop) { + let to = match types::Expression::::from(statement.stop) { types::Expression::Integer(number) => number, types::Expression::Implicit(string) => types::Integer::from_implicit(string), expression => unimplemented!("Range bounds should be integers, found {}", expression), @@ -632,9 +597,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement -{ +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::AssertStatement<'ast>) -> Self { match statement { ast::AssertStatement::AssertEq(assert_eq) => types::Statement::AssertEq( @@ -645,15 +608,13 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::Statement -{ +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::ExpressionStatement<'ast>) -> Self { types::Statement::Expression(types::Expression::from(statement.expression)) } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Statement { +impl<'ast, F: Field + PrimeField> From> for types::Statement { fn from(statement: ast::Statement<'ast>) -> Self { match statement { ast::Statement::Return(statement) => types::Statement::from(statement), @@ -684,39 +645,39 @@ impl From for types::IntegerType { } } -impl From for types::Type { +impl From for types::Type { fn from(basic_type: ast::BasicType) -> Self { match basic_type { ast::BasicType::Integer(_type) => { types::Type::IntegerType(types::IntegerType::from(_type)) } ast::BasicType::Field(_type) => types::Type::FieldElement, - ast::BasicType::Group(_type) => types::Type::GroupElement, + ast::BasicType::Group(_type) => types::Type::Group, ast::BasicType::Boolean(_type) => types::Type::Boolean, } } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Type { +impl<'ast, F: Field + PrimeField> From> for types::Type { fn from(array_type: ast::ArrayType<'ast>) -> Self { let element_type = Box::new(types::Type::from(array_type._type)); let dimensions = array_type .dimensions .into_iter() - .map(|row| types::Expression::::get_count(row)) + .map(|row| types::Expression::::get_count(row)) .collect(); types::Type::Array(element_type, dimensions) } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Type { +impl<'ast, F: Field + PrimeField> From> for types::Type { fn from(circuit_type: ast::CircuitType<'ast>) -> Self { types::Type::Circuit(types::Identifier::from(circuit_type.identifier)) } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Type { +impl<'ast, F: Field + PrimeField> From> for types::Type { fn from(_type: ast::Type<'ast>) -> Self { match _type { ast::Type::Basic(_type) => types::Type::from(_type), @@ -729,8 +690,8 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types::Typ /// pest ast -> types::Circuit -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::CircuitMember +impl<'ast, F: Field + PrimeField> From> + for types::CircuitMember { fn from(circuit_value: ast::CircuitFieldDefinition<'ast>) -> Self { types::CircuitMember::CircuitField( @@ -740,9 +701,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From From> - for types::CircuitMember -{ +impl<'ast, F: Field + PrimeField> From> for types::CircuitMember { fn from(circuit_function: ast::CircuitFunction<'ast>) -> Self { types::CircuitMember::CircuitFunction( circuit_function._static.is_some(), @@ -751,9 +710,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::CircuitMember -{ +impl<'ast, F: Field + PrimeField> From> for types::CircuitMember { fn from(object: ast::CircuitMember<'ast>) -> Self { match object { ast::CircuitMember::CircuitFieldDefinition(circuit_value) => { @@ -766,7 +723,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> } } -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Circuit { +impl<'ast, F: Field + PrimeField> From> for types::Circuit { fn from(circuit: ast::Circuit<'ast>) -> Self { let variable = types::Identifier::from(circuit.identifier); let members = circuit @@ -784,9 +741,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types:: /// pest ast -> function types::Parameters -impl<'ast, F: Field + PrimeField, G: Group> From> - for types::InputModel -{ +impl<'ast, F: Field + PrimeField> From> for types::InputModel { fn from(parameter: ast::InputModel<'ast>) -> Self { types::InputModel { identifier: types::Identifier::from(parameter.identifier), @@ -802,7 +757,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> /// pest ast -> types::Function -impl<'ast, F: Field + PrimeField, G: Group> From> for types::Function { +impl<'ast, F: Field + PrimeField> From> for types::Function { fn from(function_definition: ast::Function<'ast>) -> Self { let function_name = types::Identifier::from(function_definition.function_name); let parameters = function_definition @@ -832,7 +787,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for types: /// pest ast -> Import -impl<'ast, F: Field + PrimeField, G: Group> From> for ImportSymbol { +impl<'ast, F: Field + PrimeField> From> for ImportSymbol { fn from(symbol: ast::ImportSymbol<'ast>) -> Self { ImportSymbol { symbol: types::Identifier::from(symbol.value), @@ -841,7 +796,7 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for Im } } -impl<'ast, F: Field + PrimeField, G: Group> From> for Import { +impl<'ast, F: Field + PrimeField> From> for Import { fn from(import: ast::Import<'ast>) -> Self { Import { path_string: import.source.value, @@ -856,14 +811,14 @@ impl<'ast, F: Field + PrimeField, G: Group> From> for Import types::Program -impl<'ast, F: Field + PrimeField, G: Group> types::Program { +impl<'ast, F: Field + PrimeField> types::Program { pub fn from(file: ast::File<'ast>, name: String) -> Self { // Compiled ast -> aleo program representation let imports = file .imports .into_iter() .map(|import| Import::from(import)) - .collect::>>(); + .collect::>>(); let mut circuits = HashMap::new(); let mut functions = HashMap::new(); diff --git a/compiler/tests/array/mod.rs b/compiler/tests/array/mod.rs index 2662d894c1..b13e8590e5 100644 --- a/compiler/tests/array/mod.rs +++ b/compiler/tests/array/mod.rs @@ -6,16 +6,16 @@ use leo_compiler::{ errors::{CompilerError, FunctionError}, ConstrainedValue, InputValue, Integer, }; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::utilities::uint32::UInt32; const DIRECTORY_NAME: &str = "tests/array/"; // [1, 1, 1] -fn output_ones(program: Compiler) { +fn output_ones(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Array( + ConstrainedValue::::Return(vec![ConstrainedValue::Array( vec![ConstrainedValue::Integer(Integer::U32(UInt32::constant(1u32))); 3] )]), output @@ -24,30 +24,27 @@ fn output_ones(program: Compiler) { // [[0, 0, 0], // [0, 0, 0]] -fn output_multi(program: Compiler) { +fn output_multi(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Array(vec![ - ConstrainedValue::Array(vec![ - ConstrainedValue::Integer(Integer::U32( - UInt32::constant(0u32) - )); - 3 - ]); - 2 - ])]), + ConstrainedValue::::Return(vec![ConstrainedValue::Array(vec![ + ConstrainedValue::Array( + vec![ConstrainedValue::Integer(Integer::U32(UInt32::constant(0u32))); 3] + ); + 2 + ])]), output ) } -fn fail_array(program: Compiler) { +fn fail_array(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::InvalidArray(_string)) => {} error => panic!("Expected invalid array error, got {}", error), } } -fn fail_synthesis(program: Compiler) { +fn fail_synthesis(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::IntegerError( IntegerError::SynthesisError(_string), diff --git a/compiler/tests/boolean/mod.rs b/compiler/tests/boolean/mod.rs index 30e83609e7..cd2d9b69b3 100644 --- a/compiler/tests/boolean/mod.rs +++ b/compiler/tests/boolean/mod.rs @@ -6,32 +6,28 @@ use leo_compiler::{ errors::{CompilerError, FunctionError, StatementError}, ConstrainedValue, InputValue, }; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::utilities::boolean::Boolean; const DIRECTORY_NAME: &str = "tests/boolean/"; -fn output_true(program: Compiler) { +fn output_true(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Boolean( - Boolean::Constant(true) - )]), + ConstrainedValue::::Return(vec![ConstrainedValue::Boolean(Boolean::Constant(true))]), output ); } -fn output_false(program: Compiler) { +fn output_false(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Boolean( - Boolean::Constant(false) - )]), + ConstrainedValue::::Return(vec![ConstrainedValue::Boolean(Boolean::Constant(false))]), output ); } -fn fail_evaluate(program: Compiler) { +fn fail_evaluate(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::StatementError( StatementError::ExpressionError(ExpressionError::BooleanError( @@ -42,7 +38,7 @@ fn fail_evaluate(program: Compiler) { } } -fn fail_enforce(program: Compiler) { +fn fail_enforce(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::StatementError( StatementError::ExpressionError(ExpressionError::BooleanError( @@ -53,7 +49,7 @@ fn fail_enforce(program: Compiler) { } } -fn fail_boolean(program: Compiler) { +fn fail_boolean(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::BooleanError( BooleanError::InvalidBoolean(_string), @@ -62,7 +58,7 @@ fn fail_boolean(program: Compiler) { } } -fn fail_synthesis(program: Compiler) { +fn fail_synthesis(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::BooleanError( BooleanError::SynthesisError(_string), diff --git a/compiler/tests/circuit/mod.rs b/compiler/tests/circuit/mod.rs index 492817dbc8..581b446b68 100644 --- a/compiler/tests/circuit/mod.rs +++ b/compiler/tests/circuit/mod.rs @@ -12,29 +12,27 @@ use leo_compiler::{ ConstrainedCircuitMember, ConstrainedValue, Expression, Function, Identifier, Integer, Statement, Type, }; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::utilities::uint32::UInt32; const DIRECTORY_NAME: &str = "tests/circuit/"; // Circ { x: 1u32 } -fn output_circuit(program: Compiler) { +fn output_circuit(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ - ConstrainedValue::CircuitExpression( - Identifier::new("Circ".into()), - vec![ConstrainedCircuitMember( - Identifier::new("x".into()), - ConstrainedValue::Integer(Integer::U32(UInt32::constant(1u32))) - )] - ) - ]), + ConstrainedValue::::Return(vec![ConstrainedValue::CircuitExpression( + Identifier::new("Circ".into()), + vec![ConstrainedCircuitMember( + Identifier::new("x".into()), + ConstrainedValue::Integer(Integer::U32(UInt32::constant(1u32))) + )] + )]), output ); } -fn fail_expected_member(program: Compiler) { +fn fail_expected_member(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::StatementError( StatementError::ExpressionError(ExpressionError::ExpectedCircuitMember(_string)), @@ -43,7 +41,7 @@ fn fail_expected_member(program: Compiler) { } } -fn fail_undefined_member(program: Compiler) { +fn fail_undefined_member(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::StatementError( StatementError::ExpressionError(ExpressionError::UndefinedMemberAccess(_, _)), @@ -153,26 +151,24 @@ fn test_self() { // } // } assert_eq!( - ConstrainedValue::::Return(vec![ - ConstrainedValue::CircuitExpression( - Identifier::new("Circ".into()), - vec![ConstrainedCircuitMember( - Identifier::new("new".into()), - ConstrainedValue::Static(Box::new(ConstrainedValue::Function( - Some(Identifier::new("Circ".into())), - Function { - function_name: Identifier::new("new".into()), - inputs: vec![], - returns: vec![Type::SelfType], - statements: vec![Statement::Return(vec![Expression::Circuit( - Identifier::new("Self".into()), - vec![] - )])] - } - ))) - )] - ) - ]), + ConstrainedValue::::Return(vec![ConstrainedValue::CircuitExpression( + Identifier::new("Circ".into()), + vec![ConstrainedCircuitMember( + Identifier::new("new".into()), + ConstrainedValue::Static(Box::new(ConstrainedValue::Function( + Some(Identifier::new("Circ".into())), + Function { + function_name: Identifier::new("new".into()), + inputs: vec![], + returns: vec![Type::SelfType], + statements: vec![Statement::Return(vec![Expression::Circuit( + Identifier::new("Self".into()), + vec![] + )])] + } + ))) + )] + )]), output ); } diff --git a/compiler/tests/field_element/mod.rs b/compiler/tests/field_element/mod.rs index c0d9889c92..3d2de9d47c 100644 --- a/compiler/tests/field_element/mod.rs +++ b/compiler/tests/field_element/mod.rs @@ -6,32 +6,32 @@ use leo_compiler::{ errors::{CompilerError, FunctionError}, ConstrainedValue, FieldElement, InputValue, }; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::curves::Field; const DIRECTORY_NAME: &str = "tests/field_element/"; -fn output_zero(program: Compiler) { +fn output_zero(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::FieldElement( + ConstrainedValue::::Return(vec![ConstrainedValue::FieldElement( FieldElement::Constant(Fr::zero()) )]), output ); } -fn output_one(program: Compiler) { +fn output_one(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::FieldElement( + ConstrainedValue::::Return(vec![ConstrainedValue::FieldElement( FieldElement::Constant(Fr::one()) )]), output ); } -fn fail_field(program: Compiler) { +fn fail_field(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::FieldElementError( FieldElementError::InvalidField(_string), @@ -40,7 +40,7 @@ fn fail_field(program: Compiler) { } } -fn fail_synthesis(program: Compiler) { +fn fail_synthesis(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::FieldElementError( FieldElementError::SynthesisError(_string), diff --git a/compiler/tests/function/mod.rs b/compiler/tests/function/mod.rs index 8c5d722306..93c51ac554 100644 --- a/compiler/tests/function/mod.rs +++ b/compiler/tests/function/mod.rs @@ -5,24 +5,21 @@ use leo_compiler::{ errors::{CompilerError, ExpressionError, FunctionError, StatementError}, ConstrainedValue, }; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::utilities::boolean::Boolean; const DIRECTORY_NAME: &str = "tests/function/"; -pub(crate) fn output_empty(program: Compiler) { +pub(crate) fn output_empty(program: Compiler) { let output = get_output(program); - assert_eq!( - ConstrainedValue::::Return(vec![]), - output - ); + assert_eq!(ConstrainedValue::::Return(vec![]), output); } // (true, false) -pub(crate) fn output_multiple(program: Compiler) { +pub(crate) fn output_multiple(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ + ConstrainedValue::::Return(vec![ ConstrainedValue::Boolean(Boolean::Constant(true)), ConstrainedValue::Boolean(Boolean::Constant(false)) ]), @@ -30,7 +27,7 @@ pub(crate) fn output_multiple(program: Compiler) { ) } -fn fail_undefined_identifier(program: Compiler) { +fn fail_undefined_identifier(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::StatementError( StatementError::ExpressionError(ExpressionError::UndefinedIdentifier(_)), diff --git a/compiler/tests/group/mod.rs b/compiler/tests/group/mod.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/compiler/tests/group/mod.rs @@ -0,0 +1 @@ + diff --git a/compiler/tests/group_element/zero.leo b/compiler/tests/group/zero.leo similarity index 100% rename from compiler/tests/group_element/zero.leo rename to compiler/tests/group/zero.leo diff --git a/compiler/tests/group_element/mod.rs b/compiler/tests/group_element/mod.rs deleted file mode 100644 index 9e811fa7d4..0000000000 --- a/compiler/tests/group_element/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::{compile_program, get_output}; - -use leo_compiler::{compiler::Compiler, ConstrainedValue}; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; -use snarkos_models::curves::Group; - -const DIRECTORY_NAME: &str = "tests/group_element/"; - -pub(crate) fn output_zero(program: Compiler) { - let output = get_output(program); - assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::GroupElement( - EdwardsProjective::zero() - )]), - output - ); -} - -#[test] -fn test_zero() { - let program = compile_program(DIRECTORY_NAME, "zero.leo").unwrap(); - output_zero(program); -} diff --git a/compiler/tests/integer/u32/mod.rs b/compiler/tests/integer/u32/mod.rs index 18a2774236..23e0a0567a 100644 --- a/compiler/tests/integer/u32/mod.rs +++ b/compiler/tests/integer/u32/mod.rs @@ -3,42 +3,42 @@ use crate::{compile_program, get_error, get_output}; use leo_compiler::{compiler::Compiler, types::Integer, ConstrainedValue, InputValue}; use leo_compiler::errors::{CompilerError, FunctionError, IntegerError}; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::utilities::uint32::UInt32; const DIRECTORY_NAME: &str = "tests/integer/u32/"; -pub(crate) fn output_zero(program: Compiler) { +pub(crate) fn output_zero(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Integer( - Integer::U32(UInt32::constant(0u32)) - )]), + ConstrainedValue::::Return(vec![ConstrainedValue::Integer(Integer::U32( + UInt32::constant(0u32) + ))]), output ) } -pub(crate) fn output_one(program: Compiler) { +pub(crate) fn output_one(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Integer( - Integer::U32(UInt32::constant(1u32)) - )]), + ConstrainedValue::::Return(vec![ConstrainedValue::Integer(Integer::U32( + UInt32::constant(1u32) + ))]), output ) } -fn output_two(program: Compiler) { +fn output_two(program: Compiler) { let output = get_output(program); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Integer( - Integer::U32(UInt32::constant(2u32)) - )]), + ConstrainedValue::::Return(vec![ConstrainedValue::Integer(Integer::U32( + UInt32::constant(2u32) + ))]), output ) } -fn fail_integer(program: Compiler) { +fn fail_integer(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::IntegerError( IntegerError::InvalidInteger(_string), @@ -47,7 +47,7 @@ fn fail_integer(program: Compiler) { } } -fn fail_synthesis(program: Compiler) { +fn fail_synthesis(program: Compiler) { match get_error(program) { CompilerError::FunctionError(FunctionError::IntegerError( IntegerError::SynthesisError(_string), diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 4ad38e8d9f..669b5a80c1 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -3,7 +3,7 @@ pub mod boolean; pub mod circuit; pub mod field_element; pub mod function; -pub mod group_element; +pub mod group; pub mod import; pub mod integer; pub mod mutability; @@ -11,21 +11,18 @@ pub mod statement; use leo_compiler::{compiler::Compiler, errors::CompilerError, ConstrainedValue}; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; - +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::r1cs::TestConstraintSystem; use std::env::current_dir; -pub(crate) fn get_output( - program: Compiler, -) -> ConstrainedValue { +pub(crate) fn get_output(program: Compiler) -> ConstrainedValue { let mut cs = TestConstraintSystem::::new(); let output = program.compile_constraints(&mut cs).unwrap(); assert!(cs.is_satisfied()); output } -pub(crate) fn get_error(program: Compiler) -> CompilerError { +pub(crate) fn get_error(program: Compiler) -> CompilerError { let mut cs = TestConstraintSystem::::new(); program.compile_constraints(&mut cs).unwrap_err() } @@ -33,7 +30,7 @@ pub(crate) fn get_error(program: Compiler) -> CompilerErr pub(crate) fn compile_program( directory_name: &str, file_name: &str, -) -> Result, CompilerError> { +) -> Result, CompilerError> { let path = current_dir().map_err(|error| CompilerError::DirectoryError(error))?; // Sanitize the package path to the test directory @@ -50,5 +47,5 @@ pub(crate) fn compile_program( println!("Compiling file - {:?}", main_file_path); // Compile from the main file path - Compiler::::init(file_name.to_string(), main_file_path) + Compiler::::init(file_name.to_string(), main_file_path) } diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index 3667a54e89..f886d19e1e 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -6,25 +6,25 @@ use leo_compiler::{ types::{InputValue, Integer}, ConstrainedValue, }; -use snarkos_curves::{bls12_377::Fr, edwards_bls12::EdwardsProjective}; +use snarkos_curves::bls12_377::Fr; use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::uint32::UInt32}; const DIRECTORY_NAME: &str = "tests/mutability/"; -fn mut_success(program: Compiler) { +fn mut_success(program: Compiler) { let mut cs = TestConstraintSystem::::new(); let output = program.compile_constraints(&mut cs).unwrap(); assert!(cs.is_satisfied()); assert_eq!( - ConstrainedValue::::Return(vec![ConstrainedValue::Integer( - Integer::U32(UInt32::constant(0)) - )]), + ConstrainedValue::::Return(vec![ConstrainedValue::Integer(Integer::U32( + UInt32::constant(0) + ))]), output ); } -fn mut_fail(program: Compiler) { +fn mut_fail(program: Compiler) { let mut cs = TestConstraintSystem::::new(); let err = program.compile_constraints(&mut cs).unwrap_err(); diff --git a/leo/commands/build.rs b/leo/commands/build.rs index db8cd89f6c..5985c1dcf0 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -5,10 +5,7 @@ use crate::{cli::*, cli_types::*}; use leo_compiler::compiler::Compiler; use snarkos_algorithms::snark::KeypairAssembly; -use snarkos_curves::{ - bls12_377::{Bls12_377, Fr}, - edwards_bls12::EdwardsProjective -}; +use snarkos_curves::bls12_377::{Bls12_377, Fr}; use clap::ArgMatches; use std::convert::TryFrom; @@ -19,7 +16,7 @@ pub struct BuildCommand; impl CLI for BuildCommand { type Options = (); - type Output = (Compiler, bool); + type Output = (Compiler, bool); const NAME: NameType = "build"; const ABOUT: AboutType = "Compile the current package as a program"; @@ -63,7 +60,7 @@ impl CLI for BuildCommand { main_file_path.push(MAIN_FILE_NAME); // Compute the current program checksum - let program = Compiler::::init(package_name.clone(), main_file_path.clone())?; + let program = Compiler::::init(package_name.clone(), main_file_path.clone())?; let program_checksum = program.checksum()?; // Generate the program on the constraint system and verify correctness diff --git a/leo/commands/deploy.rs b/leo/commands/deploy.rs index 60184daacd..f93a9feeb2 100644 --- a/leo/commands/deploy.rs +++ b/leo/commands/deploy.rs @@ -1,7 +1,7 @@ -use crate::{cli::*, cli_types::*}; use crate::commands::BuildCommand; use crate::errors::CLIError; use crate::files::Manifest; +use crate::{cli::*, cli_types::*}; use clap::ArgMatches; use std::convert::TryFrom; diff --git a/leo/commands/load.rs b/leo/commands/load.rs index 9631b4b2e3..00e9e8cd76 100644 --- a/leo/commands/load.rs +++ b/leo/commands/load.rs @@ -1,7 +1,7 @@ -use crate::{cli::*, cli_types::*}; use crate::commands::BuildCommand; use crate::errors::CLIError; use crate::files::Manifest; +use crate::{cli::*, cli_types::*}; use clap::ArgMatches; use std::convert::TryFrom; diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index 1923952d5b..122e0004b8 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -1,7 +1,7 @@ -use crate::{cli::*, cli_types::*}; use crate::commands::SetupCommand; use crate::errors::CLIError; use crate::files::{Manifest, ProofFile}; +use crate::{cli::*, cli_types::*}; use snarkos_algorithms::snark::{create_random_proof, Proof}; use snarkos_curves::bls12_377::Bls12_377; @@ -45,7 +45,10 @@ impl CLI for ProveCommand { let rng = &mut thread_rng(); let program_proof = create_random_proof(program, ¶meters, rng).unwrap(); - log::info!("Prover completed in {:?} milliseconds", start.elapsed().as_millis()); + log::info!( + "Prover completed in {:?} milliseconds", + start.elapsed().as_millis() + ); // Write the proof file to the outputs directory let mut proof = vec![]; diff --git a/leo/commands/publish.rs b/leo/commands/publish.rs index 11bf07b239..8d52b2d319 100644 --- a/leo/commands/publish.rs +++ b/leo/commands/publish.rs @@ -1,7 +1,7 @@ -use crate::{cli::*, cli_types::*}; use crate::commands::BuildCommand; use crate::errors::CLIError; use crate::files::Manifest; +use crate::{cli::*, cli_types::*}; use clap::ArgMatches; use std::convert::TryFrom; diff --git a/leo/commands/run.rs b/leo/commands/run.rs index f8997b68f4..6175e2a161 100644 --- a/leo/commands/run.rs +++ b/leo/commands/run.rs @@ -1,4 +1,4 @@ -use crate::commands::{SetupCommand, ProveCommand}; +use crate::commands::{ProveCommand, SetupCommand}; use crate::errors::CLIError; use crate::{cli::*, cli_types::*}; diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index eb4c3e4cc3..ab1264d5e8 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -1,16 +1,13 @@ -use crate::{cli::*, cli_types::*}; use crate::commands::BuildCommand; use crate::errors::{CLIError, VerificationKeyFileError}; use crate::files::{Manifest, ProvingKeyFile, VerificationKeyFile}; +use crate::{cli::*, cli_types::*}; use leo_compiler::compiler::Compiler; use snarkos_algorithms::snark::{ generate_random_parameters, prepare_verifying_key, Parameters, PreparedVerifyingKey, }; -use snarkos_curves::{ - bls12_377::{Bls12_377, Fr}, - edwards_bls12::EdwardsProjective -}; +use snarkos_curves::bls12_377::{Bls12_377, Fr}; use snarkos_utilities::bytes::ToBytes; use clap::ArgMatches; @@ -25,7 +22,7 @@ pub struct SetupCommand; impl CLI for SetupCommand { type Options = (); type Output = ( - Compiler, + Compiler, Parameters, PreparedVerifyingKey, ); @@ -66,7 +63,10 @@ impl CLI for SetupCommand { let prepared_verifying_key = prepare_verifying_key::(¶meters.vk); // End the timer - log::info!("Setup completed in {:?} milliseconds", start.elapsed().as_millis()); + log::info!( + "Setup completed in {:?} milliseconds", + start.elapsed().as_millis() + ); // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. // Write the proving key file to the outputs directory @@ -95,10 +95,13 @@ impl CLI for SetupCommand { prepared_verifying_key.write(&mut verification_key)?; // Check that the constructed prepared verification key matches the stored verification key - let compare: Vec<(u8, u8)> = verification_key.into_iter().zip(stored_vk.into_iter()).collect(); + let compare: Vec<(u8, u8)> = verification_key + .into_iter() + .zip(stored_vk.into_iter()) + .collect(); for (a, b) in compare { if a != b { - return Err(VerificationKeyFileError::IncorrectVerificationKey.into()) + return Err(VerificationKeyFileError::IncorrectVerificationKey.into()); } } } diff --git a/leo/commands/unload.rs b/leo/commands/unload.rs index 69d8472b91..6384a9aed1 100644 --- a/leo/commands/unload.rs +++ b/leo/commands/unload.rs @@ -1,7 +1,7 @@ -use crate::{cli::*, cli_types::*}; use crate::commands::BuildCommand; use crate::errors::CLIError; use crate::files::Manifest; +use crate::{cli::*, cli_types::*}; use clap::ArgMatches; use std::convert::TryFrom; diff --git a/leo/files/checksum.rs b/leo/files/checksum.rs index 6c8318a699..89e171e34c 100644 --- a/leo/files/checksum.rs +++ b/leo/files/checksum.rs @@ -31,7 +31,10 @@ impl ChecksumFile { pub fn read_from(&self, path: &PathBuf) -> Result { let path = self.setup_file_path(path); - Ok(fs::read_to_string(&path).map_err(|_| ChecksumFileError::FileReadError(path.clone()))?) + Ok( + fs::read_to_string(&path) + .map_err(|_| ChecksumFileError::FileReadError(path.clone()))?, + ) } /// Writes the given checksum to a file. @@ -52,7 +55,10 @@ impl ChecksumFile { if !path.ends_with(OUTPUTS_DIRECTORY_NAME) { path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); } - path.push(PathBuf::from(format!("{}{}", self.package_name, CHECKSUM_FILE_EXTENSION))); + path.push(PathBuf::from(format!( + "{}{}", + self.package_name, CHECKSUM_FILE_EXTENSION + ))); } path } diff --git a/leo/files/proof.rs b/leo/files/proof.rs index 326d5eb6b4..03c01b59c8 100644 --- a/leo/files/proof.rs +++ b/leo/files/proof.rs @@ -31,7 +31,8 @@ impl ProofFile { pub fn read_from(&self, path: &PathBuf) -> Result { let path = self.setup_file_path(path); - let proof = fs::read_to_string(&path).map_err(|_| ProofFileError::FileReadError(path.clone()))?; + let proof = + fs::read_to_string(&path).map_err(|_| ProofFileError::FileReadError(path.clone()))?; Ok(proof) } @@ -53,7 +54,10 @@ impl ProofFile { if !path.ends_with(OUTPUTS_DIRECTORY_NAME) { path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); } - path.push(PathBuf::from(format!("{}{}", self.package_name, PROOF_FILE_EXTENSION))); + path.push(PathBuf::from(format!( + "{}{}", + self.package_name, PROOF_FILE_EXTENSION + ))); } path } diff --git a/leo/files/proving_key.rs b/leo/files/proving_key.rs index 6d9ae3d1a2..7272848961 100644 --- a/leo/files/proving_key.rs +++ b/leo/files/proving_key.rs @@ -52,7 +52,10 @@ impl ProvingKeyFile { if !path.ends_with(OUTPUTS_DIRECTORY_NAME) { path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); } - path.push(PathBuf::from(format!("{}{}", self.package_name, PROVING_KEY_FILE_EXTENSION))); + path.push(PathBuf::from(format!( + "{}{}", + self.package_name, PROVING_KEY_FILE_EXTENSION + ))); } path } diff --git a/leo/files/verification_key.rs b/leo/files/verification_key.rs index eb593af57b..c60f6be5ee 100644 --- a/leo/files/verification_key.rs +++ b/leo/files/verification_key.rs @@ -35,7 +35,11 @@ impl VerificationKeyFile { } /// Writes the given verification key to a file. - pub fn write_to(&self, path: &PathBuf, verification_key: &[u8]) -> Result<(), VerificationKeyFileError> { + pub fn write_to( + &self, + path: &PathBuf, + verification_key: &[u8], + ) -> Result<(), VerificationKeyFileError> { let path = self.setup_file_path(path); let mut file = File::create(&path)?; @@ -52,7 +56,10 @@ impl VerificationKeyFile { if !path.ends_with(OUTPUTS_DIRECTORY_NAME) { path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); } - path.push(PathBuf::from(format!("{}{}", self.package_name, VERIFICATION_KEY_FILE_EXTENSION))); + path.push(PathBuf::from(format!( + "{}{}", + self.package_name, VERIFICATION_KEY_FILE_EXTENSION + ))); } path }