From b60cf7d5e77ce1431bc8f8dd9cd2493acc0adeb7 Mon Sep 17 00:00:00 2001 From: lonerapier Date: Wed, 11 Sep 2024 21:07:49 +0530 Subject: [PATCH] pending work --- circuits/test/http/codegen.test.ts | 16 ++-- docs/http.md | 0 docs/pabuild.md | 44 ++++++---- .../{extractor => lockfile}/two_keys.json | 0 .../value_array_nested.json | 0 .../value_array_number.json | 0 .../value_array_object.json | 0 .../value_array_string.json | 0 .../{extractor => lockfile}/value_number.json | 0 .../{extractor => lockfile}/value_object.json | 0 .../{extractor => lockfile}/value_string.json | 0 src/json.rs | 25 ++++-- src/main.rs | 30 ++++++- src/witness.rs | 86 ++++++++++++++++--- 14 files changed, 153 insertions(+), 48 deletions(-) create mode 100644 docs/http.md rename examples/json/{extractor => lockfile}/two_keys.json (100%) rename examples/json/{extractor => lockfile}/value_array_nested.json (100%) rename examples/json/{extractor => lockfile}/value_array_number.json (100%) rename examples/json/{extractor => lockfile}/value_array_object.json (100%) rename examples/json/{extractor => lockfile}/value_array_string.json (100%) rename examples/json/{extractor => lockfile}/value_number.json (100%) rename examples/json/{extractor => lockfile}/value_object.json (100%) rename examples/json/{extractor => lockfile}/value_string.json (100%) diff --git a/circuits/test/http/codegen.test.ts b/circuits/test/http/codegen.test.ts index 580f72e..496176a 100644 --- a/circuits/test/http/codegen.test.ts +++ b/circuits/test/http/codegen.test.ts @@ -75,10 +75,10 @@ describe("HTTP :: Codegen :: Request", async () => { // generate extractor circuit using codegen await executeCodegen(`${lockfile}.json`, lockfile); - const lockData = await readLockFile(`${lockfile}.json`); + const lockData = readLockFile(`${lockfile}.json`); console.log("lockData: ", JSON.stringify(lockData)); - const input = await readHTTPInputFile(`${inputfile}`).input; + const input = readHTTPInputFile(`${inputfile}`).input; const headers = getHeaders(lockData); const params = [input.length, lockData.method.length, lockData.target.length, lockData.version.length]; @@ -117,9 +117,9 @@ describe("HTTP :: Codegen :: Request", async () => { // generate extractor circuit using codegen await executeCodegen(`${lockfile}.json`, lockfile); - const lockData = await readLockFile(`${lockfile}.json`); + const lockData = readLockFile(`${lockfile}.json`); - const input = await readHTTPInputFile(`${inputfile}`).input + const input = readHTTPInputFile(`${inputfile}`).input const headers = getHeaders(lockData); const params = [input.length, lockData.method.length, lockData.target.length, lockData.version.length]; @@ -163,10 +163,10 @@ describe("HTTP :: Codegen :: Response", async () => { // generate extractor circuit using codegen await executeCodegen(`${lockfile}.json`, lockfile); - const lockData = await readLockFile(`${lockfile}.json`); + const lockData = readLockFile(`${lockfile}.json`); console.log("lockData: ", JSON.stringify(lockData)); - const http = await readHTTPInputFile(`${inputfile}`); + const http = readHTTPInputFile(`${inputfile}`); const input = http.input; const headers = getHeaders(lockData); @@ -209,9 +209,9 @@ describe("HTTP :: Codegen :: Response", async () => { // generate extractor circuit using codegen await executeCodegen(`${lockfile}.json`, lockfile); - const lockData = await readLockFile(`${lockfile}.json`); + const lockData = readLockFile(`${lockfile}.json`); - const http = await readHTTPInputFile(`${inputfile}`); + const http = readHTTPInputFile(`${inputfile}`); const input = http.input; const headers = getHeaders(lockData); diff --git a/docs/http.md b/docs/http.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/pabuild.md b/docs/pabuild.md index c218d3b..97191c2 100644 --- a/docs/pabuild.md +++ b/docs/pabuild.md @@ -1,15 +1,15 @@ -# `wpbuild` CLI Tool -This repository contains a small Rust CLI tool called `wpbuild`. +# `pabuild` CLI Tool +This repository contains a small Rust CLI tool called `pabuild`. -## Install `wpbuild` +## Install `pabuild` From the root of this repository, run: ```sh cargo install --path . ``` -to install the `wpbuild` binary. +to install the `pabuild` binary. You can see a help menu with the subcommands by: ```sh -wpbuild --help +pabuild --help ``` ## Witnessgen @@ -21,19 +21,19 @@ It can process and generate JSON files to be used for these circuits. ### Examples **JSON Parsing:** -If we have a given JSON file we want to parse such as `examples/json/test/example.json` for the `json-parser` circuit (see `circuits.json`), then we can: +If we have a given JSON file we want to parse such as [`examples/json/test/example.json`](../examples/json/test/example.json) for the `json-parser` circuit (see [`circuits.json`](../circuits.json)), then we can: ```sh -pabuild witness json --input-file examples/json/test/example.json --output-dir inputs/json-parser --output-filename input.json +pabuild witness json --input-file examples/json/test/example.json --output-dir inputs/json-parser --output-filename input.json json ``` Afterwards, you can run `npx circomkit compile json-parser` then `circomkit witness json-parser input`. **HTTP Parsing:** -If we have a given HTTP request/response (as a file) we want to parse such as `examples/http/get_request.http` for the `http-parser` circuit (see `circuits.json`), then we can: +If we have a given HTTP request/response (as a file) we want to parse such as [`examples/http/get_request.http`](../examples/http/get_request.http) for the `http-parser` circuit (see `circuits.json`), then we can: ```sh -pabuild witness http --input-file examples/json/get_request.http --output-dir inputs/http-parser --output-filename input.json +pabuild witness http --input-file examples/json/get_request.http --output-dir inputs/http-parser --output-filename input.json http ``` Afterwards, you can run `npx circomkit compile http-parser` then `circomkit witness http-parser input`. @@ -44,25 +44,31 @@ Afterwards, you can run `npx circomkit compile http-parser` then `circomkit witn JSON extractor circuit is generated using rust to handle arbitrary keys and array indices. Run: -```bash -cargo run --bin codegen -- --help +```sh +pabuild json --help ``` to get options: ``` -Usage: codegen [OPTIONS] --json-file +Usage: pabuild json [OPTIONS] --template