2020-07-06 14:59:06 +03:00
|
|
|
pub mod address;
|
2020-06-20 09:02:58 +03:00
|
|
|
pub mod array;
|
2020-05-20 01:45:40 +03:00
|
|
|
pub mod boolean;
|
2020-06-20 09:02:58 +03:00
|
|
|
pub mod circuits;
|
|
|
|
pub mod field;
|
|
|
|
pub mod function;
|
|
|
|
pub mod group;
|
|
|
|
pub mod import;
|
2020-06-18 01:40:39 +03:00
|
|
|
pub mod inputs;
|
2020-06-20 09:02:58 +03:00
|
|
|
pub mod integers;
|
2020-07-10 05:23:15 +03:00
|
|
|
pub mod macros;
|
2020-06-20 09:02:58 +03:00
|
|
|
pub mod mutability;
|
2020-06-20 05:04:13 +03:00
|
|
|
pub mod statements;
|
2020-06-20 01:47:09 +03:00
|
|
|
pub mod syntax;
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-02 04:35:43 +03:00
|
|
|
use leo_compiler::{
|
2020-06-03 02:06:25 +03:00
|
|
|
compiler::Compiler,
|
2020-06-09 04:39:10 +03:00
|
|
|
errors::{CompilerError, FunctionError, StatementError},
|
2020-07-08 05:53:37 +03:00
|
|
|
group::targets::edwards_bls12::EdwardsGroupType,
|
2020-06-02 04:35:43 +03:00
|
|
|
ConstrainedValue,
|
|
|
|
};
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-02 03:52:33 +03:00
|
|
|
use snarkos_curves::edwards_bls12::Fq;
|
2020-05-20 01:45:40 +03:00
|
|
|
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
2020-06-23 08:32:57 +03:00
|
|
|
use std::path::PathBuf;
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
|
2020-06-02 03:52:33 +03:00
|
|
|
pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
|
2020-05-30 03:34:31 +03:00
|
|
|
|
|
|
|
pub(crate) fn get_output(program: EdwardsTestCompiler) -> EdwardsConstrainedValue {
|
2020-05-30 02:43:39 +03:00
|
|
|
let mut cs = TestConstraintSystem::<Fq>::new();
|
2020-05-20 01:45:40 +03:00
|
|
|
let output = program.compile_constraints(&mut cs).unwrap();
|
|
|
|
assert!(cs.is_satisfied());
|
|
|
|
output
|
|
|
|
}
|
|
|
|
|
2020-05-30 03:34:31 +03:00
|
|
|
pub(crate) fn get_error(program: EdwardsTestCompiler) -> CompilerError {
|
2020-05-30 02:43:39 +03:00
|
|
|
let mut cs = TestConstraintSystem::<Fq>::new();
|
2020-05-20 01:45:40 +03:00
|
|
|
program.compile_constraints(&mut cs).unwrap_err()
|
|
|
|
}
|
|
|
|
|
2020-06-09 04:39:10 +03:00
|
|
|
pub(crate) fn fail_enforce(program: EdwardsTestCompiler) {
|
|
|
|
match get_error(program) {
|
2020-06-20 05:04:13 +03:00
|
|
|
CompilerError::FunctionError(FunctionError::StatementError(StatementError::Error(_))) => {}
|
2020-06-09 04:39:10 +03:00
|
|
|
error => panic!("Expected evaluate error, got {}", error),
|
|
|
|
}
|
|
|
|
}
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-21 01:24:46 +03:00
|
|
|
fn new_compiler() -> EdwardsTestCompiler {
|
|
|
|
let program_name = "test".to_string();
|
2020-06-23 08:32:57 +03:00
|
|
|
let path = PathBuf::from("/test/src/main.leo");
|
2020-07-29 23:20:44 +03:00
|
|
|
let mut compiler = EdwardsTestCompiler::new(program_name, path);
|
2020-06-21 01:24:46 +03:00
|
|
|
|
2020-06-23 08:32:57 +03:00
|
|
|
compiler
|
2020-06-21 01:24:46 +03:00
|
|
|
}
|
|
|
|
|
2020-06-09 03:28:09 +03:00
|
|
|
pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
|
2020-06-21 01:24:46 +03:00
|
|
|
let mut compiler = new_compiler();
|
2020-06-09 03:28:09 +03:00
|
|
|
let program_string = String::from_utf8_lossy(bytes);
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-09 03:28:09 +03:00
|
|
|
compiler.parse_program(&program_string)?;
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-09 03:28:09 +03:00
|
|
|
Ok(compiler)
|
2020-05-19 22:01:19 +03:00
|
|
|
}
|
2020-06-11 21:43:05 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
pub(crate) fn parse_inputs(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
|
2020-06-21 01:24:46 +03:00
|
|
|
let mut compiler = new_compiler();
|
2020-06-20 09:02:58 +03:00
|
|
|
let inputs_string = String::from_utf8_lossy(bytes);
|
|
|
|
|
2020-06-20 08:07:02 +03:00
|
|
|
compiler.parse_inputs(&inputs_string)?;
|
2020-06-11 21:43:05 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
Ok(compiler)
|
2020-06-11 21:43:05 +03:00
|
|
|
}
|