1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

change endianness in bitify

This commit is contained in:
dark64 2022-12-27 11:52:10 +01:00
parent 14986816a8
commit 632a3d49c9
4 changed files with 23 additions and 11 deletions

View file

@ -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": [

View file

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

View file

@ -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;
}

View file

@ -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;
}