From 632a3d49c9d3c0147a90169c1d5f17cc069cbbce Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 27 Dec 2022 11:52:10 +0100 Subject: [PATCH] change endianness in bitify --- .../tests/tests/assembly/binary_sub.json | 13 +++++++++++++ zokrates_core_test/tests/tests/assembly/bitify.json | 8 ++++---- zokrates_core_test/tests/tests/assembly/bitify.zok | 11 +++++------ .../tests/tests/assembly/less_than.zok | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/zokrates_core_test/tests/tests/assembly/binary_sub.json b/zokrates_core_test/tests/tests/assembly/binary_sub.json index f4e06cc8..f74256be 100644 --- a/zokrates_core_test/tests/tests/assembly/binary_sub.json +++ b/zokrates_core_test/tests/tests/assembly/binary_sub.json @@ -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": [ diff --git a/zokrates_core_test/tests/tests/assembly/bitify.json b/zokrates_core_test/tests/tests/assembly/bitify.json index 392b9cce..516aed2d 100644 --- a/zokrates_core_test/tests/tests/assembly/bitify.json +++ b/zokrates_core_test/tests/tests/assembly/bitify.json @@ -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 } } diff --git a/zokrates_core_test/tests/tests/assembly/bitify.zok b/zokrates_core_test/tests/tests/assembly/bitify.zok index 9867f5f6..ae1f01a5 100644 --- a/zokrates_core_test/tests/tests/assembly/bitify.zok +++ b/zokrates_core_test/tests/tests/assembly/bitify.zok @@ -1,17 +1,16 @@ def bitify(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; } diff --git a/zokrates_core_test/tests/tests/assembly/less_than.zok b/zokrates_core_test/tests/tests/assembly/less_than.zok index 1810f6a1..6d307aee 100644 --- a/zokrates_core_test/tests/tests/assembly/less_than.zok +++ b/zokrates_core_test/tests/tests/assembly/less_than.zok @@ -5,7 +5,7 @@ from "./bitify" import bitify; def less_than(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; }