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; 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(() => {