diff --git a/packages/circuits/helpers/remove-soft-line-breaks.circom b/packages/circuits/helpers/remove-soft-line-breaks.circom index a8e246a4..b9a6dc94 100644 --- a/packages/circuits/helpers/remove-soft-line-breaks.circom +++ b/packages/circuits/helpers/remove-soft-line-breaks.circom @@ -1,7 +1,7 @@ pragma circom 2.1.6; -include "circomlib/comparators.circom"; -include "circomlib/mux1.circom"; +include "circomlib/circuits/comparators.circom"; +include "circomlib/circuits/mux1.circom"; template QuinSelector(array_length) { signal input array[array_length]; @@ -50,9 +50,6 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) { signal r_dec[decoded_length]; signal sum_dec[decoded_length]; - r_enc[0] <== 1; - r_dec[0] <== 1; - // Helper components component mux_enc[encoded_length]; @@ -102,6 +99,7 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) { } // Calculate powers of r for encoded + r_enc[0] <== 1; for (var i = 1; i < encoded_length; i++) { mux_enc[i] = Mux1(); mux_enc[i].c[0] <== r_enc[i - 1] * r; @@ -111,6 +109,7 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) { } // Calculate powers of r for decoded + r_dec[0] <== 1; for (var i = 1; i < decoded_length; i++) { r_dec[i] <== r_dec[i - 1] * r; } @@ -129,12 +128,4 @@ template RemoveSoftLineBreaks(encoded_length, decoded_length) { // Check if rlc for decoded is equal to rlc for encoded is_valid <== IsEqual()([ sum_enc[encoded_length - 1], sum_dec[decoded_length - 1]]); -} - -component main = RemoveSoftLineBreaks(17, 11); - -/* INPUT = { - "encoded": [115, 101, 115, 58, 61, 13, 10, 45, 32, 83, 114, 101, 97, 107, 61, 13, 10], - "decoded": [115, 101, 115, 58, 45, 32, 83, 114, 101, 97, 107], - "r": 69 -} */ \ No newline at end of file +} \ No newline at end of file diff --git a/packages/circuits/tests/remove-soft-line-breaks.test.ts b/packages/circuits/tests/remove-soft-line-breaks.test.ts new file mode 100644 index 00000000..f301d740 --- /dev/null +++ b/packages/circuits/tests/remove-soft-line-breaks.test.ts @@ -0,0 +1,56 @@ +import { wasm as wasm_tester } from "circom_tester"; +import path from "path"; + +describe("RemoveSoftLineBreaks", () => { + let circuit: any; + + beforeAll(async () => { + circuit = await wasm_tester( + path.join( + __dirname, + "./test-circuits/remove-soft-line-breaks-test.circom" + ), + { + recompile: true, + include: path.join(__dirname, "../../../node_modules"), + output: path.join(__dirname, "./compiled-test-circuits"), + } + ); + }); + + it("should correctly remove soft line breaks", async () => { + const input = { + encoded: [ + 115, 101, 115, 58, 61, 13, 10, 45, 32, 83, 114, 101, 97, 107, + 61, 13, 10, + ], + decoded: [115, 101, 115, 58, 45, 32, 83, 114, 101, 97, 107], + r: 69, + }; + + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + + await circuit.assertOut(witness, { + is_valid: 1, + }); + }); + + it("should fail when decoded input is incorrect", async () => { + const input = { + encoded: [ + 115, 101, 115, 58, 61, 13, 10, 45, 32, 83, 114, 101, 97, 107, + 61, 13, 10, + ], + decoded: [115, 101, 115, 58, 45, 32, 83, 114, 101, 97, 108], // Changed last character + r: 69, + }; + + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + + await circuit.assertOut(witness, { + is_valid: 0, + }); + }); +}); diff --git a/packages/circuits/tests/test-circuits/remove-soft-line-breaks-test.circom b/packages/circuits/tests/test-circuits/remove-soft-line-breaks-test.circom new file mode 100644 index 00000000..f0ee705c --- /dev/null +++ b/packages/circuits/tests/test-circuits/remove-soft-line-breaks-test.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.6; + +include "../../helpers/remove-soft-line-breaks.circom"; + +component main = RemoveSoftLineBreaks(17, 11);