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

Merge develop back to master #1379

Merged
merged 47 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4f1a904
Add link to GitHub
dannywillems Aug 30, 2023
5e91825
This TODO is done
dannywillems Aug 30, 2023
99b35be
Add helpers for inferring feature flags
mrmr1993 Oct 9, 2023
33252de
Derive binding types for FeatureFlags
mrmr1993 Oct 9, 2023
488ad18
[#14070] Add a unit check for the table id zero value condition
volhovm Oct 2, 2023
74b5b0c
[#14070] Fix the table dummy rows bug
volhovm Oct 12, 2023
eaf3184
[#14097,#14070] Move lookup table consistency checks into LookupTable…
volhovm Oct 12, 2023
2cf2ea4
Cosmetics on the lookup RFC
volhovm Oct 21, 2023
c5d1459
Capitalize book summary titles
volhovm Oct 23, 2023
d71b06b
Add .ignore file to .gitignore
volhovm Oct 23, 2023
51e2672
Improve RFC3, fix rendering in kimchi/overview.md
volhovm Oct 23, 2023
f38a2c3
Cargo: use wasm-bindgen 0.2.87
rbonichon Oct 26, 2023
57a3d8b
Merge pull request #1302 from o1-labs/rb/wasm-bindgen-0.2.87
dannywillems Oct 26, 2023
ab79316
Merge pull request #1292 from o1-labs/volhovm/rfc3-cosmetics
dannywillems Oct 30, 2023
81f1296
Initially move sections around [MinaProtocol/mina#14442]
volhovm Oct 31, 2023
992448e
Bump up actions/@checkout to 4.1.1
dannywillems Nov 1, 2023
b66e145
Merge pull request #1316 from o1-labs/dw/update-actions-to-4.1.1-develop
dannywillems Nov 1, 2023
251ab0c
[#14097,#14070] Enforce using constructor through private fields
volhovm Oct 16, 2023
cb46062
Formatting
volhovm Oct 16, 2023
e3aceaf
[#14097,#14070] Fix lookup test creating invalid id=0 zero table
volhovm Oct 16, 2023
1fac311
Add table id collision assertions to LookupConstraintSystem#create
volhovm Oct 24, 2023
d0e5de6
Improve lookup collision checks, fixed broken tests
volhovm Oct 30, 2023
64e9155
Add a test for lookup table id collisions
volhovm Oct 30, 2023
2121c7f
Address PR comments [MinaProtocol/mina#14070]
volhovm Nov 2, 2023
d79015d
Revert HashSet<LookupTable<_>> changes
volhovm Nov 2, 2023
2bcd3db
Consistency pass on book chapters / styling
volhovm Nov 2, 2023
73ae00a
Prettify sections more
volhovm Nov 7, 2023
ab36dce
Merge pull request #1275 from o1-labs/feature/infer-features-from-gates
dannywillems Nov 9, 2023
e9250aa
Merge branch 'develop' into misc/link-todo-with-gh-issues
dannywillems Nov 14, 2023
a285216
Add TODO link
dannywillems Nov 14, 2023
da65a25
Deduplicate lookup tables
mrmr1993 Nov 16, 2023
88c1776
Merge pull request #1334 from o1-labs/feature/deduplicate-lookup-table
dannywillems Nov 16, 2023
c8ebc93
Merge branch 'develop' into volhovm/mina14070-table-id-zero-row
volhovm Nov 16, 2023
7f6eba0
Merge pull request #1263 from o1-labs/volhovm/mina14070-table-id-zero…
dannywillems Nov 21, 2023
2f94807
Merge pull request #1304 from o1-labs/volhovm/mina14442-move-old-rfcs…
volhovm Nov 21, 2023
8920a01
Bare URL's are not supported and must be wrapped.
dannywillems Nov 27, 2023
25156a2
Update specifications
dannywillems Nov 27, 2023
901033a
Merge pull request #1200 from o1-labs/misc/link-todo-with-gh-issues
dannywillems Nov 28, 2023
6c6adca
Fix resolver warnings
dannywillems Nov 29, 2023
3908626
Merge pull request #1348 from o1-labs/dw/fix-resolver-warnings-develop
Nov 29, 2023
1c30635
Additional comment on the table_id_combiner
dannywillems Nov 29, 2023
bde1c05
Merge pull request #1355 from o1-labs/dw/additional-comments-on-combi…
dannywillems Nov 30, 2023
267105a
Revert "Merge pull request #1263 from o1-labs/volhovm/mina14070-table…
mrmr1993 Dec 4, 2023
5685f41
Merge pull request #1378 from o1-labs/feature/revert-bad-par
mrmr1993 Dec 4, 2023
862d172
Merge branch 'master' into merge-back-to-master
mrmr1993 Dec 4, 2023
9a999cf
Merge branch 'develop' into merge-back-to-master
mrmr1993 Dec 4, 2023
b88e61c
Reintroduce comment
mrmr1993 Dec 4, 2023
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ _build
# If symlink created for kimchi-visu
tools/srs

.ignore
optimism/*op-program-data-log.sh
optimism/cpu.pprof
optimism/meta.json
Expand Down
14 changes: 7 additions & 7 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
- [Rings](./fundamentals/zkbook_rings.md)
- [Fields](./fundamentals/zkbook.md)
- [Polynomials](./fundamentals/zkbook_polynomials.md)
- [Multiplying polynomials](./fundamentals/zkbook_multiplying_polynomials.md)
- [Fast Fourier transform](./fundamentals/zkbook_fft.md)
- [Multiplying Polynomials](./fundamentals/zkbook_multiplying_polynomials.md)
- [Fast Fourier Transform](./fundamentals/zkbook_fft.md)

# Cryptographic Tools

- [Commitments](./fundamentals/zkbook_commitment.md)
- [Polynomial commitments](./plonk/polynomial_commitments.md)
- [Inner product argument](./plonk/inner_product.md)
- [Different functionnalities](./plonk/inner_product_api.md)
- [Polynomial Commitments](./plonk/polynomial_commitments.md)
- [Inner Product Argument](./plonk/inner_product.md)
- [Different Functionnalities](./plonk/inner_product_api.md)
- [Two Party Computation](./fundamentals/zkbook_2pc/overview.md)
- [Garbled Circuits](./fundamentals/zkbook_2pc/gc.md)
- [Basics](./fundamentals/zkbook_2pc/basics.md)
Expand Down Expand Up @@ -70,8 +70,8 @@
# Technical Specifications

- [Poseidon hash](./specs/poseidon.md)
- [Polynomial commitment](./specs/poly-commitment.md)
- [Pasta curves](./specs/pasta.md)
- [Polynomial Commitment](./specs/poly-commitment.md)
- [Pasta Curves](./specs/pasta.md)
- [Kimchi](./specs/kimchi.md)
- [Universal Reference String (URS)](./specs/urs.md)
- [Pickles](./specs/pickles.md)
Expand Down
2 changes: 1 addition & 1 deletion book/src/specs/kimchi.md
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ The prover then follows the following steps to create the proof:
* $s_i$
* $w_i$
* $z$
* lookup (TODO)
* lookup (TODO, see [this issue](https://github.com/MinaProtocol/mina/issues/13886))
* generic selector
* poseidon selector

Expand Down
2 changes: 1 addition & 1 deletion kimchi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mina-poseidon = { path = "../poseidon", version = "0.1.0" }
ocaml = { version = "0.22.2", optional = true }
ocaml-gen = { version = "0.1.5", optional = true }

wasm-bindgen = { version = "0.2.81", optional = true }
wasm-bindgen = { version = "=0.2.87", optional = true }

internal-tracing = { path = "../internal-tracing", version = "0.1.0" }

Expand Down
87 changes: 61 additions & 26 deletions kimchi/src/circuits/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use crate::{
domain_constant_evaluation::DomainConstantEvaluations,
domains::EvaluationDomains,
gate::{CircuitGate, GateType},
lookup::{index::LookupConstraintSystem, lookups::LookupFeatures, tables::LookupTable},
lookup::{
index::LookupConstraintSystem,
lookups::LookupFeatures,
tables::{GateLookupTables, LookupTable},
},
polynomial::{WitnessEvals, WitnessOverDomains, WitnessShifts},
polynomials::permutation::Shifts,
wires::*,
Expand All @@ -32,6 +36,11 @@ use std::sync::Arc;
//

/// Flags for optional features in the constraint system
#[cfg_attr(
feature = "ocaml_types",
derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)
)]
#[cfg_attr(feature = "wasm_types", wasm_bindgen::prelude::wasm_bindgen)]
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
pub struct FeatureFlags {
/// RangeCheck0 gate
Expand Down Expand Up @@ -614,6 +623,47 @@ pub fn zk_rows_strict_lower_bound(num_chunks: usize) -> usize {
(2 * (PERMUTS + 1) * num_chunks - 2) / PERMUTS
}

impl FeatureFlags {
pub fn from_gates_and_lookup_features<F: PrimeField>(
gates: &[CircuitGate<F>],
lookup_features: LookupFeatures,
) -> FeatureFlags {
let mut feature_flags = FeatureFlags {
range_check0: false,
range_check1: false,
lookup_features,
foreign_field_add: false,
foreign_field_mul: false,
xor: false,
rot: false,
};

for gate in gates {
match gate.typ {
GateType::RangeCheck0 => feature_flags.range_check0 = true,
GateType::RangeCheck1 => feature_flags.range_check1 = true,
GateType::ForeignFieldAdd => feature_flags.foreign_field_add = true,
GateType::ForeignFieldMul => feature_flags.foreign_field_mul = true,
GateType::Xor16 => feature_flags.xor = true,
GateType::Rot64 => feature_flags.rot = true,
_ => (),
}
}

feature_flags
}

pub fn from_gates<F: PrimeField>(
gates: &[CircuitGate<F>],
uses_runtime_tables: bool,
) -> FeatureFlags {
FeatureFlags::from_gates_and_lookup_features(
gates,
LookupFeatures::from_gates(gates, uses_runtime_tables),
)
}
}

impl<F: PrimeField + SquareRootField> Builder<F> {
/// Set up the number of public inputs.
/// If not invoked, it equals `0` by default.
Expand Down Expand Up @@ -682,7 +732,7 @@ impl<F: PrimeField + SquareRootField> Builder<F> {
// for some reason we need more than 1 gate for the circuit to work, see TODO below
assert!(gates.len() > 1);

let lookup_features = LookupFeatures::from_gates(&gates, runtime_tables.is_some());
let feature_flags = FeatureFlags::from_gates(&gates, runtime_tables.is_some());

let lookup_domain_size = {
// First we sum over the lookup table size
Expand All @@ -705,12 +755,19 @@ impl<F: PrimeField + SquareRootField> Builder<F> {
}
}
// And we add the built-in tables, depending on the features.
let LookupFeatures { patterns, .. } = &lookup_features;
let LookupFeatures { patterns, .. } = &feature_flags.lookup_features;
let mut gate_lookup_tables = GateLookupTables {
xor: false,
range_check: false,
};
for pattern in patterns.into_iter() {
if let Some(gate_table) = pattern.table() {
lookup_domain_size += gate_table.table_size();
gate_lookup_tables[gate_table] = true
}
}
for gate_table in gate_lookup_tables.into_iter() {
lookup_domain_size += gate_table.table_size();
}
lookup_domain_size
};

Expand Down Expand Up @@ -787,28 +844,6 @@ impl<F: PrimeField + SquareRootField> Builder<F> {
.collect();
gates.append(&mut padding);

let mut feature_flags = FeatureFlags {
range_check0: false,
range_check1: false,
lookup_features,
foreign_field_add: false,
foreign_field_mul: false,
xor: false,
rot: false,
};

for gate in &gates {
match gate.typ {
GateType::RangeCheck0 => feature_flags.range_check0 = true,
GateType::RangeCheck1 => feature_flags.range_check1 = true,
GateType::ForeignFieldAdd => feature_flags.foreign_field_add = true,
GateType::ForeignFieldMul => feature_flags.foreign_field_mul = true,
GateType::Xor16 => feature_flags.xor = true,
GateType::Rot64 => feature_flags.rot = true,
_ => (),
}
}

//~ 1. sample the `PERMUTS` shifts.
let shifts = Shifts::new(&domain.d1);

Expand Down
2 changes: 2 additions & 0 deletions kimchi/src/circuits/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl<F: PrimeField + SquareRootField> CircuitGate<F> {
EndoMul => self.verify_endomul::<G>(row, witness, &index.cs),
EndoMulScalar => self.verify_endomul_scalar::<G>(row, witness, &index.cs),
// TODO: implement the verification for the lookup gate
// See https://github.com/MinaProtocol/mina/issues/14011
Lookup => Ok(()),
CairoClaim | CairoInstruction | CairoFlags | CairoTransition => {
self.verify_cairo_gate::<G>(row, witness, &index.cs)
Expand Down Expand Up @@ -303,6 +304,7 @@ impl<F: PrimeField + SquareRootField> CircuitGate<F> {
}
GateType::Lookup => {
// TODO: implement the verification for the lookup gate
// See https://github.com/MinaProtocol/mina/issues/14011
vec![]
}
GateType::CairoClaim => turshi::Claim::constraint_checks(&env, &mut cache),
Expand Down
2 changes: 2 additions & 0 deletions kimchi/src/circuits/lookup/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ where
.iter()
.enumerate()
.map(|(i, s)| {
// Snake pattern: even chunks of s are direct
// while the odd ones are reversed
let (i1, i2) = if i % 2 == 0 {
(row, row + 1)
} else {
Expand Down
1 change: 0 additions & 1 deletion kimchi/src/circuits/lookup/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ pub type JointLookupSpec<F> = JointLookup<SingleLookup<F>, LookupTableID>;
pub type JointLookupValue<F> = JointLookup<F, F>;

impl<F: Zero + One + Clone + Neg<Output = F> + From<u64>> JointLookupValue<F> {
// TODO: Support multiple tables
/// Evaluate the combined value of a joint-lookup.
pub fn evaluate(&self, joint_combiner: &F, table_id_combiner: &F) -> F {
combine_table_entry(
Expand Down
47 changes: 47 additions & 0 deletions kimchi/src/circuits/lookup/tables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,53 @@ pub enum GateLookupTable {
RangeCheck,
}

/// Enumerates the different 'fixed' lookup tables used by individual gates
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GateLookupTables {
pub xor: bool,
pub range_check: bool,
}

impl std::ops::Index<GateLookupTable> for GateLookupTables {
type Output = bool;

fn index(&self, index: GateLookupTable) -> &Self::Output {
match index {
GateLookupTable::Xor => &self.xor,
GateLookupTable::RangeCheck => &self.range_check,
}
}
}

impl std::ops::IndexMut<GateLookupTable> for GateLookupTables {
fn index_mut(&mut self, index: GateLookupTable) -> &mut Self::Output {
match index {
GateLookupTable::Xor => &mut self.xor,
GateLookupTable::RangeCheck => &mut self.range_check,
}
}
}

impl IntoIterator for GateLookupTables {
type Item = GateLookupTable;
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
// Destructor pattern to make sure we add new lookup patterns.
let GateLookupTables { xor, range_check } = self;

let mut patterns = Vec::with_capacity(2);

if xor {
patterns.push(GateLookupTable::Xor)
}
if range_check {
patterns.push(GateLookupTable::RangeCheck)
}
patterns.into_iter()
}
}

/// A table of values that can be used for a lookup, along with the ID for the table.
#[derive(Debug, Clone)]
pub struct LookupTable<F> {
Expand Down
2 changes: 1 addition & 1 deletion kimchi/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ where
//~~ * $s_i$
//~~ * $w_i$
//~~ * $z$
//~~ * lookup (TODO)
//~~ * lookup (TODO, see [this issue](https://github.com/MinaProtocol/mina/issues/13886))
//~~ * generic selector
//~~ * poseidon selector
//~
Expand Down