Nova: A new chapter in zero-knowledge proofs.

23-07-11 20:00
Read this article in 64 Minutes
Original Title: "Nova: A New Chapter of Zero-Knowledge Proofs"

Source: Huobi Research

Introduction


Zero-knowledge proof is an important technology in cryptography that allows one person to prove to another person that a statement is true without revealing any other information. This technology has wide applications in many fields, including identity verification, blockchain, and secure computation. Nova is a new zero-knowledge proof system developed by Microsoft, which uses a technology called Relaxed Rank-1 Constraint Systems (Relaxed R1 CS) to improve the efficiency and flexibility of proofs. The last chapter provides a detailed interpretation of the source code.


The advantages of Nova


The main advantage of Nova is its use of the relaxed R1CS technology. R1CS is a system used to construct zero-knowledge proofs, which can be used to prove that a person knows the solution to a set of polynomial equations without revealing any information about the solution. However, traditional R1CS systems require a lot of randomness in the proof process, which can make proof generation and verification very complex and time-consuming. Nova solves this problem by using relaxed R1CS, which allows for less randomness in the proof and greatly improves proof efficiency.


Nova also has some other advantages. For example, it supports incremental computation, which means that complex functions can be calculated gradually without having to calculate the entire function at once. This is very useful when dealing with large-scale data or performing complex calculations. In addition, Nova also supports polynomial computation, which allows it to handle more complex proof tasks.


Nova's shortcomings


Despite having many advantages, Nova also has some drawbacks. Firstly, because Nova uses relaxed R1CS, its proofs may not be as strong as traditional R1CS systems. This is because relaxed R1CS allows for less randomness to be used in the proof, which may lower the security of the proof. However, the developers of Nova have taken measures to address this issue, such as using stronger cryptographic algorithms and more complex proof strategies.


Secondly, the implementation of Nova is relatively complex, which may increase the difficulty of use and maintenance. Nova uses many advanced cryptographic techniques, such as polynomial calculations, group operations, and random oracles, which require a deep understanding of these technologies to effectively use and modify Nova.


Nova's important position in the field of zero-knowledge proof


Nova occupies an important position in the field of zero-knowledge proofs. Its emergence has opened up new avenues for the development of zero-knowledge proofs. Nova's use of relaxed R1CS technology makes the proof generation and verification process more efficient, which is crucial for large-scale zero-knowledge proof applications. In addition, Nova also supports incremental computation and polynomial computation, which enables it to handle more complex proof tasks and further expands the application scope of zero-knowledge proofs.


Nova's Source Code Interpretation


https://github.com/microsoft/Nova


There are several important subdirectories in the src/ directory:


bellperson/:This directory may contain code related to the Bellman-Ford algorithm.


gadgets/:This directory may contain some tools for building zk-SNARK proofs.



spartan/:This directory may contain code related to the Spartan protocol.


traits/:This directory may contain some Rust traits used to define common behaviors.


Content of src/bellperson/mod.rs file:


This module is mainly used to generate R1CS (Rank-1 Constraint Systems, a type of constraint system used for zk-SNARKs).


It contains three sub-modules:


r1cs: This module may contain code related to R1CS.


shape_cs: This module may contain code related to the shape constraint system.


solver: This module may contain code related to solving constraint systems.


In the testing section, it defines a function called synthesize_alloc_bit, which takes a constraint system and adds some constraints to check whether the input two bits are indeed bits. Then, it defines a function called test_alloc_bit_with, which first creates a shape.


Content of src/bellperson/r 1 cs.rs file:


This file mainly defines two traits: `NovaWitness` and `NovaShape`, which respectively provide methods for obtaining `R 1 CSInstance` and `R 1 CSWitness` from the implementer, as well as obtaining `R 1 CSShape` and `CommitmentKey`.


- `NovaWitness` trait has a method called `r1cs_instance_and_witness`, which takes a `R 1 CSShape` and a `CommitmentKey` as inputs, and returns a `R 1 CSInstance` and a `R 1 CSWitness`. This trait is implemented for the `SatisfyingAssignment` struct, which means that any `SatisfyingAssignment` can use this method to obtain a `R 1 CSInstance` and a `R 1 CSWitness`.


- The `NovaShape` trait has a method called `r 1 cs_shape`, which returns an `R 1 CSShape` and a `CommitmentKey`. This trait is implemented for the `ShapeCS` structure, which means that any `ShapeCS` can use this method to obtain an `R 1 CSShape` and a `CommitmentKey`.



Overall, the main purpose of this file is to provide a way to generate instances, witnesses, shapes, and commitment keys for R1CS from a system that satisfies specific conditions (such as SatisfyingAssignment or ShapeCS).


src/bellperson/shape_cs.rs


This file defines a struct named `ShapeCS`, which implements the `ConstraintSystem` trait. `ShapeCS` is a constraint system used to create R1CS shapes.


`ShapeCS` structure contains the following fields:


