Skip to content

Commit

Permalink
Merge pull request #208 from zkemail/feat/remove-qp-enc
Browse files Browse the repository at this point in the history
fix: remove-soft-line-break at the beginning
  • Loading branch information
Divide-By-0 authored Aug 3, 2024
2 parents e6786d8 + cdae5e7 commit 4c0d403
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 9 additions & 4 deletions packages/circuits/helpers/remove-soft-line-breaks.circom
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ template RemoveSoftLineBreaks(maxLength) {
}

// Calculate powers of r for encoded
rEnc[0] <== 1;
muxEnc[0] = Mux1();
muxEnc[0].c[0] <== r;
muxEnc[0].c[1] <== 1;
muxEnc[0].s <== shouldZero[0];
rEnc[0] <== muxEnc[0].out;

for (var i = 1; i < maxLength; i++) {
muxEnc[i] = Mux1();
muxEnc[i].c[0] <== rEnc[i - 1] * r;
Expand All @@ -99,19 +104,19 @@ template RemoveSoftLineBreaks(maxLength) {
}

// Calculate powers of r for decoded
rDec[0] <== 1;
rDec[0] <== r;
for (var i = 1; i < maxLength; i++) {
rDec[i] <== rDec[i - 1] * r;
}

// Calculate rlc for processed
sumEnc[0] <== processed[0];
sumEnc[0] <== rEnc[0] * processed[0];
for (var i = 1; i < maxLength; i++) {
sumEnc[i] <== sumEnc[i - 1] + rEnc[i] * processed[i];
}

// Calculate rlc for decoded
sumDec[0] <== decoded[0];
sumDec[0] <== rDec[0] * decoded[0];
for (var i = 1; i < maxLength; i++) {
sumDec[i] <== sumDec[i - 1] + rDec[i] * decoded[i];
}
Expand Down
4 changes: 1 addition & 3 deletions packages/circuits/tests/remove-soft-line-breaks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ describe('RemoveSoftLineBreaks', () => {
});
});

// Note: The circuit currently does not handle the case when the encoded input starts with a soft line break.
// This test is included to document the expected behavior, but it will fail with the current implementation.
xit('should handle input with soft line break at the beginning', async () => {
it('should handle input with soft line break at the beginning', async () => {
const input = {
encoded: [61, 13, 10, 104, 101, 108, 108, 111, ...Array(24).fill(0)],
decoded: [104, 101, 108, 108, 111, ...Array(27).fill(0)],
Expand Down

0 comments on commit 4c0d403

Please sign in to comment.