Mina's zkApp

1 Introduction

The pre-order blogs are:

In December 2021, the ZK Hack zkApps Workshop and zkApps Bootcamp will be jointly held by the Mina Foundation and Mina ecological partner O(1) Labs and ZK Hack . During these two events, the Mina community can learn to use SnarkyJS - a TypeScript library for writing Mina zero-knowledge smart contracts.

Related videos include:

2. How zkApps work

zkApps is Mina's zero-knowledge smart contract. zkApps adopts off-chain execution and most off-chain state models, supporting private computation and private or public state. Off-chain, zkApps can perform arbitrarily complex computations and only pay a fixed fee to send a zero-knowledge proof of the result on-chain to verify the computation, while other blockchains run computations on-chain and use dynamic gas cost model.
insert image description here
zkApps is written in TypeScript using the Mina zkApp CLI. zkApps currently supports running on the latest versions of Chrome, Firefox, Edge and Brave browsers, and will support Safari browsers in the future.

A zkApp contains 2 parts:

  • 1) A smart contract: Mina's smart contract is written in SnarkyJS .
  • 2) A UI for user interaction

insert image description here

2.1 Zero-knowledge-based smart contracts

Since zkApps are based on zero-knowledge proofs (zk-SNARKs), zkApp developers write "circuits" - based on which, the Prover function and the corresponding Verifier function can be derived.

  • Prover function: will execute the custom logic of the smart contract. The Prover function runs inside the user's web browser as part of the zkApp. When interacting with the zkApp UI, the user will enter any data (eg, "starting with yyy price to buy ABC") as input to the Prover function, which generates a zero-knowledge proof.
    insert image description here
    In the user's web browser, data needs to be entered for the private and public inputs required by the Prover function:

    • private input: Once provided to the Prover function, it will no longer be required.
    • Public input: Provided to the Prover function, and also to the Verifier function. For data you want to keep private, never enter it as public.
  • Verifier function: Verifies that the provided zero-knowledge proof passes all the constraints defined in the Prover function. No matter how complex the Prover function is, the verification of the Verifier function is usually fast and efficient.
    insert image description here

2.2 Mina's Prover function and Verification Key

When the zkApp developer finishes writing the smart contract and runs it npm run build, the output will be compiled smart_contract.js. Then, you can run the Prover function or generate a Verification Key, which is exactly what you need when running or deploying the smart contract.
The Prover function runs within the user's web browser.
The Verification Key of the specified zkApp account is located on the chain, and the Mina network will use the Verification Key on the chain to verify whether the provided zero-knowledge proof satisfies all the constraints defined in the Prover function. Verification Key is required when creating a zkApp account.

2.3 Deploying Smart Contracts

insert image description here
Developers can use the Mina zkApp CLI to deploy smart contracts into the Mina network. The deployment process is to send a transaction containing the Verification Key to an address on the Mina chain. When the address on Mina contains a Verification Key, the address can be used as a zkApp account. A regular Mina account can receive any transaction, while a zkApp account can only successfully receive transactions that contain proofs that satisfy the Verifier function. Any transaction that cannot be verified by the Verifier function will be rejected by the Mina network.

When you deploy a new Mina address, Mina protocol will charge a fee of 1 MINA for the account creation. This has nothing to do with zkApps and prevents witch or DOS attacks.

2.4 Deploy zkApp UI

insert image description here
Developers usually provide UI interfaces for users to interact with smart contracts. The UI is usually a static website that the developer deploys on a custom server. It is recommended that the web server provides a global CDN to ensure the best user experience. The website needs to contain the smart_contract.jsfiles generated by compiling the smart contract before,
insert image description here

2.5 How do users interact with zkApp?

To interact with zkApp, users must install Auro Wallet for Google Chrome . In the future, a wallet that supports zkApps will be added.

Auro is currently the only wallet that supports zkApp transactions. Once the zkApp is deployed to a host (e.g. mycolzkapp.com), users can interact with it:

  • 1) User visits mycoolzkapp.com.
  • 2) The user interacts with the zkApp and enters any required data. (For example, for automated market makers, the user can specify "to yyy price buyxxx ABC").
  • 3) The Prover function of zkApp generates a zero-knowledge proof locally based on the data input by the user. This data can be private (do not want to be visible on-chain) or public (can be stored on-chain or off-chain), depending on the developer's settings and specific use cases. Additionally, along with the proof, a list of state updates that the exchange will produce is also generated. (Mina calls these lists of status updates "events".)
  • 4) The user clicks "submit to chain" in the zkApp UI, and his wallet (such as a browser extension wallet) will pop up a box to confirm whether to send the transaction. The wallet signs the transaction containing the proof and the corresponding state description that needs to be updated, and sends the signed transaction to the Mina chain.
  • 5) When the Mina network receives the transaction, it will verify whether the proof has successfully passed the Verifier function in the zkApp account. If the proof verification is passed and the corresponding status change is valid, the network will accept the transaction and update the corresponding zkApp status.

