be less strict on cached bits bitwidth
This commit is contained in:
parent
0e47ef77dd
commit
d28f2a44f5
3 changed files with 76 additions and 5 deletions
|
@ -1958,12 +1958,21 @@ impl<'ast, T: Field> Flattener<'ast, T> {
|
|||
// constant
|
||||
|
||||
let from = std::cmp::max(from, to);
|
||||
match self.bits_cache.entry(e.field.clone().unwrap()) {
|
||||
let res = match self.bits_cache.entry(e.field.clone().unwrap()) {
|
||||
Entry::Occupied(entry) => {
|
||||
let res: Vec<_> = entry.get().clone();
|
||||
// if we already know a decomposition, it has to be of the size of the target bitwidth
|
||||
assert_eq!(res.len(), to);
|
||||
res
|
||||
// if we already know a decomposition, its number of elements has to be smaller or equal to `to`
|
||||
assert!(res.len() <= to);
|
||||
|
||||
// we then pad it with zeroes on the left (big endian) to return `to` bits
|
||||
if res.len() == to {
|
||||
res
|
||||
} else {
|
||||
(0..to - res.len())
|
||||
.map(|_| FlatExpression::Number(T::zero()))
|
||||
.chain(res)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
Entry::Vacant(_) => {
|
||||
let bits = (0..from).map(|_| self.use_sym()).collect::<Vec<_>>();
|
||||
|
@ -2006,7 +2015,11 @@ impl<'ast, T: Field> Flattener<'ast, T> {
|
|||
|
||||
bits
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(res.len(), to);
|
||||
|
||||
res
|
||||
})
|
||||
}
|
||||
|
||||
|
|
55
zokrates_core_test/tests/tests/range_check/assert_lt_u8.json
Normal file
55
zokrates_core_test/tests/tests/range_check/assert_lt_u8.json
Normal file
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"entry_point": "./tests/tests/range_check/assert_lt_u8.zok",
|
||||
"max_constraint_count": 9,
|
||||
"curves": ["Bn128"],
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x00"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x01"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x02"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": {
|
||||
"SourceAssertion": "Assertion failed at ./tests/tests/range_check/assert_lt_u8.zok:2:5"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["0x0f"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"error": {
|
||||
"SourceAssertion": "Assertion failed at ./tests/tests/range_check/assert_lt_u8.zok:2:5"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
def main(field x):
|
||||
assert(x < 2)
|
||||
return
|
Loading…
Reference in a new issue