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

add rem test

This commit is contained in:
dark64 2023-11-15 16:16:49 +03:00
parent a11c1ba0a7
commit 37e16992d8
7 changed files with 159 additions and 0 deletions

View file

@ -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),
}
}

View 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"
}
}
}
]
}

View file

@ -0,0 +1,3 @@
def main(field x, field y) -> field {
return x % y;
}

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]