Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c317f96
wip: change to bitreverse representation of MLE. Periodic columns exa…
Al-Kindi-0 Sep 23, 2024
b773f59
fix: parallel sum-check + periodic test failing
Al-Kindi-0 Sep 25, 2024
8eef5a7
wip
Al-Kindi-0 Sep 23, 2024
1c594cd
wip: POC parallel circuits w/o periodic columns support
Al-Kindi-0 Sep 23, 2024
3ea525d
fix: use with_capacity
Al-Kindi-0 Sep 23, 2024
6fcab17
wip: bring back concurrency
Al-Kindi-0 Sep 23, 2024
e0cae3f
batch hashing and move circuit layer to sum-check
Al-Kindi-0 Sep 23, 2024
e75d47e
wip: move CircuitLayerPoly to sum-check crate
Al-Kindi-0 Sep 23, 2024
3c8e1aa
wip: improve parallelism
Al-Kindi-0 Sep 24, 2024
db25786
cleanup: parallel for degree 3 sum-check
Al-Kindi-0 Sep 24, 2024
46e4ab2
fix: add with capacity
Al-Kindi-0 Sep 24, 2024
9fd2f23
fix nameing
Al-Kindi-0 Sep 24, 2024
b8899c0
after rebase
Al-Kindi-0 Sep 25, 2024
38bc6ba
added targeted bench for LogUp-GKR
Al-Kindi-0 Sep 25, 2024
2a51690
added targeted bench for LogUp-GKR
Al-Kindi-0 Sep 25, 2024
78a2bf9
lower threshold for parallelization
Al-Kindi-0 Sep 25, 2024
162ab07
feat: add parallel MLEs building
Al-Kindi-0 Sep 25, 2024
6d86956
feat: parallel s-column construction
Al-Kindi-0 Sep 25, 2024
a976bfb
wip: reduce degree in parallel GKR
Al-Kindi-0 Sep 25, 2024
13cf622
fix parallel plain sum-check
Al-Kindi-0 Sep 25, 2024
7f03a06
wip: plain sumcheck failing
Al-Kindi-0 Sep 26, 2024
cbc20d5
fix: sum-check failing
Al-Kindi-0 Sep 26, 2024
79f5b29
wip: optimize input layer generation
Al-Kindi-0 Sep 26, 2024
e6ade30
added example for logup-gkr
Al-Kindi-0 Sep 25, 2024
9efa494
increase logup-gkr example
Al-Kindi-0 Sep 26, 2024
d4da930
fix: clippy
Al-Kindi-0 Sep 26, 2024
7c1a4c1
wip
Al-Kindi-0 Sep 30, 2024
fce45c8
wip
Al-Kindi-0 Sep 30, 2024
c2bdd11
reduce size of example
Al-Kindi-0 Sep 30, 2024
6355ea5
feat: parallel input layer construction
Al-Kindi-0 Sep 30, 2024
988c9da
feat: remove restriction power of two number of fractions
Al-Kindi-0 Sep 30, 2024
22dac0a
fix: verifier check
Al-Kindi-0 Sep 30, 2024
7baa593
debug: add print statements
Al-Kindi-0 Sep 30, 2024
366881e
wip
Al-Kindi-0 Sep 30, 2024
90522e7
wip
Al-Kindi-0 Sep 30, 2024
10be06e
wip
Al-Kindi-0 Sep 30, 2024
ef922b3
wip
Al-Kindi-0 Sep 30, 2024
ea5878b
wip
Al-Kindi-0 Oct 1, 2024
4e6a6f4
wip
Al-Kindi-0 Oct 1, 2024
5e3aa34
wip
Al-Kindi-0 Oct 1, 2024
8eff9d9
feat: improve deg 3 sum-check
Al-Kindi-0 Oct 1, 2024
23af937
debug
Al-Kindi-0 Oct 1, 2024
1b73180
debug
Al-Kindi-0 Oct 1, 2024
b399be5
debug
Al-Kindi-0 Oct 1, 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
1 change: 1 addition & 0 deletions air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fri = { version = "0.9", path = "../fri", package = "winter-fri", default-featur
libm = "0.2.8"
math = { version = "0.9", path = "../math", package = "winter-math", default-features = false }
utils = { version = "0.9", path = "../utils/core", package = "winter-utils", default-features = false }
libc-print = "0.1.23"

[dev-dependencies]
rand-utils = { version = "0.9", path = "../utils/rand", package = "winter-rand-utils" }
Expand Down
6 changes: 6 additions & 0 deletions air/src/air/logup_gkr/lagrange/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ impl<E: FieldElement> LagrangeKernelTransitionConstraints<E> {
let c = lagrange_kernel_column_frame;
let v = c.num_rows() - 1;
let r = lagrange_kernel_rand_elements;
// TODO: avoid reverse()
let mut r = r.to_vec();
r.reverse();
let k = constraint_idx + 1;

(r[v - k] * c[0]) - ((E::ONE - r[v - k]) * c[v - k + 1])
Expand Down Expand Up @@ -130,6 +133,9 @@ impl<E: FieldElement> LagrangeKernelTransitionConstraints<E> {
let c = lagrange_kernel_column_frame;
let v = c.num_rows() - 1;
let r = lagrange_kernel_rand_elements;
// TODO: avoid reverse()
let mut r = r.to_vec();
r.reverse();

for k in 1..v + 1 {
transition_evals[k - 1] = (r[v - k] * c[0]) - ((E::ONE - r[v - k]) * c[v - k + 1]);
Expand Down
26 changes: 18 additions & 8 deletions air/src/air/logup_gkr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,33 @@ pub trait LogUpGkrEvaluator: Clone + Sync {
/// [1]: https://eprint.iacr.org/2023/1284
fn generate_univariate_iop_for_multi_linear_opening_data<E, H>(
&self,
openings: Vec<E>,
openings: Vec<Vec<E>>,
eval_point: Vec<E>,
public_coin: &mut impl RandomCoin<Hasher = H, BaseField = E::BaseField>,
) -> GkrData<E>
where
E: FieldElement<BaseField = Self::BaseField>,
H: ElementHasher<BaseField = E::BaseField>,
{
let openings: Vec<E> =
openings[0].clone().chunks(2).flat_map(|ops| [ops[0], ops[1]]).collect();
public_coin.reseed(H::hash_elements(&openings));

let folding_randomness: E = public_coin.draw().expect("failed to generate randomness");
let batched_openings: Vec<E> =
openings.chunks(2).map(|p| p[0] + folding_randomness * (p[1] - p[0])).collect();

let mut batching_randomness = Vec::with_capacity(openings.len() - 1);
for _ in 0..openings.len() - 1 {
batching_randomness.push(public_coin.draw().expect("failed to generate randomness"))
}
let mut eval_point = eval_point;
eval_point.push(folding_randomness);

GkrData::new(
LagrangeKernelRandElements::new(eval_point),
batching_randomness,
openings,
batched_openings,
self.get_oracles().to_vec(),
)
}
Expand Down Expand Up @@ -156,7 +164,7 @@ pub trait LogUpGkrEvaluator: Clone + Sync {
/// Returns the periodic values used in the LogUp-GKR statement, either as base field element
/// during circuit evaluation or as extension field element during the run of sum-check for
/// the input layer.
fn build_periodic_values<E>(&self) -> PeriodicTable<E>
fn build_periodic_values<E>(&self, num_rows: usize) -> PeriodicTable<E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand All @@ -166,7 +174,7 @@ pub trait LogUpGkrEvaluator: Clone + Sync {
.map(|values| values.iter().map(|x| E::from(*x)).collect())
.collect();

PeriodicTable { table }
PeriodicTable { table, num_rows }
}
}

Expand Down Expand Up @@ -264,16 +272,17 @@ pub enum LogUpGkrOracle {
#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Eq, Ord)]
pub struct PeriodicTable<E: FieldElement> {
pub table: Vec<Vec<E>>,
pub num_rows: usize,
}

impl<E> PeriodicTable<E>
where
E: FieldElement,
{
pub fn new(table: Vec<Vec<E::BaseField>>) -> Self {
pub fn new(table: Vec<Vec<E::BaseField>>, num_rows: usize) -> Self {
let table = table.iter().map(|col| col.iter().map(|x| E::from(*x)).collect()).collect();

Self { table }
Self { table, num_rows }
}

pub fn num_columns(&self) -> usize {
Expand All @@ -293,13 +302,14 @@ where

pub fn bind_least_significant_variable(&mut self, round_challenge: E) {
for col in self.table.iter_mut() {
if col.len() > 1 {
if col.len() > 1 && self.num_rows <= col.len() {
let num_evals = col.len() >> 1;
for i in 0..num_evals {
col[i] = col[i << 1] + round_challenge * (col[(i << 1) + 1] - col[i << 1]);
col[i] = col[i] + round_challenge * (col[i + num_evals] - col[i]);
}
col.truncate(num_evals)
}
}
self.num_rows /= 2;
}
}
8 changes: 7 additions & 1 deletion examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use winterfell::{
math::fields::f128::BaseElement,
FieldExtension, Proof, ProofOptions, VerifierError,
};

pub mod fibonacci;
#[cfg(feature = "std")]
pub mod lamport;
pub mod logup_gkr;
#[cfg(feature = "std")]
pub mod merkle;
pub mod rescue;
Expand Down Expand Up @@ -198,6 +198,12 @@ pub enum ExampleType {
#[structopt(short = "n", default_value = "3")]
num_signers: usize,
},
/// LogUp-GKR
LogUpGkr {
/// Length of the trace; must be a power of two
#[structopt(short = "n", default_value = "65536")]
trace_length: usize,
},
}

/// Defines a set of hash functions available for the provided examples. Some examples may not
Expand Down
172 changes: 172 additions & 0 deletions examples/src/logup_gkr/air.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use std::marker::PhantomData;

use winterfell::{
math::{fields::f64::BaseElement, ExtensionOf, FieldElement, StarkField},
Air, AirContext, Assertion, AuxRandElements, EvaluationFrame, LogUpGkrEvaluator,
LogUpGkrOracle, TraceInfo, TransitionConstraintDegree,
};

use super::ProofOptions;

pub const NUM_FRACTIONS: usize = 64;

pub(crate) struct LogUpGkrSimpleAir {
context: AirContext<BaseElement, ()>,
}

impl Air for LogUpGkrSimpleAir {
type BaseField = BaseElement;
type PublicInputs = ();

fn new(trace_info: TraceInfo, _pub_inputs: Self::PublicInputs, options: ProofOptions) -> Self {
Self {
context: AirContext::new_multi_segment(
trace_info,
_pub_inputs,
vec![TransitionConstraintDegree::new(1)],
vec![],
1,
0,
options,
),
}
}

fn context(&self) -> &AirContext<Self::BaseField, ()> {
&self.context
}

fn evaluate_transition<E: FieldElement<BaseField = Self::BaseField>>(
&self,
frame: &EvaluationFrame<E>,
_periodic_values: &[E],
result: &mut [E],
) {
let current = frame.current()[0];
let next = frame.next()[0];

// increments by 1
result[0] = next - current - E::ONE;
}

fn get_assertions(&self) -> Vec<Assertion<Self::BaseField>> {
vec![Assertion::single(0, 0, BaseElement::ZERO)]
}

fn evaluate_aux_transition<F, E>(
&self,
_main_frame: &EvaluationFrame<F>,
_aux_frame: &EvaluationFrame<E>,
_periodic_values: &[F],
_aux_rand_elements: &AuxRandElements<E>,
_result: &mut [E],
) where
F: FieldElement<BaseField = Self::BaseField>,
E: FieldElement<BaseField = Self::BaseField> + ExtensionOf<F>,
{
// do nothing
}

fn get_aux_assertions<E: FieldElement<BaseField = Self::BaseField>>(
&self,
_aux_rand_elements: &AuxRandElements<E>,
) -> Vec<Assertion<E>> {
vec![]
}

fn get_logup_gkr_evaluator(
&self,
) -> impl LogUpGkrEvaluator<BaseField = Self::BaseField, PublicInputs = Self::PublicInputs>
{
PlainLogUpGkrEval::new()
}
}

#[derive(Clone, Default)]
pub struct PlainLogUpGkrEval<B: FieldElement + StarkField> {
oracles: Vec<LogUpGkrOracle>,
_field: PhantomData<B>,
}

impl<B: FieldElement + StarkField> PlainLogUpGkrEval<B> {
pub fn new() -> Self {
let committed_0 = LogUpGkrOracle::CurrentRow(0);
let committed_1 = LogUpGkrOracle::CurrentRow(1);
let committed_2 = LogUpGkrOracle::CurrentRow(2);
let committed_3 = LogUpGkrOracle::CurrentRow(3);
let committed_4 = LogUpGkrOracle::CurrentRow(4);
let oracles = vec![committed_0, committed_1, committed_2, committed_3, committed_4];
Self { oracles, _field: PhantomData }
}
}

impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
type BaseField = BaseElement;

type PublicInputs = ();

fn get_oracles(&self) -> &[LogUpGkrOracle] {
&self.oracles
}

fn get_num_rand_values(&self) -> usize {
1
}

fn get_num_fractions(&self) -> usize {
NUM_FRACTIONS
}

fn max_degree(&self) -> usize {
10
}

fn build_query<E>(&self, frame: &EvaluationFrame<E>, query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
query.iter_mut().zip(frame.current().iter()).for_each(|(q, f)| *q = *f)
}

fn evaluate_query<F, E>(
&self,
query: &[F],
_periodic_values: &[F],
rand_values: &[E],
numerator: &mut [E],
denominator: &mut [E],
) where
F: FieldElement<BaseField = Self::BaseField>,
E: FieldElement<BaseField = Self::BaseField> + ExtensionOf<F>,
{
assert_eq!(numerator.len(), self.get_num_fractions());
assert_eq!(denominator.len(), self.get_num_fractions());
assert_eq!(query.len(), 5);

for i in (0..self.get_num_fractions()).step_by(4) {
numerator[i] = E::from(query[1]);
numerator[i + 1] = E::ONE;
numerator[i + 2] = E::ONE;
numerator[i + 3] = E::ONE;
}

for i in (0..self.get_num_fractions()).step_by(4) {
denominator[i] = rand_values[0] - E::from(query[0]);
denominator[i + 1] = -(rand_values[0] - E::from(query[2]));
denominator[i + 2] = -(rand_values[0] - E::from(query[3]));
denominator[i + 3] = -(rand_values[0] - E::from(query[4]));
}
}

fn compute_claim<E>(&self, _inputs: &Self::PublicInputs, _rand_values: &[E]) -> E
where
E: FieldElement<BaseField = Self::BaseField>,
{
E::ZERO
}
}
Loading