impl group element values

This commit is contained in:
collin 2020-05-12 20:01:47 -07:00
parent 7e36d2b5fa
commit 6efc834948
25 changed files with 112 additions and 79 deletions

View File

@ -1,10 +1,3 @@
// Basic Pedersen hash function
// 1 window x 3 bits
function main() { function main() {
let arr1: u32[2][3] = [[0; 3]; 2]; let g = 0group;
let arr2: u32[2][3] = [[0, 0, 0], [0, 0, 0]];
assert_eq(arr1, arr2);
} }

View File

@ -6,24 +6,23 @@ use snarkos_algorithms::snark::{
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
}; };
use snarkos_curves::bls12_377::{Bls12_377, Fr}; use snarkos_curves::bls12_377::{Bls12_377, Fr};
use snarkos_curves::edwards_bls12::EdwardsProjective;
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::curves::Group;
use snarkos_models::{ use snarkos_models::{
curves::{Field, PrimeField}, curves::{Field, PrimeField},
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}, gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
}; };
use snarkos_models::curves::Group;
use std::{ use std::{
fs, fs,
marker::PhantomData, marker::PhantomData,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use std::str::FromStr;
use snarkos_curves::edwards_bls12::EdwardsProjective;
#[derive(Clone)] #[derive(Clone)]
pub struct Benchmark<F: Field + PrimeField, G: Group> { pub struct Benchmark<F: Field + PrimeField, G: Group> {
program: Program<F>, program: Program<F, G>,
parameters: Vec<Option<InputValue<F>>>, parameters: Vec<Option<InputValue<F, G>>>,
_group: PhantomData<G>, _group: PhantomData<G>,
_engine: PhantomData<F>, _engine: PhantomData<F>,
} }
@ -39,12 +38,6 @@ impl<F: Field + PrimeField, G: Group> Benchmark<F, G> {
} }
pub fn evaluate_program(&mut self) -> Result<(), CompilerError> { pub fn evaluate_program(&mut self) -> Result<(), CompilerError> {
let scalar = G::ScalarField::from_str("2325446546544").unwrap_or_default();
println!("{}", scalar);
let other = G::default().mul(&G::ScalarField::one());
println!("{}", other);
assert_eq!(G::default(), G::default().double());
// Read in file as string // Read in file as string
let unparsed_file = fs::read_to_string("simple.leo").expect("cannot read file"); let unparsed_file = fs::read_to_string("simple.leo").expect("cannot read file");
@ -53,10 +46,9 @@ impl<F: Field + PrimeField, G: Group> Benchmark<F, G> {
// Build the abstract syntax tree // Build the abstract syntax tree
let syntax_tree = ast::File::from_pest(&mut file).expect("infallible"); let syntax_tree = ast::File::from_pest(&mut file).expect("infallible");
// println!("{:#?}", syntax_tree);
// Build a leo program from the syntax tree // Build a leo program from the syntax tree
self.program = Program::<F>::from(syntax_tree, "simple".into()); self.program = Program::<F, G>::from(syntax_tree, "simple".into());
self.parameters = vec![None; self.program.num_parameters]; self.parameters = vec![None; self.program.num_parameters];
println!(" compiled: {:#?}\n", self.program); println!(" compiled: {:#?}\n", self.program);
@ -70,8 +62,7 @@ impl<F: Field + PrimeField, G: Group> ConstraintSynthesizer<F> for Benchmark<F,
self, self,
cs: &mut CS, cs: &mut CS,
) -> Result<(), SynthesisError> { ) -> Result<(), SynthesisError> {
let _res = let _res = leo_compiler::generate_constraints(cs, self.program, self.parameters).unwrap();
leo_compiler::generate_constraints(cs, self.program, self.parameters).unwrap();
println!(" Result: {}", _res); println!(" Result: {}", _res);
// Write results to file or something // Write results to file or something

View File

@ -259,6 +259,7 @@ impl<'ast> fmt::Display for Integer<'ast> {
#[pest_ast(rule(Rule::value_field))] #[pest_ast(rule(Rule::value_field))]
pub struct Field<'ast> { pub struct Field<'ast> {
pub number: Number<'ast>, pub number: Number<'ast>,
pub _type: FieldType<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
@ -273,6 +274,7 @@ impl<'ast> fmt::Display for Field<'ast> {
#[pest_ast(rule(Rule::value_group))] #[pest_ast(rule(Rule::value_group))]
pub struct Group<'ast> { pub struct Group<'ast> {
pub number: Number<'ast>, pub number: Number<'ast>,
pub _type: GroupType<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }

View File

@ -9,7 +9,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}, gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
}; };

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{ gadgets::{
r1cs::ConstraintSystem, r1cs::ConstraintSystem,
utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget}, utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget},

View File

@ -10,7 +10,7 @@ use crate::{
}; };
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
}; };
@ -440,6 +440,7 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
// Values // Values
Expression::Integer(integer) => Ok(Self::get_integer_constant(integer)), Expression::Integer(integer) => Ok(Self::get_integer_constant(integer)),
Expression::FieldElement(fe) => Ok(Self::get_field_element_constant(fe)), Expression::FieldElement(fe) => Ok(Self::get_field_element_constant(fe)),
Expression::GroupElement(gr) => Ok(ConstrainedValue::GroupElement(gr)),
Expression::Boolean(bool) => Ok(Self::get_boolean_constant(bool)), Expression::Boolean(bool) => Ok(Self::get_boolean_constant(bool)),
// Binary operations // Binary operations

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::r1cs::{ConstraintSystem, LinearCombination, Variable as R1CSVariable}, gadgets::r1cs::{ConstraintSystem, LinearCombination, Variable as R1CSVariable},
}; };

