zk-NLP repository provides an E2E pipeline, supported by picozk, to test differential privacy under Zero-Knowledge Proof.
This software is designed to verify that a given string (or strings) occupies a specific position within a corpus. For instance, consider a legal dispute where a party seeks to demonstrate that a particular clause in a contract begins with a specific statement. The position is determined using a pivot string and a target string, based on which the software constructs a deterministic finite automaton (DFA) from a corpus (such as a legal document). The algorithm traverses the DFA and confirms the presence of the target strings at the designated location by checking if the DFA traversal concludes in a terminal state.
The repository offers twelve categories of zero-knowledge (ZK) statements, categorized into two groups: single-word and multi-word methods.
Run this line of code in the command line:
docker run --platform linux/amd64 -it hicsail/zk-nlp:main
Run the following in the command line to get the container up and running:
git clone https://github.com/hicsail/zk-NLP.git # Clone the repository
cd zk-NLP # Move into the root directory of the project
docker-compose up -d --build # Inside the root directory, run the build image:
Since you have a running container, you can subsequently run the following command in your terminal to start Docker Shell:
docker exec -it <containerID> bash
You can get a container-ID from the docker desktop app by clicking the small button highlighted in the red circle
If you see something like the following in your command line, you are successfully inside the docker shell
We are using Fire Alarm, one of wiztoolkit packages. After entering the container, clone wiztoolkit repo and run the following commands to install wiztoolkit:
(* You might need to set up ssh key - Follow the instruction )
git clone [email protected]:sieve-all/wiztoolkit.git
cd wiztoolkit
make
make install
All of the main scripts to run are stored in the example/substring_search/IR0 directory .
You can run your Python script in the docker shell, which outputs zk statements, using 'miniwizpl', and check its format by Fire Alarm you have just installed.
You may run any of them in the docker shell either way described hereunder:
For example, copy and paste the command into your terminal, which will run between.py in debug mode.
/bin/bash ./shell/run_IR0.sh -f between -o debug
The grammar of the shell script includes the following four tags:
/bin/bash ./run_emp.sh -f <Name of your Python script to run>
-o <Optional: test or debug>
-s <Optional: Scale of Testing Complexity>
-t <Optional: Target Directory>
Here are the meanings of the four tags: -f (Required) : Name of your Python script to run (such as "between" and "after")
-o (Optional) : Choose a mode to run your python script:
- "test" produces a synthetic test case, including an input text and target substrings.
- "debug" uses your own text corpus input in dfa_test_input.txt
- If the second argument is empty, it will assume a "debug" operation
-s (Optional) : Choose a scale of test complexity (e.g., 0 and 1, default = 0)
This value will be used as a parameter by the generate_text function
-t (Optional) : Choose a directory to save interim outputs (.rel, .ins, .wit files)
You can also run each script without the shell script without a Fire Alarm check. Here is an example:
python3 examples/substring_search/IR0/after_all_multi.py 'irs' 230584300921369395 'p2' 3 test
This will run the after_all_multi algorithm in the field size of '230584300921369395' in test mode and the input scale of 3 ('p2' is not as important a parameter as the rest of the arguments).
👨💻 Run Locally
This option doesn't require Docker, while it focuses on running the Python scripts, skipping setting Fire Alarm.
Run this in the command line:
git clone [email protected]:hicsail/zk-NLP.git
Move into the root directory of the project and install dependencies
cd zk-NLP
python3 -m venv venv # or pypy3 -m venv myenv
source venv/bin/activate # or source myenv/bin/activate
pip3 install --upgrade pip # or pypy3 -m pip install --upgrade pip
pip3 install -r requirements.txt # or pypy3 -m pip install -r requirements.txt
pip3 install . # or pypy3 -m pip install .
pip3 install git+https://github.com/gxavier38/pysnark.git@8a2a571bef430783adf8fe28cb8bb0b0bf8a7c94
In case you want to experiment manually, run inside the docker shell:
python[3] examples/simple_demos/simple.py
Run the following command:
g++ miniwizpl_test.cpp -o miniwizpl_test\
-pthread -Wall -funroll-loops -Wno-ignored-attributes -Wno-unused-result -march=native -maes -mrdseed -std=c++11 -O3 \
-I/usr/src/app/miniwizpl/boilerplate\
-I/usr/lib/openssl/include\
-L/usr/lib/openssl/lib -lssl -lcrypto \
-L/usr/src/app/emp-zk/emp-zk -lemp-zk\
-L/usr/src/app/emp-tool/emp-tool -lemp-tool\
-L/usr/local/lib -Wl,-R/usr/local/lib
Once you have compiled our EMP code, we can run the miniwizpl_test
executable in your terminal in the following way, with the prover running:
./miniwizpl_test 1 12349
and in a separate terminal, the verifier running:
./miniwizpl_test 2 12349
The first command line argument indicates whether or not to run the executable as the prover or verifier, respectively denoted by a 1
or 2
.
The second command line argument represents the communication port. For a successful proof, the above command should run and return a non-zero exit code. For a failed proof, the above should report a failed assertion.