MCPcopy Index your code
hub / github.com/eryxcoop/acvm-backend-plonky2

github.com/eryxcoop/acvm-backend-plonky2 @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
527 symbols 1,270 edges 48 files 36 documented · 7%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 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. * https://github.com/brweisz/noir * https://github.com/brweisz/plonky2

Those are forks of the official Noir and Plonky2 repositories respectively, with a couple modifications. The resulting project tree must therefore look like:

plonky-2-backend-for-acir
|_ noir
|_ noir_example
|_ plonky2
|_ plonky2-backend
|_ Makefile

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 (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, but using the custom plonky2 backend instead of barretenberg, and it's what the command will execute.

1) From the noir_example directory run: * ../noir/target/release/nargo execute witness. This will execute the noir program through the nargo acvm, generating: * The ACIR circuit in target/noir_example.json * The witness in target/witness.gz 2) From the plonky2-backend directory run: * ./target/release/plonky2-backend prove -b ../noir_example/target/noir_example.json -w ../noir_example/target/witness.gz -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.

Contact Us

Feel free to join our telegram group for suggestions, report bugs or any question you might have! https://t.me/+HeUDkQPX_w0yMDQx

Things already implemented in this version

The Plonky2 backend for ACIR is still in a development phase. As for now, these are the implemented functionalities: * AssertZero Opcode ✓ * MemoryInit Opcode ✓ * MemoryOp Opcode ✓ * BrilligCall Opcode ✓ * BlackBoxFunction ✓ * RANGE (up to 33 bits) ✓ * XOR ✓ * AND ✓ * SHA256 ✓ * EcdsaSecp256k1 ✓

Things not implemented yet are mostly BlackBoxFunctions.

Credits

We used some code from repos for the implementation of ECDSA verification and made some modifications to them: * https://github.com/0xPolygonZero/plonky2-ecdsa * https://github.com/0xPolygonZero/plonky2-u32

If you want to try this backend with a medium size Noir project here's an example of a context free grammar checker by Pablo Dallegri, the first Plonky2 backend user.

Extension points exported contracts — how you extend this code

CircuitBuilderBiguint (Interface)
(no doc) [1 implementers]
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs
WitnessBigUint (Interface)
(no doc) [1 implementers]
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs
GeneratedValuesBigUint (Interface)
(no doc) [1 implementers]
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs
WitnessU32 (Interface)
(no doc) [1 implementers]
plonky2-backend/src/plonky2_ecdsa/biguint/witness.rs
GeneratedValuesU32 (Interface)
(no doc) [1 implementers]
plonky2-backend/src/plonky2_ecdsa/biguint/witness.rs

Core symbols most depended-on inside this repo

constant_nonnative
called by 30
plonky2-backend/src/plonky2_ecdsa/biguint/gadgets/nonnative.rs
chunk_bits
called by 24
plonky2-backend/src/plonky2_ecdsa/biguint/gates/comparison.rs
constant_biguint
called by 19
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs
set_biguint_target
called by 19
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs
num_limbs
called by 18
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs
mul_nonnative
called by 18
plonky2-backend/src/plonky2_ecdsa/biguint/gadgets/nonnative.rs
add_nonnative
called by 16
plonky2-backend/src/plonky2_ecdsa/biguint/gadgets/nonnative.rs
add_virtual_biguint_target
called by 13
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs

Shape

Method 305
Function 174
Class 33
Interface 15

Languages

Rust100%
Python1%

Modules by API surface

plonky2-backend/src/plonky2_ecdsa/biguint/gadgets/nonnative.rs44 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/gates/comparison.rs34 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/gates/arithmetic_u32.rs34 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/biguint.rs33 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/gates/subtraction_u32.rs31 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/gates/add_many_u32.rs31 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/gadgets/arithmetic_u32.rs29 symbols
plonky2-backend/src/plonky2_ecdsa/biguint/gates/range_check_u32.rs26 symbols
plonky2-backend/src/circuit_translation/tests/test_sha256_internal.rs26 symbols
plonky2-backend/src/plonky2_ecdsa/curve/gadgets/curve.rs19 symbols
plonky2-backend/src/argument_parsing.rs18 symbols
plonky2-backend/src/circuit_translation/tests/factories/circuit_factory.rs17 symbols

For agents

$ claude mcp add acvm-backend-plonky2 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact