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