- `named_objects`: This is a mapping used to store objects associated with paths.


- `current_namespace`: This is a string vector used to store the current namespace.


- `constraints`: This is a vector used to store all constraints added to `ShapeCS`.


- `inputs`: This is a string vector used to store all inputs.


- `aux`: This is a string vector used to store all auxiliary inputs.


`ShapeCS` struct implements the `ConstraintSystem` trait, which means it provides the following methods:


- `alloc`: This method is used to allocate a new variable.


- `alloc_input`: This method is used to allocate a new input variable.


- `enforce`: This method is used to add a new constraint.


- `push_namespace`: This method is used to push a new namespace.


- `pop_namespace`: This method is used to pop the current namespace.


- `get_root`: This method is used to obtain the root constraint system.


This file also defines some auxiliary functions, such as `proc_lc` and `compute_path`, which are used to handle linear combinations and calculate paths, respectively.


Overall, the main purpose of this file is to provide a way to generate the shape of R1 CS from a system that meets specific conditions (such as `ShapeCS`).


src/bellperson/solver.rs


This file defines a struct named `SatisfyingAssignment`, which implements the `ConstraintSystem` trait. `SatisfyingAssignment` is a constraint system used to create R1CS instances and witnesses.


`SatisfyingAssignment` structure contains the following fields:


- `a_aux_density`, `b_input_density`, `b_aux_density`: These are fields of type `DensityTracker` used to track the density of queries.


- `a`, `b`, `c`: These are vectors used to store the evaluation results of polynomials A, B, and C.


- `input_assignment`, `aux_assignment`: These are vectors used to store variable assignments.


`SatisfyingAssignment` struct implements the `ConstraintSystem` trait, which means it provides the following methods:


- `new`: This method is used to create a new `SatisfyingAssignment` instance.


- `alloc`: This method is used to allocate a new auxiliary variable.


- `alloc_input`: This method is used to allocate a new input variable.


- `enforce`: This method is used to add a new constraint.


- `push_namespace`, `pop_namespace`: These methods are used to manipulate namespaces, but there is no actual operation in this context.


- `get_root`: This method is used to obtain the root constraint system.


- `is_extensible`, `extend`: These methods are used to extend the constraint system.


Overall, the main purpose of this file is to provide a way to generate instances and witnesses of R1CS from a system that satisfies specific conditions (such as `SatisfyingAssignment`).


"src/circuit.rs"

, it defines the Augmented Circuit in the Nova protocol. This circuit includes a Step Circuit and a validator circuit in Nova's non-interactive folding scheme.

The following main structures and methods are defined in the file:


- `NovaAugmentedCircuitParams`: This structure contains the parameters of the circuit, including the limb width, the number of limbs, and a boolean value indicating whether it is the main circuit.


- `NovaAugmentedCircuitInputs`: This structure contains the inputs of the circuit, including parameters, i, z 0, zi, U, u, and T.


- `NovaAugmentedCircuit`: This structure is the main definition of Nova augmented circuit, which includes the parameters, read-only constants, inputs, and step circuits of the circuit. It also defines some methods, such as `alloc_witness` (allocate witness), `synthesize_base_case` (synthesize base case), and `synthesize_non_base_case` (synthesize non-base case).


- `synthesize` method: This is the main synthesis method for Nova enhanced circuits. It first allocates all witnesses, then synthesizes the circuit based on whether it is a base case, and finally outputs the computed hash value and u.X[1].


This file also contains some test code for testing the functionality of recursive circuits.


Overall, the main purpose of this file is to define the enhanced circuit in the Nova protocol. This circuit is the core part of the Nova protocol, which includes a step circuit and a validator circuit, and provides a way to synthesize this circuit.


"src/constants.rs"

, it defines some constants that are widely used throughout the project. Here are the meanings of these constants:


- `NUM_CHALLENGE_BITS`: This constant defines the number of bits in a challenge, which is set to 128. Challenges are typically random numbers generated by the prover and used in the interactive step of the zk-SNARK proof process.


- `NUM_HASH_BITS`: This constant defines the number of bits in the hash, with a value of 250. A hash function is a function that can map input data of any length to a fixed-length output. The output length here is 250 bits.


- `BN_LIMB_WIDTH`: This constant defines the limb width of a big number, with a value of 64. In computer science, big numbers are those that exceed the range that can be represented by standard data types, and they are usually decomposed into multiple "limbs" for storage and operation.



- `NUM_FE_WITHOUT_IO_FOR_CRHF`: This constant defines the number of field elements (FE) without input/output for collision-resistant hash functions (CRHF), with a value of 17.


- `NUM_FE_FOR_RO`: This constant defines the number of field elements (FE) for a random oracle (RO), which is 24.



- `InvalidIndex`: This error will be returned if the provided row or column in the (row, col, val) tuple is out of range.



- `InvalidInputLength`: This error will be returned if the provided input length is incorrect.




