1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

complete merge

This commit is contained in:
schaeff 2020-09-29 17:54:53 +02:00
parent e8cdbcc318
commit cb0728d6ae
21 changed files with 232 additions and 264 deletions

View file

@ -574,7 +574,6 @@ impl<'ast> fmt::Display for Expression<'ast> {
}
write!(f, "}}")
}
Expression::ArrayInitializer(ref e, ref count) => write!(f, "[{}; {}]", e, count),
Expression::Select(ref array, ref index) => write!(f, "{}[{}]", array, index),
Expression::Member(ref struc, ref id) => write!(f, "{}.{}", struc, id),
Expression::Or(ref lhs, ref rhs) => write!(f, "({} || {})", lhs, rhs),
@ -632,9 +631,6 @@ impl<'ast> fmt::Debug for Expression<'ast> {
f.debug_list().entries(members.iter()).finish()?;
write!(f, "]")
}
Expression::ArrayInitializer(ref e, ref count) => {
write!(f, "ArrayInitializer({:?}, {:?})", e, count)
}
Expression::Select(ref array, ref index) => {
write!(f, "Select({:?}, {:?})", array, index)
}

View file

@ -1467,55 +1467,62 @@ impl<'ast, T: Field> Checker<'ast, T> {
let size = e.size();
unimplemented!()
// match e.into_inner() {
// // if we're doing a spread over an inline array, we return the inside of the array: ...[x, y, z] == x, y, z
// // this is not strictly needed, but it makes spreads memory linear rather than quadratic
// ArrayExpressionInner::Value(v) => Ok(v),
// // otherwise we return a[0], ..., a[a.size() -1 ]
// e => Ok((0..size)
// .map(|i| match &ty {
// Type::FieldElement => FieldElementExpression::select(
// e.clone().annotate(Type::FieldElement, size as usize),
// FieldElementExpression::Number(T::from(i)),
// )
// .into(),
// Type::Uint(bitwidth) => UExpression::select(
// e.clone().annotate(Type::Uint(*bitwidth), size as usize),
// FieldElementExpression::Number(T::from(i)),
// )
// .into(),
// Type::Boolean => BooleanExpression::select(
// e.clone().annotate(Type::Boolean, size as usize),
// FieldElementExpression::Number(T::from(i)),
// )
// .into(),
// Type::Array(array_type) => ArrayExpressionInner::Select(
// box e.clone().annotate(
// Type::Array(array_type.clone()),
// size as usize,
// ),
// box FieldElementExpression::Number(T::from(i)),
// )
// .annotate(*array_type.ty.clone(), array_type.size.clone())
// .into(),
// Type::Struct(members) => StructExpressionInner::Select(
// box e
// .clone()
// .annotate(Type::Struct(members.clone()), size as usize),
// box FieldElementExpression::Number(T::from(i)),
// )
// .annotate(members.clone())
// .into(),
// Type::Int => IntExpression::select(
// e.clone().annotate(Type::Int, size as usize),
// FieldElementExpression::Number(T::from(i)),
// )
// .into(),
// })
// .collect()),
// }
match size.into_inner() {
UExpressionInner::Value(size) => {
match e.into_inner() {
// if we're doing a spread over an inline array, we return the inside of the array: ...[x, y, z] == x, y, z
// this is not strictly needed, but it makes spreads memory linear rather than quadratic
ArrayExpressionInner::Value(v) => Ok(v),
// otherwise we return a[0], ..., a[a.size() -1 ]
e => Ok((0..size)
.map(|i| match &ty {
Type::FieldElement => FieldElementExpression::select(
e.clone().annotate(Type::FieldElement, size as usize),
i as u32,
)
.into(),
Type::Uint(bitwidth) => UExpression::select(
e.clone().annotate(Type::Uint(*bitwidth), size as usize),
i as u32,
)
.into(),
Type::Boolean => BooleanExpression::select(
e.clone().annotate(Type::Boolean, size as usize),
i as u32,
)
.into(),
Type::Array(array_type) => ArrayExpression::select(
e.clone().annotate(
Type::Array(array_type.clone()),
size as usize,
),
i as u32,
)
.into(),
Type::Struct(members) => StructExpression::select(
e
.clone()
.annotate(Type::Struct(members.clone()), size as usize),
i as u32,
)
.into(),
Type::Int => IntExpression::select(
e.clone().annotate(Type::Int, size as usize),
i as u32,
)
.into(),
})
.collect()),
}
},
size => Err(ErrorInner {
pos: Some(pos),
message: format!(
"The spread operator must apply on a constant-sized array, found size {}",
size.annotate(UBitwidth::B32)
),
})
}
}
e => Err(ErrorInner {
pos: Some(pos),
@ -3124,8 +3131,8 @@ mod tests {
let expr =
Expression::FieldConstant(BigUint::from(Bn128Field::max_value().to_biguint()))
.mock();
assert!(Checker::new()
.check_expression::<Bn128Field>(expr, &module_id, &types)
assert!(Checker::<Bn128Field>::new()
.check_expression(expr, &module_id, &types)
.is_ok());
}
@ -3137,8 +3144,8 @@ mod tests {
let value = Bn128Field::max_value().to_biguint().add(1u32);
let expr = Expression::FieldConstant(BigUint::from(value)).mock();
assert!(Checker::new()
.check_expression::<Bn128Field>(expr, &module_id, &types)
assert!(Checker::<Bn128Field>::new()
.check_expression(expr, &module_id, &types)
.is_err());
}
}
@ -3157,8 +3164,8 @@ mod tests {
Expression::BooleanConstant(true).mock().into(),
])
.mock();
assert!(Checker::new()
.check_expression::<Bn128Field>(a, &module_id, &types)
assert!(Checker::<Bn128Field>::new()
.check_expression(a, &module_id, &types)
.is_err());
// [[0f], [0f, 0f]]
@ -3176,8 +3183,8 @@ mod tests {
.into(),
])
.mock();
assert!(Checker::new()
.check_expression::<Bn128Field>(a, &module_id, &types)
assert!(Checker::<Bn128Field>::new()
.check_expression(a, &module_id, &types)
.is_err());
// [[0f], true]
@ -3192,8 +3199,8 @@ mod tests {
.into(),
])
.mock();
assert!(Checker::new()
.check_expression::<Bn128Field>(a, &module_id, &types)
assert!(Checker::<Bn128Field>::new()
.check_expression(a, &module_id, &types)
.is_err());
}
}
@ -3252,11 +3259,11 @@ mod tests {
mod symbols {
use super::*;
fn struct0<T: Field>() -> StructDefinitionNode<'static, T> {
fn struct0() -> StructDefinitionNode<'static> {
StructDefinition { fields: vec![] }.mock()
}
fn struct1<T: Field>() -> StructDefinitionNode<'static, T> {
fn struct1() -> StructDefinitionNode<'static> {
StructDefinition {
fields: vec![StructDefinitionField {
id: "foo".into(),
@ -3320,7 +3327,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(checker.check_module(&"bar".into(), &mut state), Ok(()));
assert_eq!(
@ -3372,7 +3379,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&PathBuf::from(MODULE_ID).into(), &mut state)
@ -3454,7 +3461,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&PathBuf::from(MODULE_ID).into(), &mut state)
@ -3503,7 +3510,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&PathBuf::from(MODULE_ID).into(), &mut state)
@ -3566,7 +3573,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&PathBuf::from(MODULE_ID).into(), &mut state)
@ -3609,7 +3616,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker.check_module(&PathBuf::from(MODULE_ID), &mut state),
Ok(())
@ -3658,7 +3665,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&"main".into(), &mut state)
@ -3696,7 +3703,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&"main".into(), &mut state)
@ -3750,7 +3757,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&PathBuf::from(MODULE_ID), &mut state)
@ -3801,7 +3808,7 @@ mod tests {
.collect(),
);
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker
.check_module(&PathBuf::from(MODULE_ID), &mut state)
@ -3838,9 +3845,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker.check_statement::<Bn128Field>(statement, &module_id, &types),
checker.check_statement(statement, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
message: "Identifier \"b\" is undefined".into()
@ -3870,9 +3877,9 @@ mod tests {
id: Variable::field_element("b"),
level: 0,
});
let mut checker = new_with_args(scope, 1, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(scope, 1, HashSet::new());
assert_eq!(
checker.check_statement::<Bn128Field>(statement, &module_id, &types),
checker.check_statement(statement, &module_id, &types),
Ok(TypedStatement::Definition(
TypedAssignee::Identifier(typed_absy::Variable::field_element("a")),
FieldElementExpression::Identifier("b".into()).into()
@ -3950,7 +3957,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker.check_module(&"main".into(), &mut state),
Err(vec![Error {
@ -4072,7 +4079,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert!(checker.check_module(&"main".into(), &mut state).is_ok());
}
@ -4083,7 +4090,7 @@ mod tests {
// endfor
// return i
// should fail
let foo_statements: Vec<StatementNode<Bn128Field>> = vec![
let foo_statements: Vec<StatementNode> = vec![
Statement::For(
absy::Variable::new("i", UnresolvedType::Uint(32).mock()).mock(),
Expression::IntConstant(0usize.into()).mock(),
@ -4113,9 +4120,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker.check_function::<Bn128Field>(foo, &module_id, &types),
checker.check_function(foo, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
message: "Identifier \"i\" is undefined".into()
@ -4191,9 +4198,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker.check_function::<Bn128Field>(foo, &module_id, &types),
checker.check_function(foo, &module_id, &types),
Ok(foo_checked)
);
}
@ -4241,9 +4248,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = new_with_args(HashSet::new(), 0, functions);
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, functions);
assert_eq!(
checker.check_function::<Bn128Field>(bar, &module_id, &types),
checker.check_function(bar, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
message:
@ -4293,9 +4300,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = new_with_args(HashSet::new(), 0, functions);
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, functions);
assert_eq!(
checker.check_function::<Bn128Field>(bar, &module_id, &types),
checker.check_function(bar, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
message: "Function definition for function foo with signature () -> _ not found."
@ -4335,9 +4342,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker.check_function::<Bn128Field>(bar, &module_id, &types),
checker.check_function(bar, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
@ -4442,7 +4449,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker.check_module(&"main".into(), &mut state),
Err(vec![Error {
@ -4537,7 +4544,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker.check_module(&"main".into(), &mut state),
Err(vec![
@ -4659,7 +4666,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![("main".into(), module)].into_iter().collect());
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker.check_module(&"main".into(), &mut state),
Err(vec![Error {
@ -4700,9 +4707,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker.check_function::<Bn128Field>(bar, &module_id, &types),
checker.check_function(bar, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
@ -4745,9 +4752,9 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker.check_function::<Bn128Field>(bar, &module_id, &types),
checker.check_function(bar, &module_id, &types),
Err(vec![ErrorInner {
pos: Some((Position::mock(), Position::mock())),
message: "Identifier \"a\" is undefined".into()
@ -4851,7 +4858,7 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = new_with_args(HashSet::new(), 0, functions);
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, functions);
assert_eq!(
checker.check_function(bar, &module_id, &types),
Ok(bar_checked)
@ -4881,10 +4888,10 @@ mod tests {
UnresolvedType::Boolean.mock(),
]);
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
let mut checker: Checker<Bn128Field> = new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(
checker
.check_function::<Bn128Field>(f, &"".into(), &HashMap::new())
.check_function(f, &"".into(), &HashMap::new())
.unwrap_err()[0]
.message,
"Duplicate name in function definition: `a` was previously declared as an argument"
@ -4968,9 +4975,9 @@ mod tests {
main: "main".into(),
};
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
assert_eq!(
checker.check_program::<Bn128Field>(program),
checker.check_program(program),
Err(vec![Error {
inner: ErrorInner {
pos: None,
@ -4990,7 +4997,7 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
let _: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker.check_statement(
Statement::Declaration(
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
@ -5027,7 +5034,7 @@ mod tests {
let types = HashMap::new();
let module_id = "".into();
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
let _: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker.check_statement(
Statement::Declaration(
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
@ -5059,7 +5066,9 @@ mod tests {
use typed_absy::types::StructMember;
/// solver function to create a module at location "" with a single symbol `Foo { foo: field }`
fn create_module_with_foo(s: StructDefinition<'static>) -> (Checker, State<Bn128Field>) {
fn create_module_with_foo(
s: StructDefinition<'static>,
) -> (Checker<Bn128Field>, State<Bn128Field>) {
let module_id: PathBuf = "".into();
let module: Module = Module {
@ -5074,7 +5083,7 @@ mod tests {
let mut state =
State::<Bn128Field>::new(vec![(module_id.clone(), module)].into_iter().collect());
let mut checker = Checker::new();
let mut checker: Checker<Bn128Field> = Checker::new();
checker.check_module(&module_id, &mut state).unwrap();
@ -5090,8 +5099,7 @@ mod tests {
// an empty struct should be allowed to be defined
let module_id = "".into();
let types = HashMap::new();
let declaration: StructDefinitionNode<Bn128Field> =
StructDefinition { fields: vec![] }.mock();
let declaration: StructDefinitionNode = StructDefinition { fields: vec![] }.mock();
let expected_type = DeclarationType::Struct(DeclarationStructType::new(
"".into(),
@ -5100,7 +5108,7 @@ mod tests {
));
assert_eq!(
Checker::new().check_struct_type_declaration::<Bn128Field>(
Checker::<Bn128Field>::new().check_struct_type_declaration(
"Foo".into(),
declaration,
&module_id,
@ -5115,7 +5123,7 @@ mod tests {
// a valid struct should be allowed to be defined
let module_id = "".into();
let types = HashMap::new();
let declaration: StructDefinitionNode<Bn128Field> = StructDefinition {
let declaration: StructDefinitionNode = StructDefinition {
fields: vec![
StructDefinitionField {
id: "foo",
@ -5141,7 +5149,7 @@ mod tests {
));
assert_eq!(
Checker::new().check_struct_type_declaration::<Bn128Field>(
Checker::<Bn128Field>::new().check_struct_type_declaration(
"Foo".into(),
declaration,
&module_id,
@ -5157,7 +5165,7 @@ mod tests {
let module_id = "".into();
let types = HashMap::new();
let declaration0: StructDefinitionNode<Bn128Field> = StructDefinition {
let declaration0: StructDefinitionNode = StructDefinition {
fields: vec![
StructDefinitionField {
id: "foo",
@ -5173,7 +5181,7 @@ mod tests {
}
.mock();
let declaration1: StructDefinitionNode<Bn128Field> = StructDefinition {
let declaration1: StructDefinitionNode = StructDefinition {
fields: vec![
StructDefinitionField {
id: "bar",
@ -5190,13 +5198,13 @@ mod tests {
.mock();
assert_ne!(
Checker::new().check_struct_type_declaration::<Bn128Field>(
Checker::<Bn128Field>::new().check_struct_type_declaration(
"Foo".into(),
declaration0,
&module_id,
&types
),
Checker::new().check_struct_type_declaration::<Bn128Field>(
Checker::<Bn128Field>::new().check_struct_type_declaration(
"Foo".into(),
declaration1,
&module_id,
@ -5211,7 +5219,7 @@ mod tests {
let module_id = "".into();
let types = HashMap::new();
let declaration: StructDefinitionNode<Bn128Field> = StructDefinition {
let declaration: StructDefinitionNode = StructDefinition {
fields: vec![
StructDefinitionField {
id: "foo",
@ -5228,8 +5236,8 @@ mod tests {
.mock();
assert_eq!(
Checker::new()
.check_struct_type_declaration::<Bn128Field>(
Checker::<Bn128Field>::new()
.check_struct_type_declaration(
"Foo".into(),
declaration,
&module_id,
@ -5453,7 +5461,7 @@ mod tests {
});
assert_eq!(
checker.check_type::<Bn128Field>(
checker.check_type(
UnresolvedType::User("Foo".into()).mock(),
&PathBuf::from(MODULE_ID).into(),
&state.types
@ -5467,7 +5475,7 @@ mod tests {
assert_eq!(
checker
.check_type::<Bn128Field>(
.check_type(
UnresolvedType::User("Bar".into()).mock(),
&PathBuf::from(MODULE_ID).into(),
&state.types
@ -5493,7 +5501,7 @@ mod tests {
});
assert_eq!(
checker.check_parameter::<Bn128Field>(
checker.check_parameter(
absy::Parameter {
id:
absy::Variable::new("a", UnresolvedType::User("Foo".into()).mock(),)
@ -5523,7 +5531,7 @@ mod tests {
assert_eq!(
checker
.check_parameter::<Bn128Field>(
.check_parameter(
absy::Parameter {
id: absy::Variable::new(
"a",
@ -5579,7 +5587,7 @@ mod tests {
assert_eq!(
checker
.check_parameter::<Bn128Field>(
.check_parameter(
absy::Parameter {
id: absy::Variable::new(
"a",
@ -5620,7 +5628,7 @@ mod tests {
});
assert_eq!(
checker.check_expression::<Bn128Field>(
checker.check_expression(
Expression::Member(
box Expression::InlineStruct(
"Foo".into(),
@ -5666,7 +5674,7 @@ mod tests {
assert_eq!(
checker
.check_expression::<Bn128Field>(
.check_expression(
Expression::Member(
box Expression::InlineStruct(
"Foo".into(),
@ -5704,7 +5712,7 @@ mod tests {
assert_eq!(
checker
.check_expression::<Bn128Field>(
.check_expression(
Expression::InlineStruct(
"Bar".into(),
vec![("foo", Expression::IntConstant(42usize.into()).mock())]
@ -5742,7 +5750,7 @@ mod tests {
});
assert_eq!(
checker.check_expression::<Bn128Field>(
checker.check_expression(
Expression::InlineStruct(
"Foo".into(),
vec![
@ -5793,7 +5801,7 @@ mod tests {
});
assert_eq!(
checker.check_expression::<Bn128Field>(
checker.check_expression(
Expression::InlineStruct(
"Foo".into(),
vec![
@ -5845,7 +5853,7 @@ mod tests {
assert_eq!(
checker
.check_expression::<Bn128Field>(
.check_expression(
Expression::InlineStruct(
"Foo".into(),
vec![("foo", Expression::IntConstant(42usize.into()).mock())]
@ -5886,7 +5894,7 @@ mod tests {
assert_eq!(
checker
.check_expression::<Bn128Field>(
.check_expression(
Expression::InlineStruct(
"Foo".into(),
vec![(
@ -5907,7 +5915,7 @@ mod tests {
assert_eq!(
checker
.check_expression::<Bn128Field>(
.check_expression(
Expression::InlineStruct(
"Foo".into(),
vec![
@ -6024,7 +6032,7 @@ mod tests {
modules: vec![("".into(), m)].into_iter().collect(),
};
let errors = Checker::new().check_program::<Bn128Field>(p).unwrap_err();
let errors = Checker::<Bn128Field>::new().check_program(p).unwrap_err();
assert_eq!(errors.len(), 1);
@ -6156,7 +6164,7 @@ mod tests {
.unwrap();
assert_eq!(
checker.check_assignee::<Bn128Field>(a, &module_id, &types),
checker.check_assignee(a, &module_id, &types),
Ok(TypedAssignee::Select(
box TypedAssignee::Select(
box TypedAssignee::Identifier(typed_absy::Variable::array(

View file

@ -45,7 +45,6 @@ fn flatten_identifier_rec<'ast>(
)
})
.collect(),
typed_absy::types::ConcreteType::Int => unreachable!(),
}
}

View file

@ -16,7 +16,7 @@
//! where any call in `main` must be to `_SHA_256_ROUND` or `_UNPACK`
use static_analysis::propagate_unroll::{Blocked, Output};
use static_analysis::propagate_unroll::Blocked;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use typed_absy::types::{
@ -863,10 +863,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
assert_eq!(program.modules.len(), 1);
assert_eq!(
@ -991,10 +988,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
assert_eq!(program.modules.len(), 1);
@ -1146,10 +1140,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
assert_eq!(program.modules.len(), 1);
assert_eq!(
@ -1320,10 +1311,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
assert_eq!(program.modules.len(), 1);
assert_eq!(
@ -1511,10 +1499,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
assert_eq!(program.modules.len(), 1);
assert_eq!(
@ -1610,10 +1595,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
assert_eq!(program.modules.len(), 1);
assert_eq!(
@ -1746,10 +1728,7 @@ mod tests {
modules,
};
let program = match Inliner::init(program.clone()).inline(program) {
Output::Complete(p) => p,
_ => unreachable!(),
};
let program = Inliner::init(program.clone()).inline(program);
let stack0 = vec![(
"id".into(),

View file

@ -52,7 +52,7 @@ impl PropagatedUnroller {
loop {
match Unroller::unroll(p.clone()) {
Output::Complete(p) => return Ok(p),
Output::Blocked(next, blocked, made_progress) => {
Output::Blocked(next, blocked, _) => {
let propagated = Propagator::propagate_main(next);
match blocked {

View file

@ -35,7 +35,6 @@ impl<'ast, T: Field> Folder<'ast, T> for ReturnBinder {
Type::Uint(bitwidth) => UExpressionInner::Identifier(i.clone())
.annotate(bitwidth)
.into(),
Type::Int => unreachable!(),
})
.collect();

View file

@ -10,7 +10,6 @@ use crate::typed_absy::*;
use std::collections::HashMap;
use std::collections::HashSet;
use typed_absy::identifier::CoreIdentifier;
use typed_absy::types::FunctionKey;
use zokrates_field::Field;
use static_analysis::propagate_unroll::{Blocked, Output};
@ -133,8 +132,7 @@ impl<'ast> Unroller<'ast> {
box head.clone(),
),
match Self::choose_many(
ArrayExpression::select(base.clone(), i.into())
.into(),
ArrayExpression::select(base.clone(), i).into(),
tail.clone(),
new_expression.clone(),
statements,
@ -145,7 +143,7 @@ impl<'ast> Unroller<'ast> {
e.get_type()
),
},
ArrayExpression::select(base.clone(), i.into()),
ArrayExpression::select(base.clone(), i),
)
.into(),
Type::Struct(..) => StructExpression::if_else(
@ -154,11 +152,8 @@ impl<'ast> Unroller<'ast> {
box head.clone(),
),
match Self::choose_many(
StructExpression::select(
base.clone(),
i.into(),
)
.into(),
StructExpression::select(base.clone(), i)
.into(),
tail.clone(),
new_expression.clone(),
statements,
@ -169,7 +164,7 @@ impl<'ast> Unroller<'ast> {
e.get_type()
),
},
StructExpression::select(base.clone(), i.into()),
StructExpression::select(base.clone(), i),
)
.into(),
Type::FieldElement => FieldElementExpression::if_else(
@ -178,11 +173,8 @@ impl<'ast> Unroller<'ast> {
box head.clone(),
),
match Self::choose_many(
FieldElementExpression::select(
base.clone(),
i.into(),
)
.into(),
FieldElementExpression::select(base.clone(), i)
.into(),
tail.clone(),
new_expression.clone(),
statements,
@ -193,10 +185,7 @@ impl<'ast> Unroller<'ast> {
e.get_type()
),
},
FieldElementExpression::select(
base.clone(),
i.into(),
),
FieldElementExpression::select(base.clone(), i),
)
.into(),
Type::Boolean => BooleanExpression::if_else(
@ -205,11 +194,8 @@ impl<'ast> Unroller<'ast> {
box head.clone(),
),
match Self::choose_many(
BooleanExpression::select(
base.clone(),
i.into(),
)
.into(),
BooleanExpression::select(base.clone(), i)
.into(),
tail.clone(),
new_expression.clone(),
statements,
@ -220,7 +206,7 @@ impl<'ast> Unroller<'ast> {
e.get_type()
),
},
BooleanExpression::select(base.clone(), i.into()),
BooleanExpression::select(base.clone(), i),
)
.into(),
Type::Uint(..) => UExpression::if_else(
@ -229,8 +215,7 @@ impl<'ast> Unroller<'ast> {
box head.clone(),
),
match Self::choose_many(
UExpression::select(base.clone(), i.into())
.into(),
UExpression::select(base.clone(), i).into(),
tail.clone(),
new_expression.clone(),
statements,
@ -241,7 +226,7 @@ impl<'ast> Unroller<'ast> {
e.get_type()
),
},
UExpression::select(base.clone(), i.into()),
UExpression::select(base.clone(), i),
)
.into(),
Type::Int => unreachable!(),
@ -360,7 +345,6 @@ impl<'ast> Unroller<'ast> {
.into()
}
}
Type::Int => unreachable!(),
})
.collect(),
)
@ -430,7 +414,6 @@ impl<'ast, T: Field> Folder<'ast, T> for Unroller<'ast> {
.annotate(members)
.into()
}
Type::Int => unreachable!(),
};
let base = self.fold_expression(base);
@ -670,19 +653,19 @@ mod tests {
FieldElementExpression::if_else(
BooleanExpression::UintEq(box 0u32.into(), box 1u32.into()),
FieldElementExpression::Number(Bn128Field::from(42)),
FieldElementExpression::select(a0.clone(), 0u32.into())
FieldElementExpression::select(a0.clone(), 0u32)
)
.into(),
FieldElementExpression::if_else(
BooleanExpression::UintEq(box 1u32.into(), box 1u32.into()),
FieldElementExpression::Number(Bn128Field::from(42)),
FieldElementExpression::select(a0.clone(), 1u32.into())
FieldElementExpression::select(a0.clone(), 1u32)
)
.into(),
FieldElementExpression::if_else(
BooleanExpression::UintEq(box 2u32.into(), box 1u32.into()),
FieldElementExpression::Number(Bn128Field::from(42)),
FieldElementExpression::select(a0.clone(), 2u32.into(),)
FieldElementExpression::select(a0.clone(), 2u32)
)
.into()
])
@ -713,19 +696,19 @@ mod tests {
ArrayExpression::if_else(
BooleanExpression::UintEq(box 0u32.into(), box 1u32.into()),
e.clone(),
ArrayExpression::select(a0.clone(), 0u32.into())
ArrayExpression::select(a0.clone(), 0u32)
)
.into(),
ArrayExpression::if_else(
BooleanExpression::UintEq(box 1u32.into(), box 1u32.into()),
e.clone(),
ArrayExpression::select(a0.clone(), 1u32.into())
ArrayExpression::select(a0.clone(), 1u32)
)
.into(),
ArrayExpression::if_else(
BooleanExpression::UintEq(box 2u32.into(), box 1u32.into()),
e.clone(),
ArrayExpression::select(a0.clone(), 2u32.into())
ArrayExpression::select(a0.clone(), 2u32)
)
.into()
])
@ -760,8 +743,8 @@ mod tests {
BooleanExpression::UintEq(box 0u32.into(), box 0u32.into()),
e.clone(),
FieldElementExpression::select(
ArrayExpression::select(a0.clone(), 0u32.into()),
0u32.into()
ArrayExpression::select(a0.clone(), 0u32),
0u32
)
)
.into(),
@ -769,14 +752,14 @@ mod tests {
BooleanExpression::UintEq(box 1u32.into(), box 0u32.into()),
e.clone(),
FieldElementExpression::select(
ArrayExpression::select(a0.clone(), 0u32.into()),
1u32.into()
ArrayExpression::select(a0.clone(), 0u32),
1u32
)
)
.into()
])
.annotate(Type::FieldElement, 2u32),
ArrayExpression::select(a0.clone(), 0u32.into())
ArrayExpression::select(a0.clone(), 0u32)
)
.into(),
ArrayExpression::if_else(
@ -786,8 +769,8 @@ mod tests {
BooleanExpression::UintEq(box 0u32.into(), box 0u32.into()),
e.clone(),
FieldElementExpression::select(
ArrayExpression::select(a0.clone(), 1u32.into()),
0u32.into()
ArrayExpression::select(a0.clone(), 1u32),
0u32
)
)
.into(),
@ -795,14 +778,14 @@ mod tests {
BooleanExpression::UintEq(box 1u32.into(), box 0u32.into()),
e.clone(),
FieldElementExpression::select(
ArrayExpression::select(a0.clone(), 1u32.into()),
1u32.into()
ArrayExpression::select(a0.clone(), 1u32),
1u32
)
)
.into()
])
.annotate(Type::FieldElement, 2u32),
ArrayExpression::select(a0.clone(), 1u32.into())
ArrayExpression::select(a0.clone(), 1u32)
)
.into(),
])

View file

@ -31,7 +31,7 @@ mod tests {
use super::*;
use std::collections::HashMap;
use typed_absy::types::{
ConcreteArrayType, ConcreteFunctionKey, ConcreteStructMember, ConcreteStructType,
ConcreteArrayType, ConcreteFunctionKey, ConcreteStructMember, ConcreteStructType, UBitwidth,
};
use typed_absy::{
parameter::DeclarationParameter, variable::DeclarationVariable, ConcreteType,
@ -113,7 +113,7 @@ mod tests {
let abi: Abi = Abi {
inputs: vec![],
outputs: vec![Type::Int],
outputs: vec![ConcreteType::Int],
};
let _ = serde_json::to_string_pretty(&abi).unwrap();
@ -172,17 +172,17 @@ mod tests {
AbiInput {
name: String::from("a"),
public: true,
ty: Type::Uint(UBitwidth::B8),
ty: ConcreteType::Uint(UBitwidth::B8),
},
AbiInput {
name: String::from("b"),
public: true,
ty: Type::Uint(UBitwidth::B16),
ty: ConcreteType::Uint(UBitwidth::B16),
},
AbiInput {
name: String::from("c"),
public: true,
ty: Type::Uint(UBitwidth::B32),
ty: ConcreteType::Uint(UBitwidth::B32),
},
],
outputs: vec![],

View file

@ -476,11 +476,12 @@ mod tests {
fn field_from_int() {
let n: IntExpression<Bn128Field> = BigUint::from(42usize).into();
let n_a: ArrayExpression<Bn128Field> =
ArrayExpressionInner::Value(vec![n.clone().into()]).annotate(Type::Int, 1);
ArrayExpressionInner::Value(vec![n.clone().into()]).annotate(Type::Int, 1u32);
let t: FieldElementExpression<Bn128Field> = Bn128Field::from(42).into();
let t_a: ArrayExpression<Bn128Field> =
ArrayExpressionInner::Value(vec![t.clone().into()]).annotate(Type::FieldElement, 1);
let i: FieldElementExpression<Bn128Field> = Bn128Field::from(0).into();
ArrayExpressionInner::Value(vec![t.clone().into()]).annotate(Type::FieldElement, 1u32);
let i: UExpression<Bn128Field> = 0u32.into();
let s: FieldElementExpression<Bn128Field> = Bn128Field::from(0).into();
let c: BooleanExpression<Bn128Field> = true.into();
let expressions = vec![
@ -518,8 +519,8 @@ mod tests {
IntExpression::xor(n.clone(), n.clone()),
IntExpression::or(n.clone(), n.clone()),
IntExpression::and(n.clone(), n.clone()),
IntExpression::left_shift(n.clone(), i.clone()),
IntExpression::right_shift(n.clone(), i.clone()),
IntExpression::left_shift(n.clone(), s.clone()),
IntExpression::right_shift(n.clone(), s.clone()),
IntExpression::not(n.clone()),
];
@ -535,11 +536,12 @@ mod tests {
fn uint_from_int() {
let n: IntExpression<Bn128Field> = BigUint::from(42usize).into();
let n_a: ArrayExpression<Bn128Field> =
ArrayExpressionInner::Value(vec![n.clone().into()]).annotate(Type::Int, 1);
ArrayExpressionInner::Value(vec![n.clone().into()]).annotate(Type::Int, 1u32);
let t: UExpression<Bn128Field> = 42u32.into();
let t_a: ArrayExpression<Bn128Field> = ArrayExpressionInner::Value(vec![t.clone().into()])
.annotate(Type::Uint(UBitwidth::B32), 1);
let i: FieldElementExpression<Bn128Field> = Bn128Field::from(0).into();
.annotate(Type::Uint(UBitwidth::B32), 1u32);
let i: UExpression<Bn128Field> = 0u32.into();
let s: FieldElementExpression<Bn128Field> = Bn128Field::from(0).into();
let c: BooleanExpression<Bn128Field> = true.into();
let expressions = vec![
@ -550,8 +552,8 @@ mod tests {
IntExpression::and(n.clone(), n.clone()),
IntExpression::sub(n.clone(), n.clone()),
IntExpression::mult(n.clone(), n.clone()),
IntExpression::left_shift(n.clone(), i.clone()),
IntExpression::right_shift(n.clone(), i.clone()),
IntExpression::left_shift(n.clone(), s.clone()),
IntExpression::right_shift(n.clone(), s.clone()),
IntExpression::not(n.clone()),
IntExpression::if_else(c.clone(), n.clone(), n.clone()),
IntExpression::select(n_a.clone(), i.clone()),
@ -565,8 +567,8 @@ mod tests {
UExpression::and(t.clone(), t.clone()),
UExpression::sub(t.clone(), t.clone()),
UExpression::mult(t.clone(), t.clone()),
UExpression::left_shift(t.clone(), i.clone()),
UExpression::right_shift(t.clone(), i.clone()),
UExpression::left_shift(t.clone(), s.clone()),
UExpression::right_shift(t.clone(), s.clone()),
UExpression::not(t.clone()),
UExpression::if_else(c.clone(), t.clone(), t.clone()),
UExpression::select(t_a.clone(), i.clone()),

View file

@ -21,7 +21,6 @@ pub use self::types::{
ConcreteSignature, ConcreteType, DeclarationType, Signature, StructType, Type, UBitwidth,
};
use self::types::{DeclarationFunctionKey, DeclarationSignature, GType};
use num_bigint::BigUint;
pub use self::variable::{DeclarationVariable, GVariable, Variable};
use std::path::PathBuf;
@ -1307,57 +1306,57 @@ impl<'ast, T: Clone> IfElse<'ast, T> for StructExpression<'ast, T> {
}
pub trait Select<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self;
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self;
}
impl<'ast, T> Select<'ast, T> for FieldElementExpression<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self {
FieldElementExpression::Select(box array, box index)
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self {
FieldElementExpression::Select(box array, box index.into())
}
}
impl<'ast, T> Select<'ast, T> for IntExpression<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self {
IntExpression::Select(box array, box index)
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self {
IntExpression::Select(box array, box index.into())
}
}
impl<'ast, T> Select<'ast, T> for BooleanExpression<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self {
BooleanExpression::Select(box array, box index)
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self {
BooleanExpression::Select(box array, box index.into())
}
}
impl<'ast, T: Clone> Select<'ast, T> for UExpression<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self {
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self {
let bitwidth = match array.inner_type().clone() {
Type::Uint(bitwidth) => bitwidth,
_ => unreachable!(),
};
UExpressionInner::Select(box array, box index).annotate(bitwidth)
UExpressionInner::Select(box array, box index.into()).annotate(bitwidth)
}
}
impl<'ast, T: Clone> Select<'ast, T> for ArrayExpression<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self {
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self {
let (ty, size) = match array.inner_type() {
Type::Array(array_type) => (array_type.ty.clone(), array_type.size.clone()),
_ => unreachable!(),
};
ArrayExpressionInner::Select(box array, box index).annotate(*ty, size)
ArrayExpressionInner::Select(box array, box index.into()).annotate(*ty, size)
}
}
impl<'ast, T: Clone> Select<'ast, T> for StructExpression<'ast, T> {
fn select(array: ArrayExpression<'ast, T>, index: UExpression<'ast, T>) -> Self {
fn select<I: Into<UExpression<'ast, T>>>(array: ArrayExpression<'ast, T>, index: I) -> Self {
let members = match array.inner_type().clone() {
Type::Struct(members) => members,
_ => unreachable!(),
};
StructExpressionInner::Select(box array, box index).annotate(members)
StructExpressionInner::Select(box array, box index.into()).annotate(members)
}
}

View file

@ -424,7 +424,10 @@ impl<'de, S: Deserialize<'de>> Deserialize<'de> for GType<S> {
let strict_type =
|m: Mapping<S>, ty: GType<S>| -> Result<Self, <D as Deserializer<'de>>::Error> {
match m.components {
Some(_) => Err(D::Error::custom(format!("unexpected `components` field",))),
Some(_) => Err(D::Error::custom(format!(
"unexpected `components` field in type {}",
m.ty
))),
None => Ok(ty),
}
};
@ -454,7 +457,7 @@ impl<'de, S: Deserialize<'de>> Deserialize<'de> for GType<S> {
"u8" => strict_type(mapping, GType::Uint(UBitwidth::B8)),
"u16" => strict_type(mapping, GType::Uint(UBitwidth::B16)),
"u32" => strict_type(mapping, GType::Uint(UBitwidth::B32)),
_ => Err(D::Error::custom(format!("invalid type"))),
t => Err(D::Error::custom(format!("invalid type `{}`", t))),
}
}
}
@ -614,7 +617,9 @@ impl<'ast, T: fmt::Display + PartialEq> Type<'ast, T> {
}
}
}
}
impl ConcreteType {
fn to_slug(&self) -> String {
match self {
GType::FieldElement => String::from("f"),
@ -647,7 +652,6 @@ impl ConcreteType {
.iter()
.map(|member| member.ty.get_primitive_count())
.sum(),
GType::Int => unreachable!(),
}
}
}
@ -730,7 +734,7 @@ impl<'ast, S> GFunctionKey<'ast, S> {
}
}
impl<'ast, S: fmt::Display + std::cmp::PartialEq> GFunctionKey<'ast, S> {
impl<'ast> ConcreteFunctionKey<'ast> {
pub fn to_slug(&self) -> String {
format!("{}_{}", self.id, self.signature.to_slug())
}
@ -932,7 +936,7 @@ pub mod signature {
}
}
impl<S: fmt::Display + std::cmp::PartialEq> GSignature<S> {
impl ConcreteSignature {
/// Returns a slug for a signature, with the following encoding:
/// i{inputs}o{outputs} where {inputs} and {outputs} each encode a list of types.
/// A list of types is encoded by compressing sequences of the same type like so:
@ -943,7 +947,7 @@ pub mod signature {
/// [field, field, bool, field] -> 2fbf
///
pub fn to_slug(&self) -> String {
let to_slug = |types: &[GType<S>]| {
let to_slug = |types: &[ConcreteType]| {
let mut res = vec![];
for t in types {
let len = res.len();
@ -958,7 +962,7 @@ pub mod signature {
}
}
res.into_iter()
.map(|(n, t): (usize, &GType<S>)| {
.map(|(n, t): (usize, &ConcreteType)| {
let mut r = String::new();
if n > 1 {

View file

@ -34,6 +34,5 @@ fn from_type(t: typed_absy::types::ConcreteType) -> Vec<zir::types::Type> {
.into_iter()
.flat_map(|struct_member| from_type(*struct_member.ty))
.collect(),
typed_absy::types::ConcreteType::Int => unreachable!(),
}
}

View file

@ -15,7 +15,7 @@ def main(bool[256] exponent, field[2] pt, BabyJubJubParams context) -> field[2]:
field[2] doubledP = pt
field[2] accumulatedP = infinity
for field i in 0..256 do
for u32 i in 0..256 do
field j = 255 - i
field[2] candidateP = add(accumulatedP, doubledP, context)
accumulatedP = if exponent[j] then candidateP else accumulatedP fi

View file

@ -7,7 +7,7 @@ def main(field x_in, field k) -> field:
field[10] t4 = [0; 10]
field[10] t6 = [0; 10]
field[10] t7 = [0; 10] // we define t7 length +1 to reference implementation as ZoKrates wont allow conditional branching. -> out of bounds array error
for field i in 0..10 do
for u32 i in 0..10 do
field i2 = if i == 0 then 0 else i - 1 fi
t = if i == 0 then k+x_in else k + t7[i2] + c[i] fi
t2[i] = t*t

View file

@ -7,7 +7,7 @@ def main(field x_in, field k) -> field:
field[20] t4 = [0; 20]
field[20] t6 = [0; 20]
field[20] t7 = [0; 20] // we define t7 length +1 to reference implementation as ZoKrates wont allow conditional branching. -> out of bounds array error
for field i in 0..20 do
for u32 i in 0..20 do
field i2 = if i == 0 then 0 else i - 1 fi
t = if i == 0 then k+x_in else k + t7[i2] + c[i] fi
t2[i] = t*t

View file

@ -7,7 +7,7 @@ def main(field x_in, field k) -> field:
field[50] t4 = [0; 50]
field[50] t6 = [0; 50]
field[50] t7 = [0; 50] // we define t7 length +1 to reference implementation as ZoKrates wont allow conditional branching.
for field i in 0..50 do
for u32 i in 0..50 do
field i2 = if i == 0 then 0 else i - 1 fi
t = if i == 0 then k+x_in else k + t7[i2] + c[i] fi
t2[i] = t*t

View file

@ -7,7 +7,7 @@ def main(field x_in, field k) -> field:
field[90] t4 = [0; 90]
field[90] t6 = [0; 90]
field[90] t7 = [0; 90] // we define t7 length +1 to reference implementation as ZoKrates wont allow conditional branching.
for field i in 0..90 do
for u32 i in 0..90 do
field i2 = if i == 0 then 0 else i - 1 fi
t = if i == 0 then k+x_in else k + t7[i2] + c[i] fi
t2[i] = t*t

View file

@ -12,7 +12,7 @@ def main(field xL_in, field xR_in, field k) -> field[2]:
field[220] xR = [0; 220] //...
field c = 0
for field i in 0..nRounds do
for u32 i in 0..nRounds do
field idx = if i == 0 then 0 else i - 1 fi
c = IV[i]

View file

@ -7,13 +7,13 @@ def main(field[2] ins, field k) -> field[3]:
field[4][2] S = [[0; 2]; 4] // Dim: (nInputs + nOutputs - 1, 2)
field[3] outs = [0; 3]
for field i in 0..nInputs do
for u32 i in 0..nInputs do
field idx = if i == 0 then 0 else i - 1 fi
S[i] = if i == 0 then MiMCFeistel(ins[0], 0, k) else MiMCFeistel(S[idx][0] + ins[i], S[idx][1], k) fi
endfor
outs[0] = S[nInputs - 1][0]
for field i in 0..(nOutputs - 1) do
for u32 i in 0..(nOutputs - 1) do
field[2] feistelRes = MiMCFeistel(S[nInputs + i - 1][0], S[nInputs + i - 1][1], k)
S[nInputs + i] = feistelRes
outs[i + 1] = S[nInputs + i][0]

View file

@ -7,7 +7,7 @@ def main(bool[128] bits) -> field:
field len = 128
for field j in 0..len do
for u32 j in 0..len do
field i = len - (j + 1)
out = out + if bits[i] then (2 ** j) else 0 fi
endfor

View file

@ -7,10 +7,10 @@ def main(bool[256] input) -> field:
field out = 0
field len = 256
u32 len = 256
for field j in 0..len do
field i = len - (j + 1)
for u32 j in 0..len do
u32 i = len - (j + 1)
out = out + if bits[i] then (2 ** j) else 0 fi
endfor