diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 55da44d852..b177bf67af 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -92,8 +92,7 @@ impl> Compiler { fn load_program(&mut self) -> Result { // Load the program syntax tree from the file path - let file_path = &self.main_file_path; - Ok(LeoParser::load_file(file_path)?) + Ok(LeoParser::load_file(&self.main_file_path)?) } pub fn parse_program(&mut self, program_string: &str) -> Result<(), CompilerError> { @@ -111,16 +110,10 @@ impl> Compiler { Ok(()) } - pub fn parse_inputs(&mut self, file_path: &PathBuf) -> Result<(), CompilerError> { - let mut path = file_path.clone(); - path.push("inputs"); - path.push("inputs.leo"); + pub fn parse_inputs(&mut self, input_file_path: &PathBuf, input_file_string: &str) -> Result<(), CompilerError> { + let syntax_tree = LeoInputsParser::parse_file(input_file_path, input_file_string)?; - let input_file = &LeoInputsParser::load_file(&path)?; - let syntax_tree = LeoInputsParser::parse_file(&path, input_file)?; - // println!("{:?}", syntax_tree); - - // Check number of private parameters here + // Check number/order of private parameters here self.program_inputs = Inputs::from_inputs_file(syntax_tree)?; Ok(()) diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 9898b6c53d..283afeb561 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -19,6 +19,7 @@ use leo_compiler::{ use snarkos_curves::edwards_bls12::Fq; use snarkos_models::gadgets::r1cs::TestConstraintSystem; +use std::path::PathBuf; pub type EdwardsTestCompiler = Compiler; pub type EdwardsConstrainedValue = ConstrainedValue; @@ -51,3 +52,13 @@ pub(crate) fn parse_program(bytes: &[u8]) -> Result Result { + let program_string = String::from_utf8_lossy(bytes); + + let mut compiler = EdwardsTestCompiler::new(); + + compiler.parse_inputs(&PathBuf::new(), &program_string)?; + + Ok(compiler) +} diff --git a/compiler/tests/syntax/inputs_semicolon.leo b/compiler/tests/syntax/inputs_semicolon.leo new file mode 100644 index 0000000000..9054049169 --- /dev/null +++ b/compiler/tests/syntax/inputs_semicolon.leo @@ -0,0 +1,2 @@ +[main] +a: private u32 = 5 \ No newline at end of file diff --git a/compiler/tests/syntax/mod.rs b/compiler/tests/syntax/mod.rs index 4cf5ec5f0b..7d5630760c 100644 --- a/compiler/tests/syntax/mod.rs +++ b/compiler/tests/syntax/mod.rs @@ -1,6 +1,7 @@ -use crate::parse_program; +use crate::{parse_inputs, parse_program}; use leo_ast::ParserError; use leo_compiler::errors::CompilerError; +use leo_inputs::InputParserError; #[test] fn test_semicolon() { @@ -12,3 +13,14 @@ fn test_semicolon() { _ => panic!("test_semicolon failed the wrong expected error, should be a ParserError"), } } + +#[test] +fn inputs_syntax_error() { + let bytes = include_bytes!("inputs_semicolon.leo"); + let error = parse_inputs(bytes).err().unwrap(); + + match error { + CompilerError::InputParserError(InputParserError::SyntaxError(_)) => {} + _ => panic!("inputs syntax error should be a ParserError"), + } +} diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index 07c49ffaf1..1bc244ad1b 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -9,8 +9,10 @@ use crate::{ use snarkos_algorithms::snark::{create_random_proof, PreparedVerifyingKey, Proof}; use snarkos_curves::bls12_377::Bls12_377; +use crate::{directories::INPUTS_DIRECTORY_NAME, files::INPUTS_FILE_NAME}; use clap::ArgMatches; use leo_compiler::{compiler::Compiler, edwards_bls12::EdwardsGroupType}; +use leo_inputs::LeoInputsParser; use rand::thread_rng; use snarkos_curves::edwards_bls12::Fq; use std::{convert::TryFrom, env::current_dir, time::Instant}; @@ -46,8 +48,14 @@ impl CLI for ProveCommand { let path = current_dir()?; let package_name = Manifest::try_from(&path)?.get_package_name(); + // Construct the path to the inputs file in the inputs directory + let mut inputs_file_path = path.clone(); + inputs_file_path.push(INPUTS_DIRECTORY_NAME); + inputs_file_path.push(INPUTS_FILE_NAME); + // Fetch private inputs here - program.parse_inputs(&path)?; + let inputs_file_string = LeoInputsParser::load_file(&inputs_file_path)?; + program.parse_inputs(&inputs_file_path, &inputs_file_string)?; // Start the timer let start = Instant::now(); diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index 007d2cffaf..53599b83cc 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -57,6 +57,12 @@ impl From for CLIError { } } +impl From for CLIError { + fn from(error: leo_inputs::errors::InputParserError) -> Self { + CLIError::Crate("leo_inputs", format!("{}", error)) + } +} + impl From for CLIError { fn from(error: snarkos_errors::gadgets::SynthesisError) -> Self { CLIError::Crate("snarkos_errors", format!("{}", error)) diff --git a/types/src/inputs/input_fields.rs b/types/src/inputs/input_fields.rs index fb7806e243..30f3324b55 100644 --- a/types/src/inputs/input_fields.rs +++ b/types/src/inputs/input_fields.rs @@ -1,5 +1,6 @@ use crate::InputValue; use leo_inputs::{types::IntegerType, InputParserError}; + use snarkos_models::curves::{Field, PairingEngine}; use std::str::FromStr; diff --git a/types/src/inputs/input_value.rs b/types/src/inputs/input_value.rs index 776a17e75c..dbc16ed44f 100644 --- a/types/src/inputs/input_value.rs +++ b/types/src/inputs/input_value.rs @@ -5,6 +5,7 @@ use leo_inputs::{ types::{ArrayType, DataType, IntegerType, Type}, values::{BooleanValue, FieldValue, GroupValue, NumberImplicitValue, NumberValue, Value}, }; + use snarkos_models::curves::PairingEngine; use std::fmt; diff --git a/types/src/inputs/inputs.rs b/types/src/inputs/inputs.rs index 028bea0d68..dc08c30e98 100644 --- a/types/src/inputs/inputs.rs +++ b/types/src/inputs/inputs.rs @@ -1,5 +1,6 @@ use crate::InputValue; use leo_inputs::{common::visibility::Visibility, files::File, InputParserError}; + use snarkos_models::curves::PairingEngine; #[derive(Clone)]