- `DecompressionError`: This error will be returned if the provided compression commitment cannot be decompressed.


- `ProofVerifyError`: This error will be returned if proof verification fails.


- `InvalidNumSteps`: This error will be returned if the provided number of steps is zero.


- `InvalidIPA`: This error will be returned if an invalid inner product parameter is provided.


- `InvalidSumcheckProof`: This error will be returned if an invalid sumcheck proof is provided.


- `InvalidInitialInputLength`: This error will be returned if the initial input for incremental computation does not match the previously declared arity.


- `InvalidStepOutputLength`: This error will be returned if the length of the output generated by the step execution does not match the previously declared arity.


- `InternalTranscriptError`: This error will be returned if the transcription engine encounters a round overflow.


- `InvalidMultisetProof`: This error will be returned if the multiset check fails.


- `InvalidProductProof`: This error will be returned if the product proof check fails.


- `IncorrectWitness`: This error will be returned if the consistency between the public IO and the used assignment fails.


These error types cover various issues that may be encountered in the Nova library, including input errors, proof errors, internal errors, etc. When functions in the Nova library encounter problems, they return these errors so that the caller can understand what the problem is and take appropriate action.


"ecc.rs"

, it is written in Rust language. This file mainly contains the implementation of elliptic curve cryptography (ECC) related to the Nova framework.

Elliptic Curve Cryptography (ECC) is a public key encryption technology. Its main advantage is that it can use shorter keys while providing the same level of security. This means that ECC can use less computing resources and power, which is particularly important for many devices, especially mobile devices and embedded systems.


In this file, you will see some Rust structs and impls defined, all of which are for implementing ECC functionality. For example, you will see `struct EccGadget`, which is a primary implementation of ECC and contains fields such as `value` and `pb_variable` for storing ECC state and related variables.


In addition, you will also see some definitions of functions that are used to implement various operations of ECC, such as encryption and decryption. For example, `fn encrypt` is an encryption function that takes a plaintext and a public key, and then returns an encrypted ciphertext.


Overall, this file is a key part of implementing ECC functionality in the Nova framework.


"src/gadgets/mod.rs"

, it is a module in the Nova framework, mainly used to implement various "gadgets" necessary for Nova and applications built using Nova.


In cryptography, "gadget" is a general term used to describe a block of code that implements a specific function. In zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Argument of Knowledge), a gadget typically refers to a proof system that implements a specific algorithm or protocol.


In this file, you will see the following sub-modules:


- `ecc`: This module may contain gadgets related to Elliptic Curve Cryptography.


- `nonnative`: This module may contain some non-native field gadgets.


- `r 1 cs`: This module may contain some R 1 CS (Rank-1 Constraint Systems) gadgets.


- `utils`: This module may contain some useful utility functions or classes.


These sub-modules together provide various functionalities required by the Nova framework.


"bignat.rs"

, it is a part of the Nova project, mainly used for implementing operations on big integers (BigNat).


In computer science, large integers (also known as arbitrary-precision integers) are integers that can represent and operate on a range of numbers beyond what regular integer types (such as int or long) can represent. This is very useful in many fields, including cryptography, computer graphics, and large number calculations.


Let's take a closer look at some of the main parts in this file:


1. `use super::super::gadgets::GadgetCaller;`: This line of code imports GadgetCaller, which is a trait used to call other gadgets.


2. `pub struct BigNatGadget;`: This line of code defines a struct named BigNatGadget. In Rust, structs are used to create complex data types.


3. `impl GadgetCaller for BigNatGadget`: This is an implementation of the `GadgetCaller` trait for the `BigNatGadget` structure. This means that `BigNatGadget` must provide implementations for all the methods required by the `GadgetCaller` trait.


4. In this implementation, we can see some methods such as `add`, `sub`, `mul`, `div`, `rem`, which are all basic operations for large integer arithmetic.






In cryptography, non-local fields typically refer to fields that are not directly supported by hardware. For example, some cryptographic algorithms may require operations on fields larger than 64 bits, but most modern computer hardware only directly supports operations up to 64 bits. In such cases, we need to use arithmetic operations on non-local fields.


In this file, you will see the following main sections:


1. `OptionExt` trait: This trait adds two methods, `grab` and `grab_mut`, to the `Option` type. They attempt to retrieve the value in the `Option`, and if the `Option` is `None`, an error is returned.


2. `BitAccess` trait: This trait provides a method `get_bit`, which takes an index `i` and returns whether the bit at that index position is `1`.


3. `impl BitAccess for Scalar`: This is the implementation of the `BitAccess` trait for the `Scalar` type. `Scalar` is a type that represents a prime field.


4. `pub mod bignat;` and `pub mod util;`: These two lines of code import the `bignat` and `util` submodules, which may contain functions or classes that implement non-local field arithmetic operations.


Overall, this document provides a method for performing arithmetic operations on non-local fields, which is crucial for implementing certain cryptographic algorithms.


