From 550b5d14d66749a90e7d95c3a25bef4943418772 Mon Sep 17 00:00:00 2001 From: boray Date: Mon, 9 Sep 2024 01:11:33 +0300 Subject: [PATCH 1/2] fix: length calculation --- src/lib/provable/string.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/provable/string.ts b/src/lib/provable/string.ts index 2a52e33cdf..1a4bd4d451 100644 --- a/src/lib/provable/string.ts +++ b/src/lib/provable/string.ts @@ -88,7 +88,7 @@ class CircuitString extends Struct(RawCircuitString) { let isNull = this.values[i].isNull(); mask[i] = isNull.and(wasntNullAlready); wasntNullAlready = isNull.not().and(wasntNullAlready); - length.add(wasntNullAlready.toField()); + length = length.add(wasntNullAlready.toField()); } // mask has length n+1, the last element is true when `this` has no null char mask[n] = wasntNullAlready; From 6e8bc9572439e287fdae8a25cda00a51b4936d17 Mon Sep 17 00:00:00 2001 From: boray Date: Mon, 9 Sep 2024 01:12:18 +0300 Subject: [PATCH 2/2] test: length method --- src/lib/provable/test/string.unit-test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/provable/test/string.unit-test.ts b/src/lib/provable/test/string.unit-test.ts index 8eccb4bee8..4360baddce 100644 --- a/src/lib/provable/test/string.unit-test.ts +++ b/src/lib/provable/test/string.unit-test.ts @@ -150,6 +150,18 @@ describe('Circuit String', () => { }); }); + describe('#length', () => { + test('length', async () => { + const str1 = CircuitString.fromString('abcd'); + expect(str1.length()).toEqual(Field(4)); + + await Provable.runAndCheck(() => { + const str1 = CircuitString.fromString('abcd'); + expect(str1.length()).toEqual(Field(4)); + }); + }); + }); + /* describe('CircuitString8', async () => { test('cannot create more than 8 chars', () => { expect(() => {