The user's privacy is protected as user interaction happens inside their native web browser (with JavaScript on the client side).

2.6 How is the on-chain status updated?

How is the status of the zkApp account on the chain updated?
When the Prover function is run in a web browser, the smart contract outputs a proof and some associated data called "events". These outputs are sent to the zkApp address as part of the transaction. These events are plaintext descriptions in JSON - describing how to update the state of a zkApp account.

In order to ensure the integrity of these events, the hash value of these events will be used as the public input of the smart contract to ensure that it will not be tampered with when transmitted to the Verifier function on the Mina chain. In this way, the Mina network can confirm the integrity of proofs and events, and update the status of the zkApp account accordingly.

2.7 zkApp Status

Mina has 2 state types:

  • 1) On-chain state: The state on the Mina chain. Each zkApp account has 8 fields of 32 bytes, and each field has any storage space. As long as the size is appropriate, anything can be stored in the field. If you expect your state to be larger than this, or if your zkApp accumulates state per user, then you will want to use off-chain state.
  • 2) Off-chain state: Stored elsewhere, such as the state of IPFS. [Coming soon. ] For larger data, consider storing the Merkle tree root in the on-chain space of zkApp, which will point to the state stored off-chain. When running a zkApp in a user's web browser, state can be inserted into external storage, such as IPFS. When the transaction is sent to the Mina chain, if the zkApp transaction is accepted (that is, the proof&sate are valid), the zkApp transaction will update the Merkle tree root stored on the chain.

insert image description here

3. How to write zkApp?

Mina zkApp CLI is currently the easiest tool for writing zkApp smart contracts. It can provide project scaffolding, including SnarkyJS, testing framework (Jest), code automatic formatting (Prettier), linting (ES-Lint) and other dependencies.

For detailed contract writing process, please refer to:

4. zkApps project highlights

In the zkApps training camp, O(1) Labs engineers introduced the high-level architecture of zkApps , how to use SanrkyJS to write smart contracts, and asked developers to use SnarkyJS to write a game.

During the 4-day zkApps training camp, there are some interesting projects:

See the collection of zkApps developed by the Mina community:

5. Mina Planning

PROJECT DESCRIPTION ESTIMATED COMPLETION DATE
zkApps Bootcamp Formerly zkApps Hackathon. Engaged with developers and educated them to build with zkApps. Q4 2021 – Completed
NEW Kimchi SNARK New SNARK to bring faster verification and prover time than the original PLONK SNARK. Q4 2021 – Completed (to be incorporated in an upcoming hard fork)
Improve Node Stability Make node operation more stable. (Example project: BitSwap) Ongoing
NEW zkApps Builders Program A program to educate, support, and work with developers who are building zkApps, and enlist their help to improve zkApps and SnarkyJS. Q2 2022
NEW Document Mina’s crypto libraries and curve points Package Mina’s proof system to be easily adopted by other ZKP-enabled products. Q2 2022
zkApps Testing Formerly zkApps Testnet. This is now a series of phases to test the stability of zkApps on a network. Q2 2022
zkApps Software Development Kit (SDK) Provide the toolkit that the developers need to build on Mina: SnarkyJS & zkApp CLI. Q2 2022
Bridge to Ethereum: One Way Mina -> Ethereum Enable Ethereum developers to access the Mina state on EVM. Q2 2022
NEW Enable 3rd-party, off-chain usage of Mina’s proof system Enable zero-knowledge (ZK) enthusiasts to adopt Mina’s proof system without having to use the Mina chain. Q3 2022
NEW Non-Native Token Support Enable creation of non-native tokens on Mina (similar to ERC20). Q3 2022
Easy zkApps Programmability on Mainnet Enable easy programmability and basic use cases of zkApps on Mina Mainnet. Q3 2022
Multi-Environment Setup Upgrade infrastructure to support more networks running in parallel for Mina. Enable community to run their own networks. Q3 2022
Non-Consensus Nodes Direct access to the Mina network for web and mobile nodes, without needing to run a consensus node. Q3 2022
ZK Oracles Formerly WebzkApps. This is to ship the Minimally Viable Product (MVP) to connect real world data to blockchain in the most trustless way possible, using HTTPS. Q4 2022
NEW ZK Rollup on Mina Increase transaction throughput on Mina using ZK Rollup. TBD

zkApps的测试流程为:
Initial Testing (started Q4 2021) → Public QANet (targeting Q1 2022) → Testnet ‘Berkeley’ (targeting Q2 2022)

参考资料

[1] Mina Protocol Product Priorities – Q1 2022 Update
[2] zkApps Workshop & Bootcamp Retro
[3] What are zkApps?
[4] zkApps开发者文档
[5] Mina: Using Zero-Knowledge To Make Web3 Useful for Everyone

Guess you like

Origin blog.csdn.net/mutourend/article/details/123638824