change endianness in bitify
This commit is contained in:
parent
14986816a8
commit
632a3d49c9
4 changed files with 23 additions and 11 deletions
|
@ -2,6 +2,19 @@
|
|||
"curves": ["Bn128"],
|
||||
"max_constraint_count": 10,
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": [
|
||||
["0", "0", "1", "1"],
|
||||
["0", "0", "0", "1"]
|
||||
]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": ["0", "0", "1", "0"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": [
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": ["1", "0", "0", "0"]
|
||||
"value": ["0", "0", "0", "1"]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -17,7 +17,7 @@
|
|||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": ["0", "1", "0", "0"]
|
||||
"value": ["0", "0", "1", "0"]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -27,7 +27,7 @@
|
|||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"value": ["1", "1", "0", "0"]
|
||||
"value": ["0", "0", "1", "1"]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -52,7 +52,7 @@
|
|||
"SourceAssemblyConstraint": {
|
||||
"file": "tests/tests/assembly/bitify.zok",
|
||||
"position": {
|
||||
"line": 14,
|
||||
"line": 13,
|
||||
"col": 9
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
def bitify<N>(field num) -> field[N] {
|
||||
field[N] mut out = [0; N];
|
||||
field mut lc1 = 0;
|
||||
field mut e2 = 1;
|
||||
field mut aux = 0;
|
||||
for u32 i in 0..N {
|
||||
u32 j = N - i - 1;
|
||||
asm {
|
||||
out[i] <-- (num >> i) & 1;
|
||||
out[i] <-- (num >> j) & 1;
|
||||
out[i] * (out[i] - 1) === 0;
|
||||
}
|
||||
lc1 = lc1 + out[i] * e2;
|
||||
e2 = e2 + e2;
|
||||
aux = aux + out[i] * (2**j);
|
||||
}
|
||||
asm {
|
||||
lc1 === num;
|
||||
aux === num;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ from "./bitify" import bitify;
|
|||
def less_than<N>(field a, field b) -> bool {
|
||||
assert(N < FIELD_SIZE_IN_BITS - 1);
|
||||
field[N + 1] bits = bitify(a + 2**N - b);
|
||||
bool out = field_to_bool_unsafe(1 - bits[N]);
|
||||
bool out = field_to_bool_unsafe(1 - bits[0]);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue