Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize auxiliary trace building #271

Merged
merged 105 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
583bfc1
`AuxTraceBuilder`
plafer Apr 18, 2024
eedada2
AuxTraceElements associated types
plafer Apr 18, 2024
adfc935
fix `generate_proof()`
plafer Apr 18, 2024
ef13e12
fix all but tests
plafer Apr 18, 2024
ea0e7a6
Air: Make `AuxRandElements` generic over E
plafer Apr 19, 2024
7a06cb3
Prover: make `AuxRandElements` generic over E
plafer Apr 19, 2024
2519fa9
AuxTraceBuilder: make `AuxRandElements` generic over E
plafer Apr 19, 2024
1a06b9d
prover: fix Lagrange benchmark
plafer Apr 19, 2024
a134514
fix verifier
plafer Apr 19, 2024
40751af
fix comment
plafer Apr 19, 2024
ce25415
prover: add `prove_with_aux_trace()`
plafer Apr 19, 2024
60328de
prover: add `prove_with_aux_trace()`
plafer Apr 19, 2024
be9b0c3
verifier: remove dead code
plafer Apr 19, 2024
13ad3b6
fix prover benches
plafer Apr 19, 2024
59bfc15
Introduce `DefaultAuxTraceVerifier`
plafer Apr 19, 2024
fe2dfe9
fix test_complex_lagrange_kernel_air
plafer Apr 19, 2024
dd5a135
prove: remove <E>
plafer Apr 19, 2024
7e3e7ff
fmt
plafer Apr 19, 2024
10c17df
verifier: split `verify()` functions
plafer Apr 19, 2024
0f32099
fix fib_small example
plafer Apr 19, 2024
e22c3dd
fix examples
plafer Apr 19, 2024
5495886
winterfell exports
plafer Apr 19, 2024
58a37ef
fix rescue_raps example
plafer Apr 19, 2024
63063f3
fix verify_with_aux_trace
plafer Apr 19, 2024
d041dfa
fix rescue_raps
plafer Apr 19, 2024
64cec4e
Remove `AuxTraceRandElements`
plafer Apr 19, 2024
1ec3020
Remove `Trace::build_aux_segment()`
plafer Apr 19, 2024
536e27e
fix verifier
plafer Apr 20, 2024
6071dab
clippy
plafer Apr 20, 2024
e911a4b
E: Send + Sync
plafer Apr 20, 2024
c787454
fix doc tests`
plafer Apr 20, 2024
2d78070
fix doctests
plafer Apr 20, 2024
5fd32e9
docs
plafer Apr 20, 2024
8913301
Rename `AuxTraceVerifier`
plafer Apr 20, 2024
58bca4f
comment
plafer Apr 20, 2024
a0c46b8
`get_lagrange_rand_elements`: return `Vec<E>`
plafer Apr 29, 2024
e852a59
move `public_coin` method
plafer Apr 29, 2024
6526ba6
Merge remote-tracking branch 'upstream/next' into plafer-generalize-a…
plafer Apr 29, 2024
367a5d2
move AuxRandElementsGenerator to air crate
plafer Apr 29, 2024
cd7f09d
use `AuxRandElementsGenerator` in `AuxTraceBuilder`
plafer Apr 29, 2024
e78433c
Revert "use `AuxRandElementsGenerator` in `AuxTraceBuilder`"
plafer Apr 29, 2024
56aaefe
Revert "move AuxRandElementsGenerator to air crate"
plafer Apr 29, 2024
75f34d3
`AuxTraceVerifier`: take a proof object
plafer Apr 29, 2024
222ebe7
Remove unused function
plafer Apr 30, 2024
11a9ec9
remove `AuxParams` from `AuxTraceBuilder`
plafer Apr 30, 2024
bdee33e
fix prover
plafer May 1, 2024
e86a2e5
fix examples
plafer May 1, 2024
7a4a435
fix examples and tests
plafer May 1, 2024
616b7b8
Add comment
plafer May 1, 2024
d50d329
fix verifier
plafer May 1, 2024
77c7007
`new_aux_trace_builder` no longer returns an `Option`
plafer May 1, 2024
49295b2
`AuxTraceBuilder` no longer generic
plafer May 1, 2024
87df97e
fix verifier
plafer May 1, 2024
af4425b
fix doc tests
plafer May 1, 2024
f336a0e
nightly fmt
plafer May 1, 2024
805af6c
Prover: add `build_aux_trace` method
plafer May 1, 2024
e1e6a49
Move `AuxProof` to `Air`
plafer May 1, 2024
fc9f205
docstrings
plafer May 1, 2024
bdfed96
Rename prover type aliases
plafer May 2, 2024
8cb2262
Fix `build_aux_trace`, and document.
plafer May 2, 2024
b54df7b
fix docs links
plafer May 2, 2024
ca87245
fmt
plafer May 2, 2024
83bd95c
Document `prove()`, and reorganize where aux proof is documented
plafer May 2, 2024
0bcf668
move separator
plafer May 2, 2024
3d525c5
fix associated types order
plafer May 2, 2024
4a37c5e
simplify `new_evaluator` arg
plafer May 2, 2024
831db7c
Remove `aux_rands` from `TraceInfo`
plafer May 2, 2024
79a9995
nightly fmt
plafer May 2, 2024
6e37bd7
Fix trait bound
plafer May 2, 2024
86f2e4f
remove helper function
plafer May 2, 2024
2a49583
`trace::validate` now takes `aux_trace_with_metadata`
plafer May 2, 2024
8990c6d
clippy
plafer May 2, 2024
cf61f24
typo
plafer May 2, 2024
9b766a9
doc tests
plafer May 2, 2024
99c1230
new paragraph in docstring
plafer May 3, 2024
7eafebb
RescueRaps: fix variable name `num_aux_rand_elements`
plafer May 3, 2024
83fd926
Introduce `AirAuxTraceWithMetadata`
plafer May 3, 2024
393bed6
re-add `drop(span)`
plafer May 3, 2024
0eff5f4
nightly fmt
plafer May 3, 2024
cd7c4e2
LagrangeRandElements
plafer May 6, 2024
c5f00f9
new `AuxRandElements`
plafer May 6, 2024
b66749f
Revert "Remove `aux_rands` from `TraceInfo`"
plafer May 6, 2024
e4b323f
Add back `TraceInfo::get_num_aux_segment_rand_elements`
plafer May 6, 2024
80c22b3
Air::get_aux_rand_elements
plafer May 6, 2024
0b41bea
Add TODO
plafer May 6, 2024
ec24939
Rename `LagrangeKernelRandElements`
plafer May 6, 2024
b27406c
Add `Prover::generate_aux_proof()`
plafer May 6, 2024
535b2a4
prover: split `build_aux_trace`
plafer May 6, 2024
69cd04d
fix verifier/tests/examples. Renamed AuxTraceVerifier -> AuxProofVeri…
plafer May 6, 2024
550093b
Move `AuxProofVerifier` to air crate
plafer May 6, 2024
58f9fbc
merge both `verify()` functions
plafer May 6, 2024
9b14e84
cargo doc tests
plafer May 6, 2024
2257a1d
fmt
plafer May 6, 2024
a44b29f
`AuxProofVerifier` doesn't return Option
plafer May 6, 2024
ed67303
docs
plafer May 6, 2024
ea0913d
remove `DefaultAuxProofVerifier`
plafer May 6, 2024
ced4911
Rename `AuxProof` -> `GkrProof`
plafer May 6, 2024
5519996
swap all mentions of "auxiliary proof" for "GKR proof"
plafer May 6, 2024
3fc2ef6
docstrings
plafer May 6, 2024
24afc61
fix `RescueRapsProver`
plafer May 6, 2024
aca41f1
fix comment
plafer May 6, 2024
c40672a
fix comments
plafer May 6, 2024
760fd0c
Rename to `VerifierError::GkrProofVerificationFailed`
plafer May 6, 2024
f96d6cc
`gkr_proof` naming
plafer May 6, 2024
2ff51fa
Rename all `aux_proof` -> `gkr_proof`
plafer May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
light-checks:
name: Ligth checks
name: Light checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Prover for WorkProver {
fn new_evaluator<'a, E: FieldElement<BaseField = BaseElement>>(
&self,
air: &'a WorkAir,
aux_rand_elements: winterfell::AuxTraceRandElements<E>,
aux_rand_elements: Option<Self::AuxRandElements<E>>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E> {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
Expand All @@ -307,10 +307,10 @@ Now, we are finally ready to generate a STARK proof. The function below, will ex
```Rust
use winterfell::{
math::{fields::f128::BaseElement, FieldElement},
FieldExtension, HashFunction, ProofOptions, StarkProof,
FieldExtension, HashFunction, ProofOptions, Proof,
};

