Merge pull request #852 from Zokrates/fix-uint-subtraction-flattening
Fix flattening of uint subtraction for values smaller than the target
This commit is contained in:
commit
e07a811ccd
10 changed files with 26 additions and 24 deletions
1
changelogs/unreleased/852-schaeff
Normal file
1
changelogs/unreleased/852-schaeff
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix treatment of uint subtraction involving constants (bug)
|
|
@ -1396,9 +1396,10 @@ impl<'ast, T: Field> Flattener<'ast, T> {
|
||||||
}
|
}
|
||||||
UExpressionInner::Sub(box left, box right) => {
|
UExpressionInner::Sub(box left, box right) => {
|
||||||
// see uint optimizer for the reasoning here
|
// see uint optimizer for the reasoning here
|
||||||
let aux = FlatExpression::Number(
|
let offset = FlatExpression::Number(T::from(2).pow(std::cmp::max(
|
||||||
T::from(2).pow(right.metadata.clone().unwrap().bitwidth() as usize),
|
right.metadata.clone().unwrap().bitwidth() as usize,
|
||||||
);
|
target_bitwidth as usize,
|
||||||
|
)));
|
||||||
|
|
||||||
let left_flattened = self
|
let left_flattened = self
|
||||||
.flatten_uint_expression(statements_flattened, left)
|
.flatten_uint_expression(statements_flattened, left)
|
||||||
|
@ -1422,7 +1423,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
|
||||||
};
|
};
|
||||||
|
|
||||||
FlatUExpression::with_field(FlatExpression::Add(
|
FlatUExpression::with_field(FlatExpression::Add(
|
||||||
box aux,
|
box offset,
|
||||||
box FlatExpression::Sub(box new_left, box new_right),
|
box FlatExpression::Sub(box new_left, box new_right),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"entry_point": "./tests/tests/uint/u16/sub.zok",
|
"entry_point": "./tests/tests/uint/u16/sub.zok",
|
||||||
"max_constraint_count": 53,
|
"max_constraint_count": 91,
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"input": {
|
"input": {
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xfffe"]
|
"values": ["0xfffe", "0xfffe", "0x0002"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xffff"]
|
"values": ["0xffff", "0xffff", "0x0001"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
def main(u16 a, u16 b) -> u16:
|
def main(u16 a, u16 b) -> (u16, u16, u16):
|
||||||
return a - b
|
return a - b, a - 1, 1 - a
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"entry_point": "./tests/tests/uint/u32/sub.zok",
|
"entry_point": "./tests/tests/uint/u32/sub.zok",
|
||||||
"max_constraint_count": 101,
|
"max_constraint_count": 171,
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"input": {
|
"input": {
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xfffffffe"]
|
"values": ["0xfffffffe", "0xfffffffe", "0x00000002"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xffffffff"]
|
"values": ["0xffffffff", "0xffffffff", "0x00000001"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
def main(u32 a, u32 b) -> u32:
|
def main(u32 a, u32 b) -> (u32, u32, u32):
|
||||||
return a - b
|
return a - b, a - 1, 1 - a
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"entry_point": "./tests/tests/uint/u64/sub.zok",
|
"entry_point": "./tests/tests/uint/u64/sub.zok",
|
||||||
"max_constraint_count": 197,
|
"max_constraint_count": 331,
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"input": {
|
"input": {
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xfffffffffffffffe"]
|
"values": ["0xfffffffffffffffe", "0xfffffffffffffffe", "0x0000000000000002"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xffffffffffffffff"]
|
"values": ["0xffffffffffffffff", "0xffffffffffffffff", "0x0000000000000001"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
def main(u64 a, u64 b) -> u64:
|
def main(u64 a, u64 b) -> (u64, u64, u64):
|
||||||
return a - b
|
return a - b, a - 1, 1 - a
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"entry_point": "./tests/tests/uint/u8/sub.zok",
|
"entry_point": "./tests/tests/uint/u8/sub.zok",
|
||||||
"max_constraint_count": 29,
|
"max_constraint_count": 51,
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"input": {
|
"input": {
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xfe"]
|
"values": ["0xfe", "0xfe", "0x02"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0xff"]
|
"values": ["0xff", "0xff", "0x01"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
def main(u8 a, u8 b) -> u8:
|
def main(u8 a, u8 b) -> (u8, u8, u8):
|
||||||
return a - b
|
return a - b, a - 1, 1 - a
|
Loading…
Reference in a new issue