Merge pull request #128 from AleoHQ/rename/input

Migrates Leo 'main' function to require 'input'
This commit is contained in:
Howard Wu 2020-08-02 20:26:27 -07:00 committed by GitHub
commit 0e4ea5c0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
239 changed files with 1276 additions and 1123 deletions

View File

@ -94,7 +94,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --release --all --no-fail-fast
args: --release --all --features ci_skip --no-fail-fast
codecov:
name: Code Coverage
@ -123,7 +123,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --all
args: --all --features ci_skip
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
CARGO_INCREMENTAL: "0"
@ -143,7 +143,7 @@ jobs:
make install DESTDIR=../../kcov-build
cd ../..
rm -rf kcov-master
for file in target/debug/deps/*-*; do if [[ "$file" != *\.* ]]; then mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; fi done
for file in target/debug/deps/*-*; do if [[ "$file" != *\.* ]]; then mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --exclude-region='@kcov_skip(start):@kcov_skip(end)' --verify "target/cov/$(basename $file)" "$file"; fi done
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1

220
Cargo.lock generated
View File

@ -134,6 +134,24 @@ dependencies = [
"byte-tools",
]
[[package]]
name = "bstr"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "bumpalo"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "byte-tools"
version = "0.3.1"
@ -167,6 +185,15 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "cast"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0"
dependencies = [
"rustc_version",
]
[[package]]
name = "cc"
version = "1.0.58"
@ -241,6 +268,42 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "criterion"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70daa7ceec6cf143990669a04c7df13391d55fb27bd4079d252fca774ba244d8"
dependencies = [
"atty",
"cast",
"clap",
"criterion-plot",
"csv",
"itertools 0.9.0",
"lazy_static",
"num-traits",
"oorandom",
"plotters",
"rayon",
"regex",
"serde",
"serde_cbor",
"serde_derive",
"serde_json",
"tinytemplate",
"walkdir",
]
[[package]]
name = "criterion-plot"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e022feadec601fba1649cfa83586381a4ad31c6bf3a9ab7d408118b05dd9889d"
dependencies = [
"cast",
"itertools 0.9.0",
]
[[package]]
name = "crossbeam-deque"
version = "0.7.3"
@ -299,6 +362,28 @@ dependencies = [
"subtle",
]
[[package]]
name = "csv"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279"
dependencies = [
"bstr",
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "derivative"
version = "2.1.1"
@ -464,6 +549,12 @@ version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
[[package]]
name = "half"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177"
[[package]]
name = "hashbrown"
version = "0.8.1"
@ -531,6 +622,15 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "js-sys"
version = "0.3.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "jsonrpc-core"
version = "14.2.0"
@ -560,7 +660,7 @@ dependencies = [
"from-pest",
"leo-compiler",
"leo-gadgets",
"leo-inputs",
"leo-input",
"log",
"rand",
"rand_core",
@ -583,6 +683,7 @@ dependencies = [
name = "leo-ast"
version = "0.1.0"
dependencies = [
"criterion",
"from-pest",
"lazy_static",
"log",
@ -602,7 +703,7 @@ dependencies = [
"hex",
"leo-ast",
"leo-gadgets",
"leo-inputs",
"leo-input",
"leo-types",
"log",
"num-bigint",
@ -634,7 +735,7 @@ dependencies = [
]
[[package]]
name = "leo-inputs"
name = "leo-input"
version = "0.1.0"
dependencies = [
"from-pest",
@ -658,7 +759,7 @@ name = "leo-types"
version = "0.1.0"
dependencies = [
"leo-ast",
"leo-inputs",
"leo-input",
"pest",
"serde",
"serde_json",
@ -775,6 +876,12 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
[[package]]
name = "oorandom"
version = "11.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c"
[[package]]
name = "opaque-debug"
version = "0.2.3"
@ -849,6 +956,18 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "plotters"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d1685fbe7beba33de0330629da9d955ac75bd54f33d7b79f9a895590124f6bb"
dependencies = [
"js-sys",
"num-traits",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "podio"
version = "0.1.7"
@ -990,6 +1109,15 @@ dependencies = [
"thread_local",
]
[[package]]
name = "regex-automata"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4"
dependencies = [
"byteorder",
]
[[package]]
name = "regex-syntax"
version = "0.6.18"
@ -1068,6 +1196,16 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde_cbor"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622"
dependencies = [
"half",
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.114"
@ -1392,6 +1530,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "tinytemplate"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d3dc76004a03cec1c5932bca4cdc2e39aaa798e3f82363dd94f9adf6098c12f"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "toml"
version = "0.5.6"
@ -1466,6 +1614,70 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-bindgen"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2 1.0.19",
"quote 1.0.7",
"syn 1.0.36",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2"
dependencies = [
"quote 1.0.7",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556"
dependencies = [
"proc-macro2 1.0.19",
"quote 1.0.7",
"syn 1.0.36",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092"
[[package]]
name = "web-sys"
version = "0.3.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -13,12 +13,12 @@ name = "leo"
path = "leo/main.rs"
[workspace]
members = [ "ast", "compiler", "gadgets", "leo-inputs", "linter", "types" ]
members = [ "ast", "compiler", "gadgets", "leo-input", "linter", "types" ]
[dependencies]
leo-compiler = { path = "compiler", version = "0.1.0" }
leo-gadgets = { path = "gadgets", version = "0.1.0" }
leo-inputs = { path = "leo-inputs", version = "0.1.0" }
leo-input = { path = "leo-input", version = "0.1.0" }
snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-algorithms", default-features = false }
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false }
@ -44,6 +44,10 @@ zip = { version = "0.5" }
[dev-dependencies]
rusty-hook = { version = "0.11.2" }
[features]
default = []
ci_skip = ["leo-compiler/ci_skip"]
[profile.release]
opt-level = 3
lto = "thin"

View File

@ -20,3 +20,8 @@ serde_json = { version = "1.0" }
thiserror = { version = "1.0" }
[dev-dependencies]
criterion = { version = "0.3" }
[features]
default = []
ci_skip = []

View File

@ -1,6 +1,6 @@
use crate::{
ast::Rule,
functions::{FunctionInput, Record, Registers, State, StateLeaf},
functions::{FunctionInput, InputKeyword},
};
use pest_ast::FromPest;
@ -9,9 +9,6 @@ use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::input))]
pub enum Input<'ast> {
InputKeyword(InputKeyword<'ast>),
FunctionInput(FunctionInput<'ast>),
Record(Record<'ast>),
Registers(Registers<'ast>),
State(State<'ast>),
StateLeaf(StateLeaf<'ast>),
}

View File

@ -0,0 +1,18 @@
use crate::{
ast::{span_into_string, Rule},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::input_keyword))]
pub struct InputKeyword<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub keyword: String,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -3,3 +3,6 @@ pub use function_input::*;
pub mod input;
pub use input::*;
pub mod input_keyword;
pub use input_keyword::*;

View File

@ -1,17 +0,0 @@
pub mod function_input;
pub use function_input::*;
pub mod input;
pub use input::*;
pub mod record;
pub use record::*;
pub mod registers;
pub use registers::*;
pub mod state;
pub use state::*;
pub mod state_leaf;
pub use state_leaf::*;

View File

@ -1,13 +0,0 @@
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::record))]
pub struct Record<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +0,0 @@
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::registers))]
pub struct Registers<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +0,0 @@
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::state))]
pub struct State<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +0,0 @@
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::state_leaf))]
pub struct StateLeaf<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,8 +1,8 @@
pub mod function;
pub use function::*;
pub mod inputs;
pub use inputs::*;
pub mod input;
pub use input::*;
pub mod test_function;
pub use test_function::*;

View File

@ -337,27 +337,15 @@ statement_return = { "return " ~ return_}
// Declared in functions/function.rs
function_definition = { "function " ~ identifier ~ "(" ~ NEWLINE* ~ input_list ~ NEWLINE* ~ ")" ~ ("->" ~ (type_ | "(" ~ type_list ~ ")"))? ~ "{" ~ NEWLINE* ~ statement* ~ NEWLINE* ~ "}" ~ NEWLINE* }
// Declared in functions/inputs/function_input.rs
// Declared in functions/input/function_input.rs
function_input = { mutable? ~ identifier ~ ":" ~ type_ }
// Declared in functions/inputs/record.rs
record = { "record" }
// Declared in functions/input/input_keyword.rs
input_keyword = { "input" }
// Declared in functions/inputs/registers.rs
registers = { "registers" }
// Declared in functions/inputs/state.rs
state = { "state" }
// Declared in functions/inputs/state_leaf.rs
state_leaf = { "state_leaf" }
// Declared in functions/inputs/input.rs
// Declared in functions/input/input.rs
input = {
record
| registers
| state_leaf
| state
input_keyword
| function_input
}
input_list = _{ (input ~ ("," ~ NEWLINE* ~ input)*)? }

View File

@ -3,7 +3,8 @@ use leo_ast::LeoAst;
use std::path::PathBuf;
#[test]
fn test_serialization() {
#[cfg(not(feature = "ci_skip"))]
fn test_serialize() {
let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
program_filepath.push("tests/serialization/main.leo");

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
leo-ast = { path = "../ast", version = "0.1.0" }
leo-gadgets = { path = "../gadgets", version = "0.1.0" }
leo-inputs = { path = "../leo-inputs", version = "0.1.0" }
leo-input = { path = "../leo-input", version = "0.1.0" }
leo-types = { path = "../types", version = "0.1.0" }
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false }
@ -30,3 +30,7 @@ thiserror = { version = "1.0" }
[dev-dependencies]
num-bigint = { version = "0.3" }
[features]
default = []
ci_skip = ["leo-ast/ci_skip", "leo-types/ci_skip"]

View File

@ -6,11 +6,11 @@ use crate::{
GroupType,
ImportParser,
OutputBytes,
OutputsFile,
OutputFile,
};
use leo_ast::LeoAst;
use leo_inputs::LeoInputsParser;
use leo_types::{Inputs, LeoTypedAst, MainInputs, Program};
use leo_input::LeoInputParser;
use leo_types::{Input, LeoTypedAst, MainInput, Program};
use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{
@ -25,22 +25,22 @@ use std::{fs, marker::PhantomData, path::PathBuf};
pub struct Compiler<F: Field + PrimeField, G: GroupType<F>> {
package_name: String,
main_file_path: PathBuf,
outputs_directory: PathBuf,
output_directory: PathBuf,
program: Program,
program_inputs: Inputs,
program_input: Input,
imported_programs: ImportParser,
_engine: PhantomData<F>,
_group: PhantomData<G>,
}
impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
pub fn new(package_name: String, main_file_path: PathBuf, outputs_directory: PathBuf) -> Self {
pub fn new(package_name: String, main_file_path: PathBuf, output_directory: PathBuf) -> Self {
Self {
package_name: package_name.clone(),
main_file_path,
outputs_directory,
output_directory,
program: Program::new(package_name),
program_inputs: Inputs::new(),
program_input: Input::new(),
imported_programs: ImportParser::new(),
_engine: PhantomData,
_group: PhantomData,
@ -48,25 +48,25 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
}
/// Parse the input and state files.
/// Stores a typed ast of all inputs to the program.
pub fn parse_inputs(&mut self, inputs_string: &str, state_string: &str) -> Result<(), CompilerError> {
let inputs_syntax_tree = LeoInputsParser::parse_file(&inputs_string)?;
let state_syntax_tree = LeoInputsParser::parse_file(&state_string)?;
/// Stores a typed ast of all input variables to the program.
pub fn parse_input(&mut self, input_string: &str, state_string: &str) -> Result<(), CompilerError> {
let input_syntax_tree = LeoInputParser::parse_file(&input_string)?;
let state_syntax_tree = LeoInputParser::parse_file(&state_string)?;
self.program_inputs.parse_inputs(inputs_syntax_tree)?;
self.program_inputs.parse_state(state_syntax_tree)?;
self.program_input.parse_input(input_syntax_tree)?;
self.program_input.parse_state(state_syntax_tree)?;
Ok(())
}
/// Parses program files.
/// Returns a compiler struct that stores the typed program abstract syntax trees (ast).
pub fn parse_program_without_inputs(
pub fn parse_program_without_input(
package_name: String,
main_file_path: PathBuf,
outputs_directory: PathBuf,
output_directory: PathBuf,
) -> Result<Self, CompilerError> {
let mut compiler = Self::new(package_name, main_file_path, outputs_directory);
let mut compiler = Self::new(package_name, main_file_path, output_directory);
compiler.parse_program()?;
@ -74,24 +74,24 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
}
/// Parses input, state, and program files.
/// Returns a compiler struct that stores the typed inputs and typed program abstract syntax trees (ast).
pub fn parse_program_with_inputs(
/// Returns a compiler struct that stores the typed input and typed program abstract syntax trees (ast).
pub fn parse_program_with_input(
package_name: String,
main_file_path: PathBuf,
outputs_directory: PathBuf,
inputs_string: &str,
output_directory: PathBuf,
input_string: &str,
state_string: &str,
) -> Result<Self, CompilerError> {
let mut compiler = Self::new(package_name, main_file_path, outputs_directory);
let mut compiler = Self::new(package_name, main_file_path, output_directory);
compiler.parse_inputs(inputs_string, state_string)?;
compiler.parse_input(input_string, state_string)?;
compiler.parse_program()?;
Ok(compiler)
}
/// Parses the Leo program file, constructs a syntax tree, and generates a program.
pub fn parse_program(&mut self) -> Result<(), CompilerError> {
pub(crate) fn parse_program(&mut self) -> Result<(), CompilerError> {
// Use the parser to construct the abstract syntax tree.
let program_string = LeoAst::load_file(&self.main_file_path)?;
@ -119,9 +119,9 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
Ok(())
}
/// Manually sets main function inputs
pub fn set_main_inputs(&mut self, inputs: MainInputs) {
self.program_inputs.set_main_inputs(inputs);
/// Manually sets main function input
pub fn set_main_input(&mut self, input: MainInput) {
self.program_input.set_main_input(input);
}
pub fn checksum(&self) -> Result<String, CompilerError> {
@ -137,21 +137,21 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
Ok(hex::encode(hash))
}
/// Synthesizes the circuit without program inputs to verify correctness.
/// Synthesizes the circuit without program input to verify correctness.
pub fn compile_constraints<CS: ConstraintSystem<F>>(self, cs: &mut CS) -> Result<OutputBytes, CompilerError> {
let path = self.main_file_path;
let inputs = self.program_inputs.empty();
let input = self.program_input.empty();
generate_constraints::<F, G, CS>(cs, self.program, inputs, &self.imported_programs).map_err(|mut error| {
generate_constraints::<F, G, CS>(cs, self.program, input, &self.imported_programs).map_err(|mut error| {
error.set_path(path);
error
})
}
/// Synthesizes the circuit for test functions with program inputs.
/// Synthesizes the circuit for test functions with program input.
pub fn compile_test_constraints(self, cs: &mut TestConstraintSystem<F>) -> Result<(), CompilerError> {
generate_test_constraints::<F, G>(cs, self.program, self.program_inputs, &self.imported_programs)
generate_test_constraints::<F, G>(cs, self.program, self.program_input, &self.imported_programs)
}
/// Calls the internal generate_constraints method with arguments
@ -160,7 +160,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
cs: &mut CS,
) -> Result<OutputBytes, CompilerError> {
let path = self.main_file_path;
generate_constraints::<_, G, _>(cs, self.program, self.program_inputs, &self.imported_programs).map_err(
generate_constraints::<_, G, _>(cs, self.program, self.program_input, &self.imported_programs).map_err(
|mut error| {
error.set_path(path);
error
@ -174,14 +174,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
pub fn from_bytes(bytes: &[u8]) -> Result<Self, CompilerError> {
let program: Program = bincode::deserialize(bytes)?;
let program_inputs = Inputs::new();
let program_input = Input::new();
Ok(Self {
package_name: program.name.clone(),
main_file_path: PathBuf::new(),
outputs_directory: PathBuf::new(),
output_directory: PathBuf::new(),
program,
program_inputs,
program_input,
imported_programs: ImportParser::new(),
_engine: PhantomData,
_group: PhantomData,
@ -190,9 +190,9 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
}
impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<F, G> {
/// Synthesizes the circuit with program inputs.
/// Synthesizes the circuit with program input.
fn generate_constraints<CS: ConstraintSystem<F>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
let outputs_directory = self.outputs_directory.clone();
let output_directory = self.output_directory.clone();
let package_name = self.package_name.clone();
let result = self.generate_constraints_helper(cs).map_err(|e| {
log::error!("{}", e);
@ -202,8 +202,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compil
log::info!("Program circuit successfully synthesized!");
// Write results to file
let outputs_file = OutputsFile::new(&package_name);
outputs_file.write(&outputs_directory, result.bytes()).unwrap();
let output_file = OutputFile::new(&package_name);
output_file.write(&output_directory, result.bytes()).unwrap();
Ok(())
}

View File

@ -9,7 +9,7 @@ use crate::{
ImportParser,
OutputBytes,
};
use leo_types::{Inputs, Program};
use leo_types::{Input, Program};
use snarkos_models::{
curves::{Field, PrimeField},
@ -19,7 +19,7 @@ use snarkos_models::{
pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
cs: &mut CS,
program: Program,
inputs: Inputs,
input: Input,
imported_programs: &ImportParser,
) -> Result<OutputBytes, CompilerError> {
let mut resolved_program = ConstrainedProgram::<F, G>::new();
@ -34,7 +34,7 @@ pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: Constrai
match main.clone() {
ConstrainedValue::Function(_circuit_identifier, function) => {
let result = resolved_program.enforce_main_function(cs, program_name, function, inputs)?;
let result = resolved_program.enforce_main_function(cs, program_name, function, input)?;
Ok(result)
}
_ => Err(CompilerError::NoMainFunction),
@ -44,7 +44,7 @@ pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: Constrai
pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
cs: &mut TestConstraintSystem<F>,
program: Program,
inputs: Inputs,
input: Input,
imported_programs: &ImportParser,
) -> Result<(), CompilerError> {
let mut resolved_program = ConstrainedProgram::<F, G>::new();
@ -63,7 +63,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
cs,
program_name.clone(),
test_function.0,
inputs.clone(), // pass program inputs into every test
input.clone(), // pass program input into every test
);
if result.is_ok() {

View File

@ -1,6 +1,6 @@
use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputsFileError};
use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError};
use leo_ast::ParserError;
use leo_inputs::InputParserError;
use leo_input::InputParserError;
use bincode::Error as SerdeError;
use std::path::PathBuf;
@ -26,7 +26,7 @@ pub enum CompilerError {
NoMainFunction,
#[error("{}", _0)]
OutputError(#[from] OutputsFileError),
OutputError(#[from] OutputFileError),
#[error("{}", _0)]
OutputStringError(#[from] OutputBytesError),

View File

@ -67,7 +67,7 @@ impl FunctionError {
}
pub fn arguments_length(expected: usize, actual: usize, span: Span) -> Self {
let message = format!("function expected {} inputs, found {} inputs", expected, actual);
let message = format!("function expected {} input variables, found {}", expected, actual);
Self::new_from_span(message, span)
}

View File

@ -1,7 +1,7 @@
use std::{io, path::PathBuf};
#[derive(Debug, Error)]
pub enum OutputsFileError {
pub enum OutputFileError {
#[error("{}: {}", _0, _1)]
Crate(&'static str, String),
@ -15,8 +15,8 @@ pub enum OutputsFileError {
Writing(io::Error),
}
impl From<std::io::Error> for OutputsFileError {
impl From<std::io::Error> for OutputFileError {
fn from(error: std::io::Error) -> Self {
OutputsFileError::Crate("std::io", format!("{}", error))
OutputFileError::Crate("std::io", format!("{}", error))
}
}

View File

@ -7,7 +7,7 @@ use crate::{
GroupType,
};
use leo_types::{Expression, Function, Input, Span};
use leo_types::{Expression, Function, InputVariable, Span};
use snarkos_models::{
curves::{Field, PrimeField},
@ -30,19 +30,31 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
scope: String,
caller_scope: String,
function: Function,
inputs: Vec<Expression>,
input: Vec<Expression>,
) -> Result<ConstrainedValue<F, G>, FunctionError> {
let function_name = new_scope(scope.clone(), function.get_name());
// Make sure we are given the correct number of inputs
check_arguments_length(function.inputs.len(), inputs.len(), function.span.clone())?;
// Make sure we are given the correct number of input variables
check_arguments_length(function.input.len(), input.len(), function.span.clone())?;
// Store input values as new variables in resolved program
for (input_model, input_expression) in function.inputs.clone().iter().zip(inputs.into_iter()) {
for (input_model, input_expression) in function.input.clone().iter().zip(input.into_iter()) {
let (name, value) = match input_model {
Input::FunctionInput(input_model) => {
InputVariable::InputKeyword(identifier) => {
let input_value = self.enforce_function_input(
cs,
scope.clone(),
caller_scope.clone(),
function_name.clone(),
vec![],
input_expression,
)?;
(identifier.name.clone(), input_value)
}
InputVariable::FunctionInput(input_model) => {
// First evaluate input expression
let mut input_value = self.enforce_input(
let mut input_value = self.enforce_function_input(
cs,
scope.clone(),
caller_scope.clone(),
@ -57,54 +69,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
(input_model.identifier.name.clone(), input_value)
}
Input::Registers(identifier) => {
let input_value = self.enforce_input(
cs,
scope.clone(),
caller_scope.clone(),
function_name.clone(),
vec![],
input_expression,
)?;
(identifier.name.clone(), input_value)
}
Input::Record(identifier) => {
let input_value = self.enforce_input(
cs,
scope.clone(),
caller_scope.clone(),
function_name.clone(),
vec![],
input_expression,
)?;
(identifier.name.clone(), input_value)
}
Input::State(identifier) => {
let input_value = self.enforce_input(
cs,
scope.clone(),
caller_scope.clone(),
function_name.clone(),
vec![],
input_expression,
)?;
(identifier.name.clone(), input_value)
}
Input::StateLeaf(identifier) => {
let input_value = self.enforce_input(
cs,
scope.clone(),
caller_scope.clone(),
function_name.clone(),
vec![],
input_expression,
)?;
(identifier.name.clone(), input_value)
}
};
// Store input as variable with {function_name}_{input_name}

View File

@ -10,7 +10,7 @@ use snarkos_models::{
};
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
pub fn enforce_input<CS: ConstraintSystem<F>>(
pub fn enforce_function_input<CS: ConstraintSystem<F>>(
&mut self,
cs: &mut CS,
scope: String,

View File

@ -0,0 +1,71 @@
use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType};
use leo_types::{Identifier, Input};
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::r1cs::ConstraintSystem,
};
pub const RECORD_VARIABLE_NAME: &str = "record";
pub const REGISTERS_VARIABLE_NAME: &str = "registers";
pub const STATE_VARIABLE_NAME: &str = "state";
pub const STATE_LEAF_VARIABLE_NAME: &str = "state_leaf";
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
pub fn allocate_input_keyword<CS: ConstraintSystem<F>>(
&mut self,
cs: &mut CS,
identifier: Identifier,
input: &Input,
) -> Result<ConstrainedValue<F, G>, FunctionError> {
// Create an identifier for each input variable
let registers_name = Identifier {
name: REGISTERS_VARIABLE_NAME.to_string(),
span: identifier.span.clone(),
};
let record_name = Identifier {
name: RECORD_VARIABLE_NAME.to_string(),
span: identifier.span.clone(),
};
let state_name = Identifier {
name: STATE_VARIABLE_NAME.to_string(),
span: identifier.span.clone(),
};
let state_leaf_name = Identifier {
name: STATE_LEAF_VARIABLE_NAME.to_string(),
span: identifier.span.clone(),
};
// Fetch each input variable's definitions
let registers_values = input.get_registers().values();
let record_values = input.get_record().values();
let state_values = input.get_state().values();
let state_leaf_values = input.get_state_leaf().values();
// Allocate each input variable as a circuit expression
let mut sections = vec![];
sections.push((registers_name, registers_values));
sections.push((record_name, record_values));
sections.push((state_name, state_values));
sections.push((state_leaf_name, state_leaf_values));
let mut members = vec![];
for (name, values) in sections {
let member_name = name.clone();
let member_value = self.allocate_input_section(cs, name, values)?;
let member = ConstrainedCircuitMember(member_name, member_value);
members.push(member)
}
// Return input variable keyword as circuit expression
Ok(ConstrainedValue::CircuitExpression(identifier, members))
}
}

View File

@ -16,7 +16,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
) -> Result<ConstrainedValue<F, G>, FunctionError> {
let mut members = vec![];
// Store each section definition as a circuit member value
// Allocate each section definition as a circuit member value
for (parameter, option) in section.into_iter() {
let member_name = parameter.variable.clone();
let member_value = self.allocate_main_function_input(
@ -32,6 +33,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
}
// Return section as circuit expression
Ok(ConstrainedValue::CircuitExpression(identifier, members))
}
}

View File

@ -1,13 +1,16 @@
//! Methods to enforce function inputs in a compiled Leo program.
//! Methods to enforce function input variables in a compiled Leo program.
pub mod array;
pub use self::array::*;
pub mod input;
pub use self::input::*;
pub mod function_input;
pub use self::function_input::*;
pub mod main_input;
pub use self::main_input::*;
pub mod main_function_input;
pub use self::main_function_input::*;
pub mod section;
pub use self::section::*;
pub mod input_keyword;
pub use self::input_keyword::*;
pub mod input_section;
pub use self::input_section::*;

View File

@ -7,7 +7,7 @@ use crate::{
OutputBytes,
};
use leo_types::{Expression, Function, Input, Inputs};
use leo_types::{Expression, Function, Input, InputVariable};
use snarkos_models::{
curves::{Field, PrimeField},
@ -20,18 +20,23 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
cs: &mut CS,
scope: String,
function: Function,
inputs: Inputs,
input: Input,
) -> Result<OutputBytes, FunctionError> {
let function_name = new_scope(scope.clone(), function.get_name());
let registers = inputs.get_registers();
let registers = input.get_registers();
// Iterate over main function inputs and allocate new passed-by variable values
// Iterate over main function input variables and allocate new values
let mut input_variables = vec![];
for input_model in function.inputs.clone().into_iter() {
for input_model in function.input.clone().into_iter() {
let (identifier, value) = match input_model {
Input::FunctionInput(input_model) => {
InputVariable::InputKeyword(identifier) => {
let value = self.allocate_input_keyword(cs, identifier.clone(), &input)?;
(identifier, value)
}
InputVariable::FunctionInput(input_model) => {
let name = input_model.identifier.name.clone();
let input_option = inputs
let input_option = input
.get(&name)
.ok_or(FunctionError::input_not_found(name.clone(), function.span.clone()))?;
let input_value = self.allocate_main_function_input(
@ -44,30 +49,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
(input_model.identifier, input_value)
}
Input::Registers(identifier) => {
let section = inputs.get_registers().values();
let value = self.allocate_input_section(cs, identifier.clone(), section)?;
(identifier, value)
}
Input::Record(identifier) => {
let section = inputs.get_record().values();
let value = self.allocate_input_section(cs, identifier.clone(), section)?;
(identifier, value)
}
Input::State(identifier) => {
let section = inputs.get_state().values();
let value = self.allocate_input_section(cs, identifier.clone(), section)?;
(identifier, value)
}
Input::StateLeaf(identifier) => {
let section = inputs.get_state_leaf().values();
let value = self.allocate_input_section(cs, identifier.clone(), section)?;
(identifier, value)
}
};
// Store input as variable with {function_name}_{identifier_name}

View File

@ -1,5 +1,5 @@
use crate::{errors::OutputBytesError, ConstrainedValue, GroupType};
use leo_types::{Parameter, Registers, Span, REGISTERS_VARIABLE_NAME};
use crate::{errors::OutputBytesError, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME};
use leo_types::{Parameter, Registers, Span};
use snarkos_models::curves::{Field, PrimeField};

View File

@ -1,6 +1,6 @@
//! The `program.out` file.
use crate::errors::OutputsFileError;
use crate::errors::OutputFileError;
use std::{
fs::{self, File},
@ -8,14 +8,14 @@ use std::{
path::PathBuf,
};
pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/";
pub static OUTPUTS_FILE_EXTENSION: &str = ".out";
pub static OUTPUT_DIRECTORY_NAME: &str = "output/";
pub static OUTPUT_FILE_EXTENSION: &str = ".out";
pub struct OutputsFile {
pub struct OutputFile {
pub package_name: String,
}
impl OutputsFile {
impl OutputFile {
pub fn new(package_name: &str) -> Self {
Self {
package_name: package_name.to_string(),
@ -27,21 +27,19 @@ impl OutputsFile {
path.exists()
}
/// Reads the outputs from the given file path if it exists.
pub fn read_from(&self, path: &PathBuf) -> Result<String, OutputsFileError> {
/// Reads the output register variables from the given file path if it exists.
pub fn read_from(&self, path: &PathBuf) -> Result<String, OutputFileError> {
let path = self.setup_file_path(path);
let inputs = fs::read_to_string(&path).map_err(|_| OutputsFileError::FileReadError(path.clone()))?;
Ok(inputs)
let output = fs::read_to_string(&path).map_err(|_| OutputFileError::FileReadError(path.clone()))?;
Ok(output)
}
/// Writes output to a file.
pub fn write(&self, path: &PathBuf, bytes: &[u8]) -> Result<(), OutputsFileError> {
pub fn write(&self, path: &PathBuf, bytes: &[u8]) -> Result<(), OutputFileError> {
// create output file
let path = self.setup_file_path(path);
println!("setup {:?}", path);
let mut file = File::create(&path)?;
println!("created");
log::info!("Writing to output registers...");
Ok(file.write_all(bytes)?)
@ -50,13 +48,10 @@ impl OutputsFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!(
"{}{}",
self.package_name, OUTPUTS_FILE_EXTENSION
)));
path.push(PathBuf::from(format!("{}{}", self.package_name, OUTPUT_FILE_EXTENSION)));
}
path
}

View File

@ -1,4 +1,4 @@
use crate::{assert_satisfied, expect_compiler_error, generate_main_inputs, parse_program};
use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program};
use leo_types::InputValue;
static TEST_ADDRESS_1: &'static str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8";
@ -57,23 +57,23 @@ fn test_ternary() {
let bytes = include_bytes!("ternary.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(true))),
("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(false))),
("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -83,25 +83,25 @@ fn test_equal() {
let bytes = include_bytes!("equal.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("c", Some(InputValue::Boolean(true))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
("c", Some(InputValue::Boolean(false))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}

View File

@ -1,22 +1,22 @@
use crate::{
assert_satisfied,
expect_compiler_error,
get_outputs,
get_output,
parse_program,
parse_program_with_inputs,
parse_program_with_input,
EdwardsTestCompiler,
};
pub fn output_ones(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_ones.out");
let actual = get_outputs(program);
let expected = include_bytes!("output_/registers_ones.out");
let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice()));
}
pub fn output_zeros(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_zeros.out");
let actual = get_outputs(program);
let expected = include_bytes!("output_/registers_zeros.out");
let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice()));
}
@ -26,16 +26,16 @@ pub fn output_zeros(program: EdwardsTestCompiler) {
#[test]
fn test_registers() {
let program_bytes = include_bytes!("registers.leo");
let ones_input_bytes = include_bytes!("inputs/registers_ones.in");
let zeros_input_bytes = include_bytes!("inputs/registers_zeros.in");
let ones_input_bytes = include_bytes!("input/registers_ones.in");
let zeros_input_bytes = include_bytes!("input/registers_zeros.in");
// test ones input register => ones output register
let program = parse_program_with_inputs(program_bytes, ones_input_bytes).unwrap();
let program = parse_program_with_input(program_bytes, ones_input_bytes).unwrap();
output_ones(program);
// test zeros input register => zeros output register
let program = parse_program_with_inputs(program_bytes, zeros_input_bytes).unwrap();
let program = parse_program_with_input(program_bytes, zeros_input_bytes).unwrap();
output_zeros(program);
}
@ -45,8 +45,8 @@ fn test_registers() {
#[test]
fn test_inline() {
let program_bytes = include_bytes!("inline.leo");
let input_bytes = include_bytes!("inputs/three_ones.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
let input_bytes = include_bytes!("input/three_ones.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}
@ -62,8 +62,8 @@ fn test_inline_fail() {
#[test]
fn test_initializer() {
let program_bytes = include_bytes!("initializer.leo");
let input_bytes = include_bytes!("inputs/three_ones.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
let input_bytes = include_bytes!("input/three_ones.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}
@ -71,8 +71,8 @@ fn test_initializer() {
#[test]
fn test_spread() {
let program_bytes = include_bytes!("spread.leo");
let input_bytes = include_bytes!("inputs/three_ones.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
let input_bytes = include_bytes!("input/three_ones.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}
@ -80,8 +80,8 @@ fn test_spread() {
#[test]
fn test_slice() {
let program_bytes = include_bytes!("slice.leo");
let input_bytes = include_bytes!("inputs/three_ones.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
let input_bytes = include_bytes!("input/three_ones.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}

View File

@ -1,3 +1,3 @@
function main(registers) -> u8[3] {
return registers.r
function main(input) -> u8[3] {
return input.registers.r
}

View File

@ -2,23 +2,23 @@ use crate::{
assert_satisfied,
expect_compiler_error,
expect_synthesis_error,
get_outputs,
get_output,
parse_program,
parse_program_with_inputs,
parse_program_with_input,
EdwardsTestCompiler,
};
use leo_compiler::errors::{BooleanError, CompilerError, ExpressionError, FunctionError, StatementError};
pub fn output_true(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_true.out");
let actual = get_outputs(program);
let expected = include_bytes!("output_/registers_true.out");
let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice());
}
pub fn output_false(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_false.out");
let actual = get_outputs(program);
let expected = include_bytes!("output_/registers_false.out");
let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice());
}
@ -35,9 +35,9 @@ fn fail_boolean_statement(program: EdwardsTestCompiler) {
#[test]
fn test_input_pass() {
let program_bytes = include_bytes!("assert_eq_input.leo");
let input_bytes = include_bytes!("inputs/true_true.in");
let input_bytes = include_bytes!("input/true_true.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}
@ -45,9 +45,9 @@ fn test_input_pass() {
#[test]
fn test_input_fail() {
let program_bytes = include_bytes!("assert_eq_input.leo");
let input_bytes = include_bytes!("inputs/true_false.in");
let input_bytes = include_bytes!("input/true_false.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
expect_synthesis_error(program);
}
@ -55,16 +55,16 @@ fn test_input_fail() {
#[test]
fn test_registers() {
let program_bytes = include_bytes!("output_register.leo");
let true_input_bytes = include_bytes!("inputs/registers_true.in");
let false_input_bytes = include_bytes!("inputs/registers_false.in");
let true_input_bytes = include_bytes!("input/registers_true.in");
let false_input_bytes = include_bytes!("input/registers_false.in");
// test true input register => true output register
let program = parse_program_with_inputs(program_bytes, true_input_bytes).unwrap();
let program = parse_program_with_input(program_bytes, true_input_bytes).unwrap();
output_true(program);
// test false input register => false output register
let program = parse_program_with_inputs(program_bytes, false_input_bytes).unwrap();
let program = parse_program_with_input(program_bytes, false_input_bytes).unwrap();
output_false(program);
}

View File

@ -1,3 +1,3 @@
function main(registers) -> bool {
return registers.r
function main(input) -> bool {
return input.registers.r
}

View File

@ -1,4 +1,4 @@
use crate::{assert_satisfied, expect_synthesis_error, generate_main_inputs, parse_program};
use crate::{assert_satisfied, expect_synthesis_error, generate_main_input, parse_program};
use leo_types::InputValue;
use snarkos_curves::edwards_bls12::Fq;
@ -41,13 +41,13 @@ fn test_add() {
let bytes = include_bytes!("add.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string))),
("c", Some(InputValue::Field(c_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program)
}
@ -71,12 +71,12 @@ fn test_sub() {
let bytes = include_bytes!("sub.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string))),
("c", Some(InputValue::Field(c_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program)
}
@ -100,12 +100,12 @@ fn test_div() {
let bytes = include_bytes!("div.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string))),
("c", Some(InputValue::Field(c_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program)
}
@ -129,13 +129,13 @@ fn test_mul() {
let bytes = include_bytes!("mul.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string))),
("c", Some(InputValue::Field(c_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program)
}
@ -157,13 +157,13 @@ fn test_eq() {
let bytes = include_bytes!("eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string.clone()))),
("b", Some(InputValue::Field(a_string.clone()))),
("c", Some(InputValue::Boolean(true))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -173,13 +173,13 @@ fn test_eq() {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -197,12 +197,12 @@ fn test_assert_eq_pass() {
let bytes = include_bytes!("assert_eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string.clone()))),
("b", Some(InputValue::Field(a_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -226,12 +226,12 @@ fn test_assert_eq_fail() {
let bytes = include_bytes!("assert_eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
expect_synthesis_error(program);
}
@ -251,43 +251,43 @@ fn test_ternary() {
let mut program = parse_program(bytes).unwrap();
// true -> field a
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(true))),
("a", Some(InputValue::Field(a_string.clone()))),
("b", Some(InputValue::Field(b_string.clone()))),
("c", Some(InputValue::Field(a_string.clone()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
let mut program = parse_program(bytes).unwrap();
// false -> field b
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(false))),
("a", Some(InputValue::Field(a_string))),
("b", Some(InputValue::Field(b_string.clone()))),
("c", Some(InputValue::Field(b_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
//
// pub fn output_one(program: EdwardsTestCompiler) {
// let expected = include_bytes!("outputs_/register_one.out");
// let actual = get_outputs(program);
// let expected = include_bytes!("output_/register_one.out");
// let actual = get_output(program);
//
// assert_eq!(expected, actual.bytes().as_slice());
// }
//
// pub fn output_zero(program: EdwardsTestCompiler) {
// let expected = include_bytes!("outputs_/register_zero.out");
// let actual = get_outputs(program);
// let expected = include_bytes!("output_/register_zero.out");
// let actual = get_output(program);
//
// assert_eq!(expected, actual.bytes().as_slice());
// }
@ -295,16 +295,16 @@ fn test_ternary() {
// #[test]
// fn test_registers() {
// let program_bytes = include_bytes!("output_register.leo");
// let one_input_bytes = include_bytes!("inputs/register_one.in");
// let zero_input_bytes = include_bytes!("inputs/register_zero.in");
// let one_input_bytes = include_bytes!("input/register_one.in");
// let zero_input_bytes = include_bytes!("input/register_zero.in");
//
// // test 1field input register => 1field output register
// let program = parse_program_with_inputs(program_bytes, one_input_bytes).unwrap();
// let program = parse_program_with_input(program_bytes, one_input_bytes).unwrap();
//
// output_one(program);
//
// // test 0field input register => 0field output register
// let program = parse_program_with_inputs(program_bytes, zero_input_bytes).unwrap();
// let program = parse_program_with_input(program_bytes, zero_input_bytes).unwrap();
//
// output_zero(program);
// }

View File

@ -1,9 +1,9 @@
use crate::{
assert_satisfied,
expect_compiler_error,
get_outputs,
get_output,
parse_program,
parse_program_with_inputs,
parse_program_with_input,
EdwardsTestCompiler,
};
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
@ -52,13 +52,13 @@ fn test_multiple_returns() {
#[test]
fn test_multiple_returns_main() {
let program_bytes = include_bytes!("multiple_main.leo");
let inputs_bytes = include_bytes!("inputs/registers.in");
let input_bytes = include_bytes!("input/registers.in");
let program = parse_program_with_inputs(program_bytes, inputs_bytes).unwrap();
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
let expected_bytes = include_bytes!("outputs_/registers.out");
let expected_bytes = include_bytes!("output_/registers.out");
let expected = std::str::from_utf8(expected_bytes).unwrap();
let actual_bytes = get_outputs(program);
let actual_bytes = get_output(program);
let actual = std::str::from_utf8(actual_bytes.bytes().as_slice()).unwrap();
assert_eq!(expected, actual);

View File

@ -1,3 +1,3 @@
function main(registers) -> (bool, bool) {
return (registers.a, registers.b)
function main(input) -> (bool, bool) {
return (input.registers.a, input.registers.b)
}

View File

@ -1,4 +1,4 @@
// Functions inputs in leo are pass-by-value.
// Functions input in leo are pass-by-value.
//
// Program execution:
// line 15: variable `a` is defined with value `1`.

View File

@ -2,9 +2,9 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
field::field_to_decimal_string,
generate_main_inputs,
generate_main_input,
parse_program,
parse_program_with_inputs,
parse_program_with_input,
};
use leo_types::InputValue;
@ -45,16 +45,16 @@ fn test_point() {
}
#[test]
fn test_inputs() {
fn test_input() {
let program_bytes = include_bytes!("input.leo");
let input_bytes_pass = include_bytes!("inputs/one_one.in");
let input_bytes_fail = include_bytes!("inputs/one_zero.in");
let input_bytes_pass = include_bytes!("input/one_one.in");
let input_bytes_fail = include_bytes!("input/one_zero.in");
let program = parse_program_with_inputs(program_bytes, input_bytes_pass).unwrap();
let program = parse_program_with_input(program_bytes, input_bytes_pass).unwrap();
assert_satisfied(program);
let program = parse_program_with_inputs(program_bytes, input_bytes_fail).unwrap();
let program = parse_program_with_input(program_bytes, input_bytes_fail).unwrap();
expect_synthesis_error(program);
}
@ -77,12 +77,12 @@ fn test_add() {
let bytes = include_bytes!("add.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Group(a_string))),
("b", Some(InputValue::Group(b_string))),
("c", Some(InputValue::Group(c_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program)
}
@ -106,12 +106,12 @@ fn test_sub() {
let bytes = include_bytes!("sub.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Group(a_string))),
("b", Some(InputValue::Group(b_string))),
("c", Some(InputValue::Group(c_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program)
}
@ -129,12 +129,12 @@ fn test_assert_eq_pass() {
let bytes = include_bytes!("assert_eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Group(a_string.clone()))),
("b", Some(InputValue::Group(a_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -158,12 +158,12 @@ fn test_assert_eq_fail() {
let bytes = include_bytes!("assert_eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Group(a_string))),
("b", Some(InputValue::Group(b_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
expect_synthesis_error(program);
}
@ -185,13 +185,13 @@ fn test_eq() {
let bytes = include_bytes!("eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Group(a_string.clone()))),
("b", Some(InputValue::Group(a_string.clone()))),
("c", Some(InputValue::Boolean(true))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -201,13 +201,13 @@ fn test_eq() {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Group(a_string))),
("b", Some(InputValue::Group(b_string))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -227,28 +227,28 @@ fn test_ternary() {
let mut program = parse_program(bytes).unwrap();
// true -> field a
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(true))),
("a", Some(InputValue::Group(a_string.clone()))),
("b", Some(InputValue::Group(b_string.clone()))),
("c", Some(InputValue::Group(a_string.clone()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
let mut program = parse_program(bytes).unwrap();
// false -> field b
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(false))),
("a", Some(InputValue::Group(a_string))),
("b", Some(InputValue::Group(b_string.clone()))),
("c", Some(InputValue::Group(b_string))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}

View File

@ -1 +1 @@
outputs/
output/

View File

@ -1 +1 @@
outputs/
output/

View File

@ -1,3 +1,3 @@
mod program_inputs;
mod program_inputs_and_state;
mod state;
mod program_input;
mod program_input_and_program_state;
mod program_state;

View File

@ -0,0 +1,49 @@
use crate::{assert_satisfied, expect_compiler_error, parse_program_with_input, EdwardsTestCompiler};
use leo_compiler::errors::CompilerError;
fn expect_fail(program: EdwardsTestCompiler) {
match expect_compiler_error(program) {
CompilerError::FunctionError(_) => {}
err => panic!("expected input parser error, got {:?}", err),
}
}
#[test]
fn test_input_pass() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("input/main.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_fail_name() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("input/main_fail_name.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
expect_fail(program);
}
#[test]
fn test_input_fail_type() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("input/main_fail_type.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
expect_fail(program);
}
#[test]
fn test_input_multiple() {
let program_bytes = include_bytes!("main_multiple.leo");
let input_bytes = include_bytes!("input/main_multiple.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}

View File

@ -0,0 +1,11 @@
function main(input, data: u8[32]) {
assert_eq!(input.registers.value_balance, 0u64);
assert_eq!(input.state.leaf_index, 0u32);
assert_eq!(input.record.value, 5u64);
assert_eq!(input.state_leaf.network_id, 0u8);
assert_eq!(data, [0u8; 32]);
}

View File

@ -0,0 +1,28 @@
use crate::{assert_satisfied, parse_input_and_state, parse_program_with_input_and_state};
#[test]
fn test_basic() {
let input_bytes = include_bytes!("input/basic.in");
let state_bytes = include_bytes!("input/basic.state");
parse_input_and_state(input_bytes, state_bytes).unwrap();
}
#[test]
fn test_full() {
let input_bytes = include_bytes!("input/token_withdraw.in");
let state_bytes = include_bytes!("input/token_withdraw.state");
parse_input_and_state(input_bytes, state_bytes).unwrap();
}
#[test]
fn test_access() {
let program_bytes = include_bytes!("access.leo");
let input_bytes = include_bytes!("input/token_withdraw.in");
let state_bytes = include_bytes!("input/token_withdraw.state");
let program = parse_program_with_input_and_state(program_bytes, input_bytes, state_bytes).unwrap();
assert_satisfied(program);
}

View File

@ -1,49 +0,0 @@
use crate::{assert_satisfied, expect_compiler_error, parse_program_with_inputs, EdwardsTestCompiler};
use leo_compiler::errors::CompilerError;
fn expect_fail(program: EdwardsTestCompiler) {
match expect_compiler_error(program) {
CompilerError::FunctionError(_) => {}
err => panic!("expected input parser error, got {:?}", err),
}
}
#[test]
fn test_inputs_pass() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("inputs/main.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_inputs_fail_name() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("inputs/main_fail_name.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
expect_fail(program);
}
#[test]
fn test_inputs_fail_type() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("inputs/main_fail_type.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
expect_fail(program);
}
#[test]
fn test_inputs_multiple() {
let program_bytes = include_bytes!("main_multiple.leo");
let input_bytes = include_bytes!("inputs/main_multiple.in");
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
assert_satisfied(program);
}

View File

@ -1,17 +0,0 @@
function main(
registers,
state,
record,
state_leaf,
data: u8[32]
) {
assert_eq!(registers.value_balance, 0u64);
assert_eq!(state.leaf_index, 0u32);
assert_eq!(record.value, 5u64);
assert_eq!(state_leaf.network_id, 0u8);
assert_eq!(data, [0u8; 32]);
}

View File

@ -1,28 +0,0 @@
use crate::{assert_satisfied, parse_inputs_and_state, parse_program_with_inputs_and_state};
#[test]
fn test_basic() {
let inputs_bytes = include_bytes!("inputs/basic.in");
let state_bytes = include_bytes!("inputs/basic.state");
parse_inputs_and_state(inputs_bytes, state_bytes).unwrap();
}
#[test]
fn test_full() {
let inputs_bytes = include_bytes!("inputs/token_withdraw.in");
let state_bytes = include_bytes!("inputs/token_withdraw.state");
parse_inputs_and_state(inputs_bytes, state_bytes).unwrap();
}
#[test]
fn test_access() {
let program_bytes = include_bytes!("access.leo");
let inputs_bytes = include_bytes!("inputs/token_withdraw.in");
let state_bytes = include_bytes!("inputs/token_withdraw.state");
let program = parse_program_with_inputs_and_state(program_bytes, inputs_bytes, state_bytes).unwrap();
assert_satisfied(program);
}

View File

@ -0,0 +1,8 @@
function main(input) {
assert_eq!(input.state.root, [0u8; 32]);
let expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
assert_eq!(input.record.owner, expected);
assert_eq!(input.state_leaf.network_id, 0u8);
}

View File

@ -0,0 +1,3 @@
function main(input) {
assert_eq!(input.state.root, [0u8; 32]);
}

View File

@ -2,14 +2,14 @@ use crate::{assert_satisfied, parse_program_with_state, parse_state};
#[test]
fn test_basic() {
let bytes = include_bytes!("inputs/basic.state");
let bytes = include_bytes!("input/basic.state");
parse_state(bytes).unwrap();
}
#[test]
fn test_token_withdraw() {
let bytes = include_bytes!("inputs/token_withdraw.state");
let bytes = include_bytes!("input/token_withdraw.state");
parse_state(bytes).unwrap();
}
@ -17,7 +17,7 @@ fn test_token_withdraw() {
#[test]
fn test_access_state() {
let program_bytes = include_bytes!("access_state.leo");
let state_bytes = include_bytes!("inputs/token_withdraw.state");
let state_bytes = include_bytes!("input/token_withdraw.state");
let program = parse_program_with_state(program_bytes, state_bytes).unwrap();
@ -27,7 +27,7 @@ fn test_access_state() {
#[test]
fn test_access_all() {
let program_bytes = include_bytes!("access_all.leo");
let state_bytes = include_bytes!("inputs/token_withdraw.state");
let state_bytes = include_bytes!("input/token_withdraw.state");
let program = parse_program_with_state(program_bytes, state_bytes).unwrap();
@ -36,7 +36,7 @@ fn test_access_all() {
#[test]
fn test_visibility_fail() {
let state_bytes = include_bytes!("inputs/visibility_fail.state");
let state_bytes = include_bytes!("input/visibility_fail.state");
let is_err = parse_state(state_bytes).is_err();
@ -45,7 +45,7 @@ fn test_visibility_fail() {
#[test]
fn test_section_undefined() {
let state_bytes = include_bytes!("inputs/section_undefined.state");
let state_bytes = include_bytes!("input/section_undefined.state");
let is_err = parse_state(state_bytes).is_err();
@ -54,7 +54,7 @@ fn test_section_undefined() {
#[test]
fn test_section_invalid() {
let state_bytes = include_bytes!("inputs/section_invalid.state");
let state_bytes = include_bytes!("input/section_invalid.state");
let is_err = parse_state(state_bytes).is_err();

View File

@ -1,8 +0,0 @@
function main(state, record, state_leaf) {
assert_eq!(state.root, [0u8; 32]);
let expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
assert_eq!(record.owner, expected);
assert_eq!(state_leaf.network_id, 0u8);
}

View File

@ -1,3 +0,0 @@
function main(state) {
assert_eq!(state.root, [0u8; 32]);
}

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I128Type, IntegerType};
use leo_input::types::{I128Type, IntegerType};
use leo_types::InputValue;
test_int!(Testi128, i128, IntegerType::I128Type(I128Type {}), Int128);

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I16Type, IntegerType};
use leo_input::types::{I16Type, IntegerType};
use leo_types::InputValue;
test_int!(Testi16, i16, IntegerType::I16Type(I16Type {}), Int16);

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I32Type, IntegerType};
use leo_input::types::{I32Type, IntegerType};
use leo_types::InputValue;
test_int!(Testi32, i32, IntegerType::I32Type(I32Type {}), Int32);

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I64Type, IntegerType};
use leo_input::types::{I64Type, IntegerType};
use leo_types::InputValue;
test_int!(Testi64, i64, IntegerType::I64Type(I64Type {}), Int64);

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I8Type, IntegerType};
use leo_input::types::{I8Type, IntegerType};
use leo_types::InputValue;
test_int!(Testi8, i8, IntegerType::I8Type(I8Type {}), Int8);

View File

@ -44,13 +44,13 @@ macro_rules! test_int {
let bytes = include_bytes!("add.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -73,13 +73,13 @@ macro_rules! test_int {
let bytes = include_bytes!("sub.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -98,13 +98,13 @@ macro_rules! test_int {
let bytes = include_bytes!("mul.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -119,14 +119,14 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
// expect an error when dividing by zero
if b == 0 {
let main_inputs = generate_main_inputs(vec![
if b == 0 || b == <$type_>::MIN {
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, b.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
expect_computation_error(program);
} else {
@ -135,13 +135,13 @@ macro_rules! test_int {
None => continue,
};
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -162,13 +162,13 @@ macro_rules! test_int {
let bytes = include_bytes!("pow.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -184,13 +184,13 @@ macro_rules! test_int {
let bytes = include_bytes!("eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
("c", Some(InputValue::Boolean(true))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -200,13 +200,13 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -222,13 +222,13 @@ macro_rules! test_int {
let bytes = include_bytes!("ge.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
("c", Some(InputValue::Boolean(true))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -238,13 +238,13 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -260,13 +260,13 @@ macro_rules! test_int {
let bytes = include_bytes!("gt.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
("c", Some(InputValue::Boolean(false))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -276,13 +276,13 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -298,13 +298,13 @@ macro_rules! test_int {
let bytes = include_bytes!("le.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
("c", Some(InputValue::Boolean(true))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -314,13 +314,13 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -336,13 +336,13 @@ macro_rules! test_int {
let bytes = include_bytes!("lt.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
("c", Some(InputValue::Boolean(false))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -352,13 +352,13 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Boolean(c))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}
@ -372,12 +372,12 @@ macro_rules! test_int {
let bytes = include_bytes!("assert_eq.leo");
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
@ -390,12 +390,12 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
expect_synthesis_error(program);
}
@ -409,28 +409,28 @@ macro_rules! test_int {
let mut program = parse_program(bytes).unwrap();
// true -> field 1
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(true))),
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, a.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
// false -> field 2
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
let main_input = generate_main_input(vec![
("s", Some(InputValue::Boolean(false))),
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
("c", Some(InputValue::Integer($integer_type, b.to_string()))),
]);
program.set_main_inputs(main_inputs);
program.set_main_input(main_input);
assert_satisfied(program);
}

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U128Type};
use leo_input::types::{IntegerType, U128Type};
use leo_types::InputValue;
test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128);

View File

@ -1,11 +1,11 @@
use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
generate_main_input,
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U16Type};
use leo_input::types::{IntegerType, U16Type};
use leo_types::InputValue;
test_uint!(TestU16, u16, IntegerType::U16Type(U16Type {}), UInt16);

Some files were not shown because too many files have changed in this diff Show More