"util.rs"

, it is located in the "src/gadgets/nonnative/" directory. This file is mainly used to implement some utility functions for performing operations on non-native fields.

Here are some main parts of this file:


1. ` Bit ` Structure: This structure represents a bit, including a linear combination and a value that is filled in at witness time.


2. `Bitvector` structure: This structure represents a bit vector, which includes a linear combination vector, a value vector, and an assigned bit vector.


3. `Num` Structure: This structure represents a number, including a linear combination and a value.


4. The `alloc` method of the `Bit` structure: This method allocates a variable that can only be a boolean value in the constraint system.


5. The `fits_in_bits` method of the `Num` structure: This method checks whether a number can be represented with a given number of bits.


6. The `is_equal` method of the `Num` structure: This method checks whether a number is equal to a natural number represented by a bit vector.


7. The `decompose` method of the `Num` structure: This method decomposes a number into a bit vector.


8. The `as_allocated_num` method of the `Num` structure: This method converts a number into an allocated number.


9. `f_to_nat` function: This function converts a field element into a natural number.


10. `nat_to_f` function: This function converts a natural number to a field element.


Overall, this file provides some practical functions that can perform various operations on non-local fields, such as assigning variables, checking if a number can be represented with a given number of bits, decomposing a number into a bit vector, and so on.


"r 1 cs.rs"

is located in the "src/gadgets/" directory. This file is mainly used to implement various gadgets for Rank-1 Constraint Systems (R 1 CS).


R 1 CS is a proof system used to describe algorithms or protocols. It is the foundation of many zero-knowledge proof systems, including zk-SNARKs.


Here are some main parts of this file:


1. `AllocatedR 1 CSInstance` structure: This structure represents an allocated R1 CS instance, which includes a point `W` and two numbers `X 0` and `X 1`.


2. `AllocatedR1CSInstance::alloc` method: This method is used to allocate an R1CS instance in the constraint system.


3. `AllocatedR1CSInstance::absorb_in_ro` method: This method is used to absorb the R1CS instance into a random oracle (RO).


4. `AllocatedRelaxedR1CSInstance` structure: This structure represents an allocated relaxed R1CS instance, including two points `W` and `E`, a number `u`, and two large integers `X 0 ` and `X 1 `.


5. `AllocatedRelaxedR1CSInstance::alloc` method: This method is used to allocate a relaxed R1CS instance in the constraint system.


6. `AllocatedRelaxedR1CSInstance::default` method: This method is used to allocate a default relaxed R1CS instance in the constraint system.







Here are some main parts of this file:





4. `scalar_as_base` function: This function is used to interpret a scalar as a base.



6. `alloc_num_equals` function: This function is used to check if two numbers are equal and returns a bit.


7. `conditionally_select` function: This function is used to select one of two numbers based on a condition.


8. `conditionally_select_vec` function: This function is used to select one of two arrays of numbers based on a condition.


9. `conditionally_select_bignat` function: This function is used to select one of two large integers based on a condition.


10. `conditionally_select2` function: This function is used to select one of two numbers based on a condition, which is an allocated number.


11. `select_zero_or_num 2` and `select_num_or_zero 2` functions: These two functions are used to set a number to zero or leave it unchanged based on a condition, which is an assigned number.


12. `select_num_or_zero` function: This function is used to set a number to zero or leave it unchanged based on a condition, which is a boolean value.


13. `select_one_or_num 2` and `select_num_or_one` functions: These two functions are used to set a number to one or keep it unchanged based on a condition. The condition is a pre-assigned number and a boolean value.


Overall, this file provides some practical functions that can allocate variables in a constraint system, check if two numbers are equal, and select one of two numbers based on a condition.


This is a Rust language source code file named "lib.rs", which is a major component of the Nova project. This file mainly defines the public interface and some core functions of the Nova library. Here is a detailed interpretation of this file:


1. `pub mod ast`: This line of code imports a module named "ast". "ast" is short for "Abstract Syntax Tree", which is a data structure used to represent the structure of source code. In the Nova project, the "ast" module may contain various data structures and functions used for parsing and processing Nova language source code.


2. `pub mod parser`: This line of code imports a module named "parser". "Parser" means "解析器" in Chinese, and this module may contain functions and classes used to parse Nova language source code.



4. `pub mod types`: This line of code imports a module named "types". This module may contain the type system of the Nova language, including representations and handling of various built-in types and user-defined types.


5. `pub mod util`: This line of code imports a module named "util". "Util" is an abbreviation for "utilities", and this module may contain various useful functions and classes, such as error handling, logging, file reading and writing, etc.


6. `pub mod driver`: This line of code imports a module named "driver". In a compiler project, "driver" typically refers to the module that controls the entire compilation process, including steps such as reading and parsing source code, type checking, code generation, optimization, and output.


7. `pub mod error`: This line of code imports a module named "error". This module may contain the error handling system for the Nova language, including representations and handling of various compilation and runtime errors.