View File

@ -13,7 +13,7 @@ use crate::{
}; };
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::r1cs::ConstraintSystem, gadgets::r1cs::ConstraintSystem,
}; };

View File

@ -8,7 +8,7 @@ use crate::{
use from_pest::FromPest; use from_pest::FromPest;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::r1cs::ConstraintSystem, gadgets::r1cs::ConstraintSystem,
}; };
use std::fs; use std::fs;

View File

@ -8,7 +8,7 @@ use crate::{
}; };
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
}; };

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{ gadgets::{
r1cs::ConstraintSystem, r1cs::ConstraintSystem,
utilities::{alloc::AllocGadget, eq::EqGadget, uint128::UInt128}, utilities::{alloc::AllocGadget, eq::EqGadget, uint128::UInt128},

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{ gadgets::{
r1cs::ConstraintSystem, r1cs::ConstraintSystem,
utilities::{alloc::AllocGadget, eq::EqGadget, uint16::UInt16}, utilities::{alloc::AllocGadget, eq::EqGadget, uint16::UInt16},

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{ gadgets::{
r1cs::ConstraintSystem, r1cs::ConstraintSystem,
utilities::{alloc::AllocGadget, eq::EqGadget, uint32::UInt32}, utilities::{alloc::AllocGadget, eq::EqGadget, uint32::UInt32},

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{ gadgets::{
r1cs::ConstraintSystem, r1cs::ConstraintSystem,
utilities::{alloc::AllocGadget, eq::EqGadget, uint64::UInt64}, utilities::{alloc::AllocGadget, eq::EqGadget, uint64::UInt64},

View File

@ -8,7 +8,7 @@ use crate::{
use snarkos_errors::gadgets::SynthesisError; use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{ gadgets::{
r1cs::ConstraintSystem, r1cs::ConstraintSystem,
utilities::{alloc::AllocGadget, eq::EqGadget, uint8::UInt8}, utilities::{alloc::AllocGadget, eq::EqGadget, uint8::UInt8},

View File

@ -33,7 +33,7 @@ use crate::{
}; };
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::r1cs::ConstraintSystem, gadgets::r1cs::ConstraintSystem,
}; };

View File

@ -3,7 +3,7 @@
use crate::{constraints::ConstrainedValue, types::Variable}; use crate::{constraints::ConstrainedValue, types::Variable};
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::r1cs::ConstraintSystem, gadgets::r1cs::ConstraintSystem,
}; };
use std::{collections::HashMap, marker::PhantomData}; use std::{collections::HashMap, marker::PhantomData};
@ -31,7 +31,7 @@ pub fn new_variable_from_variable<F: Field + PrimeField, G: Group>(
Variable { Variable {
name: new_scope_from_variable(outer, inner), name: new_scope_from_variable(outer, inner),
_engine: PhantomData::<F>, _engine: PhantomData::<F>,
_group: PhantomData::<G> _group: PhantomData::<G>,
} }
} }
@ -58,7 +58,11 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
self.resolved_names.insert(name, value); self.resolved_names.insert(name, value);
} }
pub(crate) fn store_variable(&mut self, variable: Variable<F, G>, value: ConstrainedValue<F, G>) { pub(crate) fn store_variable(
&mut self,
variable: Variable<F, G>,
value: ConstrainedValue<F, G>,
) {
self.store(variable.name, value); self.store(variable.name, value);
} }

View File

@ -10,7 +10,7 @@ use crate::{
}; };
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean, utilities::uint32::UInt32}, gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean, utilities::uint32::UInt32},
}; };

