From a7f73193e1a8d24f65818ffc7261de82613e0ee9 Mon Sep 17 00:00:00 2001 From: bruno Date: Wed, 18 Sep 2024 17:33:16 -0300 Subject: [PATCH] changes in the makefile, readme, and adds Dockerfile --- Dockerfile | 26 ++++++++++++++++++++++++++ Makefile | 14 +++++++------- README.md | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0e6cf10 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +from python:3.13.0rc2-slim-bookworm as initial_build +run apt upgrade -y +run apt update -y +run apt install -y git build-essential make curl + +run curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y +env PATH="/root/.cargo/bin:${PATH}" + +arg CACHEBUST=1 +run git clone https://github.com/eryxcoop/acvm-backend-plonky2.git +workdir acvm-backend-plonky2 +run make build_external +run make build_backend + +from python:3.13.0rc2-slim-bookworm as final_build +copy --from=initial_build /acvm-backend-plonky2/noir/target/release/nargo /acvm-backend-plonky2/noir/target/release/nargo +copy --from=initial_build /acvm-backend-plonky2/plonky2-backend /acvm-backend-plonky2/plonky2-backend +copy --from=initial_build /acvm-backend-plonky2/Makefile /acvm-backend-plonky2/Makefile +copy --from=initial_build /acvm-backend-plonky2/prepare_compiled_noir_test_programs.py /acvm-backend-plonky2/prepare_compiled_noir_test_programs.py + +run apt upgrade -y +run apt update -y +run apt install -y build-essential make +workdir acvm-backend-plonky2 + +run make precompile_tests diff --git a/Makefile b/Makefile index 3d0b110..facc06c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: clone_custom_noir build_noir clone_custom_plonky2 build_plonky2 build_backend precompile_tests +all: build_external build_backend precompile_tests # Cloning and building external resources @@ -35,6 +35,12 @@ precompile_tests: # Execution +verification_happy_path: + $(MAKE) nargo_execute + $(MAKE) prove + $(MAKE) write_vk + $(MAKE) verify + nargo_execute: cd noir_example && ../noir/target/release/nargo execute witness --print-acir @@ -47,10 +53,4 @@ write_vk: verify: cd plonky2-backend && ./target/release/plonky2-backend verify -k ../noir_example/target/vk -p ../noir_example/proof -verification_happy_path: - $(MAKE) nargo_execute - $(MAKE) prove - $(MAKE) write_vk - $(MAKE) verify - .PHONY: all clone_custom_noir build_noir clone_custom_plonky2 build_plonky2 build_backend \ No newline at end of file diff --git a/README.md b/README.md index 4435192..9d49590 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,26 @@ # acvm-backend-plonky2 This is an open source backend for the ACIR standard as implemented in the Noir programming languaje, written in Rust. Check out [the docs](https://eryxcoop.github.io/acvm-backend-plonky2/foreword.html) for more detail on what this repo does. +## How to generate Plonky2 proofs for your Noir circuit with docker +1. You need to install docker, if you haven't already +2. From a terminal, run ```docker pull bweisz/acvm-backend-plonky2:0.3``` to pull the docker image from dockerhub + +Fast version (execute, prove, write_vk and verify all at once) +3. Run ```docker run -v /full/path/to/your/noir/project:/acvm-backend-plonky2/noir_example bweisz/acvm-backend-plonky2 make verification_happy_path```. This will create a container from the image 'bweisz/acvm-backend-plonky2', copy the contents of your noir project into the 'noir_example' folder inside the container and run a complete workflow of executing the circuit, generating the proof, writing the vk and verifying the proof. + + +Alternatively, if you want to run the commands separately and know something about docker (or not), follow the following steps. +3. Run ```docker run -d --name noir_with_plonky2 -v /full/path/to/your/noir/project:/acvm-backend-plonky2/noir_example bweisz/acvm-backend-plonky2 tail -f /dev/null```. This will create a container named 'noir_with_plonky2' +4. Run ```docker exec -it noir_with_plonky2 bash```. This will allow you to execute commands in the container. +5. From the container terminal, run separately: + 1. ```make nargo_execute``` + 2. ```make prove``` + 3. ```make write_vk``` + 4. ```make verify ``` + + +## How to set up the project locally (without docker) + For the setup, run ```make``` on the root directory. This will do the following: For now, until the corresponding PRs are made in the Plonky2 and the Noir repositories, the command will clone these repositories inside the project root. @@ -21,9 +41,16 @@ plonky-2-backend-for-acir Then it'll build noir and plonky2. The latter with the nightly toolchain. Lastly, it'll build the custom plonky2 backend. +## Running some predefined examples +If you want to try out some Noir examples, execute the python script ```run_examples.py``` with the name of the example as the only parameter from the ```plonky2-backend``` directory: +* ```basic_if``` +* ```fibonacci``` +* ```basic_div``` + + ## Manual testing -For some manual testing, the workflow is as follows: in the ```noir_example``` folder there's a Noir project. In the ```noir_example/src/main.nr``` file you can write the main function of any noir program you want to prove. +For some manual testing (local), the workflow is as follows: in the ```noir_example``` folder there's a Noir project. In the ```noir_example/src/main.nr``` file you can write the main function of any noir program you want to prove. Run ```make run_noir_example``` from the root directory. The following explanation is similar to the official [Noir docs](https://noir-lang.org/docs/dev/getting_started/hello_noir/#execute-our-noir-program), but using the custom plonky2 backend instead of barretenberg, and it's what the command will execute. 1) From the ```noir_example``` directory run: @@ -33,14 +60,7 @@ Run ```make run_noir_example``` from the root directory. The following explanati 2) From the ```plonky2-backend``` directory run: * ```./target/release/plonky2-backend prove -c ../noir_example/target/noir_example.json -w ../noir_example/target/witness -o ../noir_example/proof```. This will create a Plonky2 proof in ```../noir_example/proof```. * ```./target/release/plonky2-backend write_vk -b ../noir_example/target/noir_example.json -o ../noir_example/target/vk```. This will create the verification key in ```../noir_example/target/vk``` -* ```./target/release/plonky2-backend verify -k ../noir_example/target/vk -p ../noir_example/proof```. This will verify the Plonky2 proof. An empty output is sign of verification success. - - -## Running some predefined examples -If you want to try out some Noir examples, execute the python script ```run_examples.py``` with the name of the example as the only parameter from the ```plonky2-backend``` directory: -* ```basic_if``` -* ```fibonacci``` -* ```basic_div``` +* ```./target/release/plonky2-backend verify -k ../noir_example/target/vk -p ../noir_example/proof```. This will verify the Plonky2 proof. An empty output is sign of verification success. ## Contact Us Feel free to join our telegram group for suggestions, report bugs or any question you might have!