From de26e4c4a75ac54c030be8aeb755efddac294e9b Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Fri, 20 Sep 2024 11:28:22 -0700 Subject: [PATCH] silence logs in tests --- circuits/aes-gcm/gctr.circom | 18 +- circuits/aes-gcm/nistgmul.circom | 14 +- circuits/test/gfmulint/nistgfmul.test.ts | 480 +++++++++++------------ circuits/test/hashes/polyval.test.ts | 4 +- nistgmul.circom | 12 - 5 files changed, 258 insertions(+), 270 deletions(-) delete mode 100644 nistgmul.circom diff --git a/circuits/aes-gcm/gctr.circom b/circuits/aes-gcm/gctr.circom index dd11364..e644984 100644 --- a/circuits/aes-gcm/gctr.circom +++ b/circuits/aes-gcm/gctr.circom @@ -47,14 +47,14 @@ template GCTR(INPUT_LEN, nk) { // total number of bits in the plaintext blocks var bytesExcludingLastBlock = 16 * (nBlocks); - log("INPUT_LEN"); - log(INPUT_LEN); - log("nBlocks"); - log(nBlocks); - log("lastBlockSize"); - log(lastBlockSize); - log("bytesExcludingLastBlock"); - log(bytesExcludingLastBlock); + // log("INPUT_LEN"); + // log(INPUT_LEN); + // log("nBlocks"); + // log(nBlocks); + // log("lastBlockSize"); + // log(lastBlockSize); + // log("bytesExcludingLastBlock"); + // log(bytesExcludingLastBlock); assert(INPUT_LEN == nBlocks * 16 + lastBlockSize); @@ -137,4 +137,4 @@ template GCTR(INPUT_LEN, nk) { for (var i = 0; i < lastBlockSize; i++) { cipherText[bytesExcludingLastBlock + i] <== addLastCipher.out[i]; } -} \ No newline at end of file +} diff --git a/circuits/aes-gcm/nistgmul.circom b/circuits/aes-gcm/nistgmul.circom index b728c86..1c8ed22 100644 --- a/circuits/aes-gcm/nistgmul.circom +++ b/circuits/aes-gcm/nistgmul.circom @@ -84,8 +84,8 @@ template debug_1_byte() { bytesToBits.in <== X; bitsX <== bytesToBits.out; for (var i = 0; i < 8; i++) { - log("i", i); - log("bitsX[i]", bitsX[i]); + // log("i", i); + // log("bitsX[i]", bitsX[i]); z_i_update[i] = Z_I_UPDATE(1); z_i_update[i].Z <== Z[i]; z_i_update[i].V <== V[i]; @@ -97,7 +97,7 @@ template debug_1_byte() { mulx[i].in <== V[i]; V[i + 1] <== mulx[i].out; - log("V[i]", V[i][0]); + // log("V[i]", V[i][0]); } out <== Z[8]; } @@ -120,8 +120,8 @@ template debug_2_bytes() { bytesToBits.in <== X; bitsX <== bytesToBits.out; for (var i = 0; i < 16; i++) { - log("i", i); - log("bitsX[i]", bitsX[i]); + // log("i", i); + // log("bitsX[i]", bitsX[i]); z_i_update[i] = Z_I_UPDATE(2); z_i_update[i].Z <== Z[i]; z_i_update[i].V <== V[i]; @@ -133,8 +133,8 @@ template debug_2_bytes() { mulx[i].in <== V[i]; V[i + 1] <== mulx[i].out; - log("V[i][0]", V[i][0]); - log("V[i][1]", V[i][1]); + // log("V[i][0]", V[i][0]); + // log("V[i][1]", V[i][1]); } out <== Z[16]; diff --git a/circuits/test/gfmulint/nistgfmul.test.ts b/circuits/test/gfmulint/nistgfmul.test.ts index f0a7ea4..1e610ad 100644 --- a/circuits/test/gfmulint/nistgfmul.test.ts +++ b/circuits/test/gfmulint/nistgfmul.test.ts @@ -16,18 +16,18 @@ describe("NistGMulByte", () => { it("Should Compute NistGMulByte Correctly", async () => { - let X = [0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let X = [0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; let Y = [0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - + const expected = [0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; await circuit.expectPass({ X: X, Y: Y }, { out: expected }); }); it("Should Compute NistGMulByte of LSB=1 Correctly", async () => { - let X = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + let X = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; let Y = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - + const expected = [0xe6, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03]; await circuit.expectPass({ X: X, Y: Y }, { out: expected }); }); @@ -36,9 +36,9 @@ describe("NistGMulByte", () => { // x = "aae06992acbf52a3e8f4a96ec9300bd7" // y = "98e7247c07f0fe411c267e4384b0f600" // expected = "90e87315fb7d4e1b4092ec0cbfda5d7d" - let X = [0xaa, 0xe0, 0x69, 0x92, 0xac, 0xbf, 0x52, 0xa3, 0xe8, 0xf4, 0xa9, 0x6e, 0xc9, 0x30, 0x0b, 0xd7]; + let X = [0xaa, 0xe0, 0x69, 0x92, 0xac, 0xbf, 0x52, 0xa3, 0xe8, 0xf4, 0xa9, 0x6e, 0xc9, 0x30, 0x0b, 0xd7]; let Y = [0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00]; - + const expected = [0x90, 0xe8, 0x73, 0x15, 0xfb, 0x7d, 0x4e, 0x1b, 0x40, 0x92, 0xec, 0x0c, 0xbf, 0xda, 0x5d, 0x7d]; await circuit.expectPass({ X: X, Y: Y }, { out: expected }); }); @@ -46,291 +46,291 @@ describe("NistGMulByte", () => { }); describe("debug1", () => { - let circuit: WitnessTester<["X", "Y"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("debug1", { - file: "aes-gcm/nistgmul", - template: "debug_1_byte", - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); + let circuit: WitnessTester<["X", "Y"], ["out"]>; - it("Should Compute Correctly", async () => { - let inputX = [0x80]; - let inputY = [0x80]; - const expected = [0x80]; - console.log("expected", expected); - const _res = await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); + before(async () => { + circuit = await circomkit.WitnessTester("debug1", { + file: "aes-gcm/nistgmul", + template: "debug_1_byte", }); - it("Should Compute Correctly", async () => { - let inputX = [0x01]; - let inputY = [0x01]; + console.log("#constraints:", await circuit.getConstraintCount()); + }); - const expected = [0x5E]; - console.log("expected", expected); - await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); - }); + it("Should Compute Correctly", async () => { + let inputX = [0x80]; + let inputY = [0x80]; + const expected = [0x80]; + // console.log("expected", expected); + const _res = await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); + }); + it("Should Compute Correctly", async () => { + let inputX = [0x01]; + let inputY = [0x01]; + + const expected = [0x5E]; + // console.log("expected", expected); + await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); + }); }); describe("debug2", () => { - let circuit: WitnessTester<["X", "Y"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("debug1", { - file: "aes-gcm/nistgmul", - template: "debug_2_bytes", - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); + let circuit: WitnessTester<["X", "Y"], ["out"]>; - it("Should Compute Correctly", async () => { - let inputX = [0x80, 0x00]; - let inputY = [0x80, 0x00]; - const expected = [0x80, 0x00]; - console.log("expected", expected); - const _res = await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); + before(async () => { + circuit = await circomkit.WitnessTester("debug1", { + file: "aes-gcm/nistgmul", + template: "debug_2_bytes", }); - it("Should Compute Correctly", async () => { - let inputX = [0x00, 0x01]; - let inputY = [0x00, 0x01]; + console.log("#constraints:", await circuit.getConstraintCount()); + }); - const expected = [0xE6, 0x0B]; - console.log("expected", expected); - await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); - }); + it("Should Compute Correctly", async () => { + let inputX = [0x80, 0x00]; + let inputY = [0x80, 0x00]; + const expected = [0x80, 0x00]; + // console.log("expected", expected); + const _res = await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); + }); + it("Should Compute Correctly", async () => { + let inputX = [0x00, 0x01]; + let inputY = [0x00, 0x01]; + + const expected = [0xE6, 0x0B]; + // console.log("expected", expected); + await circuit.expectPass({ X: inputX, Y: inputY }, { out: expected }); + }); }); describe("ToBits", () => { - let circuit: WitnessTester<["in"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("bytesToBits", { - file: "aes-gcm/nistgmul", - template: "BytesToBits", - params: [1] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); + let circuit: WitnessTester<["in"], ["out"]>; - it("Should Compute bytesToBits Correctly", async () => { - let input = 0x01; - const expected = hexToBitArray("0x01"); - console.log("expected", expected); - const _res = await circuit.expectPass({ in: input }, { out: expected }); - }); - it("Should Compute bytesToBits Correctly", async () => { - let input = 0xFF; - const expected = hexToBitArray("0xFF"); - console.log("expected", expected); - const _res = await circuit.expectPass({ in: input }, { out: expected }); + before(async () => { + circuit = await circomkit.WitnessTester("bytesToBits", { + file: "aes-gcm/nistgmul", + template: "BytesToBits", + params: [1] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + + it("Should Compute bytesToBits Correctly", async () => { + let input = 0x01; + const expected = hexToBitArray("0x01"); + // console.log("expected", expected); + const _res = await circuit.expectPass({ in: input }, { out: expected }); + }); + it("Should Compute bytesToBits Correctly", async () => { + let input = 0xFF; + const expected = hexToBitArray("0xFF"); + // console.log("expected", expected); + const _res = await circuit.expectPass({ in: input }, { out: expected }); + }); }); describe("ToBits", () => { - let circuit: WitnessTester<["in"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("bytesToBits", { - file: "aes-gcm/nistgmul", - template: "BytesToBits", - params: [2] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); + let circuit: WitnessTester<["in"], ["out"]>; - it("Should Compute bytesToBits Correctly", async () => { - let input = [0x01, 0x00]; - const expected = hexToBitArray("0x0100"); - console.log("expected", expected); - const _res = await circuit.expectPass({ in: input }, { out: expected }); - }); - it("Should Compute bytesToBits Correctly", async () => { - let input = [0xFF, 0x00]; - const expected = hexToBitArray("0xFF00"); - console.log("expected", expected); - const _res = await circuit.expectPass({ in: input }, { out: expected }); + before(async () => { + circuit = await circomkit.WitnessTester("bytesToBits", { + file: "aes-gcm/nistgmul", + template: "BytesToBits", + params: [2] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + + it("Should Compute bytesToBits Correctly", async () => { + let input = [0x01, 0x00]; + const expected = hexToBitArray("0x0100"); + // console.log("expected", expected); + const _res = await circuit.expectPass({ in: input }, { out: expected }); + }); + it("Should Compute bytesToBits Correctly", async () => { + let input = [0xFF, 0x00]; + const expected = hexToBitArray("0xFF00"); + // console.log("expected", expected); + const _res = await circuit.expectPass({ in: input }, { out: expected }); + }); }); describe("ToBytes", () => { - let circuit: WitnessTester<["in"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("bytesToBits", { - file: "aes-gcm/nistgmul", - template: "BitsToBytes", - params: [1] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); + let circuit: WitnessTester<["in"], ["out"]>; - it("Should Compute bytesToBits Correctly", async () => { - let input = hexToBitArray("0x01"); - const expected = hexByteToBigInt("0x01"); - console.log("expected", expected); - const _res = await circuit.compute({ in: input }, ["out"]); - console.log("res:", _res.out); - assert.deepEqual(_res.out, expected); - }); - it("Should Compute bytesToBits Correctly", async () => { - let input = hexToBitArray("0xFF"); - const expected = hexByteToBigInt("0xFF"); - console.log("expected", expected); - const _res = await circuit.compute({ in: input }, ["out"]); - console.log("res:", _res.out); - assert.deepEqual(_res.out, expected); + before(async () => { + circuit = await circomkit.WitnessTester("bytesToBits", { + file: "aes-gcm/nistgmul", + template: "BitsToBytes", + params: [1] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + + it("Should Compute bytesToBits Correctly", async () => { + let input = hexToBitArray("0x01"); + const expected = hexByteToBigInt("0x01"); + // console.log("expected", expected); + const _res = await circuit.compute({ in: input }, ["out"]); + // console.log("res:", _res.out); + assert.deepEqual(_res.out, expected); + }); + it("Should Compute bytesToBits Correctly", async () => { + let input = hexToBitArray("0xFF"); + const expected = hexByteToBigInt("0xFF"); + // console.log("expected", expected); + const _res = await circuit.compute({ in: input }, ["out"]); + // console.log("res:", _res.out); + assert.deepEqual(_res.out, expected); + }); }); describe("intrightshift", () => { - let circuit: WitnessTester<["in"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("intrightshift", { - file: "aes-gcm/helper_functions", - template: "IntRightShift", - params: [8, 1] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); - - it("Should Compute IntRightShift Correctly", async () => { - let input = 0x02; // little endian hex vectors - const expected = hexByteToBigInt("0x01"); - const _res = await circuit.compute({ in: input }, ["out"]); - console.log("res:", _res.out); - assert.deepEqual(_res.out, expected); + let circuit: WitnessTester<["in"], ["out"]>; + + before(async () => { + circuit = await circomkit.WitnessTester("intrightshift", { + file: "aes-gcm/helper_functions", + template: "IntRightShift", + params: [8, 1] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); - it("Should Compute IntRightShift Correctly", async () => { - let input = 0x04; // little endian hex vectors - const expected = hexByteToBigInt("0x02"); - const _res = await circuit.compute({ in: input }, ["out"]); - console.log("res:", _res.out); - assert.deepEqual(_res.out, expected); - }); + it("Should Compute IntRightShift Correctly", async () => { + let input = 0x02; // little endian hex vectors + const expected = hexByteToBigInt("0x01"); + const _res = await circuit.compute({ in: input }, ["out"]); + // console.log("res:", _res.out); + assert.deepEqual(_res.out, expected); }); + it("Should Compute IntRightShift Correctly", async () => { + let input = 0x04; // little endian hex vectors + const expected = hexByteToBigInt("0x02"); + const _res = await circuit.compute({ in: input }, ["out"]); + // console.log("res:", _res.out); + assert.deepEqual(_res.out, expected); + }); +}); + describe("BlockRightShift", () => { - let circuit: WitnessTester<["in"], ["out", "msb"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("BlockRightShift", { - file: "aes-gcm/nistgmul", - template: "BlockRightShift", - params: [16] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); + let circuit: WitnessTester<["in"], ["out", "msb"]>; - it("Should Compute BlockRightShift Correctly", async () => { - let input = [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - const expected = [0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - await circuit.expectPass({ in: input }, { out: expected, msb: 0 }); - }); - it("Should Compute BlockRightShift Correctly", async () => { - let input = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - const expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - await circuit.expectPass({ in: input }, { out: expected, msb: 1 }); + before(async () => { + circuit = await circomkit.WitnessTester("BlockRightShift", { + file: "aes-gcm/nistgmul", + template: "BlockRightShift", + params: [16] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + + it("Should Compute BlockRightShift Correctly", async () => { + let input = [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + const expected = [0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + await circuit.expectPass({ in: input }, { out: expected, msb: 0 }); + }); + it("Should Compute BlockRightShift Correctly", async () => { + let input = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + const expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + await circuit.expectPass({ in: input }, { out: expected, msb: 1 }); + }); }); describe("Mulx", () => { - let circuit: WitnessTester<["in"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("Mulx", { - file: "aes-gcm/nistgmul", - template: "Mulx", - params: [16] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); - // msb is 1 so we xor the first byte with 0xE1 - it("Should Compute Mulx Correctly", async () => { - let input = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - const expected = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - await circuit.expectPass({ in: input }, { out: expected }); + let circuit: WitnessTester<["in"], ["out"]>; + + before(async () => { + circuit = await circomkit.WitnessTester("Mulx", { + file: "aes-gcm/nistgmul", + template: "Mulx", + params: [16] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + // msb is 1 so we xor the first byte with 0xE1 + it("Should Compute Mulx Correctly", async () => { + let input = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + const expected = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + await circuit.expectPass({ in: input }, { out: expected }); + }); }); describe("XORBLOCK", () => { - let circuit: WitnessTester<["a", "b"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("XORBLOCK", { - file: "aes-gcm/nistgmul", - template: "XORBLOCK", - params: [16] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); - // msb is 1 so we xor the first byte with 0xE1 - it("Should Compute block XOR Correctly", async () => { - let inputa = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let inputb = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - const expected = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - await circuit.expectPass({ a: inputa, b: inputb }, { out: expected }); + let circuit: WitnessTester<["a", "b"], ["out"]>; + + before(async () => { + circuit = await circomkit.WitnessTester("XORBLOCK", { + file: "aes-gcm/nistgmul", + template: "XORBLOCK", + params: [16] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + // msb is 1 so we xor the first byte with 0xE1 + it("Should Compute block XOR Correctly", async () => { + let inputa = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let inputb = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + const expected = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + await circuit.expectPass({ a: inputa, b: inputb }, { out: expected }); + }); }); describe("ArrayMux", () => { - let circuit: WitnessTester<["a", "b", "sel"], ["out"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("XORBLOCK", { - file: "aes-gcm/nistgmul", - template: "ArrayMux", - params: [16] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); - // msb is 1 so we xor the first byte with 0xE1 - it("Should Compute selector mux Correctly", async () => { - let a= [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let b = [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - let sel = 0x00; - let expected= [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - await circuit.expectPass({ a: a, b: b, sel: sel }, { out: expected }); - }); + let circuit: WitnessTester<["a", "b", "sel"], ["out"]>; - it("Should Compute block XOR Correctly", async () => { - let a= [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let b = [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - let sel = 0x01; - let expected= [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - await circuit.expectPass({ a: a, b: b, sel: sel }, { out: expected }); + before(async () => { + circuit = await circomkit.WitnessTester("XORBLOCK", { + file: "aes-gcm/nistgmul", + template: "ArrayMux", + params: [16] }); + console.log("#constraints:", await circuit.getConstraintCount()); + }); + // msb is 1 so we xor the first byte with 0xE1 + it("Should Compute selector mux Correctly", async () => { + let a = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let b = [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + let sel = 0x00; + let expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + await circuit.expectPass({ a: a, b: b, sel: sel }, { out: expected }); + }); + + it("Should Compute block XOR Correctly", async () => { + let a = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let b = [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + let sel = 0x01; + let expected = [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + await circuit.expectPass({ a: a, b: b, sel: sel }, { out: expected }); + }); }); describe("Z_I_UPDATE", () => { - let circuit: WitnessTester<["Z", "V", "bit_val"], ["Z_new"]>; - - before(async () => { - circuit = await circomkit.WitnessTester("XORBLOCK", { - file: "aes-gcm/nistgmul", - template: "Z_I_UPDATE", - params: [16] - }); - console.log("#constraints:", await circuit.getConstraintCount()); - }); - // msb is 1 so we xor the first byte with 0xE1 - it("Should Compute block XOR Correctly", async () => { - let inputZ= [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let inputV = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - let inputc = 0x00; - let expected= [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - await circuit.expectPass({ Z: inputZ, V: inputV, bit_val: inputc }, { Z_new: expected }); - }); + let circuit: WitnessTester<["Z", "V", "bit_val"], ["Z_new"]>; - it("Should Compute block XOR Correctly", async () => { - let inputa = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let inputb = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - let inputc = 0x01; - const expected = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; - await circuit.expectPass({ Z: inputa, V: inputb, bit_val: inputc }, { Z_new: expected }); + before(async () => { + circuit = await circomkit.WitnessTester("XORBLOCK", { + file: "aes-gcm/nistgmul", + template: "Z_I_UPDATE", + params: [16] }); -}); \ No newline at end of file + console.log("#constraints:", await circuit.getConstraintCount()); + }); + // msb is 1 so we xor the first byte with 0xE1 + it("Should Compute block XOR Correctly", async () => { + let inputZ = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let inputV = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + let inputc = 0x00; + let expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + await circuit.expectPass({ Z: inputZ, V: inputV, bit_val: inputc }, { Z_new: expected }); + }); + + it("Should Compute block XOR Correctly", async () => { + let inputa = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let inputb = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + let inputc = 0x01; + const expected = [0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; + await circuit.expectPass({ Z: inputa, V: inputb, bit_val: inputc }, { Z_new: expected }); + }); +}); diff --git a/circuits/test/hashes/polyval.test.ts b/circuits/test/hashes/polyval.test.ts index a6ea8f9..83424c0 100644 --- a/circuits/test/hashes/polyval.test.ts +++ b/circuits/test/hashes/polyval.test.ts @@ -29,7 +29,7 @@ describe("POLYVAL_HASH_1", () => { const result = bitArrayToHex( (_res.out as number[][])[0].map((bit) => Number(bit)) ) - console.log("expect: ", EXPECT, "\nresult: ", result); + // console.log("expect: ", EXPECT, "\nresult: ", result); assert.equal(result, EXPECT); }); }); @@ -54,7 +54,7 @@ describe("POLYVAL_HASH_2", () => { const result = bitArrayToHex( (_res.out as number[][])[0].map((bit) => Number(bit)) ); - console.log("expect: ", EXPECT_2, "\nresult: ", result); + // console.log("expect: ", EXPECT_2, "\nresult: ", result); assert.equal(result, EXPECT_2); }); }); diff --git a/nistgmul.circom b/nistgmul.circom deleted file mode 100644 index 8e49be9..0000000 --- a/nistgmul.circom +++ /dev/null @@ -1,12 +0,0 @@ -template BytesToBits(n) { - signal input in[n]; - signal output out[n*8]; - component num2bits[n]; - for (var i = 0; i < n; i++) { - // ... existing code ... - for (var j = 0; j < 8; j++) { - // Reverse the bit order within each byte - out[i*8 + (7 - j)] <== num2bits[i].out[j]; - } - } -} \ No newline at end of file