1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00

fix tests

This commit is contained in:
dark64 2022-05-11 21:33:57 +02:00
parent 2b9c1e8854
commit f1c7d76cf5
37 changed files with 538 additions and 555 deletions

View file

@ -1,11 +1,9 @@
def func<N>() -> bool {
for u32 i in 0..N {}
u64[N] y = [...[0; N-1], 1]; // the rhs should *not* be reduced to [1] because the spread is not empty
u64 q = 0;
for u32 i in 0..N {
q = y[i]
q = y[i];
}
return true;

View file

@ -4,7 +4,7 @@ import "hashes/utils/256bitsDirectionHelper" as multiplex;
const u32 DEPTH = 3;
def select(bool condition, u32[8] left, u32[8] right) -> (u32[8], u32[8]) {
return condition ? right : left, condition ? left : right
return condition ? right : left, condition ? left : right;
}
// Merke-Tree inclusion proof for tree depth 4 using sha256

View file

@ -1,8 +1,8 @@
// simple ifelse example
// simple conditional example
// x = 2 -> 2 + 1 + 2**3 = 11
// x = 5 -> 5 + 5 + 5**3 = 135
def main(field x) -> field {
field y = x < 3 ? 1 : 5;
field z = y < x ? x**3 : y**3:
field z = y < x ? x**3 : y**3;
return x + y + z;
}

View file

@ -906,7 +906,7 @@ mod tests {
#[test]
fn return_forty_two() {
let source = "def main() -> field: return 42";
let source = "def main() -> field { return 42; }";
let ast = pest::generate_ast(source).unwrap();
let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration {
@ -937,7 +937,7 @@ mod tests {
#[test]
fn return_true() {
let source = "def main() -> bool: return true";
let source = "def main() -> bool { return true; }";
let ast = pest::generate_ast(source).unwrap();
let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration {
@ -966,7 +966,7 @@ mod tests {
#[test]
fn arguments() {
let source = "def main(private field a, bool b) -> field: return 42";
let source = "def main(private field a, bool b) -> field { return 42; }";
let ast = pest::generate_ast(source).unwrap();
let expected: absy::Module = absy::Module {
@ -1020,7 +1020,7 @@ mod tests {
mod types {
use super::*;
/// Helper method to generate the ast for `def main(private {ty} a): return` which we use to check ty
/// Helper method to generate the ast for `def main(private {ty} a) { return; }` which we use to check ty
fn wrap(ty: UnresolvedType<'static>) -> absy::Module<'static> {
absy::Module {
symbols: vec![absy::SymbolDeclaration {
@ -1084,7 +1084,7 @@ mod tests {
];
for (ty, expected) in vectors {
let source = format!("def main(private {} a): return", ty);
let source = format!("def main(private {} a) {{ return; }}", ty);
let expected = wrap(expected);
let ast = pest::generate_ast(&source).unwrap();
assert_eq!(absy::Module::from(ast), expected);
@ -1184,7 +1184,7 @@ mod tests {
];
for (source, expected) in vectors {
let source = format!("def main(): return {}", source);
let source = format!("def main() {{ return {}; }}", source);
let expected = wrap(expected);
let ast = pest::generate_ast(&source).unwrap();
assert_eq!(absy::Module::from(ast), expected);
@ -1194,7 +1194,7 @@ mod tests {
#[test]
fn call_array_element() {
// a call after an array access should be accepted
let source = "def main(): return a[2](3)";
let source = "def main() { return a[2](3); }";
let ast = pest::generate_ast(source).unwrap();
assert_eq!(
absy::Module::from(ast),
@ -1215,7 +1215,7 @@ mod tests {
#[test]
fn call_call_result() {
// a call after a call should be accepted
let source = "def main(): return a(2)(3)";
let source = "def main() { return a(2)(3); }";
let ast = pest::generate_ast(source).unwrap();
assert_eq!(

View file

@ -316,10 +316,11 @@ mod test {
#[test]
fn no_resolver_with_imports() {
let source = r#"
import "./path/to/file" as foo
def main() -> field:
return foo()
"#
import "./path/to/file" as foo;
def main() -> field {
return foo();
}
"#
.to_string();
let arena = Arena::new();
let res: Result<CompilationArtifacts<Bn128Field, _>, CompileErrors> = compile(
@ -341,9 +342,10 @@ mod test {
#[test]
fn no_resolver_without_imports() {
let source = r#"
def main() -> field:
return 1
"#
def main() -> field {
return 1;
}
"#
.to_string();
let arena = Arena::new();
@ -368,10 +370,10 @@ mod test {
// when importing types and renaming them, we use the canonical struct names in the ABI
// // main.zok
// from foo import Foo as FooMain
// from foo import Foo as FooMain;
//
// // foo.zok
// from bar import Bar as BarFoo
// from bar import Bar as BarFoo;
// struct Foo { BarFoo b }
//
// // bar.zok
@ -381,9 +383,10 @@ mod test {
// Foo { Bar b }
let main = r#"
from "foo" import Foo as FooMain
def main(FooMain f):
return
from "foo" import Foo as FooMain;
def main(FooMain f) {
return;
}
"#;
struct CustomResolver;
@ -398,9 +401,10 @@ def main(FooMain f):
if loc == "main" {
Ok((
r#"
from "foo" import Foo as FooMain
def main(FooMain f):
return
from "foo" import Foo as FooMain;
def main(FooMain f) {
return;
}
"#
.into(),
"main".into(),
@ -408,9 +412,9 @@ def main(FooMain f):
} else if loc == "foo" {
Ok((
r#"
from "bar" import Bar as BarFoo
from "bar" import Bar as BarFoo;
struct Foo {
BarFoo b
BarFoo b;
}
"#
.into(),
@ -419,7 +423,7 @@ struct Foo {
} else if loc == "bar" {
Ok((
r#"
struct Bar { field a }
struct Bar { field a; }
"#
.into(),
"bar".into(),

View file

@ -88,9 +88,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConditionRedefiner<'ast, T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::typed_absy::{
Block, BooleanExpression, Conditional, ConditionalKind, FieldElementExpression, Type,
};
use crate::typed_absy::{Block, BooleanExpression, Conditional, FieldElementExpression, Type};
use zokrates_field::Bn128Field;
#[test]
@ -104,7 +102,6 @@ mod tests {
BooleanExpression::Value(true),
FieldElementExpression::Number(Bn128Field::from(1)),
FieldElementExpression::Number(Bn128Field::from(2)),
ConditionalKind::IfElse,
)
.into(),
);
@ -125,7 +122,6 @@ mod tests {
BooleanExpression::Identifier("c".into()),
FieldElementExpression::Number(Bn128Field::from(1)),
FieldElementExpression::Number(Bn128Field::from(2)),
ConditionalKind::IfElse,
)
.into(),
);
@ -153,7 +149,6 @@ mod tests {
condition.clone(),
FieldElementExpression::Number(Bn128Field::from(1)),
FieldElementExpression::Number(Bn128Field::from(2)),
ConditionalKind::IfElse,
)
.into(),
);
@ -173,7 +168,6 @@ mod tests {
BooleanExpression::Identifier(CoreIdentifier::Condition(0).into()),
FieldElementExpression::Number(Bn128Field::from(1)),
FieldElementExpression::Number(Bn128Field::from(2)),
ConditionalKind::IfElse,
)
.into(),
),
@ -210,10 +204,8 @@ mod tests {
condition_1.clone(),
FieldElementExpression::Number(Bn128Field::from(1)),
FieldElementExpression::Number(Bn128Field::from(2)),
ConditionalKind::IfElse,
),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
)
.into(),
);
@ -239,10 +231,8 @@ mod tests {
BooleanExpression::Identifier(CoreIdentifier::Condition(1).into()),
FieldElementExpression::Number(Bn128Field::from(1)),
FieldElementExpression::Number(Bn128Field::from(2)),
ConditionalKind::IfElse,
),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
)
.into(),
),
@ -306,7 +296,6 @@ mod tests {
condition_1.clone(),
FieldElementExpression::Number(Bn128Field::from(2)),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
),
),
FieldElementExpression::block(
@ -318,10 +307,8 @@ mod tests {
condition_2.clone(),
FieldElementExpression::Number(Bn128Field::from(2)),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
),
),
ConditionalKind::IfElse,
)
.into(),
);
@ -358,7 +345,6 @@ mod tests {
condition_id_1,
FieldElementExpression::Number(Bn128Field::from(2)),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
),
),
FieldElementExpression::block(
@ -380,10 +366,8 @@ mod tests {
condition_id_2,
FieldElementExpression::Number(Bn128Field::from(2)),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
),
),
ConditionalKind::IfElse,
)
.into(),
),

View file

@ -1484,7 +1484,6 @@ mod tests {
BooleanExpression::Value(true),
FieldElementExpression::Number(Bn128Field::from(2)),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
);
assert_eq!(
@ -1499,7 +1498,6 @@ mod tests {
BooleanExpression::Value(false),
FieldElementExpression::Number(Bn128Field::from(2)),
FieldElementExpression::Number(Bn128Field::from(3)),
ConditionalKind::IfElse,
);
assert_eq!(

View file

@ -789,7 +789,6 @@ impl<'ast, T> From<BigUint> for IntExpression<'ast, T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::typed_absy::ConditionalKind;
use zokrates_field::Bn128Field;
#[test]
@ -811,7 +810,7 @@ mod tests {
n.clone() * n.clone(),
IntExpression::pow(n.clone(), n.clone()),
n.clone() / n.clone(),
IntExpression::conditional(c.clone(), n.clone(), n.clone(), ConditionalKind::IfElse),
IntExpression::conditional(c.clone(), n.clone(), n.clone()),
IntExpression::select(n_a.clone(), i.clone()),
];
@ -822,12 +821,7 @@ mod tests {
t.clone() * t.clone(),
FieldElementExpression::pow(t.clone(), i.clone()),
t.clone() / t.clone(),
FieldElementExpression::conditional(
c.clone(),
t.clone(),
t.clone(),
ConditionalKind::IfElse,
),
FieldElementExpression::conditional(c.clone(), t.clone(), t.clone()),
FieldElementExpression::select(t_a.clone(), i.clone()),
];
@ -882,7 +876,7 @@ mod tests {
IntExpression::left_shift(n.clone(), i.clone()),
IntExpression::right_shift(n.clone(), i.clone()),
!n.clone(),
IntExpression::conditional(c.clone(), n.clone(), n.clone(), ConditionalKind::IfElse),
IntExpression::conditional(c.clone(), n.clone(), n.clone()),
IntExpression::select(n_a.clone(), i.clone()),
];
@ -899,7 +893,7 @@ mod tests {
UExpression::left_shift(t.clone(), i.clone()),
UExpression::right_shift(t.clone(), i.clone()),
!t.clone(),
UExpression::conditional(c.clone(), t.clone(), t.clone(), ConditionalKind::IfElse),
UExpression::conditional(c.clone(), t.clone(), t.clone()),
UExpression::select(t_a.clone(), i.clone()),
];

View file

@ -22,7 +22,7 @@
"left": "0",
"right": "1",
"error": {
"SourceAssertion": "Assertion failed at ./tests/tests/assert_array_equality.zok:2:2"
"SourceAssertion": "Assertion failed at ./tests/tests/assert_array_equality.zok:2:5"
}
}
}

View file

@ -8,7 +8,7 @@ struct State {
const State STATE = State {
a: [1, 2],
b: [[3, 4], [5, 6]]
}
};
def main() -> State {
return STATE;

View file

@ -10,7 +10,7 @@ def le<N>(bool[N] a_bits, bool[N] c_bits) -> bool {
size_unknown = true;
for u32 i in 0..N {
verified_conditions = verified_conditions + c_bits[i] || (!size_unknown || !a_bits[i]) ? 1 : 0;
verified_conditions = verified_conditions + (c_bits[i] || (!size_unknown || !a_bits[i]) ? 1 : 0);
size_unknown = c_bits[i] ? size_unknown && a_bits[i] : size_unknown; // this is actually not required in the last round
}

View file

@ -14,7 +14,7 @@
"left": "0",
"right": "1",
"error": {
"SourceAssertion": "Assertion failed at ./tests/tests/panics/loop_bound.zok:2:3"
"SourceAssertion": "Assertion failed at ./tests/tests/panics/loop_bound.zok:2:5"
}
}
}

View file

@ -20,7 +20,7 @@
"left": "1",
"right": "21888242871839275222246405745257275088548364400416034343698204186575808495577",
"error": {
"SourceAssertion": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:18:5"
"SourceAssertion": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:22:5"
}
}
}

View file

@ -20,7 +20,7 @@
"left": "1",
"right": "0",
"error": {
"SourceAssertion": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:14:5"
"SourceAssertion": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:17:5"
}
}
}

View file

@ -1,4 +1,4 @@
from "EMBED" import snark_verify_bls12_377
from "EMBED" import snark_verify_bls12_377;
// Verifies a proof with 1 public input (0 inputs + 1 output)
// Circuit used in this test:

View file

@ -1,4 +1,4 @@
from "EMBED" import snark_verify_bls12_377
from "EMBED" import snark_verify_bls12_377;
// Verifies a proof with 2 public inputs (1 input + 1 output)
// Circuit used in this test:

View file

@ -1,4 +1,4 @@
from "EMBED" import snark_verify_bls12_377
from "EMBED" import snark_verify_bls12_377;
// Verifies a proof with 5 public inputs (4 inputs + 1 output)
// Circuit used in this test:

View file

@ -1131,50 +1131,50 @@ mod tests {
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
source: AnyString {
value: String::from("foo"),
span: Span::new(source, 8, 11).unwrap()
span: Span::new(source, 17, 20).unwrap()
},
alias: None,
span: Span::new(source, 0, 29).unwrap()
span: Span::new(source, 9, 21).unwrap()
})),
SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(source, 33, 37).unwrap()
span: Span::new(source, 36, 40).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(source, 44, 49).unwrap()
span: Span::new(source, 47, 52).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::add(
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
value: DecimalNumber {
span: Span::new(source, 59, 60).unwrap()
span: Span::new(source, 75, 76).unwrap()
},
suffix: None,
span: Span::new(source, 59, 60).unwrap()
span: Span::new(source, 75, 76).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
value: DecimalNumber {
span: Span::new(source, 63, 64).unwrap()
span: Span::new(source, 79, 80).unwrap()
},
suffix: None,
span: Span::new(source, 63, 64).unwrap()
span: Span::new(source, 79, 80).unwrap()
}
)),
Span::new(source, 59, 64).unwrap()
Span::new(source, 75, 80).unwrap()
)],
span: Span::new(source, 52, 64).unwrap(),
span: Span::new(source, 68, 80).unwrap(),
})],
span: Span::new(source, 29, source.len()).unwrap(),
span: Span::new(source, 32, 91).unwrap(),
})
],
eoi: EOI {},
span: Span::new(source, 0, 65).unwrap()
span: Span::new(source, 0, 92).unwrap()
})
);
}
@ -1196,20 +1196,20 @@ mod tests {
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
source: AnyString {
value: String::from("foo"),
span: Span::new(source, 8, 11).unwrap()
span: Span::new(source, 17, 20).unwrap()
},
alias: None,
span: Span::new(source, 0, 29).unwrap()
span: Span::new(source, 9, 21).unwrap()
})),
SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(source, 33, 37).unwrap()
span: Span::new(source, 36, 40).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(source, 44, 49).unwrap()
span: Span::new(source, 47, 52).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::add(
@ -1217,9 +1217,9 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 59, 60).unwrap()
span: Span::new(source, 75, 76).unwrap()
},
span: Span::new(source, 59, 60).unwrap()
span: Span::new(source, 75, 76).unwrap()
}
)),
Expression::mul(
@ -1227,9 +1227,9 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 63, 64).unwrap()
span: Span::new(source, 79, 80).unwrap()
},
span: Span::new(source, 63, 64).unwrap()
span: Span::new(source, 79, 80).unwrap()
}
)),
Expression::pow(
@ -1237,33 +1237,33 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 67, 68).unwrap()
span: Span::new(source, 83, 84).unwrap()
},
span: Span::new(source, 67, 68).unwrap()
span: Span::new(source, 83, 84).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 72, 73).unwrap()
span: Span::new(source, 88, 89).unwrap()
},
span: Span::new(source, 72, 73).unwrap()
span: Span::new(source, 88, 89).unwrap()
}
)),
Span::new(source, 67, 73).unwrap()
Span::new(source, 83, 89).unwrap()
),
Span::new(source, 63, 73).unwrap()
Span::new(source, 79, 89).unwrap()
),
Span::new(source, 59, 73).unwrap()
Span::new(source, 75, 89).unwrap()
)],
span: Span::new(source, 52, 73).unwrap(),
span: Span::new(source, 68, 89).unwrap(),
})],
span: Span::new(source, 29, 74).unwrap(),
span: Span::new(source, 32, 100).unwrap(),
})
],
eoi: EOI {},
span: Span::new(source, 0, 74).unwrap()
span: Span::new(source, 0, 101).unwrap()
})
);
}
@ -1285,20 +1285,20 @@ mod tests {
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
source: AnyString {
value: String::from("foo"),
span: Span::new(source, 8, 11).unwrap()
span: Span::new(source, 17, 20).unwrap()
},
alias: None,
span: Span::new(source, 0, 29).unwrap()
span: Span::new(source, 9, 21).unwrap()
})),
SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(source, 33, 37).unwrap()
span: Span::new(source, 36, 40).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(source, 44, 49).unwrap()
span: Span::new(source, 47, 52).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::ternary(
@ -1306,38 +1306,38 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 62, 63).unwrap()
span: Span::new(source, 75, 76).unwrap()
},
span: Span::new(source, 62, 63).unwrap()
span: Span::new(source, 75, 76).unwrap()
}
))),
Box::new(Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 69, 70).unwrap()
span: Span::new(source, 79, 80).unwrap()
},
span: Span::new(source, 69, 70).unwrap()
span: Span::new(source, 79, 80).unwrap()
}
))),
Box::new(Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 76, 77).unwrap()
span: Span::new(source, 83, 84).unwrap()
},
span: Span::new(source, 76, 77).unwrap()
span: Span::new(source, 83, 84).unwrap()
}
))),
Span::new(source, 59, 80).unwrap()
Span::new(source, 75, 84).unwrap()
)],
span: Span::new(source, 52, 80).unwrap(),
span: Span::new(source, 68, 84).unwrap(),
})],
span: Span::new(source, 29, 81).unwrap(),
span: Span::new(source, 32, 95).unwrap(),
})
],
eoi: EOI {},
span: Span::new(source, 0, 81).unwrap()
span: Span::new(source, 0, 96).unwrap()
})
);
}
@ -1365,17 +1365,17 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 31, 32).unwrap()
span: Span::new(source, 32, 33).unwrap()
},
span: Span::new(source, 31, 32).unwrap()
span: Span::new(source, 32, 33).unwrap()
}
))],
span: Span::new(source, 23, 33).unwrap(),
span: Span::new(source, 24, 34).unwrap(),
})],
span: Span::new(source, 0, 34).unwrap(),
span: Span::new(source, 0, 37).unwrap(),
})],
eoi: EOI {},
span: Span::new(source, 0, 34).unwrap()
span: Span::new(source, 0, 38).unwrap()
})
);
}
@ -1402,27 +1402,27 @@ mod tests {
lhs: vec![
TypedIdentifierOrAssignee::TypedIdentifier(TypedIdentifier {
ty: Type::Basic(BasicType::Field(FieldType {
span: Span::new(source, 23, 28).unwrap()
span: Span::new(source, 24, 29).unwrap()
})),
identifier: IdentifierExpression {
value: String::from("a"),
span: Span::new(source, 29, 30).unwrap(),
span: Span::new(source, 30, 31).unwrap(),
},
span: Span::new(source, 23, 30).unwrap()
span: Span::new(source, 24, 31).unwrap()
}),
TypedIdentifierOrAssignee::Assignee(Assignee {
id: IdentifierExpression {
value: String::from("b"),
span: Span::new(source, 32, 33).unwrap(),
span: Span::new(source, 33, 34).unwrap(),
},
accesses: vec![],
span: Span::new(source, 32, 34).unwrap()
span: Span::new(source, 33, 35).unwrap()
}),
],
expression: Expression::Postfix(PostfixExpression {
base: Box::new(Expression::Identifier(IdentifierExpression {
value: String::from("foo"),
span: Span::new(source, 36, 39).unwrap()
span: Span::new(source, 37, 40).unwrap()
})),
accesses: vec![Access::Call(CallAccess {
explicit_generics: None,
@ -1432,9 +1432,9 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 40, 41).unwrap()
span: Span::new(source, 41, 42).unwrap()
},
span: Span::new(source, 40, 41).unwrap()
span: Span::new(source, 41, 42).unwrap()
}
)),
Expression::add(
@ -1442,35 +1442,35 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 43, 44).unwrap()
span: Span::new(source, 44, 45).unwrap()
},
span: Span::new(source, 43, 44).unwrap()
span: Span::new(source, 44, 45).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(source, 47, 48).unwrap()
span: Span::new(source, 48, 49).unwrap()
},
span: Span::new(source, 47, 48).unwrap()
span: Span::new(source, 48, 49).unwrap()
}
)),
Span::new(source, 43, 48).unwrap()
Span::new(source, 44, 49).unwrap()
),
],
span: Span::new(source, 40, 48).unwrap()
span: Span::new(source, 41, 49).unwrap()
},
span: Span::new(source, 39, 49).unwrap()
span: Span::new(source, 40, 50).unwrap()
})],
span: Span::new(source, 36, 49).unwrap(),
span: Span::new(source, 37, 50).unwrap(),
}),
span: Span::new(source, 23, 49).unwrap()
span: Span::new(source, 24, 50).unwrap()
})],
span: Span::new(source, 0, 50).unwrap(),
span: Span::new(source, 0, 53).unwrap(),
})],
eoi: EOI {},
span: Span::new(source, 0, 50).unwrap()
span: Span::new(source, 0, 54).unwrap()
})
);
}