pub fn prove_work() -> (BaseElement, StarkProof) {
pub fn prove_work() -> (BaseElement, Proof) {
// We'll just hard-code the parameters here for this example.
let start = BaseElement::new(3);
let n = 1_048_576;
Expand Down Expand Up @@ -343,12 +343,12 @@ We can then give this proof (together with the public inputs) to anyone, and the
use winterfell::{
crypto::{hashers::Blake3_256, DefaultRandomCoin},
math::fields::f128::BaseElement,
verify, AcceptableOptions, StarkProof,
verify, AcceptableOptions, Proof,
};

type Blake3 = Blake3_256<BaseElement>;

pub fn verify_work(start: BaseElement, result: BaseElement, proof: StarkProof) {
pub fn verify_work(start: BaseElement, result: BaseElement, proof: Proof) {
// The verifier will accept proofs with parameters which guarantee 95 bits or more of
// conjectured security
let min_opts = AcceptableOptions::MinConjecturedSecurity(95);
Expand Down
2 changes: 1 addition & 1 deletion air/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ To describe Randomized AIR, you will need to do the following when implementing
4. Blowup factor - higher values increase proof security, but also increase proof generation time and proof size. However, higher blowup factors require fewer queries for the same security level. Thus, it is frequently possible to increase blowup factor and at the same time decrease the number of queries in such a way that the proofs become smaller.
5. Grinding factor - higher values increase proof security, but also may increase proof generation time.

See [options.rs](src/options.rs) for more info on currently available options and their meaning. Additionally, security level of a proof can be estimated using `StarkProof::security_level()` function.
See [options.rs](src/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.

## Crate features
This crate can be compiled with the following features:
Expand Down
90 changes: 90 additions & 0 deletions air/src/air/aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use alloc::{string::ToString, vec::Vec};
use crypto::{ElementHasher, RandomCoin, RandomCoinError};
use math::FieldElement;
use utils::Deserializable;

use super::lagrange::LagrangeKernelRandElements;

/// Holds the randomly generated elements necessary to build the auxiliary trace.
///
/// Specifically, [`AuxRandElements`] currently supports 2 types of random elements:
/// - the ones needed to build the Lagrange kernel column (when using GKR to accelerate LogUp),
/// - the ones needed to build all the other auxiliary columns
#[derive(Debug, Clone)]
pub struct AuxRandElements<E> {
rand_elements: Vec<E>,
lagrange: Option<LagrangeKernelRandElements<E>>,
}

impl<E> AuxRandElements<E> {
/// Creates a new [`AuxRandElements`], where the auxiliary trace doesn't contain a Lagrange
/// kernel column.
pub fn new(rand_elements: Vec<E>) -> Self {
Self {
rand_elements,
lagrange: None,
}
}

/// Creates a new [`AuxRandElements`], where the auxiliary trace contains a Lagrange kernel
/// column.
pub fn new_with_lagrange(
rand_elements: Vec<E>,
lagrange: Option<LagrangeKernelRandElements<E>>,
) -> Self {
Self {
rand_elements,
lagrange,
}
}

/// Returns the random elements needed to build all columns other than the Lagrange kernel one.
pub fn rand_elements(&self) -> &[E] {
&self.rand_elements
}

/// Returns the random elements needed to build the Lagrange kernel column.
pub fn lagrange(&self) -> Option<&LagrangeKernelRandElements<E>> {
self.lagrange.as_ref()
}
}

/// A trait for verifying a GKR proof.
///
/// Specifically, the use case in mind is proving the constraints of a LogUp bus using GKR, as
/// described in [Improving logarithmic derivative lookups using
/// GKR](https://eprint.iacr.org/2023/1284.pdf).
pub trait GkrVerifier {
/// The GKR proof.
type GkrProof: Deserializable;
/// The error that can occur during GKR proof verification.
type Error: ToString;

/// Verifies the GKR proof, and returns the random elements that were used in building
/// the Lagrange kernel auxiliary column.
fn verify<E, Hasher>(
&self,
gkr_proof: Self::GkrProof,
public_coin: &mut impl RandomCoin<BaseField = E::BaseField, Hasher = Hasher>,
) -> Result<LagrangeKernelRandElements<E>, Self::Error>
where
E: FieldElement,
Hasher: ElementHasher<BaseField = E::BaseField>;
}

impl GkrVerifier for () {
type GkrProof = ();
type Error = RandomCoinError;

fn verify<E, Hasher>(
&self,
_gkr_proof: Self::GkrProof,
_public_coin: &mut impl RandomCoin<BaseField = E::BaseField, Hasher = Hasher>,
) -> Result<LagrangeKernelRandElements<E>, Self::Error>
where
E: FieldElement,
Hasher: ElementHasher<BaseField = E::BaseField>,
{
Ok(LagrangeKernelRandElements::new(Vec::new()))
}
}
36 changes: 0 additions & 36 deletions air/src/air/coefficients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,6 @@
use alloc::vec::Vec;
use math::FieldElement;

// AUXILIARY TRACE SEGMENT RANDOMNESS
// ================================================================================================

/// Random elements used in construction of the auxiliary trace segment.
///
/// These elements are generated by the
/// [Air::get_aux_trace_segment_random_elements()](crate::Air::get_aux_trace_segment_random_elements)
/// function for each auxiliary trace segment. In the interactive version of the protocol, the
/// verifier draws these elements uniformly at random from the extension field of the protocol
/// after the prover commits to a previous trace segment.
#[derive(Debug, Clone)]
pub struct AuxTraceRandElements<E: FieldElement>(Vec<E>);

impl<E: FieldElement> AuxTraceRandElements<E> {
/// Instantiates and returns an empty set of random elements.
pub fn new() -> Self {
Self(Vec::new())
}

/// Returns a list of random elements for the auxiliary segment.
pub fn get_segment_elements(&self) -> &[E] {
&self.0
}

/// Sets the random elements associated with the auxiliary segment.
pub fn set_segment_elements(&mut self, rand_elements: Vec<E>) {
self.0 = rand_elements;
}
}

impl<E: FieldElement> Default for AuxTraceRandElements<E> {
fn default() -> Self {
Self::new()
}
}

// CONSTRAINT COMPOSITION COEFFICIENTS
// ================================================================================================
/// Coefficients used in construction of constraint composition polynomial.
Expand Down
11 changes: 7 additions & 4 deletions air/src/air/lagrange/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use math::FieldElement;

use crate::LagrangeKernelEvaluationFrame;
use crate::{LagrangeKernelEvaluationFrame, LagrangeKernelRandElements};

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct LagrangeKernelBoundaryConstraint<E>
Expand All @@ -21,7 +21,10 @@ where
E: FieldElement,
{
/// Creates a new Lagrange kernel boundary constraint.
pub fn new(composition_coefficient: E, lagrange_kernel_rand_elements: &[E]) -> Self {
pub fn new(
composition_coefficient: E,
lagrange_kernel_rand_elements: &LagrangeKernelRandElements<E>,
) -> Self {
Self {
assertion_value: Self::assertion_value(lagrange_kernel_rand_elements),
composition_coefficient,
Expand Down Expand Up @@ -57,9 +60,9 @@ where
}

/// Computes the assertion value given the provided random elements.
pub fn assertion_value(lagrange_kernel_rand_elements: &[E]) -> E {
pub fn assertion_value(lagrange_kernel_rand_elements: &LagrangeKernelRandElements<E>) -> E {
let mut assertion_value = E::ONE;
for &rand_ele in lagrange_kernel_rand_elements {
for &rand_ele in lagrange_kernel_rand_elements.as_ref() {
assertion_value *= E::ONE - rand_ele;
}

Expand Down
38 changes: 37 additions & 1 deletion air/src/air/lagrange/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// LICENSE file in the root directory of this source tree.

mod boundary;
use core::ops::Deref;

use alloc::vec::Vec;
pub use boundary::LagrangeKernelBoundaryConstraint;

mod frame;
Expand All @@ -26,7 +29,7 @@ impl<E: FieldElement> LagrangeKernelConstraints<E> {
/// Constructs a new [`LagrangeKernelConstraints`].
pub fn new(
lagrange_composition_coefficients: LagrangeConstraintsCompositionCoefficients<E>,
lagrange_kernel_rand_elements: &[E],
lagrange_kernel_rand_elements: &LagrangeKernelRandElements<E>,
lagrange_kernel_col_idx: usize,
) -> Self {
Self {
Expand All @@ -41,3 +44,36 @@ impl<E: FieldElement> LagrangeKernelConstraints<E> {
}
}
}

/// Holds the randomly generated elements needed to build the Lagrange kernel auxiliary column.
#[derive(Debug, Clone)]
pub struct LagrangeKernelRandElements<E> {
elements: Vec<E>,
}

impl<E> LagrangeKernelRandElements<E> {
/// Creates a new [`LagrangeKernelRandElements`].
pub fn new(elements: Vec<E>) -> Self {
Self { elements }
}
}

impl<E> Deref for LagrangeKernelRandElements<E> {
type Target = Vec<E>;

fn deref(&self) -> &Self::Target {
&self.elements
}
}

impl<E> AsRef<[E]> for LagrangeKernelRandElements<E> {
fn as_ref(&self) -> &[E] {
&self.elements
}
}

impl<E> From<LagrangeKernelRandElements<E>> for Vec<E> {
fn from(lagrange_rand_elements: LagrangeKernelRandElements<E>) -> Self {
lagrange_rand_elements.elements
}
}
Loading