The wave of private and scalable smart contracts in Web3 is underway, and Mina Protocol, with its constant-sized succinct blockchain and easy-to-write zero knowledge apps, zkApps, is leading in this transformation.
Mina is finally putting ZK in the hands of the Web3 developer with zkApps, short for zero knowledge decentralized applications.
Although building zkApps is relatively simple, there are three fundamental things you should understand before starting to build.
1. TypeScript Syntax
To ensure an intuitive developer experience, zkApps are written in TypeScript. TypeScript is a superset of JavaScript that adds type safety, meaning type correctness is checked at compile time. Another benefit of writing smart contracts in TypeScript is having familiar developer experience and TypeScript toolings, such as npm, Prettier, Jest, ESLint, VScode with IntelliSense code auto-completion, and more.
The main difference between writing zkApps and other zero knowledge smart contracts is that others use custom programming languages, requiring builders to learn something entirely new.
With most developers already knowing TypeScript, zkApps will be the easiest way to start building. If you aren’t familiar with TypeScript, however, there are many existing resources to learn how to write in TypeScript here or here. You can find the official TypeScript documentation here.
As long as you know TypeScript syntax, you will be ready to get started quickly. Installing TypeScript is unnecessary because the Mina zkApp CLI contains TypeScript locally.
2. How zkApps Work
zkApps use zero knowledge proofs, specifically zk-SNARKs. They use off-chain computations and an off-chain state model, allowing for private executions and a flexible state model so users can choose to set their states private or public. As opposed to other blockchains that run computations on-chain with variable gas fees for running dApp executions, zkApps offer limitless off-chain computations and on-chain verification for a low flat fee. o1js (formerly SnarkyJS), the TypeScript library for writing zkApps, uses a Merkle tree to store data off-chain and zkOracles, which are a feature on the roadmap, will also further help with off-chain storage.
In order to understand how zkApps work, there are a couple of concepts that you have to generally understand about zero knowledge smart contracts. There’s a prover function and a verifier function.
zkApps consists of two parts: a UI and a smart contract. The prover and verifier functions are part of the smart contract. As privacy becomes more important to end-users, zkApps protect sensitive data so they don’t need to share publicly on a blockchain, but instead via the zkApp’s UI. Since the prover function runs locally, this private data acts as a private input to the prover function. Then the prover function generates a zero knowledge proof of its execution, without revealing any sensitive user data. This ZK proof is sent to the Mina blockchain, where the corresponding verifier function validates the proof.
Mina’s off-chain execution allows users to keep their data in user custody and only share proof of computation with the world. Learn more about how zkApps work here.
3. How Circuits and o1js (formerly SnarkyJS) Work
Lastly, you need to learn the difference between developing smart contracts and ZK smart contracts. In ZK smart contracts, a zero knowledge proof is generated over computations inside a function called a circuit.
To understand the zk-SNARK circuits, think of the boolean circuits analogy. In boolean circuits, a gate represents one of the Boolean operations (AND, OR, XOR, NOR). Inputs are variables on which the boolean operations are applied, and outputs are results of the boolean operations on these variables.
In an arithmetic circuit, the gate represents arithmetic operations (PLUS, MINUS, MULTIPLICATION, DIVISION), where inputs are variables, and outputs are a result of arithmetic operation on the inputs.
o1js (formerly SnarkyJS) is a library for writing zkApps for Mina Protocol, and it hides many zk-SNARK complexities from developers, providing a straightforward way of building on Mina. The experience of writing a zkApp is similar to writing regular TypeScript programs. SnarkysJS circuits work similarly to boolean and arithmetic circuits with their own assertions for inputs so you can set parameters to constrain state updates. The only difference is that o1js (formerly SnarkyJS) uses built-in data types and methods, instead of their JavaScript counterparts. Learn more in the o1js (formerly SnarkyJS) docs.
Next Steps
Once you’re familiar with these things, you will be equipped to start writing zkApps on Mina. Here are a few tips on how you can get started:
- Install the zkApp CLI here.
- Learn to code an example zkApp using this tutorial.
- Build a zkApp with zkIgnite, Cohort 2 to get hands-on support and funding.
There are many more resources on how to write, test, and deploy a zkApps here, but these steps should get you started.
If you have questions, please visit the #zkapp-developers channel on Discord.
About Mina Protocol
Mina is the world’s lightest blockchain, powered by participants. Rather than apply brute computing force, Mina uses advanced cryptography and recursive zk-SNARKs to design an entire blockchain that is about 22kb, the size of a couple of tweets. It is the first layer-1 to enable efficient implementation and easy programmability of zero knowledge smart contracts (zkApps). With its unique privacy features and ability to connect to any website, Mina is building a private gateway between the real world and crypto—and the secure, democratic future we all deserve.