Skip to content

Commit

Permalink
reduce AES public io
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Nov 5, 2024
1 parent e50209a commit 38e9370
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 62 deletions.
3 changes: 1 addition & 2 deletions builds/target_1024b/aes_gctr_nivc_1024b.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pragma circom 2.1.9;

include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom";

// the circomkit tests become unhappy when there is a main.
component main { public [step_in] } = AESGCTRFOLD(1024, 10);
component main { public [step_in] } = AESGCTRFOLD(1024);
6 changes: 0 additions & 6 deletions builds/target_256b/aes_gctr_nivc_256b.circom

This file was deleted.

6 changes: 0 additions & 6 deletions builds/target_256b/http_body_mask_256b.circom

This file was deleted.

5 changes: 0 additions & 5 deletions builds/target_256b/http_lock_header_256b.circom

This file was deleted.

5 changes: 0 additions & 5 deletions builds/target_256b/http_parse_and_lock_start_line_256b.circom

This file was deleted.

5 changes: 0 additions & 5 deletions builds/target_256b/json_extract_value_256b.circom

This file was deleted.

5 changes: 0 additions & 5 deletions builds/target_256b/json_mask_array_index_256b.circom

This file was deleted.

5 changes: 0 additions & 5 deletions builds/target_256b/json_mask_object_256b.circom

This file was deleted.

6 changes: 0 additions & 6 deletions builds/target_256b/json_parse_256b.circom

This file was deleted.

3 changes: 1 addition & 2 deletions builds/target_512b/aes_gctr_nivc_512b.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pragma circom 2.1.9;

include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom";

// the circomkit tests become unhappy when there is a main.
component main { public [step_in] } = AESGCTRFOLD(512, 10);
component main { public [step_in] } = AESGCTRFOLD(512);
9 changes: 3 additions & 6 deletions circuits/aes-gcm/nivc/aes-gctr-nivc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ include "../../utils/array.circom";


// Compute AES-GCTR
template AESGCTRFOLD(DATA_BYTES, MAX_STACK_HEIGHT) {
template AESGCTRFOLD(DATA_BYTES) {
// ------------------------------------------------------------------------------------------------------------------ //
// ~~ Set sizes at compile time ~~
assert(DATA_BYTES % 16 == 0);
// Total number of variables in the parser for each byte of data
var PER_ITERATION_DATA_LENGTH = MAX_STACK_HEIGHT * 2 + 2;
var TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * (PER_ITERATION_DATA_LENGTH + 1) + 1;
// Value for accumulating both plaintext and ciphertext as well as counter
var TOTAL_BYTES_ACROSS_NIVC = 2 * DATA_BYTES + 4;
// ------------------------------------------------------------------------------------------------------------------ //


Expand Down Expand Up @@ -75,8 +74,6 @@ template AESGCTRFOLD(DATA_BYTES, MAX_STACK_HEIGHT) {
step_out[i] <== nextTexts.outSecond[i - DATA_BYTES];
} else if(i < 2 * DATA_BYTES + 4) {
step_out[i] <== aes.counter[i - (2 * DATA_BYTES)];
} else {
step_out[i] <== 0;
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import { assert } from "chai";
import { WitnessTester } from "circomkit";
import { circomkit } from "../../common";

const MAX_STACK_HEIGHT = 0;

describe("aes-gctr-nivc", () => {
let circuit_one_block: WitnessTester<["key", "iv", "plainText", "aad", "step_in"], ["step_out"]>;


const DATA_BYTES_0 = 16;
const TOTAL_BYTES_ACROSS_NIVC_0 = DATA_BYTES_0 * (MAX_STACK_HEIGHT + 2 + 1) + 1;
const TOTAL_BYTES_ACROSS_NIVC_0 = 2 * DATA_BYTES_0 + 4;

it("all correct for self generated single zero pt block case", async () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [DATA_BYTES_0, MAX_STACK_HEIGHT], // input len is 16 bytes
params: [DATA_BYTES_0], // input len is 16 bytes
});

let key = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
Expand All @@ -40,7 +38,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [DATA_BYTES_0, MAX_STACK_HEIGHT], // input len is 16 bytes
params: [DATA_BYTES_0], // input len is 16 bytes
});

let key = [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31];
Expand All @@ -63,7 +61,7 @@ describe("aes-gctr-nivc", () => {
});

const DATA_BYTES_1 = 32;
const TOTAL_BYTES_ACROSS_NIVC_1 = DATA_BYTES_1 * (MAX_STACK_HEIGHT + 2 + 1) + 1;
const TOTAL_BYTES_ACROSS_NIVC_1 = DATA_BYTES_1 * 2 + 4;


let zero_block = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
Expand All @@ -79,7 +77,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [DATA_BYTES_1, MAX_STACK_HEIGHT], // input len is 32 bytes
params: [DATA_BYTES_1], // input len is 32 bytes
});

const counter = [0x00, 0x00, 0x00, 0x01];
Expand All @@ -98,7 +96,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [DATA_BYTES_1, MAX_STACK_HEIGHT], // input len is 32 bytes
params: [DATA_BYTES_1], // input len is 32 bytes
});

const counter = [0x00, 0x00, 0x00, 0x02];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web-prover-circuits",
"description": "ZK Circuits for WebProofs",
"version": "0.2.7",
"version": "0.3.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down

0 comments on commit 38e9370

Please sign in to comment.