View file

@ -236,7 +236,7 @@ def main(field xL_in, field xR_in, field k) -> field[2] {
for u32 i in 0..R {
u32 j = i == 0 ? 0 : i - 1;
c = IV[i]
c = IV[i];
t = i == 0 ? k + xL_in : k + xL[j] + c;
t2[i] = t * t;

View file

@ -3,7 +3,7 @@ import "utils/casts/u32_to_bits" as to_bits;
import "utils/casts/u32_from_bits" as from_bits;
def main(u32[16] inputs) -> u32[8] {
bool[512] e = [\
bool[512] e = [
...to_bits(inputs[0]),
...to_bits(inputs[1]),
...to_bits(inputs[2]),
@ -23,7 +23,7 @@ def main(u32[16] inputs) -> u32[8] {
];
bool[256] aC = pedersen(e);
return [\
return [
from_bits(aC[0..32]),
from_bits(aC[32..64]),
from_bits(aC[64..96]),

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ def main(u32[8] a, u32[8] b) -> u32[8] {
// Hash is computed on the full 512bit block size
// padding does not fit in the primary block
// add dummy block (single "1" followed by "0" + total length)
u32[8] dummyblock1 = [ \
u32[8] dummyblock1 = [
0x80000000,
0x00000000,
0x00000000,
@ -18,7 +18,7 @@ def main(u32[8] a, u32[8] b) -> u32[8] {
0x00000000
];
u32[8] dummyblock2 = [ \
u32[8] dummyblock2 = [
0x00000000,
0x00000000,
0x00000000,

View file

@ -1,4 +1,4 @@
import "hashes/keccak/keccak" as keccak
import "hashes/keccak/keccak" as keccak;
def main<N>(u64[N] input) -> (u64[8]) {
return keccak::<_, 512>(input, 0x0000000000000006)[..8];

View file

@ -1,3 +1,4 @@
// Concatenate two u32[8] arrays in an order defined by a boolean selector
def main(bool selector, u32[8] lhs, u32[8] rhs) -> u32[16]:
return if selector then [...rhs, ...lhs] else [...lhs, ...rhs] fi
def main(bool selector, u32[8] lhs, u32[8] rhs) -> u32[16] {
return selector ? [...rhs, ...lhs] : [...lhs, ...rhs];
}

View file

@ -1,12 +1,12 @@
import "hashes/sha256/1024bitPadded" as sha256
import "ecc/edwardsScalarMult" as scalarMult
import "ecc/edwardsAdd" as add
import "utils/pack/bool/nonStrictUnpack256" as unpack256bool
import "utils/pack/u32/nonStrictUnpack256" as unpack256u
import "ecc/edwardsOnCurve" as onCurve
import "ecc/edwardsOrderCheck" as orderCheck
from "ecc/babyjubjubParams" import BabyJubJubParams
import "utils/casts/u32_8_to_bool_256"
import "hashes/sha256/1024bitPadded" as sha256;
import "ecc/edwardsScalarMult" as scalarMult;
import "ecc/edwardsAdd" as add;
import "utils/pack/bool/nonStrictUnpack256" as unpack256bool;
import "utils/pack/u32/nonStrictUnpack256" as unpack256u;
import "ecc/edwardsOnCurve" as onCurve;
import "ecc/edwardsOrderCheck" as orderCheck;
from "ecc/babyjubjubParams" import BabyJubJubParams;
import "utils/casts/u32_8_to_bool_256";
/// Verifies an EdDSA Signature.
///
@ -29,24 +29,23 @@ import "utils/casts/u32_8_to_bool_256"
///
/// Returns:
/// Return true for S being a valid EdDSA Signature, false otherwise.
def main(private field[2] R, private field S, field[2] A, u32[8] M0, u32[8] M1, BabyJubJubParams context) -> bool:
field[2] G = [context.Gu, context.Gv]
def main(private field[2] R, private field S, field[2] A, u32[8] M0, u32[8] M1, BabyJubJubParams context) -> bool {
field[2] G = [context.Gu, context.Gv];
// Check if R is on curve and if it is not in a small subgroup. A is public input and can be checked offline
assert(onCurve(R, context)) // throws if R is not on curve
assert(orderCheck(R, context))
assert(onCurve(R, context)); // throws if R is not on curve
assert(orderCheck(R, context));
u32[8] Rx = unpack256u(R[0])
u32[8] Ax = unpack256u(A[0])
bool[256] hRAM = u32_8_to_bool_256(sha256(Rx, Ax, M0, M1))
u32[8] Rx = unpack256u(R[0]);
u32[8] Ax = unpack256u(A[0]);
bool[256] hRAM = u32_8_to_bool_256(sha256(Rx, Ax, M0, M1));
bool[256] sBits = unpack256bool(S)
field[2] lhs = scalarMult(sBits, G, context)
bool[256] sBits = unpack256bool(S);
field[2] lhs = scalarMult(sBits, G, context);
field[2] AhRAM = scalarMult(hRAM, A, context)
field[2] rhs = add(R, AhRAM, context)
field[2] AhRAM = scalarMult(hRAM, A, context);
field[2] rhs = add(R, AhRAM, context);
bool out = rhs[0] == lhs[0] && rhs[1] == lhs[1]
return out
bool out = rhs[0] == lhs[0] && rhs[1] == lhs[1];
return out;
}

View file

@ -1,44 +1,47 @@
#pragma curve bw6_761
from "EMBED" import snark_verify_bls12_377 as verify
from "EMBED" import snark_verify_bls12_377 as verify;
struct ProofInner {
field[2] a
field[2][2] b
field[2] c
field[2] a;
field[2][2] b;
field[2] c;
}
struct Proof<N> {
ProofInner proof
field[N] inputs
ProofInner proof;
field[N] inputs;
}
struct VerificationKey<N> {
field[2][2] h
field[2] g_alpha
field[2][2] h_beta
field[2] g_gamma
field[2][2] h_gamma
field[N][2] query // input length + 1
field[2][2] h;
field[2] g_alpha;
field[2][2] h_beta;
field[2] g_gamma;
field[2][2] h_gamma;
field[N][2] query; // input length + 1
}
def flat<N, F>(field[N][2] input) -> field[F]:
assert(F == N * 2)
field[F] out = [0; F]
for u32 i in 0..N do
for u32 j in 0..2 do
out[(i * 2) + j] = input[i][j]
endfor
endfor
return out
def flat<N, F>(field[N][2] input) -> field[F] {
assert(F == N * 2);
field[F] out = [0; F];
for u32 i in 0..N {
for u32 j in 0..2 {
out[(i * 2) + j] = input[i][j];
}
}
return out;
}
def main<N, Q>(Proof<N> proof, VerificationKey<Q> vk) -> bool:
assert(Q == N + 1) // query length (Q) should be N + 1
def main<N, Q>(Proof<N> proof, VerificationKey<Q> vk) -> bool {
assert(Q == N + 1); // query length (Q) should be N + 1
field[8] flat_proof = [
...proof.proof.a,
...flat::<2, 4>(proof.proof.b),
...proof.proof.c
]
];
u32 two_Q = 2 * Q
u32 two_Q = 2 * Q;
field[16 + (2 * Q)] flat_vk = [
...flat::<2, 4>(vk.h),
@ -47,6 +50,7 @@ def main<N, Q>(Proof<N> proof, VerificationKey<Q> vk) -> bool:
...vk.g_gamma,
...flat::<2, 4>(vk.h_gamma),
...flat::<Q, two_Q>(vk.query)
]
];
return verify(proof.inputs, flat_proof, flat_vk)
return verify(proof.inputs, flat_proof, flat_vk);
}

View file

@ -5,7 +5,7 @@ def main(u16 i) -> field {
field res = 0;
for u32 j in 0..16 {
u32 exponent = 16 - j - 1;
res = res + bits[j] ? 2 ** exponent : 0;
res = res + (bits[j] ? 2 ** exponent : 0);
}
return res;
}

View file

@ -5,7 +5,7 @@ def main(u32 i) -> field {
field res = 0;
for u32 j in 0..32 {
u32 exponent = 32 - j - 1;
res = res + bits[j] ? 2 ** exponent : 0;
res = res + (bits[j] ? 2 ** exponent : 0);
}
return res;
}

View file

@ -5,7 +5,7 @@ def main(u64 i) -> field {
field res = 0;
for u32 j in 0..64 {
u32 exponent = 64 - j - 1;
res = res + bits[j] ? 2 ** exponent : 0;
res = res + (bits[j] ? 2 ** exponent : 0);
}
return res;
}

View file

@ -5,7 +5,7 @@ def main(u8 i) -> field {
field res = 0;
for u32 j in 0..8 {
u32 exponent = 8 - j - 1;
res = res + bits[j] ? 2 ** exponent : 0;
res = res + (bits[j] ? 2 ** exponent : 0);
}
return res;
}

View file

@ -1,7 +1,7 @@
// Two-bit window lookup table using one constraint
// Maps the bits `b` to a list of field elements `c`
def main(bool[2] b, field[4] c) -> field {
field alpha = c[1] - c[0] + b[1] ? (c[3] - c[2] - c[1] + c[0]) : 0;
field out = b[0] ? alpha : 0 + c[0] - (b[1] ? (0 - c[2] + c[0]) : 0);
field alpha = c[1] - c[0] + (b[1] ? (c[3] - c[2] - c[1] + c[0]) : 0);
field out = (b[0] ? alpha : 0) + c[0] - (b[1] ? (0 - c[2] + c[0]) : 0);
return out;
}

View file

@ -4,6 +4,6 @@ import "./lookup2bit" as lookup;
// using two constraints. Maps the bits `b` to a list of constants `c`
def main(bool[3] b, field[4] c) -> field {
field alpha = lookup([b[0], b[1]], c);
field out = alpha - 2 * b[2] ? alpha : 0;
field out = alpha - 2 * (b[2] ? alpha : 0);
return out;
}

View file

@ -2,7 +2,7 @@ def main<N>(bool[N] bits) -> field {
field out = 0;
for u32 j in 0..N {
u32 i = N - (j + 1);
out = out + bits[i] ? (2 ** j) : 0;
out = out + (bits[i] ? 2 ** j : 0);
}
return out;
}

View file

@ -1,4 +1,4 @@
import "./unpack_unchecked.zok"
import "./unpack_unchecked.zok";
from "field" import FIELD_SIZE_IN_BITS;
from "EMBED" import bit_array_le;

View file

@ -1,4 +1,4 @@
from "field" import FIELD_MIN, FIELD_MAX, FIELD_SIZE_IN_BITS
from "field" import FIELD_MIN, FIELD_MAX, FIELD_SIZE_IN_BITS;
def main() -> (field, field, u32) {
return FIELD_MIN, FIELD_MAX, FIELD_SIZE_IN_BITS;

View file

@ -6,6 +6,7 @@ def first() -> bool {
assert(0 == lookup(sel, t));
return true;
}
def firstNeg() -> bool {
bool[3] sel = [false, false, true];
@ -32,7 +33,7 @@ def secondNeg() -> bool {
return true;
}
def thrid() -> bool {
def third() -> bool {
bool[3] sel = [false, true, false];
field[4] t = [0, 1, 2, 3];
@ -40,7 +41,7 @@ def thrid() -> bool {
return true;
}
def thridNeg() -> bool {
def thirdNeg() -> bool {
bool[3] sel = [false, true, true];
field[4] t = [0, 1, 2, 3];
@ -71,8 +72,8 @@ def main() {
assert(firstNeg());
assert(second());
assert(secondNeg());
assert(thrid());
assert(thridNeg());
assert(third());
assert(thirdNeg());
assert(fourth());
assert(fourthNeg());
return;

View file

@ -16,7 +16,7 @@ def testZero() -> bool {
return true;
}
def testMax() -> bool:
def testMax() -> bool {
bool[128] b = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
field n = pack128(b);