From 0f2ee7f0f1f5f38ede31b9db0cb9b0a070f5aa5d Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Tue, 20 Feb 2024 19:39:15 +0000 Subject: [PATCH 1/4] Test rust client for gnark prover --- .github/workflows/rust.yml | 10 ++ .gitmodules | 3 + Cargo.lock | 49 +++++++- .../circuit-lib.circom/scripts/buildMerkle.sh | 2 +- circuit-lib/circuit-lib.js/package.json | 3 + circuit-lib/circuit-lib.js/scripts/prover.sh | 20 +++ .../circuit-lib.js/tests/gnark.test.ts | 73 +++++++++++ circuit-lib/circuitlib-rs/Cargo.toml | 8 ++ circuit-lib/circuitlib-rs/scripts/prover.sh | 1 + circuit-lib/circuitlib-rs/src/helpers.rs | 9 ++ .../circuitlib-rs/src/merkle_proof_inputs.rs | 1 + .../circuitlib-rs/tests/gnark/constants.rs | 5 + .../circuitlib-rs/tests/gnark/helpers.rs | 114 ++++++++++++++++++ circuit-lib/circuitlib-rs/tests/gnark/main.rs | 11 ++ .../circuitlib-rs/tests/gnark/prove.rs | 26 ++++ .../circuitlib-rs/tests/merkle/main.rs | 9 +- gnark-prover | 1 + pnpm-lock.yaml | 3 + 18 files changed, 337 insertions(+), 11 deletions(-) create mode 100755 circuit-lib/circuit-lib.js/scripts/prover.sh create mode 100644 circuit-lib/circuit-lib.js/tests/gnark.test.ts create mode 120000 circuit-lib/circuitlib-rs/scripts/prover.sh create mode 100644 circuit-lib/circuitlib-rs/tests/gnark/constants.rs create mode 100644 circuit-lib/circuitlib-rs/tests/gnark/helpers.rs create mode 100644 circuit-lib/circuitlib-rs/tests/gnark/main.rs create mode 100644 circuit-lib/circuitlib-rs/tests/gnark/prove.rs create mode 160000 gnark-prover diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8371c7c2f4..0f615ea36e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -32,6 +32,7 @@ jobs: uses: actions/checkout@v4 with: lfs: true + submodules: true - name: Cache .local directory uses: buildjet/cache@v3 @@ -45,6 +46,15 @@ jobs: ./scripts/install.sh source ./scripts/devenv.sh + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: './gnark-prover/go.mod' + - name: Build + run: | + cd gnark-prover + go build + - name: Build and test run: | source ./scripts/devenv.sh diff --git a/.gitmodules b/.gitmodules index e69de29bb2..6b3a57064a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "gnark-prover"] + path = gnark-prover + url = git@github.com:Lightprotocol/gnark-prover.git diff --git a/Cargo.lock b/Cargo.lock index f9fffed0a5..8eea68308e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1531,15 +1531,21 @@ dependencies = [ "ark-serialize 0.4.2", "ark-std 0.4.0", "color-eyre", + "duct", "env_logger 0.10.2", "groth16-solana 0.0.2 (git+https://github.com/Lightprotocol/groth16-solana.git)", "light-hasher", "light-merkle-tree-reference", "log", "num-bigint 0.4.4", + "num-traits", "once_cell", + "reqwest", + "serde", + "serde_json", "solana-program", "thiserror", + "tokio", "zeroize", ] @@ -2166,6 +2172,18 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "duct" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ab5718d1224b63252cd0c6f74f6480f9ffeb117438a2e0f5cf6d9a4798929c" +dependencies = [ + "libc", + "once_cell", + "os_pipe", + "shared_child", +] + [[package]] name = "eager" version = "0.1.0" @@ -3944,6 +3962,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "os_pipe" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "os_str_bytes" version = "6.5.1" @@ -4592,9 +4620,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.22" +version = "0.11.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" dependencies = [ "async-compression", "base64 0.21.4", @@ -4621,6 +4649,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "sync_wrapper", "system-configuration", "tokio", "tokio-native-tls", @@ -5074,6 +5103,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shared_child" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "shell-words" version = "1.1.0" @@ -6673,6 +6712,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "synstructure" version = "0.12.6" diff --git a/circuit-lib/circuit-lib.circom/scripts/buildMerkle.sh b/circuit-lib/circuit-lib.circom/scripts/buildMerkle.sh index 69622cda96..d35a8388e9 100755 --- a/circuit-lib/circuit-lib.circom/scripts/buildMerkle.sh +++ b/circuit-lib/circuit-lib.circom/scripts/buildMerkle.sh @@ -79,4 +79,4 @@ for ((i=1; i<=MAX_COUNT; i++)); do execute_commands "$MERKLE_TREE_HEIGHT" "$i" "$POWERS_OF_TAU" || exit done -execute_commands "$MERKLE_TREE_HEIGHT" 8 "$POWERS_OF_TAU" || exit \ No newline at end of file +execute_commands "$MERKLE_TREE_HEIGHT" 8 "$POWERS_OF_TAU" || exit diff --git a/circuit-lib/circuit-lib.js/package.json b/circuit-lib/circuit-lib.js/package.json index 40b04c9dab..cec87195a1 100644 --- a/circuit-lib/circuit-lib.js/package.json +++ b/circuit-lib/circuit-lib.js/package.json @@ -6,6 +6,8 @@ "scripts": { "test": "ts-mocha --resolveJsonModule ./tsconfig.json -t 100000000 tests/**/*.ts --exit", "test-merkle": "ts-mocha --resolveJsonModule ./tsconfig.json -t 100000000 tests/merkle-tree.test.ts --exit", + "test-gnark": "pnpm gnark-prover && ts-mocha --resolveJsonModule ./tsconfig.json -t 100000000 tests/gnark.test.ts --exit", + "gnark-prover": "./scripts/prover.sh", "format": "prettier --write \"tests/**/*.{ts,js}\" \"src/**/*.{ts,js}\"", "lint": "pnpm prettier \"tests/**/*.{ts,js}\" \"src/**/*.{ts,js}\" --check", "build": "rimraf lib && pnpm tsc" @@ -25,6 +27,7 @@ "@types/chai-as-promised": "^7.1.6", "@types/mocha": "^10.0.3", "@types/node-fetch": "^2.6.2", + "axios": "^1.5.0", "chai": "^4.3.10", "chai-as-promised": "^7.1.1", "circom_tester": "^0.0.19", diff --git a/circuit-lib/circuit-lib.js/scripts/prover.sh b/circuit-lib/circuit-lib.js/scripts/prover.sh new file mode 100755 index 0000000000..21f88d2f3a --- /dev/null +++ b/circuit-lib/circuit-lib.js/scripts/prover.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +killall light-prover + +# Get the root directory of the Git repository +root_dir=$(git rev-parse --show-toplevel) + +# Change the directory to 'gnark-prover' within the Git root directory +# shellcheck disable=SC2164 +cd "$root_dir/gnark-prover" + +# If 'gnark-prover' directory does not exist, print error and exit +if [ $? -ne 0 ]; then + echo "Directory gnark-prover does not exist in the Git root directory. Run \`git submodule update --init\` to fetch the submodule." + exit 1 +fi + +go build +# Execute 'go run main.go start' +./light-prover start & \ No newline at end of file diff --git a/circuit-lib/circuit-lib.js/tests/gnark.test.ts b/circuit-lib/circuit-lib.js/tests/gnark.test.ts new file mode 100644 index 0000000000..0cb274d7a9 --- /dev/null +++ b/circuit-lib/circuit-lib.js/tests/gnark.test.ts @@ -0,0 +1,73 @@ +import { MerkleTree } from "../src"; +import { LightWasm, WasmFactory } from "@lightprotocol/account.rs"; +import axios from "axios"; +import { BN } from "@coral-xyz/anchor"; +import { assert } from "chai"; + +describe("Tests", () => { + let lightWasm: LightWasm; + const MAX_RETRIES = 20; + const DELAY_MS = 5000; + const SERVER_URL = "http://localhost:3001"; + const PROVE_URL = `${SERVER_URL}/prove`; + const HEALTH_CHECK_URL = `${SERVER_URL}/health`; + + async function pingServer(serverUrl: string) { + for (let attempt = 0; attempt < MAX_RETRIES; attempt++) { + try { + const response = await axios.get(serverUrl); + if (response.status === 200) { + console.log("Server is up!"); + break; + } + } catch (error) { + console.log( + `Attempt ${attempt + 1} failed. Retrying in ${ + DELAY_MS / 1000 + } seconds...`, + ); + } + await new Promise((res) => setTimeout(res, DELAY_MS)); // Wait before retrying + } + } + + before(async () => { + lightWasm = await WasmFactory.getInstance(); + }); + + it("merkle proofgen", async () => { + await pingServer(HEALTH_CHECK_URL); + + const hasher = await WasmFactory.getInstance(); + const merkleHeights = [26]; + const utxos = [1, 2, 3, 4, 8]; + for (let i = 0; i < merkleHeights.length; i++) { + for (let j = 0; j < utxos.length; j++) { + const leaf = hasher.poseidonHashString(["1"]); + const merkleTree = new MerkleTree(merkleHeights[i], hasher, [leaf]); + + const pathEements: string[] = merkleTree.path( + merkleTree.indexOf(leaf), + ).pathElements; + const hexPathElements = pathEements.map((value) => toHex(value)); + let inputs = { + root: new Array(utxos[j]).fill(toHex(merkleTree.root())), + inPathIndices: new Array(utxos[j]).fill(merkleTree.indexOf(leaf)), + inPathElements: new Array(utxos[j]).fill(hexPathElements), + leaf: new Array(utxos[j]).fill(toHex(leaf)), + }; + const inputsData = JSON.stringify(inputs); + console.time(`Proof generation for ${merkleHeights[i]} ${utxos[j]}`); + const response = await axios.post(PROVE_URL, inputsData); + console.timeEnd(`Proof generation for ${merkleHeights[i]} ${utxos[j]}`); + + assert.equal(response.status, 200); + assert.isNotEmpty(response.data.toString()); + } + } + }); + + function toHex(bnString: string) { + return "0x" + new BN(bnString).toString(16); + } +}); diff --git a/circuit-lib/circuitlib-rs/Cargo.toml b/circuit-lib/circuitlib-rs/Cargo.toml index a32209cd9d..fa8d49d2f0 100644 --- a/circuit-lib/circuitlib-rs/Cargo.toml +++ b/circuit-lib/circuitlib-rs/Cargo.toml @@ -33,3 +33,11 @@ log = "0.4" env_logger = "0.10.2" # 1.3.0 required by package `aes-gcm-siv v0.10.3` zeroize = "=1.3.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.60" +num-traits = "0.2.18" + +[dev-dependencies] +tokio = { version = "1.36.0", features = ["rt", "macros"] } +reqwest = { version = "0.11.24", features = ["json", "rustls-tls"] } +duct = "0.13.7" \ No newline at end of file diff --git a/circuit-lib/circuitlib-rs/scripts/prover.sh b/circuit-lib/circuitlib-rs/scripts/prover.sh new file mode 120000 index 0000000000..fb24787cf4 --- /dev/null +++ b/circuit-lib/circuitlib-rs/scripts/prover.sh @@ -0,0 +1 @@ +../../circuit-lib.js/scripts/prover.sh \ No newline at end of file diff --git a/circuit-lib/circuitlib-rs/src/helpers.rs b/circuit-lib/circuitlib-rs/src/helpers.rs index 7b085084de..1c4f85f35f 100644 --- a/circuit-lib/circuitlib-rs/src/helpers.rs +++ b/circuit-lib/circuitlib-rs/src/helpers.rs @@ -1,3 +1,6 @@ +use env_logger::Builder; +use log::LevelFilter; + pub fn change_endianness(bytes: &[u8]) -> Vec { let mut vec = Vec::new(); for b in bytes.chunks(32) { @@ -13,3 +16,9 @@ pub fn convert_endianness_128(bytes: &[u8]) -> Vec { .flat_map(|b| b.iter().copied().rev().collect::>()) .collect::>() } + +pub fn init_logger() { + let _ = Builder::new() + .filter_module("circuitlib_rs", LevelFilter::Info) + .try_init(); +} diff --git a/circuit-lib/circuitlib-rs/src/merkle_proof_inputs.rs b/circuit-lib/circuitlib-rs/src/merkle_proof_inputs.rs index 339341d2c3..0ed41cc437 100644 --- a/circuit-lib/circuitlib-rs/src/merkle_proof_inputs.rs +++ b/circuit-lib/circuitlib-rs/src/merkle_proof_inputs.rs @@ -64,6 +64,7 @@ pub fn public_inputs(merkle_proof_inputs: &[MerkleTreeProofInput]) -> Vec<[u8; 3 } pub struct ProofInputs<'a>(pub &'a [MerkleTreeProofInput]); + impl<'a> TryInto> for ProofInputs<'a> { type Error = std::io::Error; diff --git a/circuit-lib/circuitlib-rs/tests/gnark/constants.rs b/circuit-lib/circuitlib-rs/tests/gnark/constants.rs new file mode 100644 index 0000000000..cd6843844c --- /dev/null +++ b/circuit-lib/circuitlib-rs/tests/gnark/constants.rs @@ -0,0 +1,5 @@ +pub const SERVER_ADDRESS: &str = "http://localhost:3001"; +pub const HEALTH_CHECK: &str = "/health"; +pub const PROVE: &str = "/prove"; + +const CONTENT_TYPE: &str = "text/plain; charset=utf-8"; diff --git a/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs b/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs new file mode 100644 index 0000000000..26790f3fd5 --- /dev/null +++ b/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs @@ -0,0 +1,114 @@ +use std::{ + process::{Child, Command}, + thread, + time::Duration, +}; + +use circuitlib_rs::{init_merkle_tree::merkle_tree_inputs, merkle_proof_inputs::MerkleTreeInfo}; +use num_bigint::BigInt; +use num_traits::ToPrimitive; +use serde::Serialize; +use serde_json::json; + +use crate::constants::{HEALTH_CHECK, SERVER_ADDRESS}; + +#[allow(non_snake_case)] +#[derive(Serialize)] +pub struct JsonStruct { + root: Vec, + leaf: Vec, + inPathIndices: Vec, + inPathElements: Vec>, +} + +impl JsonStruct { + fn new(number_of_utxos: usize) -> Self { + let merkle_inputs = merkle_tree_inputs(MerkleTreeInfo::H26); + let roots = create_vec_of_string(number_of_utxos, &merkle_inputs.root); + let leafs = create_vec_of_string(number_of_utxos, &merkle_inputs.leaf); + let in_path_indices = create_vec_of_u32(number_of_utxos, &merkle_inputs.in_path_indices); + let in_path_elements = + create_vec_of_vec_of_string(number_of_utxos, &merkle_inputs.in_path_elements); + Self { + root: roots, + leaf: leafs, + inPathIndices: in_path_indices, + inPathElements: in_path_elements, + } + } +} +pub fn prepare_inputs(number_of_utxos: usize) -> String { + let json_struct = JsonStruct::new(number_of_utxos); + create_json_from_struct(&json_struct) +} + +pub fn spawn_gnark_server() -> Child { + let server_process = Command::new("sh") + .arg("-c") + .arg("scripts/prover.sh") + .spawn() + .expect("Failed to start server process"); + + // Wait for the server to launch before proceeding. + thread::sleep(Duration::from_secs(5)); + + server_process +} + +pub fn kill_gnark_server(gnark: &mut Child) { + println!("kill gnark!"); + Command::new("sh") + .arg("-c") + .arg("killall light-prover") + .spawn() + .unwrap(); + gnark.kill().unwrap(); + println!("gnark killed!"); +} + +pub async fn health_check() { + const MAX_RETRIES: usize = 20; + const TIMEOUT: usize = 5; + + let client = reqwest::Client::new(); + + for _ in 0..MAX_RETRIES { + match client + .get(&format!("{}{}", SERVER_ADDRESS, HEALTH_CHECK)) + .send() + .await + { + Ok(_) => break, + Err(_) => { + tokio::time::sleep(Duration::from_secs(TIMEOUT as u64)).await; + } + } + } +} + +pub fn create_vec_of_string(number_of_utxos: usize, element: &BigInt) -> Vec { + vec![format!("0x{}", element.to_str_radix(16)); number_of_utxos] +} + +pub fn create_vec_of_u32(number_of_utxos: usize, element: &BigInt) -> Vec { + vec![element.to_u32().unwrap(); number_of_utxos] +} + +pub fn create_vec_of_vec_of_string( + number_of_utxos: usize, + elements: &[BigInt], +) -> Vec> { + let vec: Vec = elements + .iter() + .map(|e| format!("0x{}", e.to_str_radix(16))) + .collect(); + vec![vec; number_of_utxos] +} + +pub fn create_json_from_struct(json_struct: &JsonStruct) -> String { + let json = json!(json_struct); + match serde_json::to_string_pretty(&json) { + Ok(json) => json, + Err(_) => panic!("Merkle tree data invalid"), + } +} diff --git a/circuit-lib/circuitlib-rs/tests/gnark/main.rs b/circuit-lib/circuitlib-rs/tests/gnark/main.rs new file mode 100644 index 0000000000..29e6dfd4fa --- /dev/null +++ b/circuit-lib/circuitlib-rs/tests/gnark/main.rs @@ -0,0 +1,11 @@ +mod constants; +mod helpers; +mod prove; + +use std::{ + process::{Child, Command}, + thread, + time::Duration, +}; + +use circuitlib_rs::helpers::init_logger; diff --git a/circuit-lib/circuitlib-rs/tests/gnark/prove.rs b/circuit-lib/circuitlib-rs/tests/gnark/prove.rs new file mode 100644 index 0000000000..8f88dcfa34 --- /dev/null +++ b/circuit-lib/circuitlib-rs/tests/gnark/prove.rs @@ -0,0 +1,26 @@ +use circuitlib_rs::helpers::init_logger; +use reqwest::header::CONTENT_TYPE; + +use crate::{ + constants::{PROVE, SERVER_ADDRESS}, + helpers::{health_check, kill_gnark_server, prepare_inputs, spawn_gnark_server}, +}; + +#[tokio::test] +async fn prove_inclusion() { + let number_of_utxos = 1; + init_logger(); + let mut gnark = spawn_gnark_server(); + health_check().await; + let inputs = prepare_inputs(number_of_utxos); + let client = reqwest::Client::new(); + let response_result = client + .post(&format!("{}{}", SERVER_ADDRESS, PROVE)) + .header("Content-Type", CONTENT_TYPE) + .body(inputs) + .send() + .await + .expect("Failed to execute request."); + assert!(response_result.status().is_success()); + kill_gnark_server(&mut gnark); +} diff --git a/circuit-lib/circuitlib-rs/tests/merkle/main.rs b/circuit-lib/circuitlib-rs/tests/merkle/main.rs index e662306f7f..760862bfc8 100644 --- a/circuit-lib/circuitlib-rs/tests/merkle/main.rs +++ b/circuit-lib/circuitlib-rs/tests/merkle/main.rs @@ -1,11 +1,10 @@ use circuitlib_rs::{ groth16_solana_verifier::{groth16_solana_verify, merkle_inclusion_proof}, + helpers::init_logger, init_merkle_tree::merkle_tree_inputs, merkle_proof_inputs::{MerkleTreeInfo, MerkleTreeProofInput}, verifying_keys::vk, }; -use env_logger::Builder; -use log::LevelFilter; macro_rules! test_and_prove { ($fn_name:ident, $mt_height:expr, $nr_inputs:expr) => { @@ -33,9 +32,3 @@ test_and_prove!(test_and_prove_26_2, MerkleTreeInfo::H26, 2); test_and_prove!(test_and_prove_26_3, MerkleTreeInfo::H26, 3); test_and_prove!(test_and_prove_26_4, MerkleTreeInfo::H26, 4); test_and_prove!(test_and_prove_26_8, MerkleTreeInfo::H26, 8); - -fn init_logger() { - let _ = Builder::new() - .filter_module("circuitlib_rs", LevelFilter::Info) - .try_init(); -} diff --git a/gnark-prover b/gnark-prover new file mode 160000 index 0000000000..deaef991ae --- /dev/null +++ b/gnark-prover @@ -0,0 +1 @@ +Subproject commit deaef991aebe058d3a82b54cd38d0de8dac2dcb0 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e31f82138..27d18d293c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -199,6 +199,9 @@ importers: '@types/node-fetch': specifier: ^2.6.2 version: 2.6.6 + axios: + specifier: ^1.5.0 + version: 1.5.0 chai: specifier: ^4.3.10 version: 4.3.10 From 4c850bcdba7c3352f79b0fea0776361c2889933d Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Tue, 27 Feb 2024 00:50:32 +0000 Subject: [PATCH 2/4] Update README with Git LFS and submodules instructions --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74b41cf087..b7e241afde 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,6 @@ Developers can use Light to build applications such as - on-chain games with encrypted game state - zk-identity - - ## ZK Anchor ZK Anchor is what we call the collection of developer tools for writing Private Solana Programs (PSPs). @@ -34,6 +32,20 @@ To get started, a good PSP reference implementation is available [here](https:// Otherwise, to work with this Monorepo, read below: +## Git Large File Storage (LFS) +This project uses Git LFS to manage and version large files. Before you can clone the project and fetch all the necessary data, you need to install and configure Git LFS on your machine. + +If you already have Git installed, run the following command: +``` +git lfs install +``` + +To verify that Git LFS is properly configured, use: +``` +git lfs env +``` + +The output should show that Git LFS is installed and configured correctly. After setting up Git LFS, you can proceed to clone the project. ## Development environment @@ -96,6 +108,10 @@ If you still want to setup dependencies manually, these are the requirements: * [NodeJS](https://nodejs.org/) [(16.16 LTS)](https://nodejs.org/en/blog/release/v16.16.0) * [Anchor](https://www.anchor-lang.com/) [(0.26.0)](https://crates.io/crates/anchor-cli/0.26.0) +## Initializing Submodules +Before building, make sure to initialize the submodules: +```git submodule update --init``` + ## Building To build the project, use the following commands: From 61fc6cba00e14ce2a849e434604fe54d9743c720 Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Tue, 27 Feb 2024 00:50:55 +0000 Subject: [PATCH 3/4] Refactor gnark testing and remove unused constants Removed unused constant CONTENT_TYPE and moved it inline in the test module. Refactored the prove_inclusion test to iterate over several UTXO counts for better coverage. Unnecessary logging and imports were also removed for cleaner code. --- .../circuitlib-rs/tests/gnark/constants.rs | 2 -- .../circuitlib-rs/tests/gnark/helpers.rs | 2 -- circuit-lib/circuitlib-rs/tests/gnark/main.rs | 10 +------- .../circuitlib-rs/tests/gnark/prove.rs | 23 ++++++++++--------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/circuit-lib/circuitlib-rs/tests/gnark/constants.rs b/circuit-lib/circuitlib-rs/tests/gnark/constants.rs index cd6843844c..c74b883e58 100644 --- a/circuit-lib/circuitlib-rs/tests/gnark/constants.rs +++ b/circuit-lib/circuitlib-rs/tests/gnark/constants.rs @@ -1,5 +1,3 @@ pub const SERVER_ADDRESS: &str = "http://localhost:3001"; pub const HEALTH_CHECK: &str = "/health"; pub const PROVE: &str = "/prove"; - -const CONTENT_TYPE: &str = "text/plain; charset=utf-8"; diff --git a/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs b/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs index 26790f3fd5..95d7ed4081 100644 --- a/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs +++ b/circuit-lib/circuitlib-rs/tests/gnark/helpers.rs @@ -56,14 +56,12 @@ pub fn spawn_gnark_server() -> Child { } pub fn kill_gnark_server(gnark: &mut Child) { - println!("kill gnark!"); Command::new("sh") .arg("-c") .arg("killall light-prover") .spawn() .unwrap(); gnark.kill().unwrap(); - println!("gnark killed!"); } pub async fn health_check() { diff --git a/circuit-lib/circuitlib-rs/tests/gnark/main.rs b/circuit-lib/circuitlib-rs/tests/gnark/main.rs index 29e6dfd4fa..71883de5e6 100644 --- a/circuit-lib/circuitlib-rs/tests/gnark/main.rs +++ b/circuit-lib/circuitlib-rs/tests/gnark/main.rs @@ -1,11 +1,3 @@ mod constants; mod helpers; -mod prove; - -use std::{ - process::{Child, Command}, - thread, - time::Duration, -}; - -use circuitlib_rs::helpers::init_logger; +mod prove; \ No newline at end of file diff --git a/circuit-lib/circuitlib-rs/tests/gnark/prove.rs b/circuit-lib/circuitlib-rs/tests/gnark/prove.rs index 8f88dcfa34..84cdaa24b5 100644 --- a/circuit-lib/circuitlib-rs/tests/gnark/prove.rs +++ b/circuit-lib/circuitlib-rs/tests/gnark/prove.rs @@ -1,5 +1,4 @@ use circuitlib_rs::helpers::init_logger; -use reqwest::header::CONTENT_TYPE; use crate::{ constants::{PROVE, SERVER_ADDRESS}, @@ -8,19 +7,21 @@ use crate::{ #[tokio::test] async fn prove_inclusion() { - let number_of_utxos = 1; init_logger(); let mut gnark = spawn_gnark_server(); health_check().await; - let inputs = prepare_inputs(number_of_utxos); let client = reqwest::Client::new(); - let response_result = client - .post(&format!("{}{}", SERVER_ADDRESS, PROVE)) - .header("Content-Type", CONTENT_TYPE) - .body(inputs) - .send() - .await - .expect("Failed to execute request."); - assert!(response_result.status().is_success()); + for number_of_utxos in &[1, 2, 3, 4, 8] { + let inputs = prepare_inputs(*number_of_utxos as usize); + let response_result = client + .post(&format!("{}{}", SERVER_ADDRESS, PROVE)) + .header("Content-Type", "text/plain; charset=utf-8") + .body(inputs) + .send() + .await + .expect("Failed to execute request."); + assert!(response_result.status().is_success()); + } + kill_gnark_server(&mut gnark); } From 618b6b8d8c1ec56249e8558c42ccd8d758aa2b44 Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Tue, 27 Feb 2024 11:57:58 +0000 Subject: [PATCH 4/4] Add newline at end of 'prove' module --- circuit-lib/circuitlib-rs/tests/gnark/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuit-lib/circuitlib-rs/tests/gnark/main.rs b/circuit-lib/circuitlib-rs/tests/gnark/main.rs index 71883de5e6..e50d4a7196 100644 --- a/circuit-lib/circuitlib-rs/tests/gnark/main.rs +++ b/circuit-lib/circuitlib-rs/tests/gnark/main.rs @@ -1,3 +1,3 @@ mod constants; mod helpers; -mod prove; \ No newline at end of file +mod prove;