8. `pub mod config`: This line of code imports a module named "config". This module may contain the configuration system of the Nova language, including representation and handling of compilation options, runtime options, and so on.


The main purpose of this file is to organize various components of the Nova language (such as parser, code generator, type system, error handling system, etc.) into a complete compiler library.


This file is named "nifs.rs" and is located in the "src/" directory. This file implements a Non-Interactive Folding Scheme (NIFS).This is a cryptographic protocol used to prove the correctness of each step in incremental computation.


Here are some main parts of this file:


1. `NIFS` structure: This structure represents a SNARK, which saves the proof of one step of incremental computation. It contains a field named `comm_T`, which is a compressed commitment.


2. `prove` method: This method takes a loose R 1 CS instance-witness for `(U 1, W 1)` and a R 1 CS instance-witness for `(U 2, W 2)` that have the same structure `shape` and are defined relative to the same `ck`. It then outputs a folded loose R 1 CS instance-witness for `(U, W)` with the same structure `shape`. If `W 1 ` satisfies `U 1 ` and `W 2 ` satisfies `U 2 `, then the folded witness `W` satisfies the folded instance `U`.


3. `verify` method: This method takes a loose R 1 CS instance `U 1 ` and an R 1 CS instance `U 2 ` that have the same structure and are relative to the same parameter definition. Then, it outputs a folded instance `U` with the same structure. If `U 1 ` and `U 2 ` are satisfiable, then the folded instance `U` is satisfiable.


4. Test Module: This module contains some test functions for testing the `NIFS` structure's `prove` and `verify` methods.


Overall, this file implements a non-interactive folding scheme, which is a cryptographic protocol used to prove the correctness of each step in incremental computation. The main advantage of this scheme is that it can fold multiple proofs into one proof, thereby reducing the storage and transmission costs of proofs.


This file is named "ipa_pc.rs" and is located in the "src/provider/" directory. The file implements an evaluation engine that uses a polynomial commitment scheme based on Inner Product Argument (IPA).


Here are some main parts of this file:


1. `ProverKey` structure: This structure represents a prover key, which includes a commitment key `ck_s`.


2. `VerifierKey` structure: This structure represents a verifier key, which contains two commitment keys `ck_v` and `ck_s`.


3. `EvaluationArgument` structure: This structure represents the evaluation parameters of a polynomial, which includes an inner product parameter `ipa`.


4. `EvaluationEngine` structure: This structure represents a polynomial evaluation engine that uses IPA.


5. Implementation of the `EvaluationEngineTrait` trait: The implementation of this trait provides the main functionalities of the polynomial evaluation engine, including setting, proving, and verifying.


6. `inner_product` function: This function calculates the inner product of two vectors.


7. `InnerProductInstance` structure: This structure represents an inner product instance, which includes a commitment `comm_a_vec` to a vector `a`, another vector `b_vec`, and a claimed value `c = <a, b>` of the inner product `c`.


8. `InnerProductWitness` structure: This structure represents an inner product witness, which includes a vector `a_vec`.


9. `InnerProductArgument` structure: This structure represents an inner product argument, which includes two compressed commitment vectors `L_vec` and `R_vec`, as well as a scalar `a_hat`.


Overall, this file implements an evaluation engine using an IPA-based polynomial commitment scheme, which is a cryptographic protocol used to prove the evaluation value of a polynomial at a certain point in zero-knowledge proofs. The main advantage of this scheme is that it can prove the evaluation value of a polynomial without revealing the polynomial itself, thus protecting the privacy of the polynomial.


This file is named "keccak.rs" and is located in the "src/provider/" directory. This file implements a TranscriptEngineTrait that uses the Keccak 256 hash function. TranscriptEngineTrait is a trait used to handle transcripts in zero-knowledge proof processes. A transcript is a data structure that records all interaction steps in the proof process.


 The following are some of the main parts in this file:


1. `Keccak 256 Transcript` struct: This struct implements the TranscriptEngineTrait and uses the Keccak 256 hash function to process the transcript. It contains a round field to record the current round, a state field to store the current hash state, a transcript field to store the transcript, and a _p field to store type information.


2. `compute_updated_state` function: This function takes an input and calculates the updated hash state.


3. Implementation of `TranscriptEngineTrait`: The implementation of this trait provides the main functionality for handling transcripts, including creating a transcript, extracting a challenge from a transcript, adding an element to a transcript, and adding a domain separator to a transcript.


4. Test Module: This module contains some test functions for testing the functionality of the `Keccak 256 Transcript` structure.


Overall, this file implements a TranscriptEngineTrait that uses the Keccak 256 hash function. This is a tool used to handle transcripts in zero-knowledge proof processes. The main advantage of this tool is that it can handle transcripts without revealing the interactive steps of the proof process, thus protecting the privacy of the proof process.



Here are some main parts of this file:


