Skip to content

Commit

Permalink
merged with v0.2.3 from 0xPolygonZero
Browse files Browse the repository at this point in the history
  • Loading branch information
dloghin committed Aug 8, 2024
2 parents 5b3bada + 76da138 commit 5a8b6a3
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 99 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.3] - 2024-04-16

- Code refactoring ([#1558](https://github.com/0xPolygonZero/plonky2/pull/1558))
- Simplify types: remove option from CTL filters ([#1567](https://github.com/0xPolygonZero/plonky2/pull/1567))
- Add stdarch_x86_avx512 feature ([#1566](https://github.com/0xPolygonZero/plonky2/pull/1566))

## [0.2.2] - 2024-03-21

### Changed
Expand Down
2 changes: 1 addition & 1 deletion field/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "plonky2_field"
description = "Finite field arithmetic"
version = "0.2.1"
version = "0.2.2"
authors = ["Daniel Lubarov <[email protected]>", "William Borgeaud <[email protected]>", "Jacqueline Nabaglo <[email protected]>", "Hamish Ivey-Law <[email protected]>"]
edition.workspace = true
license.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions field/src/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn fft_dispatch_cpu<F: Field>(
zero_factor: Option<usize>,
root_table: Option<&FftRootTable<F>>,
) {
/*
if root_table.is_some() {
return fft_classic(input, zero_factor.unwrap_or(0), root_table.unwrap());
} else {
Expand All @@ -68,6 +69,11 @@ fn fft_dispatch_cpu<F: Field>(
return fft_classic(input, zero_factor.unwrap_or(0), computed.as_ref());
};
*/
let computed_root_table = root_table.is_none().then(|| fft_root_table(input.len()));
let used_root_table = root_table.or(computed_root_table.as_ref()).unwrap();

fft_classic(input, zero_factor.unwrap_or(0), used_root_table);
}

#[inline]
Expand Down
1 change: 1 addition & 0 deletions field/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(missing_debug_implementations)]
#![feature(specialization)]
#![cfg_attr(target_arch = "x86_64", feature(stdarch_x86_avx512))]
#![cfg_attr(not(test), no_std)]
#![cfg(not(test))]
extern crate alloc;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "plonky2"
description = "Recursive SNARKs based on PLONK and FRI"
version = "0.2.1"
version = "0.2.2"
authors = ["Daniel Lubarov <[email protected]>", "William Borgeaud <[email protected]>", "Nicholas Ward <[email protected]>"]
readme = "README.md"
edition.workspace = true
Expand Down Expand Up @@ -41,7 +41,7 @@ once_cell = { version = "1.18.0" }
papi-bindings = { version = "0.5.2" }

# Local dependencies
plonky2_field = { version = "0.2.1", path = "../field", default-features = false }
plonky2_field = { version = "0.2.2", path = "../field", default-features = false }
plonky2_maybe_rayon = { version = "0.2.0", path = "../maybe_rayon", default-features = false }
plonky2_util = { version = "0.2.0", path = "../util", default-features = false }
cryptography_cuda = { workspace = true, optional = true }
Expand Down
1 change: 0 additions & 1 deletion plonky2/src/gates/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloc::{
vec,
vec::Vec,
};
use core::usize;

use itertools::Itertools;
use keccak_hash::keccak;
Expand Down
1 change: 0 additions & 1 deletion plonky2/src/gates/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use alloc::{
vec,
vec::Vec,
};
use core::usize;
#[cfg(feature = "std")]
use std::sync::Arc;

Expand Down
1 change: 1 addition & 0 deletions plonky2/src/plonk/copy_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::iop::target::Target;
#[derive(Debug, Clone)]
pub struct CopyConstraint {
pub pair: (Target, Target),
#[allow(dead_code)]
pub name: String,
}

Expand Down
4 changes: 2 additions & 2 deletions starky/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "starky"
description = "Implementation of STARKs"
version = "0.3.0"
version = "0.4.0"
authors = ["Daniel Lubarov <[email protected]>", "William Borgeaud <[email protected]>"]
readme = "README.md"
edition.workspace = true
Expand All @@ -26,7 +26,7 @@ log = { workspace = true }
num-bigint = { version = "0.4.3", default-features = false }

# Local dependencies
plonky2 = { version = "0.2.1", path = "../plonky2", default-features = false }
plonky2 = { version = "0.2.2", path = "../plonky2", default-features = false }
plonky2_maybe_rayon = { version = "0.2.0", path = "../maybe_rayon", default-features = false }
plonky2_util = { version = "0.2.0", path = "../util", default-features = false }

Expand Down
58 changes: 14 additions & 44 deletions starky/src/cross_table_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ pub type TableIdx = usize;
pub struct TableWithColumns<F: Field> {
table: TableIdx,
columns: Vec<Column<F>>,
filter: Option<Filter<F>>,
filter: Filter<F>,
}

impl<F: Field> TableWithColumns<F> {
/// Generates a new `TableWithColumns` given a `table` index, a linear combination of columns `columns` and a `filter`.
pub fn new(table: TableIdx, columns: Vec<Column<F>>, filter: Option<Filter<F>>) -> Self {
pub fn new(table: TableIdx, columns: Vec<Column<F>>, filter: Filter<F>) -> Self {
Self {
table,
columns,
Expand Down Expand Up @@ -163,7 +163,7 @@ pub struct CtlZData<'a, F: Field> {
pub(crate) columns: Vec<&'a [Column<F>]>,
/// Vector of filter columns for the current table.
/// Each filter evaluates to either 1 or 0.
pub(crate) filter: Vec<Option<Filter<F>>>,
pub(crate) filter: Vec<Filter<F>>,
}

impl<'a, F: Field> CtlZData<'a, F> {
Expand All @@ -173,7 +173,7 @@ impl<'a, F: Field> CtlZData<'a, F> {
z: PolynomialValues<F>,
challenge: GrandProductChallenge<F>,
columns: Vec<&'a [Column<F>]>,
filter: Vec<Option<Filter<F>>>,
filter: Vec<Filter<F>>,
) -> Self {
Self {
helper_columns,
Expand Down Expand Up @@ -404,7 +404,7 @@ fn ctl_helper_zs_cols<F: Field, const N: usize>(
.map(|(table, group)| {
let columns_filters = group
.map(|table| (&table.columns[..], &table.filter))
.collect::<Vec<(&[Column<F>], &Option<Filter<F>>)>>();
.collect::<Vec<(&[Column<F>], &Filter<F>)>>();
(
table,
partial_sums(
Expand Down Expand Up @@ -484,7 +484,7 @@ where
/// Column linear combinations of the `CrossTableLookup`s.
pub(crate) columns: Vec<&'a [Column<F>]>,
/// Filter that evaluates to either 1 or 0.
pub(crate) filter: Vec<Option<Filter<F>>>,
pub(crate) filter: Vec<Filter<F>>,
}

impl<'a, F: RichField + Extendable<D>, const D: usize>
Expand Down Expand Up @@ -682,16 +682,8 @@ pub(crate) fn eval_cross_table_lookup_checks<F, FE, P, S, const D: usize, const
let combin0 = challenges.combine(&evals[0]);
let combin1 = challenges.combine(&evals[1]);

let f0 = if let Some(filter0) = &filter[0] {
filter0.eval_filter(local_values, next_values)
} else {
P::ONES
};
let f1 = if let Some(filter1) = &filter[1] {
filter1.eval_filter(local_values, next_values)
} else {
P::ONES
};
let f0 = filter[0].eval_filter(local_values, next_values);
let f1 = filter[1].eval_filter(local_values, next_values);

consumer
.constraint_last_row(combin0 * combin1 * *local_z - f0 * combin1 - f1 * combin0);
Expand All @@ -700,11 +692,7 @@ pub(crate) fn eval_cross_table_lookup_checks<F, FE, P, S, const D: usize, const
);
} else {
let combin0 = challenges.combine(&evals[0]);
let f0 = if let Some(filter0) = &filter[0] {
filter0.eval_filter(local_values, next_values)
} else {
P::ONES
};
let f0 = filter[0].eval_filter(local_values, next_values);
consumer.constraint_last_row(combin0 * *local_z - f0);
consumer.constraint_transition(combin0 * (*local_z - *next_z) - f0);
}
Expand All @@ -726,7 +714,7 @@ pub struct CtlCheckVarsTarget<F: Field, const D: usize> {
/// Column linear combinations of the `CrossTableLookup`s.
pub(crate) columns: Vec<Vec<Column<F>>>,
/// Filter that evaluates to either 1 or 0.
pub(crate) filter: Vec<Option<Filter<F>>>,
pub(crate) filter: Vec<Filter<F>>,
}

impl<'a, F: Field, const D: usize> CtlCheckVarsTarget<F, D> {
Expand Down Expand Up @@ -856,8 +844,6 @@ pub(crate) fn eval_cross_table_lookup_checks_circuit<
let local_values = vars.get_local_values();
let next_values = vars.get_next_values();

let one = builder.one_extension();

for lookup_vars in ctl_vars {
let CtlCheckVarsTarget {
helper_columns,
Expand Down Expand Up @@ -906,16 +892,8 @@ pub(crate) fn eval_cross_table_lookup_checks_circuit<
let combin0 = challenges.combine_circuit(builder, &evals[0]);
let combin1 = challenges.combine_circuit(builder, &evals[1]);

let f0 = if let Some(filter0) = &filter[0] {
filter0.eval_filter_circuit(builder, local_values, next_values)
} else {
one
};
let f1 = if let Some(filter1) = &filter[1] {
filter1.eval_filter_circuit(builder, local_values, next_values)
} else {
one
};
let f0 = filter[0].eval_filter_circuit(builder, local_values, next_values);
let f1 = filter[1].eval_filter_circuit(builder, local_values, next_values);

let combined = builder.mul_sub_extension(combin1, *local_z, f1);
let combined = builder.mul_extension(combined, combin0);
Expand All @@ -928,11 +906,7 @@ pub(crate) fn eval_cross_table_lookup_checks_circuit<
consumer.constraint_last_row(builder, constr);
} else {
let combin0 = challenges.combine_circuit(builder, &evals[0]);
let f0 = if let Some(filter0) = &filter[0] {
filter0.eval_filter_circuit(builder, local_values, next_values)
} else {
one
};
let f0 = filter[0].eval_filter_circuit(builder, local_values, next_values);

let constr = builder.mul_sub_extension(combin0, *local_z, f0);
consumer.constraint_last_row(builder, constr);
Expand Down Expand Up @@ -1121,11 +1095,7 @@ pub mod debug_utils {
) {
let trace = &trace_poly_values[table.table];
for i in 0..trace[0].len() {
let filter = if let Some(combin) = &table.filter {
combin.eval_table(trace, i)
} else {
F::ONE
};
let filter = table.filter.eval_table(trace, i);
if filter.is_one() {
let row = table
.columns
Expand Down
Loading

0 comments on commit 5a8b6a3

Please sign in to comment.