mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-29 12:34:20 +03:00
remove visibility syntax and functionality
This commit is contained in:
parent
4efd06fd41
commit
c77e6a51b3
28
README.md
28
README.md
@ -146,7 +146,7 @@ function main() -> u32 {
|
||||
** **Experimental** **
|
||||
The current constraint system is not optimized for statement branching. Please use the ternary expression above until this feature is stable.
|
||||
```rust
|
||||
function main(a: private bool, b: private bool) -> u32 {
|
||||
function main(a: bool, b: bool) -> u32 {
|
||||
let mut res = 0u32;
|
||||
if (a) {
|
||||
res = 1;
|
||||
@ -218,18 +218,8 @@ function main() -> u32[3] {
|
||||
```
|
||||
|
||||
### Main function inputs
|
||||
Main function inputs are allocated as public or private variables in the program's constaint system.
|
||||
```rust
|
||||
function main(a: private field) -> field {
|
||||
return a
|
||||
}
|
||||
```
|
||||
```rust
|
||||
function main(a: public field) -> field {
|
||||
return a
|
||||
}
|
||||
```
|
||||
Private by default. Below `a` is implicitly private.
|
||||
Main function inputs are allocated private variables in the program's constraint system.
|
||||
`a` is implicitly private.
|
||||
```rust
|
||||
function main(a: field) -> field {
|
||||
return a
|
||||
@ -383,7 +373,7 @@ test function expect_fail() {
|
||||
|
||||
# Leo Inputs
|
||||
|
||||
Public and private inputs for a Leo program are specified in the `inputs/` directory. The syntax for an input file is a limited subset of the Leo program syntax. The default inputs file is `inputs/inputs.leo`.
|
||||
Private inputs for a Leo program are specified in the `inputs/` directory. The syntax for an input file is a limited subset of the Leo program syntax. The default inputs file is `inputs/inputs.leo`.
|
||||
|
||||
## Sections
|
||||
A Leo input file is made up of sections. Sections are defined by a section header in brackets followed by one or more input definitions.
|
||||
@ -394,14 +384,14 @@ Section headers specify the target file which must have a main function with mat
|
||||
|
||||
```rust
|
||||
[main] // <- section header
|
||||
a: private u32 = 1; // <- private input
|
||||
b: public u32 = 2; // <- public input
|
||||
a: u32 = 1;
|
||||
b: u32 = 2;
|
||||
```
|
||||
|
||||
`src/main.leo`
|
||||
|
||||
```rust
|
||||
function main(a: private u32, b: public u32) -> u32 {
|
||||
function main(a: u32, b: u32) -> u32 {
|
||||
let c: u32 = a + b;
|
||||
return c
|
||||
}
|
||||
@ -421,8 +411,8 @@ d: group = (0, 1)group // <- group tuples
|
||||
### Arrays
|
||||
```rust
|
||||
[main]
|
||||
a: private u8[4] = [0u8; 4]; // <- single
|
||||
b: private u8[2][3] = [[0u8; 2]; 3]; // <- multi-dimensional
|
||||
a: u8[4] = [0u8; 4]; // <- single
|
||||
b: u8[2][3] = [[0u8; 2]; 3]; // <- multi-dimensional
|
||||
```
|
||||
|
||||
# Leo CLI
|
||||
|
@ -30,6 +30,3 @@ pub use static_::*;
|
||||
|
||||
pub mod variable;
|
||||
pub use variable::*;
|
||||
|
||||
pub mod visibility;
|
||||
pub use visibility::*;
|
||||
|
@ -1,18 +0,0 @@
|
||||
use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::visibility))]
|
||||
pub enum Visibility {
|
||||
Public(Public),
|
||||
Private(Private),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::visibility_public))]
|
||||
pub struct Public {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::visibility_private))]
|
||||
pub struct Private {}
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
common::{Identifier, Mutable, Visibility},
|
||||
common::{Identifier, Mutable},
|
||||
types::Type,
|
||||
};
|
||||
|
||||
@ -12,7 +12,6 @@ use pest_ast::FromPest;
|
||||
pub struct FunctionInput<'ast> {
|
||||
pub mutable: Option<Mutable>,
|
||||
pub identifier: Identifier<'ast>,
|
||||
pub visibility: Option<Visibility>,
|
||||
pub _type: Type<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -8,7 +8,7 @@ file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ circuit_definition* ~ NEWLINE* ~
|
||||
|
||||
// Declared in common/identifier.rs
|
||||
identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
protected_name = { visibility | "let" | "for"| "if" | "else" | "as" | "return" }
|
||||
protected_name = { "let" | "for"| "if" | "else" | "as" | "return" }
|
||||
|
||||
// Declared in common/line_end.rs
|
||||
LINE_END = { ";" ~ NEWLINE* }
|
||||
@ -36,11 +36,6 @@ static_ = { "static" }
|
||||
// Declared in common/variable.rs
|
||||
variable = { mutable? ~ identifier ~ (":" ~ type_)? }
|
||||
|
||||
// Declared in common/visibility.rs
|
||||
visibility = { visibility_public | visibility_private }
|
||||
visibility_public = { "public" }
|
||||
visibility_private = { "private" }
|
||||
|
||||
/// Operations
|
||||
|
||||
// Declared in operations/not_operation.rs
|
||||
@ -275,7 +270,7 @@ statement_return = { "return" ~ expression_tuple }
|
||||
function_definition = { "function" ~ identifier ~ "(" ~ input_model_list ~ ")" ~ ("->" ~ (type_ | "(" ~ type_list ~ ")"))? ~ "{" ~ NEWLINE* ~ statement* ~ NEWLINE* ~ "}" ~ NEWLINE* }
|
||||
|
||||
// Declared in functions/function_input.rs
|
||||
function_input = { mutable? ~ identifier ~ ":" ~ visibility? ~ type_ }
|
||||
function_input = { mutable? ~ identifier ~ ":" ~ type_ }
|
||||
input_model_list = _{ (function_input ~ ("," ~ function_input)*)? }
|
||||
|
||||
// Declared in functions/test_function.rs
|
||||
|
@ -16,7 +16,6 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
use snarkos_models::curves::PairingEngine;
|
||||
use std::{fs, marker::PhantomData, path::PathBuf};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -62,10 +61,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
self.program_inputs.set_inputs(program_inputs);
|
||||
}
|
||||
|
||||
pub fn get_public_inputs<E: PairingEngine>(&self) -> Result<Vec<E::Fr>, CompilerError> {
|
||||
Ok(self.program_inputs.get_public_inputs::<E>()?)
|
||||
}
|
||||
|
||||
pub fn checksum(&self) -> Result<String, CompilerError> {
|
||||
// Read in the main file as string
|
||||
let unparsed_file = fs::read_to_string(&self.main_file_path)
|
||||
@ -113,7 +108,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
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)?;
|
||||
|
||||
// Check number/order of private parameters here
|
||||
// Check number/order of parameters here
|
||||
self.program_inputs = Inputs::from_inputs_file(syntax_tree, self.program.expected_inputs.clone())?;
|
||||
|
||||
Ok(())
|
||||
|
@ -21,7 +21,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
name: String,
|
||||
private: bool,
|
||||
input_value: Option<InputValue>,
|
||||
) -> Result<ConstrainedValue<F, G>, BooleanError> {
|
||||
// Check that the input value is the correct type
|
||||
@ -36,12 +35,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
None => None,
|
||||
};
|
||||
|
||||
// Check visibility of input
|
||||
let number = if private {
|
||||
Boolean::alloc(cs.ns(|| name), || bool_value.ok_or(SynthesisError::AssignmentMissing))?
|
||||
} else {
|
||||
Boolean::alloc_input(cs.ns(|| name), || bool_value.ok_or(SynthesisError::AssignmentMissing))?
|
||||
};
|
||||
let number = Boolean::alloc(cs.ns(|| name), || bool_value.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Ok(ConstrainedValue::Boolean(number))
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ use snarkos_models::{
|
||||
pub(crate) fn field_from_input<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: String,
|
||||
private: bool,
|
||||
input_value: Option<InputValue>,
|
||||
) -> Result<ConstrainedValue<F, G>, FieldError> {
|
||||
// Check that the parameter value is the correct type
|
||||
@ -27,12 +26,7 @@ pub(crate) fn field_from_input<F: Field + PrimeField, G: GroupType<F>, CS: Const
|
||||
None => None,
|
||||
};
|
||||
|
||||
// Check visibility of parameter
|
||||
let field_value = if private {
|
||||
FieldType::alloc(cs.ns(|| name), || field_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
} else {
|
||||
FieldType::alloc_input(cs.ns(|| name), || field_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
};
|
||||
let field_value = FieldType::alloc(cs.ns(|| name), || field_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Ok(ConstrainedValue::Field(field_value))
|
||||
}
|
||||
|
@ -107,7 +107,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
name: String,
|
||||
private: bool,
|
||||
array_type: Type,
|
||||
array_dimensions: Vec<usize>,
|
||||
input_value: Option<InputValue>,
|
||||
@ -125,13 +124,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
let value_name = new_scope(name.clone(), i.to_string());
|
||||
let value_type = array_type.outer_dimension(&array_dimensions);
|
||||
|
||||
array_value.push(self.allocate_main_function_input(
|
||||
cs,
|
||||
value_type,
|
||||
value_name,
|
||||
private,
|
||||
Some(value),
|
||||
)?)
|
||||
array_value.push(self.allocate_main_function_input(cs, value_type, value_name, Some(value))?)
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@ -140,7 +133,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
let value_name = new_scope(name.clone(), i.to_string());
|
||||
let value_type = array_type.outer_dimension(&array_dimensions);
|
||||
|
||||
array_value.push(self.allocate_main_function_input(cs, value_type, value_name, private, None)?);
|
||||
array_value.push(self.allocate_main_function_input(cs, value_type, value_name, None)?);
|
||||
}
|
||||
}
|
||||
_ => return Err(FunctionError::InvalidArray(input_value.unwrap().to_string())),
|
||||
@ -154,7 +147,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
cs: &mut CS,
|
||||
_type: Type,
|
||||
name: String,
|
||||
private: bool,
|
||||
input_value: Option<InputValue>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
match _type {
|
||||
@ -162,13 +154,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
cs,
|
||||
integer_type,
|
||||
name,
|
||||
private,
|
||||
input_value,
|
||||
)?)),
|
||||
Type::Field => Ok(field_from_input(cs, name, private, input_value)?),
|
||||
Type::Group => Ok(group_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),
|
||||
Type::Field => Ok(field_from_input(cs, name, input_value)?),
|
||||
Type::Group => Ok(group_from_input(cs, name, input_value)?),
|
||||
Type::Boolean => Ok(self.bool_from_input(cs, name, input_value)?),
|
||||
Type::Array(_type, dimensions) => self.allocate_array(cs, name, *_type, dimensions, input_value),
|
||||
_ => unimplemented!("main function input not implemented for type"),
|
||||
}
|
||||
}
|
||||
@ -189,13 +180,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
let mut input_variables = vec![];
|
||||
for (input_model, input_option) in function.inputs.clone().into_iter().zip(inputs.into_iter()) {
|
||||
let input_name = new_scope(function_name.clone(), input_model.identifier.name.clone());
|
||||
let input_value = self.allocate_main_function_input(
|
||||
cs,
|
||||
input_model._type,
|
||||
input_name.clone(),
|
||||
input_model.private,
|
||||
input_option,
|
||||
)?;
|
||||
let input_value =
|
||||
self.allocate_main_function_input(cs, input_model._type, input_name.clone(), input_option)?;
|
||||
|
||||
// Store a new variable for every allocated main function input
|
||||
self.store(input_name.clone(), input_value);
|
||||
|
@ -10,7 +10,6 @@ use snarkos_models::{
|
||||
pub(crate) fn group_from_input<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: String,
|
||||
private: bool,
|
||||
input_value: Option<InputValue>,
|
||||
) -> Result<ConstrainedValue<F, G>, GroupError> {
|
||||
// Check that the parameter value is the correct type
|
||||
@ -25,12 +24,7 @@ pub(crate) fn group_from_input<F: Field + PrimeField, G: GroupType<F>, CS: Const
|
||||
None => None,
|
||||
};
|
||||
|
||||
// Check visibility of parameter
|
||||
let group_value = if private {
|
||||
G::alloc(cs.ns(|| name), || group_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
} else {
|
||||
G::alloc_input(cs.ns(|| name), || group_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
};
|
||||
let group_value = G::alloc(cs.ns(|| name), || group_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Ok(ConstrainedValue::Group(group_value))
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ circuit PedersenHash {
|
||||
}
|
||||
}
|
||||
|
||||
function main(parameters: private group[512]) -> group {
|
||||
function main(parameters: group[512]) -> group {
|
||||
let pedersen = PedersenHash::new(parameters);
|
||||
|
||||
let input: bool[512] = [true; 512]; // use mock private key until `.bits()` function is implemented
|
||||
|
@ -1,2 +1,2 @@
|
||||
[main]
|
||||
b: private bool = true;
|
||||
b: bool = true;
|
@ -1,2 +1,2 @@
|
||||
[main]
|
||||
bad_name: private bool = true;
|
||||
bad_name: bool = true;
|
@ -1,2 +1,2 @@
|
||||
[main]
|
||||
b: private u8 = 1;
|
||||
b: u8 = 1;
|
@ -1,2 +0,0 @@
|
||||
[main]
|
||||
b: public bool = true;
|
@ -1,3 +1,3 @@
|
||||
[main]
|
||||
b: private bool = true;
|
||||
a: public bool = false;
|
||||
b: bool = true;
|
||||
a: bool = false;
|
@ -1,3 +1,3 @@
|
||||
function main(b: private bool) -> bool {
|
||||
function main(b: bool) -> bool {
|
||||
return b
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: public bool, b: private bool) -> bool {
|
||||
function main(a: bool, b: bool) -> bool {
|
||||
return a || b
|
||||
}
|
@ -47,18 +47,6 @@ fn test_inputs_fail_type() {
|
||||
fail_input_parser(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inputs_fail_visibility() {
|
||||
let program_bytes = include_bytes!("main.leo");
|
||||
let input_bytes = include_bytes!("inputs_fail_visibility.leo");
|
||||
let input_string = String::from_utf8_lossy(input_bytes);
|
||||
|
||||
let mut program = parse_program(program_bytes).unwrap();
|
||||
let error = program.parse_inputs(&PathBuf::new(), &input_string).unwrap_err();
|
||||
|
||||
fail_input_parser(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inputs_multiple() {
|
||||
let program_bytes = include_bytes!("main_multiple.leo");
|
||||
|
@ -1,4 +1,4 @@
|
||||
function main(bit: private u32) {
|
||||
function main(bit: u32) {
|
||||
if bit == 1 {
|
||||
assert_eq!(bit, 1);
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ fn empty_output_satisfied(program: EdwardsTestCompiler) {
|
||||
|
||||
// Tests a statements.conditional enforceBit() program
|
||||
//
|
||||
// function main(bit: private u8) {
|
||||
// function main(bit: u8) {
|
||||
// if bit == 1u8 {
|
||||
// assert_eq!(bit, 1u8);
|
||||
// } else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
function main(bit: private u32) -> u32 {
|
||||
function main(bit: u32) -> u32 {
|
||||
let mut a = 5u32;
|
||||
|
||||
if bit == 1 {
|
||||
|
@ -1,2 +1,2 @@
|
||||
[main]
|
||||
a: private u32 = 5
|
||||
a: u32 = 5
|
@ -1,4 +0,0 @@
|
||||
[main]
|
||||
a: private u32 = 5;
|
||||
b: public field = 1field;
|
||||
c: private bool = true;
|
@ -6,6 +6,3 @@ pub use identifier::*;
|
||||
|
||||
pub mod line_end;
|
||||
pub use line_end::*;
|
||||
|
||||
pub mod visibility;
|
||||
pub use visibility::*;
|
||||
|
@ -1,18 +0,0 @@
|
||||
use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::visibility))]
|
||||
pub enum Visibility {
|
||||
Public(Public),
|
||||
Private(Private),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::visibility_public))]
|
||||
pub struct Public {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::visibility_private))]
|
||||
pub struct Private {}
|
@ -2,15 +2,11 @@
|
||||
|
||||
// Declared in common/identifier.rs
|
||||
identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
protected_name = { visibility | "let" | "for"| "if" | "else" | "as" | "return" }
|
||||
protected_name = { "let" | "for"| "if" | "else" | "as" | "return" }
|
||||
|
||||
// Declared in common/line_end.rs
|
||||
LINE_END = { ";" ~ NEWLINE* }
|
||||
|
||||
// Declared in common/visibility.rs
|
||||
visibility = { visibility_public | visibility_private }
|
||||
visibility_public = { "public" }
|
||||
visibility_private = { "private" }
|
||||
|
||||
/// Types
|
||||
|
||||
@ -89,7 +85,7 @@ expression = {
|
||||
/// Parameters
|
||||
|
||||
// Declared in parameters/parameters.rs
|
||||
parameter = { identifier ~ ":" ~ visibility? ~ type_ }
|
||||
parameter = { identifier ~ ":" ~ type_ }
|
||||
|
||||
/// Section
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
use leo_inputs::{self, LeoInputsParser};
|
||||
|
||||
use std::env::current_dir;
|
||||
|
||||
fn main() {
|
||||
let mut path = current_dir().unwrap();
|
||||
path.push("input.leo");
|
||||
|
||||
let input_file = &LeoInputsParser::load_file(&path).expect("cannot read file");
|
||||
let syntax_tree = LeoInputsParser::parse_file(&path, input_file).unwrap();
|
||||
|
||||
println!("tree: {:#?}", syntax_tree);
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
common::{Identifier, Visibility},
|
||||
types::Type,
|
||||
};
|
||||
use crate::{ast::Rule, common::Identifier, types::Type};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -11,7 +7,6 @@ use pest_ast::FromPest;
|
||||
#[pest_ast(rule(Rule::parameter))]
|
||||
pub struct Parameter<'ast> {
|
||||
pub variable: Identifier<'ast>,
|
||||
pub visibility: Option<Visibility>,
|
||||
pub type_: Type<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -11,10 +11,8 @@ 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};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -22,11 +20,7 @@ pub struct ProveCommand;
|
||||
|
||||
impl CLI for ProveCommand {
|
||||
type Options = ();
|
||||
type Output = (
|
||||
Compiler<Fq, EdwardsGroupType>,
|
||||
Proof<Bls12_377>,
|
||||
PreparedVerifyingKey<Bls12_377>,
|
||||
);
|
||||
type Output = (Proof<Bls12_377>, PreparedVerifyingKey<Bls12_377>);
|
||||
|
||||
const ABOUT: AboutType = "Run the program and produce a proof";
|
||||
const ARGUMENTS: &'static [ArgumentType] = &[];
|
||||
@ -72,6 +66,6 @@ impl CLI for ProveCommand {
|
||||
|
||||
log::info!("Completed program proving");
|
||||
|
||||
Ok((program, program_proof, prepared_verifying_key))
|
||||
Ok((program_proof, prepared_verifying_key))
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::{cli::*, cli_types::*, commands::ProveCommand, errors::CLIError};
|
||||
|
||||
use snarkos_algorithms::snark::verify_proof;
|
||||
use snarkos_curves::bls12_377::Bls12_377;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::time::{Duration, Instant};
|
||||
@ -27,16 +26,13 @@ impl CLI for RunCommand {
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn output(options: Self::Options) -> Result<(), CLIError> {
|
||||
let (program, proof, prepared_verifying_key) = ProveCommand::output(options)?;
|
||||
let (proof, prepared_verifying_key) = ProveCommand::output(options)?;
|
||||
|
||||
let mut verifying = Duration::new(0, 0);
|
||||
|
||||
// fetch public inputs
|
||||
let inputs: Vec<_> = program.get_public_inputs::<Bls12_377>().unwrap();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
let is_success = verify_proof(&prepared_verifying_key, &proof, &inputs).unwrap();
|
||||
let is_success = verify_proof(&prepared_verifying_key, &proof, &vec![]).unwrap();
|
||||
|
||||
verifying += start.elapsed();
|
||||
|
||||
|
@ -47,8 +47,8 @@ impl InputsFile {
|
||||
format!(
|
||||
r#"// The inputs for {}/src/main.leo
|
||||
[main]
|
||||
a: private u32 = 1;
|
||||
b: public u32 = 2;
|
||||
a: u32 = 1;
|
||||
b: u32 = 2;
|
||||
"#,
|
||||
self.package_name
|
||||
)
|
||||
|
@ -46,7 +46,7 @@ impl MainFile {
|
||||
fn template(&self) -> String {
|
||||
format!(
|
||||
r#"// The '{}' main function.
|
||||
function main(a: private u32, b: public u32) -> u32 {{
|
||||
function main(a: u32, b: u32) -> u32 {{
|
||||
let c: u32 = a + b;
|
||||
return c
|
||||
}}
|
||||
|
@ -1,4 +1,4 @@
|
||||
function test(p: public bool) {
|
||||
function test(p: bool) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
use crate::{Identifier, Type};
|
||||
use leo_ast::{
|
||||
common::{Private, Visibility},
|
||||
functions::FunctionInput as AstFunctionInput,
|
||||
};
|
||||
use leo_ast::functions::FunctionInput as AstFunctionInput;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@ -10,7 +7,6 @@ use std::fmt;
|
||||
pub struct FunctionInput {
|
||||
pub identifier: Identifier,
|
||||
pub mutable: bool,
|
||||
pub private: bool,
|
||||
pub _type: Type,
|
||||
}
|
||||
|
||||
@ -19,10 +15,6 @@ impl<'ast> From<AstFunctionInput<'ast>> for FunctionInput {
|
||||
FunctionInput {
|
||||
identifier: Identifier::from(parameter.identifier),
|
||||
mutable: parameter.mutable.is_some(),
|
||||
// private by default
|
||||
private: parameter
|
||||
.visibility
|
||||
.map_or(true, |visibility| visibility.eq(&Visibility::Private(Private {}))),
|
||||
_type: Type::from(parameter._type),
|
||||
}
|
||||
}
|
||||
@ -30,16 +22,11 @@ impl<'ast> From<AstFunctionInput<'ast>> for FunctionInput {
|
||||
|
||||
impl FunctionInput {
|
||||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// mut var: private bool
|
||||
// mut var: bool
|
||||
if self.mutable {
|
||||
write!(f, "mut ")?;
|
||||
}
|
||||
write!(f, "{}: ", self.identifier)?;
|
||||
if self.private {
|
||||
write!(f, "private ")?;
|
||||
} else {
|
||||
write!(f, "public ")?;
|
||||
}
|
||||
write!(f, "{}", self._type)
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
use crate::InputValue;
|
||||
use leo_inputs::{types::IntegerType, InputParserError};
|
||||
|
||||
use snarkos_models::curves::{Field, PairingEngine};
|
||||
use std::str::FromStr;
|
||||
|
||||
pub struct InputFields<E: PairingEngine>(pub Vec<E::Fr>);
|
||||
|
||||
impl<E: PairingEngine> InputFields<E> {
|
||||
pub(crate) fn from_boolean(boolean: &bool) -> Self {
|
||||
if *boolean {
|
||||
Self(vec![E::Fr::one()])
|
||||
} else {
|
||||
Self(vec![E::Fr::zero()])
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_integer(type_: &IntegerType, integer: &u128) -> Self {
|
||||
let bits: usize = match type_ {
|
||||
IntegerType::U8Type(_) => 8,
|
||||
IntegerType::U16Type(_) => 16,
|
||||
IntegerType::U32Type(_) => 32,
|
||||
IntegerType::U64Type(_) => 64,
|
||||
IntegerType::U128Type(_) => 128,
|
||||
};
|
||||
let mut fields = vec![];
|
||||
|
||||
for i in 0..bits {
|
||||
let boolean = (integer.to_le() >> i) & 1 == 1;
|
||||
let mut boolean_fields = InputFields::<E>::from_boolean(&boolean);
|
||||
|
||||
fields.append(&mut boolean_fields.0);
|
||||
}
|
||||
|
||||
Self(fields)
|
||||
}
|
||||
|
||||
pub(crate) fn from_field(field: &str) -> Result<Self, InputParserError> {
|
||||
let field = E::Fr::from_str(field).map_err(|_| InputParserError::ParseFieldError(field.to_string()))?;
|
||||
|
||||
Ok(Self(vec![field]))
|
||||
}
|
||||
|
||||
pub(crate) fn from_group(group: &str) -> Result<Self, InputParserError> {
|
||||
let s = group.trim();
|
||||
let mut fields = vec![];
|
||||
|
||||
for substr in s.split(|c| c == '(' || c == ')' || c == ',' || c == ' ') {
|
||||
if !substr.is_empty() {
|
||||
let mut input_fields = InputFields::<E>::from_field(&substr)?;
|
||||
|
||||
fields.append(&mut input_fields.0);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self(fields))
|
||||
}
|
||||
|
||||
pub(crate) fn from_array(array: &Vec<InputValue>) -> Result<Self, InputParserError> {
|
||||
let mut fields = vec![];
|
||||
|
||||
for input in array.iter() {
|
||||
let mut input_fields = input.to_input_fields::<E>()?;
|
||||
|
||||
fields.append(&mut input_fields.0);
|
||||
}
|
||||
|
||||
Ok(Self(fields))
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
use crate::InputFields;
|
||||
use leo_inputs::{
|
||||
errors::InputParserError,
|
||||
expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression},
|
||||
@ -6,7 +5,6 @@ use leo_inputs::{
|
||||
values::{BooleanValue, FieldValue, GroupValue, NumberImplicitValue, NumberValue, Value},
|
||||
};
|
||||
|
||||
use snarkos_models::curves::PairingEngine;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
@ -149,16 +147,6 @@ impl<'ast> InputValue {
|
||||
|
||||
Ok(InputValue::Array(values))
|
||||
}
|
||||
|
||||
pub(crate) fn to_input_fields<E: PairingEngine>(&self) -> Result<InputFields<E>, InputParserError> {
|
||||
match self {
|
||||
InputValue::Boolean(boolean) => Ok(InputFields::from_boolean(boolean)),
|
||||
InputValue::Integer(type_, number) => Ok(InputFields::from_integer(type_, number)),
|
||||
InputValue::Group(group) => InputFields::from_group(group),
|
||||
InputValue::Field(field) => InputFields::from_field(field),
|
||||
InputValue::Array(array) => InputFields::from_array(array),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for InputValue {
|
||||
|
@ -1,21 +1,14 @@
|
||||
use crate::{FunctionInput, InputValue};
|
||||
use leo_inputs::{common::visibility::Visibility, files::File, InputParserError};
|
||||
|
||||
use leo_inputs::common::Private;
|
||||
use snarkos_models::curves::PairingEngine;
|
||||
use leo_inputs::{files::File, InputParserError};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Inputs {
|
||||
program_inputs: Vec<Option<InputValue>>,
|
||||
public: Vec<InputValue>,
|
||||
}
|
||||
|
||||
impl Inputs {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
program_inputs: vec![],
|
||||
public: vec![],
|
||||
}
|
||||
Self { program_inputs: vec![] }
|
||||
}
|
||||
|
||||
pub fn get_inputs(&self) -> Vec<Option<InputValue>> {
|
||||
@ -32,23 +25,14 @@ impl Inputs {
|
||||
|
||||
pub fn from_inputs_file(file: File, expected_inputs: Vec<FunctionInput>) -> Result<Self, InputParserError> {
|
||||
let mut program_inputs = vec![];
|
||||
let mut public = vec![];
|
||||
|
||||
for section in file.sections.into_iter() {
|
||||
if section.header.name.value.eq("main") {
|
||||
for input in &expected_inputs {
|
||||
// find input with matching name
|
||||
let matched_input = section.assignments.clone().into_iter().find(|assignment| {
|
||||
let visibility = assignment
|
||||
.parameter
|
||||
.visibility
|
||||
.as_ref()
|
||||
.map_or(true, |visibility| visibility.eq(&Visibility::Private(Private {})));
|
||||
|
||||
// name match
|
||||
assignment.parameter.variable.value.eq(&input.identifier.name)
|
||||
// visibility match
|
||||
&& visibility.eq(&input.private)
|
||||
// type match
|
||||
&& assignment.parameter.type_.to_string().eq(&input._type.to_string())
|
||||
});
|
||||
@ -56,10 +40,6 @@ impl Inputs {
|
||||
match matched_input {
|
||||
Some(assignment) => {
|
||||
let value = InputValue::from_expression(assignment.parameter.type_, assignment.expression)?;
|
||||
if let Some(Visibility::Public(_)) = assignment.parameter.visibility {
|
||||
// Collect public inputs here
|
||||
public.push(value.clone());
|
||||
}
|
||||
|
||||
// push value to vector
|
||||
program_inputs.push(Some(value));
|
||||
@ -70,20 +50,6 @@ impl Inputs {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self { program_inputs, public })
|
||||
}
|
||||
|
||||
pub fn get_public_inputs<E: PairingEngine>(&self) -> Result<Vec<E::Fr>, InputParserError> {
|
||||
let mut input_vec = vec![];
|
||||
|
||||
for input in self.public.iter() {
|
||||
// get fields
|
||||
let mut input_fields = input.to_input_fields::<E>()?;
|
||||
|
||||
// push fields to input_vec
|
||||
input_vec.append(&mut input_fields.0)
|
||||
}
|
||||
|
||||
Ok(input_vec)
|
||||
Ok(Self { program_inputs })
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
pub mod inputs;
|
||||
pub use inputs::*;
|
||||
|
||||
pub mod input_fields;
|
||||
pub use input_fields::*;
|
||||
|
||||
pub mod input_value;
|
||||
pub use input_value::*;
|
||||
|
@ -82,7 +82,6 @@ impl Integer {
|
||||
cs: &mut CS,
|
||||
integer_type: IntegerType,
|
||||
name: String,
|
||||
private: bool,
|
||||
integer_value: Option<InputValue>,
|
||||
) -> Result<Self, IntegerError> {
|
||||
// Check that the input value is the correct type
|
||||
@ -100,50 +99,33 @@ impl Integer {
|
||||
Ok(match integer_type {
|
||||
IntegerType::U8 => {
|
||||
let u8_option = integer_option.map(|integer| integer as u8);
|
||||
let u8_result = match private {
|
||||
true => UInt8::alloc(cs.ns(|| name), || u8_option.ok_or(SynthesisError::AssignmentMissing))?,
|
||||
false => UInt8::alloc_input(cs.ns(|| name), || u8_option.ok_or(SynthesisError::AssignmentMissing))?,
|
||||
};
|
||||
let u8_result = UInt8::alloc(cs.ns(|| name), || u8_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Integer::U8(u8_result)
|
||||
}
|
||||
IntegerType::U16 => {
|
||||
let u16_option = integer_option.map(|integer| integer as u16);
|
||||
let u16_result = match private {
|
||||
true => UInt16::alloc(cs.ns(|| name), || u16_option.ok_or(SynthesisError::AssignmentMissing))?,
|
||||
false => {
|
||||
UInt16::alloc_input(cs.ns(|| name), || u16_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
}
|
||||
};
|
||||
let u16_result = UInt16::alloc(cs.ns(|| name), || u16_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Integer::U16(u16_result)
|
||||
}
|
||||
IntegerType::U32 => {
|
||||
let u32_option = integer_option.map(|integer| integer as u32);
|
||||
let u32_result = match private {
|
||||
true => UInt32::alloc(cs.ns(|| name), || u32_option.ok_or(SynthesisError::AssignmentMissing))?,
|
||||
false => {
|
||||
UInt32::alloc_input(cs.ns(|| name), || u32_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
}
|
||||
};
|
||||
let u32_result = UInt32::alloc(cs.ns(|| name), || u32_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Integer::U32(u32_result)
|
||||
}
|
||||
IntegerType::U64 => {
|
||||
let u64_option = integer_option.map(|integer| integer as u64);
|
||||
let u64_result = match private {
|
||||
true => UInt64::alloc(cs.ns(|| name), || u64_option.ok_or(SynthesisError::AssignmentMissing))?,
|
||||
false => {
|
||||
UInt64::alloc_input(cs.ns(|| name), || u64_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
}
|
||||
};
|
||||
let u64_result = UInt64::alloc(cs.ns(|| name), || u64_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Integer::U64(u64_result)
|
||||
}
|
||||
IntegerType::U128 => {
|
||||
let u128_option = integer_option.map(|integer| integer as u128);
|
||||
let u128_result = match private {
|
||||
true => UInt128::alloc(cs.ns(|| name), || u128_option.ok_or(SynthesisError::AssignmentMissing))?,
|
||||
false => {
|
||||
UInt128::alloc_input(cs.ns(|| name), || u128_option.ok_or(SynthesisError::AssignmentMissing))?
|
||||
}
|
||||
};
|
||||
let u128_result =
|
||||
UInt128::alloc(cs.ns(|| name), || u128_option.ok_or(SynthesisError::AssignmentMissing))?;
|
||||
|
||||
Integer::U128(u128_result)
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user