Table of Contents
What is the verification of ZK instructions?
Why is it difficult to verify ZK instructions?
#What does the verification of ZK instructions mean?
How to verify ZK instructions?
Step One: Stack Memory
Step 2: Arithmetic Operations
Step Three: Execution Flow
Home web3.0 Advanced Formal Verification of Zero-Knowledge Proofs: How to Verify a ZK Instruction

Advanced Formal Verification of Zero-Knowledge Proofs: How to Verify a ZK Instruction

May 01, 2024 am 08:40 AM
Blockchain Ethereum web3.0

In order to deeply understand how formal verification technology is applied to zkVM (zero-knowledge virtual machine), this article will focus on the verification of a single instruction. For the overall situation of advanced formal verification of ZKP (zero-knowledge proof), please refer to the article "Advanced Formal Verification of Zero-Knowledge Proof Blockchain" that we published at the same time.

What is the verification of ZK instructions?

zkVM (zero-knowledge virtual machine) can create short proof objects as evidence that a specific program can run on certain inputs and terminate successfully. In the Web3.0 field, the application of zkVM enables high throughput because the L1 node only needs to verify a short proof of the smart contract's transition from input state to output state, and the actual contract code execution can be completed off-chain.

The zkVM prover will first run the program to generate an execution record of each step, and then convert the execution record data into a set of numerical tables (this process is called "arithmeticization"). A set of constraints (i.e., circuits) must be satisfied between these numbers, which includes the connection equations between specific table cells, fixed constants, database search constraints between tables, and the constraints that need to be satisfied between each pair of adjacent table rows. Polynomial equations (aka "gates"). On-chain verification can confirm that there is indeed a table that satisfies all constraints, while ensuring that the specific numbers in the table will not be seen.

The execution of each VM instruction faces many such constraints. Here we refer to this set of constraints of the VM instruction as its "ZK instruction". Below is an example of a zkWasm memory load instruction constraint written in Rust.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

#Formal verification of ZK instructions is done by performing formal reasoning on these codes, which we first translate into a formal language.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

#If even a single constraint contains an error, it is possible for an attacker to submit a malicious ZK proof. The data table corresponding to the malicious proof does not correspond to the legal operation of the smart contract. Unlike non-ZK chains such as Ethereum, which have many nodes running different EVM (Ethereum Virtual Machine) implementations, making it unlikely that the same bug will occur in the same place at the same time, a zkVM chain only has a single VM implementation. From this perspective alone, the ZK chain is more fragile than the traditional Web3.0 system.

What’s worse is that unlike non-ZK chains, since the calculation details of zkVM transactions are not submitted and stored on the chain, after the attack occurs, it is not only very difficult to discover the specific details of the attack, but also Even identifying the attacks themselves can become challenging.

The zkVM system requires extremely strict inspection. Unfortunately, the correctness of the zkVM circuit is difficult to guarantee.

Why is it difficult to verify ZK instructions?

VM (Virtual Machine) is one of the most complex parts of the Web3.0 system architecture. The powerful functions of smart contracts are the core of supporting Web3.0 capabilities. Their power comes from the underlying VMs, which are both flexible and complex: in order to complete general computing and storage tasks, these VMs must be able to support numerous instructions and states. For example, the EVM's geth implementation requires more than 7,500 lines of Go language code. Similarly, the ZK circuitry that constrains the execution of these instructions is equally large and complex. Like in the zkWasm project, the implementation of the ZK circuit requires more than 6000 lines of Rust code.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

zkWasm circuit architecture

with ZK systems designed for specific applications such as private payments Compared with the dedicated ZK circuits used in Thousands of digital cells.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

#What does the verification of ZK instructions mean?

We want to verify the correctness of the XOR instruction in zkWasm here. Technically speaking, zkWasm's execution table corresponds to a legal Wasm VM execution sequence. So from a macro perspective, what we want to verify is that each execution of this instruction will always generate a new legal zkVM state: each row in the table corresponds to a legal state of the VM, and the following row always It is generated by executing the corresponding VM instructions. The figure below shows the formal theorem for the correctness of the XOR instruction.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

Here "state_rel i st" indicates that state "st" is the legal zkVM state of the smart contract in step "i". As you might guess, proving "state_rel (i 1) ..." is not trivial.

How to verify ZK instructions?