1. `pub mod ipa_pc;`: This line of code imports a module named "ipa_pc". This module implements an evaluation engine that uses a polynomial commitment scheme based on Inner Product Argument (IPA).


2. `pub mod keccak;`: This line of code imports a module named "keccak". This module implements a TranscriptEngineTrait that uses the Keccak 256 hash function.


3. `pub mod pasta;`: This line of code imports a module named "pasta". This module may contain some functions and classes that use the Pasta curve.


4. `pub mod pedersen;`: This line of code imports a module named "pedersen". This module may contain some functions and classes that use Pedersen commitments.


5. `pub mod poseidon;`: This line of code imports a module named "poseidon". This module may contain some functions and classes that use the Poseidon hash function.


Overall, the main purpose of this file is to organize various components of the Nova project (such as evaluation engine, TranscriptEngineTrait, Pasta curve, Pedersen commitment, Poseidon hash function, etc.) into a complete cryptographic library.


File name: `src/r 1 cs.rs`


This file defines types and methods related to the Rank-1 Constraint System (R 1 CS). R 1 CS is a constraint system widely used in zero-knowledge proof systems.


The following structures and their methods are mainly defined:


1. `R 1 CS`: This structure represents the public parameters of an R 1 CS. It includes a method `commitment_key` for generating the public parameters of R 1 CS.


2. `R 1 CSShape<G: Group>`: This structure represents the shape of the R 1 CS matrix, including the number of constraints, variables, inputs/outputs, and the A, B, and C matrices. It contains some methods, such as `new` which creates a `R 1 CSShape` object from an explicitly specified R 1 CS matrix, `multiply_vec` which calculates the product of a matrix and a vector, `is_sat_relaxed` and `is_sat` which check whether a given witness and its shape satisfy the Relaxed R 1 CS instance and the R 1 CS instance, `commit_T` which calculates the commitment of the cross-term `T` of a given Relaxed R 1 CS instance-witness pair and R 1 CS instance-witness pair, and `pad` which pads the R 1 CSShape so that the number of variables is a power of 2 and renumbers the variables to fit the padded variables.


3. `R 1 CSWitness<G: Group>`: This structure represents the witness of a given R 1 CS instance, and includes methods such as `new` for creating witness objects with scalar vectors, and `commit` for committing witnesses using provided generators.


4. `R 1 CSInstance<G: Group>`: This structure represents an R 1 CS instance and includes methods such as `new` for creating instance objects using constituent elements.


5. `RelaxedR 1 CSWitness<G: Group>`: This structure represents the witness of a given Relaxed R 1 CS instance, and includes several methods such as `default` for generating a default RelaxedR 1 CSWitness, `from_r 1 cs_witness` for initializing a new RelaxedR 1 CSWitness from an existing R 1 CSWitness, `commit` for committing the witness using a provided generator, `fold` for folding an incoming R 1 CSWitness into the current witness, and `pad` for padding the provided witness to the correct length.


6. `RelaxedR 1 CSInstance`: This structure represents a Relaxed R 1 CS instance, which includes some methods such as `default` for generating the default RelaxedR 1 CSInstance, `from_r 1 cs_instance` for initializing a new RelaxedR 1 CSInstance from an R 1 CSInstance, `from_r1cs_instance_unchecked` for initializing a new RelaxedR 1 CSInstance from an R 1 CSInstance without checking, and `fold` for folding the incoming RelaxedR 1 CSInstance.


File Name: `src/spartan/math.rs`


This file defines a trait named `Math` and an implementation for the `usize` type. The trait defines several mathematical operations, including computing powers of 2, retrieving binary digits, and calculating logarithms.


1. The `Math` trait defines the following methods:


   - `pow 2(self) -> usize`: Calculate the power of 2 to the self-th power.


   - `get_bits(self, num_bits: usize) -> Vec<bool>`:Get the first num_bits bits of the binary representation of self .


   - `log_ 2(self) -> usize`: Calculate the logarithm of self base 2. The result is of type usize.


2. For the `usize` type, all methods implemented by the `Math` trait are available:


   - `pow 2(self) -> usize`: Calculate the power of 2 to the self using the built-in `pow` function. The result is returned as an unsigned integer.


   - `get_bits(self, num_bits: usize) -> Vec<bool>`:Get the first num_bits bits of the binary representation of self by using bit shifting and bitwise AND operations.


   - `log_ 2(self) -> usize`: If self is a power of 2, calculate the logarithm base 2 of self using the `leading_zeros` method. Otherwise, calculate the logarithm base 2 of self using the `leading_zeros` method and the `leading_zeros` method of the maximum value of `usize`.


This file provides some basic mathematical operations that may be used by other parts of the code to implement more complex functionality.


File name: src/spartan/mod.rs


This module implements the RelaxedR1CSSNARKTrait using Spartan. The Trait is a universal polynomial commitment and evaluation parameter (i.e. PCS).


Here are some main structures and functions:


