add rem test
This commit is contained in:
parent
a11c1ba0a7
commit
37e16992d8
7 changed files with 159 additions and 0 deletions
|
@ -108,6 +108,25 @@ impl<'ast, T: Field> Folder<'ast, T> for PanicExtractor<'ast, T> {
|
|||
);
|
||||
FieldElementExpression::idiv(n, d)
|
||||
}
|
||||
FieldElementExpression::Rem(e) => {
|
||||
let n = self.fold_field_expression(*e.left);
|
||||
let d = self.fold_field_expression(*e.right);
|
||||
self.panic_buffer.push(
|
||||
ZirStatement::assertion(
|
||||
BooleanExpression::not(
|
||||
BooleanExpression::field_eq(
|
||||
d.clone().span(span),
|
||||
FieldElementExpression::value(T::zero()).span(span),
|
||||
)
|
||||
.span(span),
|
||||
)
|
||||
.span(span),
|
||||
RuntimeError::DivisionByZero,
|
||||
)
|
||||
.span(span),
|
||||
);
|
||||
FieldElementExpression::rem(n, d)
|
||||
}
|
||||
e => fold_field_expression_cases(self, e),
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +188,25 @@ impl<'ast, T: Field> Folder<'ast, T> for PanicExtractor<'ast, T> {
|
|||
);
|
||||
UExpression::div(n, d).into_inner()
|
||||
}
|
||||
UExpressionInner::Rem(e) => {
|
||||
let n = self.fold_uint_expression(*e.left);
|
||||
let d = self.fold_uint_expression(*e.right);
|
||||
self.panic_buffer.push(
|
||||
ZirStatement::assertion(
|
||||
BooleanExpression::not(
|
||||
BooleanExpression::uint_eq(
|
||||
d.clone().span(span),
|
||||
UExpression::value(0).annotate(b).span(span),
|
||||
)
|
||||
.span(span),
|
||||
)
|
||||
.span(span),
|
||||
RuntimeError::DivisionByZero,
|
||||
)
|
||||
.span(span),
|
||||
);
|
||||
UExpression::rem(n, d).into_inner()
|
||||
}
|
||||
e => fold_uint_expression_cases(self, b, e),
|
||||
}
|
||||
}
|
||||
|
|
70
zokrates_core_test/tests/tests/rem.json
Normal file
70
zokrates_core_test/tests/tests/rem.json
Normal file
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"max_constraint_count": 1131,
|
||||
"curves": ["Bn128", "Bls12_381", "Bls12_377", "Bw6_761"],
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0", "0"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": "Inverse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["1", "0"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": "Inverse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0", "1"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["2", "2"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["4", "2"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["5", "2"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
3
zokrates_core_test/tests/tests/rem.zok
Normal file
3
zokrates_core_test/tests/tests/rem.zok
Normal file
|
@ -0,0 +1,3 @@
|
|||
def main(field x, field y) -> field {
|
||||
return x % y;
|
||||
}
|
|
@ -2,6 +2,18 @@
|
|||
"entry_point": "./tests/tests/uint/u16/rem.zok",
|
||||
"max_constraint_count": 88,
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x0001", "0x0000"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": "Inverse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x0002", "0x0004"]
|
||||
|
|
|
@ -2,6 +2,18 @@
|
|||
"entry_point": "./tests/tests/uint/u32/rem.zok",
|
||||
"max_constraint_count": 168,
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x00000001", "0x00000000"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": "Inverse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x00000002", "0x00000004"]
|
||||
|
|
|
@ -2,6 +2,18 @@
|
|||
"entry_point": "./tests/tests/uint/u64/rem.zok",
|
||||
"max_constraint_count": 328,
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x0000000000000001", "0x0000000000000000"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": "Inverse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x0000000000000002", "0x0000000000000004"]
|
||||
|
|
|
@ -2,6 +2,18 @@
|
|||
"entry_point": "./tests/tests/uint/u8/rem.zok",
|
||||
"max_constraint_count": 48,
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x01", "0x00"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": "Inverse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x02", "0x04"]
|
||||
|
|
Loading…
Reference in a new issue