Although the calculation semantics of the XOR instruction are very simple, which is to calculate the bitwise exclusive OR (bitwise Take two integers from memory, perform XOR calculation, and then store the new integer calculated back to the same stack. In addition, the execution steps of this instruction should be integrated into the entire smart contract execution process, and the order and timing of its execution must be correct.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

Therefore, the execution effect of the XOR instruction should be to pop two numbers from the data stack, push their XOR results, and at the same time increment the program counter to point to the smart contract Next instruction.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

It is not difficult to see that the correctness attribute definition here is generally the same as when we verify traditional bytecode VM (such as the EVM interpreter in the Ethereum L1 node) The situations faced are very similar. It relies on a high-level abstract definition of the machine state (here stack memory and execution flow) and a definition of the expected behavior of each instruction (here arithmetic logic).

However, as we will see below, due to the special nature of ZKP and zkVM, the verification process for their correctness is often very different from that of regular VMs. Just to verify our single instruction here depends on the correctness of many tables in zkWASM: among them is a range table used to limit the size of the value, a bit table used for the intermediate results of binary bit calculations, An execution table that stores constant-sized VM state per row (similar to data in registers and latches in a physical CPU), and memory that represents dynamically variable-sized VM state (memory, data stack, and call stack) tables and jump tables.

Step One: Stack Memory

Similar to traditional VM, we need to ensure that the two integer parameters of the instruction can be read from the stack, and that their XOR result values ​​are correctly written back stack. The formal representation of the stack also looks fairly familiar (there's also global memory and heap memory, but the XOR instruction doesn't use them).

零知识证明的先进形式化验证:如何验证一条 ZK 指令

#zkVM uses a complex scheme to represent dynamic data because the ZK prover does not natively support data structures like stacks or arrays. On the contrary, for each value pushed onto the stack, the memory table records a separate row, and some of the columns are used to indicate the effective time of the entry. Of course, the data in these tables can be controlled by attackers, so some constraints must be imposed to ensure that the table entries actually correspond to the actual stack instructions in contract execution. This is achieved by carefully calculating the number of stack pushes during program execution. When verifying each instruction, we need to ensure that this count is always correct. In addition, we have a series of lemmas that relate the constraints generated by a single instruction to the table lookups and time range checks that implement stack operations. From the top level, the counting constraints for memory operations are defined as follows.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

Step 2: Arithmetic Operations

Similar to traditional VM, we want to ensure that the bitwise XOR operation is correct. This seems easy, after all our physical computer CPUs are capable of doing this in one go.

But for zkVM, this is actually not simple. The only arithmetic instructions natively supported by the ZK prover are addition and multiplication. In order to perform binary bit operations, VM uses a rather complex scheme, in which one table stores the fixed byte-level operation results, and the other table acts as a "scratch pad" to show how to perform operations on multiple table rows. The 64-bit number is broken down into 8 bytes and then reassembled to give the result.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

Fragment of the zkWasm bittable specification

Very simple XOR in a traditional programming language Operations, here many lemmas are needed to verify the correctness of these auxiliary tables. For our directive we have:

零知识证明的先进形式化验证:如何验证一条 ZK 指令

Step Three: Execution Flow

Similar to a traditional VM, we need to ensure that the value of the program counter is updated correctly. For sequential instructions like XOR, the program counter needs to be incremented by one after each step.

Since zkWasm is designed to run Wasm code, it is also important to ensure that the immutable nature of Wasm memory is maintained throughout execution.

Traditional programming languages ​​have native support for data types such as Boolean values, 8-bit integers, and 64-bit integers. However, in the ZK circuit, variables are always within the range of integers modulo large prime numbers (≈ 2254). Variety. Since VMs typically run at 64 bits, circuit developers need to use a system of constraints to ensure they have the correct numerical ranges, and formal verification engineers need to track invariant properties about these ranges throughout the verification process. Reasoning about execution flows and execution tables involves all other auxiliary tables, so we need to check that the ranges of all table data are correct.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

Similar to the case of memory operation number management, zkVM requires a similar set of lemmas to verify control flow. Specifically, each call and return instruction requires the use of a call stack. The call stack is implemented using a table scheme similar to the data stack. For the XOR instruction, we do not need to modify the call stack; but when verifying the entire instruction, we still need to track and verify whether the control flow operation count is correct.

零知识证明的先进形式化验证:如何验证一条 ZK 指令Verify this instruction

Let's put all the steps together and verify the end-to-end correctness theorem of the zkWasm XOR instruction. The following verifications are completed in an interactive proof environment, where every formal construction and logical reasoning step undergoes the most rigorous machine checks.

零知识证明的先进形式化验证:如何验证一条 ZK 指令

#As seen above, formal verification of zkVM circuits is feasible. But this is a difficult task that requires understanding and tracking many complex invariant properties. This reflects the complexity of the software being verified: every lemma involved in the verification needs to be handled correctly by the circuit developer. Given the high stakes involved, it would be valuable to have them machine-checked by a formal verification system, rather than relying solely on careful human review.

The above is the detailed content of Advanced Formal Verification of Zero-Knowledge Proofs: How to Verify a ZK Instruction. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is Ouyi for? What is Ouyi What is Ouyi for? What is Ouyi Apr 01, 2025 pm 03:18 PM

OKX is a global digital asset trading platform. Its main functions include: 1. Buying and selling digital assets (spot trading), 2. Trading between digital assets, 3. Providing market conditions and data, 4. Providing diversified trading products (such as derivatives), 5. Providing asset value-added services, 6. Convenient asset management.

How to roll positions in digital currency? What are the digital currency rolling platforms? How to roll positions in digital currency? What are the digital currency rolling platforms? Mar 31, 2025 pm 07:36 PM

Digital currency rolling positions is an investment strategy that uses lending to amplify trading leverage to increase returns. This article explains the digital currency rolling process in detail, including key steps such as selecting trading platforms that support rolling (such as Binance, OKEx, gate.io, Huobi, Bybit, etc.), opening a leverage account, setting a leverage multiple, borrowing funds for trading, and real-time monitoring of the market and adjusting positions or adding margin to avoid liquidation. However, rolling position trading is extremely risky, and investors need to operate with caution and formulate complete risk management strategies. To learn more about digital currency rolling tips, please continue reading.

How to calculate the transaction fee of gate.io trading platform? How to calculate the transaction fee of gate.io trading platform? Mar 31, 2025 pm 09:15 PM

The handling fees of the Gate.io trading platform vary according to factors such as transaction type, transaction pair, and user VIP level. The default fee rate for spot trading is 0.15% (VIP0 level, Maker and Taker), but the VIP level will be adjusted based on the user's 30-day trading volume and GT position. The higher the level, the lower the fee rate will be. It supports GT platform coin deduction, and you can enjoy a minimum discount of 55% off. The default rate for contract transactions is Maker 0.02%, Taker 0.05% (VIP0 level), which is also affected by VIP level, and different contract types and leverages

Binance binance computer version entrance Binance binance computer version PC official website login entrance Binance binance computer version entrance Binance binance computer version PC official website login entrance Mar 31, 2025 pm 04:36 PM

This article provides a complete guide to login and registration on Binance PC version. First, we explained in detail the steps for logging in Binance PC version: search for "Binance Official Website" in the browser, click the login button, enter the email and password (enable 2FA to enter the verification code) to log in. Secondly, the article explains the registration process: click the "Register" button, fill in the email address, set a strong password, and verify the email address to complete the registration. Finally, the article also emphasizes account security, reminding users to pay attention to the official domain name, network environment, and regularly updating passwords to ensure account security and better use of various functions provided by Binance PC version, such as viewing market conditions, conducting transactions and managing assets.

Tutorial on how to register, use and cancel Ouyi okex account Tutorial on how to register, use and cancel Ouyi okex account Mar 31, 2025 pm 04:21 PM

This article introduces in detail the registration, use and cancellation procedures of Ouyi OKEx account. To register, you need to download the APP, enter your mobile phone number or email address to register, and complete real-name authentication. The usage covers the operation steps such as login, recharge and withdrawal, transaction and security settings. To cancel an account, you need to contact Ouyi OKEx customer service, provide necessary information and wait for processing, and finally obtain the account cancellation confirmation. Through this article, users can easily master the complete life cycle management of Ouyi OKEx account and conduct digital asset transactions safely and conveniently.

What are the recommended websites for virtual currency app software? What are the recommended websites for virtual currency app software? Mar 31, 2025 pm 09:06 PM

This article recommends ten well-known virtual currency-related APP recommendation websites, including Binance Academy, OKX Learn, CoinGecko, CryptoSlate, CoinDesk, Investopedia, CoinMarketCap, Huobi University, Coinbase Learn and CryptoCompare. These websites not only provide information such as virtual currency market data, price trend analysis, etc., but also provide rich learning resources, including basic blockchain knowledge, trading strategies, and tutorials and reviews of various trading platform APPs, helping users better understand and make use of them

Currency Trading Network Official Website Collection 2025 Currency Trading Network Official Website Collection 2025 Mar 31, 2025 pm 03:57 PM

It ranks among the top in the world, supports all categories of transactions such as spot, contracts, and Web3 wallets. It has high security and low handling fees. A comprehensive trading platform with a long history, known for its compliance and high liquidity, supports multilingual services. The industry leader covers currency trading, leverage, options, etc., with strong liquidity and supports BNB deduction fees.

On which platform is web3 transaction? On which platform is web3 transaction? Mar 31, 2025 pm 07:54 PM

This article lists the top ten well-known Web3 trading platforms, including Binance, OKX, Gate.io, Kraken, Bybit, Coinbase, KuCoin, Bitget, Gemini and Bitstamp. The article compares the characteristics of each platform in detail, such as the number of currencies, trading types (spot, futures, options, NFT, etc.), handling fees, security, compliance, user groups, etc., aiming to help investors choose the most suitable trading platform. Whether it is high-frequency traders, contract trading enthusiasts, or investors who focus on compliance and security, they can find reference information from it.