Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove-soft-line-break at the beginning #208

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading