Skip to content

Commit

Permalink
Merge pull request #1814 from o1-labs/fix/circuit-string-length
Browse files Browse the repository at this point in the history
Fix CircuitString length calculation
  • Loading branch information
boray authored Sep 9, 2024
2 parents d446403 + 6e8bc95 commit 81dd73c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/provable/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/lib/provable/test/string.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 81dd73c

Please sign in to comment.