View File

@ -7,13 +7,16 @@ use crate::{
}; };
use snarkos_models::{ use snarkos_models::{
curves::{Group, Field, PrimeField}, curves::{Field, Group, PrimeField},
gadgets::utilities::boolean::Boolean, gadgets::utilities::boolean::Boolean,
}; };
use std::fmt; use std::fmt;
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq)]
pub struct ConstrainedStructMember<F: Field + PrimeField, G: Group>(pub Variable<F, G>, pub ConstrainedValue<F, G>); pub struct ConstrainedStructMember<F: Field + PrimeField, G: Group>(
pub Variable<F, G>,
pub ConstrainedValue<F, G>,
);
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq)]
pub enum ConstrainedValue<F: Field + PrimeField, G: Group> { pub enum ConstrainedValue<F: Field + PrimeField, G: Group> {

View File

@ -2,7 +2,7 @@
use crate::Variable; use crate::Variable;
use snarkos_models::curves::{Field, PrimeField, Group}; use snarkos_models::curves::{Field, Group, PrimeField};
use std::fmt; use std::fmt;
#[derive(Clone)] #[derive(Clone)]

View File

@ -72,7 +72,7 @@ type_integer = {
type_field = {"field"} type_field = {"field"}
type_group = {"group"} type_group = {"group"}
type_bool = {"bool"} type_bool = {"bool"}
type_basic = { type_integer | type_field | type_group | type_bool } type_basic = { type_field | type_group | type_bool | type_integer }
type_struct = { variable } type_struct = { variable }
type_basic_or_struct = {type_basic | type_struct } type_basic_or_struct = {type_basic | type_struct }
type_array = {type_basic ~ ("[" ~ value ~ "]")+ } type_array = {type_basic ~ ("[" ~ value ~ "]")+ }
@ -83,10 +83,10 @@ type_list = _{(_type ~ ("," ~ _type)*)?}
value_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } value_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* }
value_integer = { value_number ~ type_integer? } value_integer = { value_number ~ type_integer? }
value_field = { value_number ~ "fe" } value_field = { value_number ~ type_field }
value_group = { value_number ~ "gr" } value_group = { value_number ~ type_group }
value_boolean = { "true" | "false" } value_boolean = { "true" | "false" }
value = { value_field | value_boolean | value_integer } value = { value_field | value_group | value_boolean | value_integer }
/// Variables /// Variables

View File

@ -4,7 +4,7 @@
use crate::{errors::IntegerError, Import}; use crate::{errors::IntegerError, Import};
use crate::errors::ValueError; use crate::errors::ValueError;
use snarkos_models::curves::{Field, PrimeField, Group}; use snarkos_models::curves::{Field, Group, PrimeField};
use snarkos_models::gadgets::{ use snarkos_models::gadgets::{
r1cs::Variable as R1CSVariable, r1cs::Variable as R1CSVariable,
utilities::{ utilities::{
@ -135,7 +135,11 @@ pub enum Expression<F: Field + PrimeField, G: Group> {
Lt(Box<Expression<F, G>>, Box<Expression<F, G>>), Lt(Box<Expression<F, G>>, Box<Expression<F, G>>),
// Conditionals // Conditionals
IfElse(Box<Expression<F, G>>, Box<Expression<F, G>>, Box<Expression<F, G>>), IfElse(
Box<Expression<F, G>>,
Box<Expression<F, G>>,
Box<Expression<F, G>>,
),
// Arrays // Arrays
Array(Vec<Box<SpreadOrExpression<F, G>>>), Array(Vec<Box<SpreadOrExpression<F, G>>>),

View File

@ -6,7 +6,7 @@ use crate::{
SpreadOrExpression, Statement, Struct, StructField, Type, Variable, SpreadOrExpression, Statement, Struct, StructField, Type, Variable,
}; };
use snarkos_models::curves::{Group, Field, PrimeField}; use snarkos_models::curves::{Field, Group, PrimeField};
use std::fmt; use std::fmt;
impl<F: Field + PrimeField, G: Group> fmt::Display for Variable<F, G> { impl<F: Field + PrimeField, G: Group> fmt::Display for Variable<F, G> {
@ -34,7 +34,7 @@ impl<F: Field + PrimeField> FieldElement<F> {
if option.is_some() { if option.is_some() {
write!(f, "{}", option.unwrap()) write!(f, "{}", option.unwrap())
} else { } else {
write!(f, "allocated fe") write!(f, "allocated field")
} }
} }
} }
@ -314,6 +314,7 @@ impl<F: Field + PrimeField, G: Group> fmt::Display for InputValue<F, G> {
match self { match self {
InputValue::Integer(ref integer) => write!(f, "{}", integer), InputValue::Integer(ref integer) => write!(f, "{}", integer),
InputValue::Field(ref field) => write!(f, "{}", field), InputValue::Field(ref field) => write!(f, "{}", field),
InputValue::Group(ref group) => write!(f, "{}", group),
InputValue::Boolean(ref bool) => write!(f, "{}", bool), InputValue::Boolean(ref bool) => write!(f, "{}", bool),
InputValue::Array(ref array) => { InputValue::Array(ref array) => {
write!(f, "[")?; write!(f, "[")?;

View File

@ -2,7 +2,7 @@
use crate::{ast, types, Import, ImportSymbol}; use crate::{ast, types, Import, ImportSymbol};
use snarkos_models::curves::{Field, PrimeField, Group}; use snarkos_models::curves::{Field, Group, PrimeField};
use snarkos_models::gadgets::utilities::{ use snarkos_models::gadgets::utilities::{
boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64, boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64,
uint8::UInt8, uint8::UInt8,
@ -80,12 +80,14 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::RangeOrExpression<'ast>>
unimplemented!("Range bounds should be integers, found {}", expression) unimplemented!("Range bounds should be integers, found {}", expression)
} }
}); });
let to = range.to.map(|to| match types::Expression::<F, G>::from(to.0) { let to = range
types::Expression::Integer(number) => number, .to
expression => { .map(|to| match types::Expression::<F, G>::from(to.0) {
unimplemented!("Range bounds should be integers, found {}", expression) types::Expression::Integer(number) => number,
} expression => {
}); unimplemented!("Range bounds should be integers, found {}", expression)
}
});
types::RangeOrExpression::Range(from, to) types::RangeOrExpression::Range(from, to)
} }
@ -133,14 +135,16 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::Value<'ast>> for types::Ex
fn from(value: ast::Value<'ast>) -> Self { fn from(value: ast::Value<'ast>) -> Self {
match value { match value {
ast::Value::Integer(num) => types::Expression::from(num), ast::Value::Integer(num) => types::Expression::from(num),
ast::Value::Field(fe) => types::Expression::from(fe), ast::Value::Field(field) => types::Expression::from(field),
ast::Value::Group(group) => unimplemented!("no groups yet"), ast::Value::Group(group) => types::Expression::from(group),
ast::Value::Boolean(bool) => types::Expression::from(bool), ast::Value::Boolean(bool) => types::Expression::from(bool),
} }
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::NotExpression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::NotExpression<'ast>>
for types::Expression<F, G>
{
fn from(expression: ast::NotExpression<'ast>) -> Self { fn from(expression: ast::NotExpression<'ast>) -> Self {
types::Expression::Not(Box::new(types::Expression::from(*expression.expression))) types::Expression::Not(Box::new(types::Expression::from(*expression.expression)))
} }
@ -161,7 +165,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::SpreadOrExpression<'ast>>
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::BinaryExpression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::BinaryExpression<'ast>>
for types::Expression<F, G>
{
fn from(expression: ast::BinaryExpression<'ast>) -> Self { fn from(expression: ast::BinaryExpression<'ast>) -> Self {
match expression.operation { match expression.operation {
// Boolean operations // Boolean operations
@ -221,7 +227,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::BinaryExpression<'ast>> fo
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::TernaryExpression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::TernaryExpression<'ast>>
for types::Expression<F, G>
{
fn from(expression: ast::TernaryExpression<'ast>) -> Self { fn from(expression: ast::TernaryExpression<'ast>) -> Self {
types::Expression::IfElse( types::Expression::IfElse(
Box::new(types::Expression::from(*expression.first)), Box::new(types::Expression::from(*expression.first)),
@ -231,7 +239,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::TernaryExpression<'ast>> f
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ArrayInlineExpression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::ArrayInlineExpression<'ast>>
for types::Expression<F, G>
{
fn from(array: ast::ArrayInlineExpression<'ast>) -> Self { fn from(array: ast::ArrayInlineExpression<'ast>) -> Self {
types::Expression::Array( types::Expression::Array(
array array
@ -253,7 +263,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::ArrayInitializerExpression
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::InlineStructMember<'ast>> for types::StructMember<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::InlineStructMember<'ast>>
for types::StructMember<F, G>
{
fn from(member: ast::InlineStructMember<'ast>) -> Self { fn from(member: ast::InlineStructMember<'ast>) -> Self {
types::StructMember { types::StructMember {
variable: types::Variable::from(member.variable), variable: types::Variable::from(member.variable),
@ -262,7 +274,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::InlineStructMember<'ast>>
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructInlineExpression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructInlineExpression<'ast>>
for types::Expression<F, G>
{
fn from(expression: ast::StructInlineExpression<'ast>) -> Self { fn from(expression: ast::StructInlineExpression<'ast>) -> Self {
let variable = types::Variable::from(expression.variable); let variable = types::Variable::from(expression.variable);
let members = expression let members = expression
@ -275,7 +289,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructInlineExpression<'as
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::PostfixExpression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::PostfixExpression<'ast>>
for types::Expression<F, G>
{
fn from(expression: ast::PostfixExpression<'ast>) -> Self { fn from(expression: ast::PostfixExpression<'ast>) -> Self {
let variable = types::Expression::Variable(types::Variable::from(expression.variable)); let variable = types::Expression::Variable(types::Variable::from(expression.variable));
@ -312,7 +328,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::PostfixExpression<'ast>> f
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Expression<'ast>> for types::Expression<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::Expression<'ast>>
for types::Expression<F, G>
{
fn from(expression: ast::Expression<'ast>) -> Self { fn from(expression: ast::Expression<'ast>) -> Self {
match expression { match expression {
ast::Expression::Value(value) => types::Expression::from(value), ast::Expression::Value(value) => types::Expression::from(value),
@ -396,7 +414,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::Assignee<'ast>> for types:
/// pest ast -> types::Statement /// pest ast -> types::Statement
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ReturnStatement<'ast>> for types::Statement<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::ReturnStatement<'ast>>
for types::Statement<F, G>
{
fn from(statement: ast::ReturnStatement<'ast>) -> Self { fn from(statement: ast::ReturnStatement<'ast>) -> Self {
types::Statement::Return( types::Statement::Return(
statement statement
@ -408,17 +428,23 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::ReturnStatement<'ast>> for
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::DefinitionStatement<'ast>> for types::Statement<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::DefinitionStatement<'ast>>
for types::Statement<F, G>
{
fn from(statement: ast::DefinitionStatement<'ast>) -> Self { fn from(statement: ast::DefinitionStatement<'ast>) -> Self {
types::Statement::Definition( types::Statement::Definition(
types::Assignee::from(statement.variable), types::Assignee::from(statement.variable),
statement._type.map(|_type| types::Type::<F, G>::from(_type)), statement
._type
.map(|_type| types::Type::<F, G>::from(_type)),
types::Expression::from(statement.expression), types::Expression::from(statement.expression),
) )
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssignStatement<'ast>> for types::Statement<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssignStatement<'ast>>
for types::Statement<F, G>
{
fn from(statement: ast::AssignStatement<'ast>) -> Self { fn from(statement: ast::AssignStatement<'ast>) -> Self {
match statement.assign { match statement.assign {
ast::OperationAssign::Assign(ref _assign) => types::Statement::Assign( ast::OperationAssign::Assign(ref _assign) => types::Statement::Assign(
@ -535,7 +561,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::ConditionalStatement<'ast>
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ForStatement<'ast>> for types::Statement<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::ForStatement<'ast>>
for types::Statement<F, G>
{
fn from(statement: ast::ForStatement<'ast>) -> Self { fn from(statement: ast::ForStatement<'ast>) -> Self {
let from = match types::Expression::<F, G>::from(statement.start) { let from = match types::Expression::<F, G>::from(statement.start) {
types::Expression::Integer(number) => number, types::Expression::Integer(number) => number,
@ -559,7 +587,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::ForStatement<'ast>> for ty
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssertStatement<'ast>> for types::Statement<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssertStatement<'ast>>
for types::Statement<F, G>
{
fn from(statement: ast::AssertStatement<'ast>) -> Self { fn from(statement: ast::AssertStatement<'ast>) -> Self {
match statement { match statement {
ast::AssertStatement::AssertEq(assert_eq) => types::Statement::AssertEq( ast::AssertStatement::AssertEq(assert_eq) => types::Statement::AssertEq(
@ -570,7 +600,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssertStatement<'ast>> for
} }
} }
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ExpressionStatement<'ast>> for types::Statement<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::ExpressionStatement<'ast>>
for types::Statement<F, G>
{
fn from(statement: ast::ExpressionStatement<'ast>) -> Self { fn from(statement: ast::ExpressionStatement<'ast>) -> Self {
types::Statement::Expression(types::Expression::from(statement.expression)) types::Statement::Expression(types::Expression::from(statement.expression))
} }
@ -610,7 +642,9 @@ impl From<ast::IntegerType> for types::IntegerType {
impl<'ast, F: Field + PrimeField, G: Group> From<ast::BasicType<'ast>> for types::Type<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::BasicType<'ast>> for types::Type<F, G> {
fn from(basic_type: ast::BasicType<'ast>) -> Self { fn from(basic_type: ast::BasicType<'ast>) -> Self {
match basic_type { match basic_type {
ast::BasicType::Integer(_type) => types::Type::IntegerType(types::IntegerType::from(_type)), ast::BasicType::Integer(_type) => {
types::Type::IntegerType(types::IntegerType::from(_type))
}
ast::BasicType::Field(_type) => types::Type::FieldElement, ast::BasicType::Field(_type) => types::Type::FieldElement,
ast::BasicType::Group(_type) => unimplemented!(), ast::BasicType::Group(_type) => unimplemented!(),
ast::BasicType::Boolean(_type) => types::Type::Boolean, ast::BasicType::Boolean(_type) => types::Type::Boolean,
@ -649,7 +683,9 @@ impl<'ast, F: Field + PrimeField, G: Group> From<ast::Type<'ast>> for types::Typ
/// pest ast -> types::Struct /// pest ast -> types::Struct
impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructField<'ast>> for types::StructField<F, G> { impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructField<'ast>>
for types::StructField<F, G>
{
fn from(struct_field: ast::StructField<'ast>) -> Self { fn from(struct_field: ast::StructField<'ast>) -> Self {
types::StructField { types::StructField {
variable: types::Variable::from(struct_field.variable), variable: types::Variable::from(struct_field.variable),

View File

@ -1,2 +0,0 @@
// 3 bit Pedersen hash function
fn main() ->