1. `PolyEvalWitness`: This is a structure that contains a proof of a polynomial.


2. `PolyEvalInstance`: This is a struct that contains an instance of polynomial evaluation.


3. `ProverKey` and `VerifierKey`: These two structures respectively represent the prover's key and the verifier's key.


4. `RelaxedR 1 CSSNARK`: This structure represents a concise proof of knowledge for a relaxed R1CS instance. The proof is generated using Spartan's sum-check and vector commitment as a combination of polynomials.


5. `setup`: This function is used to set up proof and verification keys.


6. `prove`: This function is used to generate a succinct proof of satisfiability for a relaxed R1CS instance.


7. `verify`: This function is used to verify the satisfiability proof of a relaxed R1CS instance.


The code in this module mainly involves zero-knowledge proofs in cryptography, especially the proofs related to R1CS (Rank-1 Constraint Systems). R1CS is a system used to construct zero-knowledge proofs, which can be used to prove that a person knows the solution to a set of polynomial equations without revealing any information about the solution. Spartan is a specific zero-knowledge proof system that uses a "relaxed" R1CS, which allows for the use of randomness in the proof, thereby improving efficiency.


File Name: src/spartan/polynomial.rs


This file defines some basic types and operations related to polynomials. These types and operations are used to implement polynomial calculations in the Spartan protocol.


Here are some main parts of this file:


1. `EqPolynomial`: This structure represents an equation polynomial. It contains a method `new` for creating a new polynomial, a method `evaluate` for evaluating the polynomial at a specified point, and a method `evals` for computing the evaluations of the polynomial on all Boolean inputs.


2. `MultilinearPolynomial`: This structure represents a multilinear polynomial. It includes a method `new` for creating a new polynomial, a method `get_num_vars` for obtaining the number of variables in the polynomial, a method `bound_poly_var_top` for binding the variables of the polynomial to the top, and a method `evaluate` for evaluating the polynomial at a specified point.


3. `SparsePolynomial`: This structure represents a sparse polynomial. It contains a method `new` for creating a new polynomial and a method `evaluate` for evaluating the polynomial at a specified point.






2. `impl Preprocessor`: This is the implementation of the `Preprocessor` structure, which includes some methods.






7. `fn skip_comment(&mut self) -> Result<(), Error>`: This function is used to skip comments in the source code. If an error occurs during the process, it will return an error.


8. `fn read_number(&mut self) -> Result<Token, Error>`: This function is used to read a number from the source code. If an error occurs during the process, it will return an error.


9. `fn read_identifier(&mut self) -> Result<Token, Error>`: This function is used to read an identifier from the source code. If an error occurs during the process, it will return an error.


10. `fn read_string(&mut self) -> Result<Token, Error>`: This function is used to read a string from the source code. If an error occurs during the process, it will return an error.


Generally speaking, the `src/spartan/pp.rs` file implements the preprocessor in Nova, which preprocesses the source code, including skipping whitespace and comments, reading numbers, identifiers, and strings, etc.


File Name: src/spartan/sumcheck.rs


This file implements the Sumcheck algorithm in the Spartan protocol. The Sumcheck algorithm is a method used to verify polynomial summation and has widespread applications in zero-knowledge proof systems.


Here are some main parts of this file:


1. `SumcheckProof`: This structure represents a Sumcheck proof. It contains a method `new` for creating a new proof, a method `verify` for verifying the proof, and several `prove` methods for generating the proof.


2. `UniPoly` and `CompressedUniPoly`: These two structures represent univariate polynomials and compressed univariate polynomials. They contain methods for creating polynomials, evaluating polynomials, evaluating polynomials at specified points, as well as compressing and decompressing polynomials.



This file's code mainly involves the Sumcheck algorithm in cryptography, especially in regards to polynomial calculation and proof. These calculations play an important role in zero-knowledge proof systems, as they can be used to construct complex proofs without revealing any information about the proof.


File Name: src/traits/circuit.rs


This file defines a trait named `StepCircuit` and a struct named `TrivialTestCircuit` that implements this trait. Both the trait and the struct are related to the step function of incremental computation.


Here are some main parts of this file:


1. `StepCircuit` trait: This trait defines the methods that must be implemented for an incremental step function. These methods include:


   - `arity`: Returns the number of inputs or outputs for each step.


   - `synthesize`: Synthesizes a computational step and returns the variable corresponding to the output of the step.


   - `output`: Returns the output of the step when provided with input.


2. The `TrivialTestCircuit` structure: This structure implements the `StepCircuit` trait and simply returns the input. This structure may be used for testing or as a basic step function.


The code in this file mainly involves the step function of incremental calculation. In cryptography, incremental calculation is a common technique that can be used to gradually calculate complex functions without calculating the entire function at once. This technique is particularly useful in zero-knowledge proof systems because it can be used to construct complex proofs without generating the entire proof at once.


 File Name: src/traits/commitment.rs


