winter_fri/lib.rs
1// Copyright (c) Facebook, Inc. and its affiliates.
2//
3// This source code is licensed under the MIT license found in the
4// LICENSE file in the root directory of this source tree.
5
6//! This crate contains an implementation of the FRI protocol used by the Winterfell STARK prover
7//! and verifier.
8//!
9//! FRI stands for Fast Reed-Solomon Interactive Oracle Proof of Proximity, and is used in the
10//! STARK protocol for low-degree testing. Specifically, given a commitment to a set of evaluations
11//! of some function over domain *D*, the verifier can be convinced that the function is a
12//! polynomial of degree at most *d*, by making a small number of queries to the commitment.
13//!
14//! # Proof generation
15//! FRI proofs are generated by a [FriProver] in two steps:
16//!
17//! 1. First, the commit phase of the protocol is executed via
18//! [build_layers()](prover::FriProver::build_layers()) function. During this phase, the degree
19//! of the polynomial is repeatedly reduced by applying a degree-respecting projection, until the
20//! size of the domain over which the polynomial is evaluated falls under `max_remainder_size`
21//! parameter. While performing the reduction, the prover writes a set of layer commitments into
22//! the [ProverChannel]. These commitments should be recorded and sent to the verifier as they
23//! will be needed during the proof verification procedure.
24//! 2. Then, the query phase of the protocol is executed via
25//! [build_proof()](prover::FriProver::build_proof()) function. The output of this function is an
26//! instance of the [FriProof] struct. When FRI is executed as a part of the STARK protocol, FRI
27//! proof is included into a STARK proof.
28//!
29//! When the crate is compiled with `concurrent` feature enabled, proof generation will be
30//! performed in multiple threads (usually, as many threads as there are logical cores on the
31//! machine). The number of threads can be configured via `RAYON_NUM_THREADS` environment variable.
32//!
33//! # Proof verification
34//! FRI proofs are verified by a [FriVerifier] as follows:
35//! 1. First, a FRI proof needs to be converted into a [VerifierChannel]. This crate provides a
36//! default implementation of the verifier channel, but when FRI proof verification is executed
37//! as a part of the larger STARK protocol, STARK verifier handles this conversion.
38//! 2. Then, a [FriVerifier] should be instantiated (via [new()](FriVerifier::new()) function). This
39//! will execute the commit phase of the FRI protocol from the verifier's perspective - i.e., the
40//! verifier will read FRI layer commitments from the channel, and generates random values needed
41//! for layer folding.
42//! 3. Finally, the query phase of the FRI protocol should be executed via
43//! [verify()](FriVerifier::verify()) function. Note that query values at the first FRI layer are
44//! provided to the [verify()](FriVerifier::verify()) function directly. The values at remaining
45//! layers, the verifier reads from the specified verifier channel.
46//!
47//! # Protocol parameters
48//! The current implementation supports executing FRI protocol with dynamically configurable
49//! parameters including:
50//!
51//! * Base STARK field,
52//! * Extension field,
53//! * Domain blowup factor,
54//! * Hash function (used for building vector commitments),
55//! * Folding factor (used for degree reduction for each FRI layer),
56//! * Maximum size of the last FRI layer.
57//!
58//! # References
59//! * StarkWare's blog post on [Low Degree Testing](https://medium.com/starkware/low-degree-testing-f7614f5172db)
60//! * [Fast Reed-Solomon Interactive Oracle Proofs of Proximity](https://eccc.weizmann.ac.il/report/2017/134/)
61//! * [DEEP-FRI: Sampling Outside the Box Improves Soundness](https://eprint.iacr.org/2019/336)
62//! * Swastik Kooparty's [talk on DEEP-FRI](https://www.youtube.com/watch?v=txo_kPSn59Y&list=PLcIyXLwiPilWvjvNkhMn283LV370Pk5CT&index=6)
63
64#![no_std]
65
66#[macro_use]
67extern crate alloc;
68
69pub mod folding;
70
71mod prover;
72pub use prover::{DefaultProverChannel, FriProver, ProverChannel};
73
74mod verifier;
75pub use verifier::{DefaultVerifierChannel, FriVerifier, VerifierChannel};
76
77mod options;
78pub use options::FriOptions;
79
80mod proof;
81pub use proof::FriProof;
82
83mod errors;
84pub use errors::VerifierError;
85
86pub mod utils;