DEV Community

Cover image for Introducing Niftyzk
Peter Horvath
Peter Horvath

Posted on

Introducing Niftyzk

Niftyzk is a circom development tool and framework that targets CosmWasm ecosystem supporting groth-16 proofs with bn128 curve.

https://github.com/NiftyZk/niftyzk

Project scaffolding
Initialize a new project niftyzk init and select from the available templates, the generated code can be configured based on the verification schemes selected. There is support for Poseidon, Pedersen, MiMC and MiMCSponge hashing functions and additional circuit inputs. Niftyzk generates code instead of cloning a repository, so you get the benefit of configuration.

Javascript library
A library will be generated for you with all functions required to interact with the circuits and merkle tree. The javascript is isomorphic and typed using JSDoc so you can run it in the browser and server without modification and use it with Typescript.

Hot reload
Develop your circom circuits using hot reload. niftyzk devIterative development allows you to debug and update your circuits without recompiling them each time which is time consuming. The circuits are rebuilt and the outputs are asserted. Niftyzk expects the circuit inputs and output asserts defined in an input.js file, which allows you to keep your business logic to generate inputs neat and fully tested during development.

Powers of Tau
The powers of tau ceremony is essential for zero knowledge proof circuits for security. niftyzk ptaufilesThe phase 1 ceremony is reusable hence we can use the Polygon Hermez ceremony files. The files are available to download from the CLI with a simple command

Compilation
niftyzk compile uses circom compiler for compilation and so depends on Rust and requires circom to be installed. It wraps and abstracts away complex commands and makes compiling straight forward

Verification Keys
The compiled circuits require the exporting of verification keys, these keys are used for testing in deployment. niftyzk vkey

Phase-2 ceremony
The built in ceremony server allows you to host a phase-2 ceremony.Invoking the command niftyzk ceremony will start up a server that hosts a contribution page.The contribution is anonymous and the contributors are queued using websockets. The project at this stage can be deployed on a VPS using Git and the ceremony can be hosted there.The ceremony server only supports smaller PTAU files due to the netwoking, each client needs to download it to make a contribution.Only a single contributor to the phase-2 ceremony needs to be honest for the process to work.

Finalization
After the ceremony we can finalize the circuit, this means we can’t update our circuits anymore and it will be ready for deployment. niftyzk finalize expects a --beacon argument which is our random beacon used for finalization. The process wraps snarkjs and simplifies the commands used there. If you want to learn more about it, you can read the snarkjs documentation. After finalization, you will need to export a new vkey

Generate CosmWasm contract
And finally we can generate a CosmWasm verifier contract for the circuit. niftyzk gencontact You can generate it before finalization for testing your smart contracts, it requires passing unit tests and the verification key to generate the contract.The gencontract command expects an argument for the Rust library used, which can be Arkworks or Bellman. The Bellman requires an adapter which will be generated in javascript for you.Check the readme for verifying cosmwasm contracts.

Full test coverage
All generated code contains full test coverage, including the CosmWasm contracts. Niftyzk supports test based development and runtime assertions.

Support
You can support this project by using it. Open a issue if you encounter any errors. This is a public good and available for quadratic funding in the Atom Economic Zone, you can contribute Atom on dorahacks
https://dorahacks.io/buidl/14323

Top comments (0)