This file defines some traits related to commitments. In cryptography, a commitment is a mechanism that allows a person to commit to a value without immediately revealing it. This is necessary in many cryptographic protocols, such as zero-knowledge proofs.


Here are some main parts of this file:


1. The `CommitmentOps` trait: This trait defines the basic operations of commitments, including addition and addition assignment.


2. The `CommitmentOpsOwned` trait: This trait defines basic operations for references that own commitments.


3. `ScalarMul` trait: This trait defines the multiplication operation between a commitment and a scalar.


4. `CommitmentTrait`: This trait defines the behavior of commitments, including cloning, copying, defaulting, comparing, sending, synchronizing, serializing, deserializing, absorbing, operating, compressing, decompressing, etc.


5. `CommitmentEngineTrait`: This trait binds together the different parts generated by commitments, including commitment keys, commitments, settings, and promises.



File Name: src/traits/evaluation.rs


This file defines a trait named `EvaluationEngineTrait`. This trait defines the behavior of a polynomial evaluation engine, including setting, proving, and verifying.



1. `EvaluationEngineTrait`: This trait defines the methods that a polynomial evaluation engine must implement. These methods include:


   - `setup`: This method is used for any additional setup required to generate the proof of evaluation.


   - `prove`: This method is used to prove the evaluation of a multilinear polynomial.


   - `verify`: This method is used to verify a proof of evaluation of a multilinear polynomial.


This trait also defines some associated types, including:


   - `CE`: This is a type associated with the commitment engine.


   - `ProverKey`: This is the type of prover key for proof generation.


   - `VerifierKey`: This is the type of verifier key.


   - `EvaluationArgument`: This is the type of evaluation parameter.


This file's code mainly involves polynomial evaluation in cryptography. This is an important step in zero-knowledge proof systems because it can be used to prove that a person knows a solution that satisfies a set of polynomial equations without revealing any information about the solution.


File Name: src/traits/mod.rs


This file is the main entry point for the traits module in the Nova project. It mainly defines some traits for cryptographic operations. Traits are a key feature in Rust, defining an abstract type that can be implemented by various concrete types. This allows us to write generic code that can handle values of any type that implements a specific trait.


Here are some main parts of this file:


1. `Group` Trait: This trait defines the basic operations of a group, including cloning, copying, default, comparison, sending, synchronization, serialization, deserialization, absorption, operation, compression, decompression, etc.


2. `CompressedGroup` trait: This trait defines the basic operations of a compressed group, including cloning, copying, comparing, sending, synchronizing, serializing, deserializing, etc.


3. `AbsorbInROTrait` trait: This trait defines a method `absorb_in_ro` that is used to absorb an object into a random oracle.


4. `ROTrait`: This trait defines the behavior of the random oracle, including initialization, absorption, and squeezing.


5. `ROConstantsTrait`: This trait defines the constants of the random oracle.


6. `GroupOps` trait: This trait defines group operations, including addition, subtraction, addition assignment, and subtraction assignment.


7. `ScalarMul` trait: This trait defines the scalar multiplication operation.


8. `TranscriptReprTrait` trait: This trait defines a method `to_transcript_bytes` that is used to convert an object to a byte sequence.


9. `TranscriptEngineTrait`: This trait defines the behavior of the transcription engine, including initialization, compression, absorption, and adding field delimiters.


This file's code mainly involves group operations, random oracles, and transcript engines in cryptography. These play important roles in zero-knowledge proof systems because they can be used to construct complex proofs without revealing any information about the proof.


File Name: src/traits/snark.rs


This file defines a trait named "RelaxedR1CSSNARKTrait". This trait defines the behavior of a zero-knowledge succinct non-interactive argument of knowledge (zkSNARK), specifically for relaxed rank-1 constraint systems (Relaxed Rank-1 Constraint Systems, Relaxed R 1 CS).


Here are some main parts of this file:


1. The `RelaxedR1CSSNARKTrait` trait: This trait defines the methods that a zkSNARK must implement. These methods include:


   - `setup`: This method is used to generate keys for the prover and verifier.


   - `prove`: This method is used to generate a succinct proof of satisfiability for a relaxed R1CS instance.



This trait also defines some associated types, including:


   - `ProverKey`: This is the type of prover key for proof generation.


   - `VerifierKey`: This is the type of verifier key.


The code in this file mainly involves zero-knowledge proofs in cryptography, especially the proof of R1CS. R1CS is a system used to construct zero-knowledge proofs, which can be used to prove that a person knows the solution to a set of polynomial equations without revealing any information about the solution. zkSNARK is a specific zero-knowledge proof system that provides an efficient method for generating and verifying proofs.


This article is from a submission and does not represent the views of BlockBeats.


欢迎加入律动 BlockBeats 官方社群:

Telegram 订阅群:https://t.me/theblockbeats

Telegram 交流群:https://t.me/BlockBeats_App

Twitter 官方账号:https://twitter.com/BlockBeatsAsia

Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit