Crates.io | winter-air |
lib.rs | winter-air |
version | 0.10.1 |
source | src |
created_at | 2021-08-04 06:44:58.233288 |
updated_at | 2024-10-30 15:08:47.816189 |
description | AIR components for the Winterfell STARK prover/verifier |
homepage | |
repository | https://github.com/novifinancial/winterfell |
max_upload_size | |
id | 431410 |
size | 277,224 |
This crate contains components needed to describe arbitrary computations in a STARK-specific format.
Before we can generate proofs attesting that some computations were executed correctly, we need to reduce these computations to algebraic statements involving a set of bounded-degree polynomials. This step is usually called arithmetization. For basics of AIR arithmetization please refer to the excellent posts from StarkWare:
Coming up with efficient arithmetizations for computations is highly non-trivial, and describing arithmetizations could be tedious and error-prone. Air
trait aims to help with the latter, which, hopefully, also makes the former a little simpler.
To define AIR for a given computation, you'll need to implement the Air
trait which involves the following:
BaseField
associated type (see math crate for available field options).PublicInputs
associated type.Air::new()
function. As a part of this function you should create a AirContext
struct which takes degrees for all transition constraints as one of the constructor parameters.context()
method which should return a reference to the AirContext
struct created in Air::new()
function.evaluate_transition()
method which should evaluate transition constraints over a given evaluation frame.get_assertions()
method which should return a vector of assertions for a given instance of your computation.get_periodic_column_values()
method.For more information, take a look at the definition at the Air trait and check out examples crate which illustrates how to implement the trait for a several different computations.
Transition constraints define algebraic relations between two consecutive steps of a computation. In Winterfell, transition constraints are evaluated inside evaluate_transition()
function which takes the following parameters:
&EvaluationFrame<FieldElement>
, which contains vectors with current and next states of the computation.&[FieldElement]
, when periodic columns are defined for a computation, this will contain values of periodic columns at the current step of the computation. Otherwise, this will be an empty slice.&mut [FieldElement]
, this is the slice where constraint evaluation results should be written to.The constraints are considered to be satisfied if and only if, after the function returns, the result
slice contains all zeros. In general, it is important for the transition constraint evaluation function to work as follows:
Keep in mind is that since transition constraints define algebraic relations, they should be described using only algebraic operations: additions, subtractions, and multiplications (divisions can be emulated using inverse of multiplication).
One of the main factors impacting proof generation time and proof size is the maximum degree of transition constraints. The higher is this degree, the larger our blowup factor needs to be. Usually, we want to keep this degree as low as possible - e.g. under 4 or 8. To accurately describe degrees of your transition constraints, keep the following in mind:
1
.1
. For example, if our constraint involves multiplication of two columns, the degree of this constraint will be 2
. We can describe this constraint using TransitionConstraintDegree
struct as follows: TransitionConstraintDegree::new(2)
.1
.with_cycles()
constructor of TransitionConstraintDegree
struct. For example, if our constraint involves multiplication of one trace column and one periodic column with a cycle of 32 steps, the degree can be described as: TransitionConstraintDegree::with_cycles(1, vec![32])
.In general, multiplications should be used judiciously - though, there are ways to ease this restriction a bit (check out mulfib8 example).
Assertions are used to specify that a valid execution trace of a computation must contain certain values in certain cells. They are frequently used to tie public inputs to a specific execution trace, but can be used to constrain a computation in other ways as well. Internally within Winterfell, assertions are converted into boundary constraints.
To define assertions for your computation, you'll need to implement get_assertions()
function of the Air
trait. Every computation must have at least one assertion. Assertions can be of the following types:
For more information on how to define assertions see the assertions module and check out the examples in the examples crate.
Sometimes, it may be useful to define a column in an execution trace which contains a set of repeating values. For example, let's say we have a column which contains value 1 on every 4th step, and 0 otherwise. Such a column can be described with a simple periodic sequence of [1, 0, 0, 0]
.
To define such columns for your computation, you can override get_periodic_column_values()
method of the Air
trait. The values of the periodic columns at a given step of the computation will be supplied to the evaluate_transition()
method via the periodic_values
parameter.
Randomized AIR is a powerful extension of AIR which enables, among other things, multiset and permutation checks similar to the ones available in PLONKish systems. These, in turn, allow efficient descriptions of "non-local" constraints which can be used to build such components as efficient range checks, random access memory, and many others.
With Randomized AIR, construction of the execution trace is split into multiple stages. During the first stage, the main trace segment is built in a manner similar to how the trace is built for regular AIR. In the subsequent stages, auxiliary trace segment is built. When building the auxiliary trace segment, the prover has access to extra randomness sent by the verifier (in the non-interactive version of the protocol, this randomness is derived from the previous trace segment commitments).
To describe Randomized AIR, you will need to do the following when implementing the Air
trait:
AirContext
struct returned from Air::context()
method must be instantiated using AirContext::new_multi_segment()
constructor. When building AIR context in this way, you will need to provide a TraceLayout
which describes the shape of a multi-segment execution trace.Air::evaluate_aux_transition()
method. This method is similar to the Air::evaluate_transition()
method but it also accepts two extra parameters: aux_evaluation_frame
and aux_rand_elements
. These parameters are needed for evaluating transition constraints over the auxiliary trace segment.Air::get_aux_assertions()
method. This method is similar to the Air::get_assertions()
method, but it should return assertions against columns of the auxiliary trace segment.ProofOptions
struct defines a set of options which are used during STARK proof generation and verification. These options have a direct impact on the security of the generated proofs as well as the proof generation time. Specifically, security of STARK proofs depends on:
See options.rs for more info on currently available options and their meaning. Additionally, security level of a proof can be estimated using Proof::security_level()
function.
This crate can be compiled with the following features:
std
- enabled by default and relies on the Rust standard library.no_std
- does not rely on the Rust standard library and enables compilation to WebAssembly.To compile with no_std
, disable default features via --no-default-features
flag.
This project is MIT licensed.