From d52625a22d21dc86f1b5d1d6f00316b330da48b4 Mon Sep 17 00:00:00 2001 From: yash1io Date: Fri, 2 Aug 2024 10:48:53 +0530 Subject: [PATCH] added more tests --- circuits/ctr.circom | 5 +- tests/ctr.test.ts | 124 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 107 insertions(+), 22 deletions(-) diff --git a/circuits/ctr.circom b/circuits/ctr.circom index 3191ccd..954da62 100644 --- a/circuits/ctr.circom +++ b/circuits/ctr.circom @@ -26,7 +26,7 @@ template EncryptCTR(l,nk){ signal cipherBlocks[n][4][4]; component AddCipher[n]; - for(var i=0;i { { blocks: [ [ - [0x32, 0x88, 0x31, 0xe0], - [0x43, 0x5a, 0x31, 0x37], - [0xf6, 0x30, 0x98, 0x07], - [0xa8, 0x8d, 0xa2, 0x34], + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x34], ], ], } @@ -43,10 +43,10 @@ describe("ToBlocks", () => { { blocks: [ [ - [0x32, 0x88, 0x31, 0xe0], - [0x43, 0x5a, 0x31, 0x37], - [0xf6, 0x30, 0x98, 0x07], - [0xa8, 0x8d, 0xa2, 0x01], + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x01], ], ], } @@ -67,10 +67,10 @@ describe("ToBlocks", () => { { blocks: [ [ - [0x32, 0x88, 0x31, 0xe0], - [0x43, 0x5a, 0x31, 0x37], - [0xf6, 0x30, 0x98, 0x07], - [0xa8, 0x8d, 0x01, 0x00], + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0x01], + [0xe0, 0x37, 0x07, 0x00], ], ], } @@ -86,19 +86,19 @@ describe("ToBlocks", () => { await circuit.expectPass( { - stream: [0x32, 0x88, 0x31, 0xe0, 0x43, 0x5a, 0x31, 0x37, 0xf6, 0x30, 0x98, 0x07, 0xa8, 0x8d, 0xa2, 0x34, 0x12], + stream: [0x32, 0x88, 0x31, 0xe0, 0x42, 0x5a, 0x31, 0x37, 0xf6, 0x30, 0x98, 0x07, 0xa8, 0x8d, 0xa2, 0x34, 0x12], }, { blocks: [ [ - [0x32, 0x88, 0x31, 0xe0], - [0x43, 0x5a, 0x31, 0x37], - [0xf6, 0x30, 0x98, 0x07], - [0xa8, 0x8d, 0xa2, 0x34], + [0x32, 0x42, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x34], ], [ - [0x12, 0x01, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], + [0x12, 0x00, 0x00, 0x00], + [0x01, 0x00, 0x00, 0x00], [0x00, 0x00, 0x00, 0x00], [0x00, 0x00, 0x00, 0x00], ], @@ -145,7 +145,7 @@ describe("EncryptCTR", () => { // 5AE4DF3E DBD5D35E 5B4F0902 0DB03EAB // 1E031DDA 2FBE03D1 792170A0 F3009CEE - it.skip("should encrypt multiple blocks correctly", async () => { + it("should encrypt multiple blocks correctly", async () => { circuit = await circomkit.WitnessTester(`EncryptCTR`, { file: "ctr", template: "EncryptCTR", @@ -175,3 +175,87 @@ describe("EncryptCTR", () => { ); }); }); + +describe("ToStream", () => { + let circuit: WitnessTester<["blocks"], ["stream"]>; + it("should convert blocks to stream#1", async () => { + circuit = await circomkit.WitnessTester(`ToStream`, { + file: "ctr", + template: "ToStream", + params: [1, 16], + }); + console.log("@ToStream #constraints:", await circuit.getConstraintCount()); + + await circuit.expectPass( + { + blocks: [ + [ + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x34], + ], + ], + }, + { + stream: [0x32, 0x88, 0x31, 0xe0, 0x43, 0x5a, 0x31, 0x37, 0xf6, 0x30, 0x98, 0x07, 0xa8, 0x8d, 0xa2, 0x34], + } + ); + }); + it("should convert blocks to stream#2", async () => { + circuit = await circomkit.WitnessTester(`ToStream`, { + file: "ctr", + template: "ToStream", + params: [1, 15], + }); + console.log("@ToStream #constraints:", await circuit.getConstraintCount()); + + await circuit.expectPass( + { + blocks: [ + [ + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x01], + ], + ], + }, + { + stream: [0x32, 0x88, 0x31, 0xe0, 0x43, 0x5a, 0x31, 0x37, 0xf6, 0x30, 0x98, 0x07, 0xa8, 0x8d, 0xa2], + } + ); + }); + it("should convert multiple blocks to stream", async () => { + circuit = await circomkit.WitnessTester(`ToStream`, { + file: "ctr", + template: "ToStream", + params: [2, 18], + }); + console.log("@ToStream #constraints:", await circuit.getConstraintCount()); + + await circuit.expectPass( + { + blocks: [ + [ + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x01], + ], + [ + [0x32, 0x43, 0xf6, 0xa8], + [0x88, 0x5a, 0x30, 0x8d], + [0x31, 0x31, 0x98, 0xa2], + [0xe0, 0x37, 0x07, 0x01], + ], + ], + }, + { + stream: [ + 0x32, 0x88, 0x31, 0xe0, 0x43, 0x5a, 0x31, 0x37, 0xf6, 0x30, 0x98, 0x07, 0xa8, 0x8d, 0xa2, 0x01, 0x32, 0x88, + ], + } + ); + }); +});