Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Snark payments for Effect

Dependencies

Install the following

Also make sure to run pnpm install in the workspace root.

Makefile

All steps of the circuit and key generation are detailed in the Makefile. The Makefile expects to find node, pnpm, and circom on the path, but these can be overwritten with environment variables.

Ceremony Phase 1

We are currently using a trusted setup usings powers of tau of size 2^19. Generating the ptau file can take hours, so before making the circuits and proving keys it is recommended to download a pre-generated pot19_final.ptau file (which is around 600MB).

  1. Download (Google Drive, 600MB)
  2. Move the file to zkp/setup/pot19_final.ptau

If you want to run the Phase 1 ceremony yourself, you can invoke it with:

make zkp/setup/pot19_final.ptau

Or run a smaller ceremony with:

TAU_SIZE=14 make zkp/setup/pot14_final.ptau

The goal of larger tau ceremony is to have larger payment batch sizes.

Building the circuits

The main circuit is called PaymentBatch and is located in zkp/circuits/PaymentBatch.circom.

Make sure to adjust the (60) on the last line to reflect the batch size you want. For a 2^14 tau size that is max 1.

Compile the circuit with:

make PaymentBatch.r1cs

This will generate:

  • zkp/circtuis/PaymentBatch.r1cs: needed to generate proving and verifying keys in Phase 2 of the ceremony
  • zkp/circtuis/PaymentBatch_js/PaymentBatch.wasm: needed to generate proofs in the client using snarkjs

Ceremony Phase 2

The last part of the ceremony is done with:

make zkp/circuits/PaymentBatch_0001.zkey

This zkey file is the proving key required by the client to generate proofs in snarkjs.

Verification Key

We can now export the verification key. As the verification step will be executed in a Solana program, the key must be exported to a rust file, which is done by the verification_to_rust.cjs script. This file must be placed in the ../solana/programs/effect-payment/program/src folder. These 3 steps are executed by the Makefile:

make solana/programs/effect-payment/program/src/verifying_key.rs

Alternative: quick start

The quickest way to get started, is do a small ceremony yourself and let the Makefile do all the work. First reduce the batch size in the PaymentBatch.circom from 60 to 1, then run:

TAU_SIZE=14 make solana/programs/effect-payment/program/src/verifying_key.rs

This should take a few minutes and generate all the files for you.

Note, 14 is the smallest tau size we support, and 1 is the largest batch size.

Testing the Solana contract

Test suite is in ../solana/tests/suites/payment.spec.ts:

cd ../solana
anchor test

Make sure the batchSize constant reflects the exact same batch size as is used in the circom file.