From 73a1bffed1614bf157fc592da056878991bc1a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anai=CC=88s=20Querol?= Date: Mon, 2 May 2022 17:48:58 +0200 Subject: [PATCH 01/21] adding circuit creation example to readme --- README.md | 120 +++++++++++++++++++++++++++++++++++++++++++++++ kimchi/README.md | 1 + 2 files changed, 121 insertions(+) diff --git a/README.md b/README.md index d6f1863213..4fa97c3033 100644 --- a/README.md +++ b/README.md @@ -81,3 +81,123 @@ The project is organized in the following way: ## Contributing Check [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in contributing to this project. + +## Guidelines + +There are three main steps to follow in order to start using this library: + +1. Create the circuit for the targetted relation as a vector of gates. You can use our own custom gates as building blocks, or build your own. + +2. Feed the circuit with a witness that will satisfy the relation. This is equivalent to finding (or computing) a correct instantiation of the execution trace. + +3. Generate and verify the proof of the witness for the relation. + +## Example + +When using this library, make sure to include in your Cargo.toml the following dependencies: + +` +[dependencies] +kimchi = { git = "https://github.com/o1-labs/proof-systems" } +mina-curves = { git = "https://github.com/o1-labs/proof-systems" } +oracle = { git = "https://github.com/o1-labs/proof-systems" } +commitment_dlog = { git = "https://github.com/o1-labs/proof-systems" } +` + +Here is an example that uses this library. This code takes the output of a hash and makes sure that the prover knows the input to the hash function. + +```rust + +use itertools::iterate; +use kimchi::circuits::{ + gate::CircuitGate, + wires::Wire, + polynomials::generic::GenericGateSpec}; +use mina_curves::pasta::Fp; + +/// create a simple circuit to hash an input +fn create_circuit() -> Vec> { + let mut gates = vec![]; + let mut gates_row = iterate(0, |&i| i + 1); + let mut row = || gates_row.next().unwrap(); + + // the output to the hash function is a public input + // and public inputs are handled with generic gates + gates.push(CircuitGate::create_generic_gadget( + Wire::new(row()), + GenericGateSpec::Pub, + None, + )); + gates.push(CircuitGate::create_generic_gadget( + Wire::new(row()), + GenericGateSpec::Pub, + None, + )); + gates.push(CircuitGate::create_generic_gadget( + Wire::new(row()), + GenericGateSpec::Pub, + None, + )); + + // hash a private input + let poseidon_params = oracle::pasta::fp_kimchi::params(); + let round_constants = &poseidon_params.round_constants; + let row = row(); + let (g, final_row) = CircuitGate::::create_poseidon_gadget( + row, + [Wire::new(row), Wire::new(row + 11)], // TODO: this argument should be deleted from the fn + round_constants, + ); + gates.extend(g); + + // wire the output to the public input + // TODO: it'd be nice if we had functions that would do this for us, + // and panic if a permutation is already in place + let last_row = gates.iter_mut().last().unwrap(); + last_row.wires[0] = Wire { row: 0, col: 0 }; + last_row.wires[1] = Wire { row: 0, col: 1 }; + last_row.wires[2] = Wire { row: 0, col: 2 }; + + gates[0].wires[0] = Wire { + row: final_row, + col: 0, + }; + gates[0].wires[1] = Wire { + row: final_row, + col: 1, + }; + gates[0].wires[2] = Wire { + row: final_row, + col: 2, + }; + + gates +} + +/* +fn create_witness(gates: &Vec>) -> [Vec; COLUMNS] { + // TODO +} + +fn verify_proof(gates: Vec>, witness: [Vec; COLUMNS], public: &[Fp]) { + // TODO +} +*/ + +fn test_example() { + // first define the circuit + let gates = create_circuit(); + + // then compute the witness for the circuit and the public input + /* + let public = /*the output of the hash function*/ + // TODO: we need simple witness generators for each gate + let mut witness: [Vec; COLUMNS] = create_witness(&gates, &public); + + // generate and verify a proof + verify_proof(gates, witness, &public); + */ + +} + +``` \ No newline at end of file diff --git a/kimchi/README.md b/kimchi/README.md index 9e32eb2ab8..76a71006cc 100644 --- a/kimchi/README.md +++ b/kimchi/README.md @@ -53,3 +53,4 @@ To obtain a flamegraph: the [binary](src/bin/flamegraph.rs) will run forever, so you have to C-c to exit and produce the `flamegraph.svg` file. Note: lots of good advice on system performance in the [flamegraph repo](https://github.com/flamegraph-rs/flamegraph#systems-performance-work-guided-by-flamegraphs). + From 09525c09d78437eec5c50179733e75ee977c6159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anai=CC=88s=20Querol?= Date: Wed, 4 May 2022 20:01:34 +0200 Subject: [PATCH 02/21] pub use modules --- README.md | 3 --- kimchi/src/lib.rs | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4fa97c3033..890e277a54 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,6 @@ When using this library, make sure to include in your Cargo.toml the following d ` [dependencies] kimchi = { git = "https://github.com/o1-labs/proof-systems" } -mina-curves = { git = "https://github.com/o1-labs/proof-systems" } -oracle = { git = "https://github.com/o1-labs/proof-systems" } -commitment_dlog = { git = "https://github.com/o1-labs/proof-systems" } ` Here is an example that uses this library. This code takes the output of a hash and makes sure that the prover knows the input to the hash function. diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index a1f033a4c5..efa0fdccb5 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,6 +3,10 @@ #[macro_use] extern crate num_derive; +pub use commitment_dlog::*; +pub use mina_curves::*; +pub use oracle::*; + pub mod alphas; pub mod bench; pub mod circuits; From 434900a19be68b24c06deebb3f2403761f744076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anai=CC=88s=20Querol?= Date: Thu, 5 May 2022 13:29:26 +0200 Subject: [PATCH 03/21] pub use all modules used in kimchi --- kimchi/src/lib.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index efa0fdccb5..91e73be46d 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,9 +3,34 @@ #[macro_use] extern crate num_derive; -pub use commitment_dlog::*; -pub use mina_curves::*; -pub use oracle::*; +pub use cairo::{ + memory::CairoMemory, + runner::{CairoInstruction, CairoProgram, Pointers}, + word::{FlagBits, Offsets}, +}; +pub use commitment_dlog::{ + commitment::{ + b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, + Evaluation, PolyComm, + }, + evaluation_proof::OpeningProof, + srs::{endos, SRS}, +}; +pub use groupmap::{BWParameters, GroupMap}; +pub use mina_curves::pasta::{ + fp::Fp, + pallas::Affine as Other, + vesta::{Affine, VestaParameters}, +}; +pub use o1_utils::{ + field_helpers::i32_to_field, hasher::CryptoDigest, math, types::fields::*, + ExtendedDensePolynomial, ExtendedEvaluations, +}; +pub use oracle::{ + constants::{PlonkSpongeConstantsKimchi, SpongeConstants}, + poseidon::{sbox, ArithmeticSponge, ArithmeticSpongeParams, Sponge}, + sponge::{DefaultFqSponge, DefaultFrSponge, FqSponge, ScalarChallenge}, +}; pub mod alphas; pub mod bench; From 322d4b447398691cbf9376c10b58946a781a78e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anai=CC=88s=20Querol?= Date: Fri, 6 May 2022 09:55:18 +0200 Subject: [PATCH 04/21] pub use cairo --- cairo/src/lib.rs | 4 ++++ kimchi/src/lib.rs | 5 ----- kimchi/src/tests/turshi.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cairo/src/lib.rs b/cairo/src/lib.rs index 334abf56ce..1b557205d0 100644 --- a/cairo/src/lib.rs +++ b/cairo/src/lib.rs @@ -9,3 +9,7 @@ pub mod helper; pub mod memory; pub mod runner; pub mod word; + +pub use memory::CairoMemory; +pub use runner::{CairoInstruction, CairoProgram, Pointers}; +pub use word::{FlagBits, Offsets}; diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 91e73be46d..71eb3e931b 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,11 +3,6 @@ #[macro_use] extern crate num_derive; -pub use cairo::{ - memory::CairoMemory, - runner::{CairoInstruction, CairoProgram, Pointers}, - word::{FlagBits, Offsets}, -}; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, diff --git a/kimchi/src/tests/turshi.rs b/kimchi/src/tests/turshi.rs index 27a749e553..919c304807 100644 --- a/kimchi/src/tests/turshi.rs +++ b/kimchi/src/tests/turshi.rs @@ -1,6 +1,6 @@ use crate::circuits::gate::CircuitGate; use crate::circuits::polynomials::turshi::{testing::*, witness::*}; -use cairo::{memory::CairoMemory, runner::CairoProgram}; +use cairo::{CairoMemory, CairoProgram}; use mina_curves::pasta::fp::Fp as F; #[test] From 087c43af8c5cfec72793d3283e5c430690f17376 Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 3 Jun 2022 17:03:46 +0200 Subject: [PATCH 05/21] include pub use cairo --- cairo/src/lib.rs | 6 +-- kimchi/README.md | 106 ++++++++++++++++++++++++++++++++++++++++++++++ kimchi/src/lib.rs | 1 + 3 files changed, 110 insertions(+), 3 deletions(-) diff --git a/cairo/src/lib.rs b/cairo/src/lib.rs index 1b557205d0..3ff29c73ed 100644 --- a/cairo/src/lib.rs +++ b/cairo/src/lib.rs @@ -10,6 +10,6 @@ pub mod memory; pub mod runner; pub mod word; -pub use memory::CairoMemory; -pub use runner::{CairoInstruction, CairoProgram, Pointers}; -pub use word::{FlagBits, Offsets}; +pub use crate::memory::CairoMemory; +pub use crate::runner::{CairoInstruction, CairoProgram, Pointers}; +pub use crate::word::{FlagBits, Offsets}; diff --git a/kimchi/README.md b/kimchi/README.md index 76a71006cc..1789c1bef1 100644 --- a/kimchi/README.md +++ b/kimchi/README.md @@ -54,3 +54,109 @@ To obtain a flamegraph: Note: lots of good advice on system performance in the [flamegraph repo](https://github.com/flamegraph-rs/flamegraph#systems-performance-work-guided-by-flamegraphs). +## Contributing + +Check [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in contributing to this project. + +## Guidelines + +There are three main steps to follow in order to start using this library: + +1. Create the circuit for the targetted relation as a vector of gates. You can use our own custom gates as building blocks, or build your own. + +2. Feed the circuit with a witness that will satisfy the relation. This is equivalent to finding (or computing) a correct instantiation of the execution trace. + +3. Generate and verify the proof of the witness for the relation. + +## Example + +When using this library, make sure to include in your Cargo.toml the following dependency: + +` +[dependencies] +kimchi = { git = "https://github.com/o1-labs/proof-systems" } +` + +Here is an example that uses this library. This code takes the output of a hash and makes sure that the prover knows the input to the hash function. + +```rust +use itertools::iterate; +use kimchi::circuits::{ + gate::CircuitGate, + wires::Wire, + polynomials::generic::GenericGateSpec}; +use mina_curves::pasta::Fp; +/// create a simple circuit to hash an input +fn create_circuit() -> Vec> { + let mut gates = vec![]; + let mut gates_row = iterate(0, |&i| i + 1); + let mut row = || gates_row.next().unwrap(); + // the output to the hash function is a public input + // and public inputs are handled with generic gates + gates.push(CircuitGate::create_generic_gadget( + Wire::new(row()), + GenericGateSpec::Pub, + None, + )); + gates.push(CircuitGate::create_generic_gadget( + Wire::new(row()), + GenericGateSpec::Pub, + None, + )); + gates.push(CircuitGate::create_generic_gadget( + Wire::new(row()), + GenericGateSpec::Pub, + None, + )); + // hash a private input + let poseidon_params = oracle::pasta::fp_kimchi::params(); + let round_constants = &poseidon_params.round_constants; + let row = row(); + let (g, final_row) = CircuitGate::::create_poseidon_gadget( + row, + [Wire::new(row), Wire::new(row + 11)], // TODO: this argument should be deleted from the fn + round_constants, + ); + gates.extend(g); + // wire the output to the public input + // TODO: it'd be nice if we had functions that would do this for us, + // and panic if a permutation is already in place + let last_row = gates.iter_mut().last().unwrap(); + last_row.wires[0] = Wire { row: 0, col: 0 }; + last_row.wires[1] = Wire { row: 0, col: 1 }; + last_row.wires[2] = Wire { row: 0, col: 2 }; + gates[0].wires[0] = Wire { + row: final_row, + col: 0, + }; + gates[0].wires[1] = Wire { + row: final_row, + col: 1, + }; + gates[0].wires[2] = Wire { + row: final_row, + col: 2, + }; + gates +} +/* +fn create_witness(gates: &Vec>) -> [Vec; COLUMNS] { + // TODO +} +fn verify_proof(gates: Vec>, witness: [Vec; COLUMNS], public: &[Fp]) { + // TODO +} +*/ +fn test_example() { + // first define the circuit + let gates = create_circuit(); + // then compute the witness for the circuit and the public input + /* + let public = /*the output of the hash function*/ + // TODO: we need simple witness generators for each gate + let mut witness: [Vec; COLUMNS] = create_witness(&gates, &public); + // generate and verify a proof + verify_proof(gates, witness, &public); + */ +} +``` \ No newline at end of file diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 71eb3e931b..416eaf077b 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate num_derive; +pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, From b69576a6e98aa9d9badbc6f797f114238d6d547c Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 3 Jun 2022 17:42:54 +0200 Subject: [PATCH 06/21] export some crate modules --- cairo/src/lib.rs | 8 +++++--- kimchi/src/lib.rs | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cairo/src/lib.rs b/cairo/src/lib.rs index 3ff29c73ed..eac47688be 100644 --- a/cairo/src/lib.rs +++ b/cairo/src/lib.rs @@ -10,6 +10,8 @@ pub mod memory; pub mod runner; pub mod word; -pub use crate::memory::CairoMemory; -pub use crate::runner::{CairoInstruction, CairoProgram, Pointers}; -pub use crate::word::{FlagBits, Offsets}; +pub use crate::{ + memory::CairoMemory, + runner::{CairoInstruction, CairoProgram, Pointers}, + word::{FlagBits, Offsets}, +}; diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 416eaf077b..4f70925fe3 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,6 +3,12 @@ #[macro_use] extern crate num_derive; +pub use crate::circuits::{ + constraints::ConstraintSystem, + gate::{CircuitGate, GateType}, + polynomials::generic::GenericGateSpec, + wires::Wire, +}; pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; pub use commitment_dlog::{ commitment::{ @@ -24,6 +30,7 @@ pub use o1_utils::{ }; pub use oracle::{ constants::{PlonkSpongeConstantsKimchi, SpongeConstants}, + pasta::fp_kimchi::*, poseidon::{sbox, ArithmeticSponge, ArithmeticSpongeParams, Sponge}, sponge::{DefaultFqSponge, DefaultFrSponge, FqSponge, ScalarChallenge}, }; From 4f1ae23bf166e6baca688382e73c74abab6df419 Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 3 Jun 2022 17:44:40 +0200 Subject: [PATCH 07/21] remove crate from pub use --- kimchi/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 4f70925fe3..653be2f4ea 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,13 +3,13 @@ #[macro_use] extern crate num_derive; -pub use crate::circuits::{ +pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; +pub use circuits::{ constraints::ConstraintSystem, gate::{CircuitGate, GateType}, polynomials::generic::GenericGateSpec, wires::Wire, }; -pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, From 01427c8654697edba30085f3c66736eeb8aee64b Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 16:34:45 +0200 Subject: [PATCH 08/21] test pub extern crate --- kimchi/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 653be2f4ea..8981cf8e91 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,13 +3,14 @@ #[macro_use] extern crate num_derive; -pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; -pub use circuits::{ +pub use crate::circuits::{ constraints::ConstraintSystem, gate::{CircuitGate, GateType}, polynomials::generic::GenericGateSpec, wires::Wire, }; +pub extern crate cairo; +//::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, From 7f3fe2115d1db33a8ac090e8a7d23bffca6e8eab Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 16:55:38 +0200 Subject: [PATCH 09/21] include params --- kimchi/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 8981cf8e91..4977f8b95a 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -9,8 +9,7 @@ pub use crate::circuits::{ polynomials::generic::GenericGateSpec, wires::Wire, }; -pub extern crate cairo; -//::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; +pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, @@ -31,7 +30,7 @@ pub use o1_utils::{ }; pub use oracle::{ constants::{PlonkSpongeConstantsKimchi, SpongeConstants}, - pasta::fp_kimchi::*, + pasta::fp_kimchi::params, poseidon::{sbox, ArithmeticSponge, ArithmeticSpongeParams, Sponge}, sponge::{DefaultFqSponge, DefaultFrSponge, FqSponge, ScalarChallenge}, }; From b70838c7bf19a98fa9324cbc1aea7bd45e70c671 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 17:37:59 +0200 Subject: [PATCH 10/21] remove params again --- kimchi/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 4977f8b95a..c306ac2091 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -25,12 +25,12 @@ pub use mina_curves::pasta::{ vesta::{Affine, VestaParameters}, }; pub use o1_utils::{ - field_helpers::i32_to_field, hasher::CryptoDigest, math, types::fields::*, - ExtendedDensePolynomial, ExtendedEvaluations, + field_helpers::*, hasher::CryptoDigest, math, types::fields::*, ExtendedDensePolynomial, + ExtendedEvaluations, }; pub use oracle::{ constants::{PlonkSpongeConstantsKimchi, SpongeConstants}, - pasta::fp_kimchi::params, + pasta::fp_kimchi::*, poseidon::{sbox, ArithmeticSponge, ArithmeticSpongeParams, Sponge}, sponge::{DefaultFqSponge, DefaultFrSponge, FqSponge, ScalarChallenge}, }; From dd3573df3c44b2bf053710f03feedbefb996d867 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 17:38:49 +0200 Subject: [PATCH 11/21] remove * --- kimchi/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index c306ac2091..1e5613f32e 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -25,12 +25,12 @@ pub use mina_curves::pasta::{ vesta::{Affine, VestaParameters}, }; pub use o1_utils::{ - field_helpers::*, hasher::CryptoDigest, math, types::fields::*, ExtendedDensePolynomial, + field_helpers, hasher::CryptoDigest, math, types::fields, ExtendedDensePolynomial, ExtendedEvaluations, }; pub use oracle::{ constants::{PlonkSpongeConstantsKimchi, SpongeConstants}, - pasta::fp_kimchi::*, + pasta::fp_kimchi, poseidon::{sbox, ArithmeticSponge, ArithmeticSpongeParams, Sponge}, sponge::{DefaultFqSponge, DefaultFrSponge, FqSponge, ScalarChallenge}, }; From 977a16600b36df21b8c32b26c941e1b5a0f4bd0a Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 17:42:06 +0200 Subject: [PATCH 12/21] check less modules --- kimchi/src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 1e5613f32e..687f7e0eed 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -9,7 +9,7 @@ pub use crate::circuits::{ polynomials::generic::GenericGateSpec, wires::Wire, }; -pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; +pub use cairo; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, @@ -28,12 +28,7 @@ pub use o1_utils::{ field_helpers, hasher::CryptoDigest, math, types::fields, ExtendedDensePolynomial, ExtendedEvaluations, }; -pub use oracle::{ - constants::{PlonkSpongeConstantsKimchi, SpongeConstants}, - pasta::fp_kimchi, - poseidon::{sbox, ArithmeticSponge, ArithmeticSpongeParams, Sponge}, - sponge::{DefaultFqSponge, DefaultFrSponge, FqSponge, ScalarChallenge}, -}; +pub use oracle::{constants, pasta, poseidon, sponge}; pub mod alphas; pub mod bench; From 6a16f64e62ddd0773e802cfa13dfefcf3435eeb0 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 17:45:16 +0200 Subject: [PATCH 13/21] cairo again --- kimchi/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 687f7e0eed..6c3812b699 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -9,7 +9,7 @@ pub use crate::circuits::{ polynomials::generic::GenericGateSpec, wires::Wire, }; -pub use cairo; +pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; pub use commitment_dlog::{ commitment::{ b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, From 4b9678534f4d982fe0d729efb44940284540e150 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 17:51:14 +0200 Subject: [PATCH 14/21] add fp_kimchi --- kimchi/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 6c3812b699..0358937b0b 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -28,7 +28,7 @@ pub use o1_utils::{ field_helpers, hasher::CryptoDigest, math, types::fields, ExtendedDensePolynomial, ExtendedEvaluations, }; -pub use oracle::{constants, pasta, poseidon, sponge}; +pub use oracle::{constants, pasta::fp_kimchi, poseidon, sponge}; pub mod alphas; pub mod bench; From ac1e1cf11d6fa2ad6168ea301419144d2563105a Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 6 Jun 2022 17:52:59 +0200 Subject: [PATCH 15/21] add params --- kimchi/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 0358937b0b..0fefde7cf7 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -28,7 +28,7 @@ pub use o1_utils::{ field_helpers, hasher::CryptoDigest, math, types::fields, ExtendedDensePolynomial, ExtendedEvaluations, }; -pub use oracle::{constants, pasta::fp_kimchi, poseidon, sponge}; +pub use oracle::{constants, pasta::fp_kimchi::params, poseidon, sponge}; pub mod alphas; pub mod bench; From fd02235bff26a1102b6361cf7211d387b99b5109 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 13 Jun 2022 21:04:31 +0200 Subject: [PATCH 16/21] pub use kimchi --- cairo/src/lib.rs | 2 +- kimchi/src/lib.rs | 32 ++++++-------------------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/cairo/src/lib.rs b/cairo/src/lib.rs index eac47688be..0439932a88 100644 --- a/cairo/src/lib.rs +++ b/cairo/src/lib.rs @@ -10,7 +10,7 @@ pub mod memory; pub mod runner; pub mod word; -pub use crate::{ +pub use self::{ memory::CairoMemory, runner::{CairoInstruction, CairoProgram, Pointers}, word::{FlagBits, Offsets}, diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 87cffde29e..bfe27fb55a 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -3,32 +3,12 @@ #[macro_use] extern crate num_derive; -pub use crate::circuits::{ - constraints::ConstraintSystem, - gate::{CircuitGate, GateType}, - polynomials::generic::GenericGateSpec, - wires::Wire, -}; -pub use cairo::{CairoInstruction, CairoMemory, CairoProgram, FlagBits, Offsets, Pointers}; -pub use commitment_dlog::{ - commitment::{ - b_poly, b_poly_coefficients, combined_inner_product, BatchEvaluationProof, CommitmentCurve, - Evaluation, PolyComm, - }, - evaluation_proof::OpeningProof, - srs::{endos, SRS}, -}; -pub use groupmap::{BWParameters, GroupMap}; -pub use mina_curves::pasta::{ - fp::Fp, - pallas::Affine as Other, - vesta::{Affine, VestaParameters}, -}; -pub use o1_utils::{ - field_helpers, hasher::CryptoDigest, math, types::fields, ExtendedDensePolynomial, - ExtendedEvaluations, -}; -pub use oracle::{constants, pasta::fp_kimchi::params, poseidon, sponge}; +pub use cairo; +pub use commitment_dlog; +pub use groupmap; +pub use mina_curves; +pub use o1_utils; +pub use oracle; pub mod alphas; pub mod bench; From 11e5fe5f072ee02ce216d77f037baf7b63b3ec7b Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 13 Jun 2022 21:19:39 +0200 Subject: [PATCH 17/21] re exporting crates in kimchi --- kimchi/README.md | 94 ----------------------------------------------- kimchi/src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 95 deletions(-) diff --git a/kimchi/README.md b/kimchi/README.md index 1789c1bef1..b9cfca5ba5 100644 --- a/kimchi/README.md +++ b/kimchi/README.md @@ -60,103 +60,9 @@ Check [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in contributing t ## Guidelines -There are three main steps to follow in order to start using this library: - -1. Create the circuit for the targetted relation as a vector of gates. You can use our own custom gates as building blocks, or build your own. - -2. Feed the circuit with a witness that will satisfy the relation. This is equivalent to finding (or computing) a correct instantiation of the execution trace. - -3. Generate and verify the proof of the witness for the relation. - -## Example - When using this library, make sure to include in your Cargo.toml the following dependency: ` [dependencies] kimchi = { git = "https://github.com/o1-labs/proof-systems" } ` - -Here is an example that uses this library. This code takes the output of a hash and makes sure that the prover knows the input to the hash function. - -```rust -use itertools::iterate; -use kimchi::circuits::{ - gate::CircuitGate, - wires::Wire, - polynomials::generic::GenericGateSpec}; -use mina_curves::pasta::Fp; -/// create a simple circuit to hash an input -fn create_circuit() -> Vec> { - let mut gates = vec![]; - let mut gates_row = iterate(0, |&i| i + 1); - let mut row = || gates_row.next().unwrap(); - // the output to the hash function is a public input - // and public inputs are handled with generic gates - gates.push(CircuitGate::create_generic_gadget( - Wire::new(row()), - GenericGateSpec::Pub, - None, - )); - gates.push(CircuitGate::create_generic_gadget( - Wire::new(row()), - GenericGateSpec::Pub, - None, - )); - gates.push(CircuitGate::create_generic_gadget( - Wire::new(row()), - GenericGateSpec::Pub, - None, - )); - // hash a private input - let poseidon_params = oracle::pasta::fp_kimchi::params(); - let round_constants = &poseidon_params.round_constants; - let row = row(); - let (g, final_row) = CircuitGate::::create_poseidon_gadget( - row, - [Wire::new(row), Wire::new(row + 11)], // TODO: this argument should be deleted from the fn - round_constants, - ); - gates.extend(g); - // wire the output to the public input - // TODO: it'd be nice if we had functions that would do this for us, - // and panic if a permutation is already in place - let last_row = gates.iter_mut().last().unwrap(); - last_row.wires[0] = Wire { row: 0, col: 0 }; - last_row.wires[1] = Wire { row: 0, col: 1 }; - last_row.wires[2] = Wire { row: 0, col: 2 }; - gates[0].wires[0] = Wire { - row: final_row, - col: 0, - }; - gates[0].wires[1] = Wire { - row: final_row, - col: 1, - }; - gates[0].wires[2] = Wire { - row: final_row, - col: 2, - }; - gates -} -/* -fn create_witness(gates: &Vec>) -> [Vec; COLUMNS] { - // TODO -} -fn verify_proof(gates: Vec>, witness: [Vec; COLUMNS], public: &[Fp]) { - // TODO -} -*/ -fn test_example() { - // first define the circuit - let gates = create_circuit(); - // then compute the witness for the circuit and the public input - /* - let public = /*the output of the hash function*/ - // TODO: we need simple witness generators for each gate - let mut witness: [Vec; COLUMNS] = create_witness(&gates, &public); - // generate and verify a proof - verify_proof(gates, witness, &public); - */ -} -``` \ No newline at end of file diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index bfe27fb55a..6789f620db 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../../README.md")] #[macro_use] extern crate num_derive; From 8d3b157ca8f924b3057991bc48d3df1554ac6f42 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 13 Jun 2022 21:33:22 +0200 Subject: [PATCH 18/21] restore general readme --- README.md | 117 ----------------------------------------------- kimchi/README.md | 3 -- 2 files changed, 120 deletions(-) diff --git a/README.md b/README.md index 7f7fcc5764..a35b29ea2a 100644 --- a/README.md +++ b/README.md @@ -132,120 +132,3 @@ The project is organized in the following way: ## Contributing Check [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in contributing to this project. - -## Guidelines - -There are three main steps to follow in order to start using this library: - -1. Create the circuit for the targetted relation as a vector of gates. You can use our own custom gates as building blocks, or build your own. - -2. Feed the circuit with a witness that will satisfy the relation. This is equivalent to finding (or computing) a correct instantiation of the execution trace. - -3. Generate and verify the proof of the witness for the relation. - -## Example - -When using this library, make sure to include in your Cargo.toml the following dependencies: - -` -[dependencies] -kimchi = { git = "https://github.com/o1-labs/proof-systems" } -` - -Here is an example that uses this library. This code takes the output of a hash and makes sure that the prover knows the input to the hash function. - -```rust - -use itertools::iterate; -use kimchi::circuits::{ - gate::CircuitGate, - wires::Wire, - polynomials::generic::GenericGateSpec}; -use mina_curves::pasta::Fp; - -/// create a simple circuit to hash an input -fn create_circuit() -> Vec> { - let mut gates = vec![]; - let mut gates_row = iterate(0, |&i| i + 1); - let mut row = || gates_row.next().unwrap(); - - // the output to the hash function is a public input - // and public inputs are handled with generic gates - gates.push(CircuitGate::create_generic_gadget( - Wire::new(row()), - GenericGateSpec::Pub, - None, - )); - gates.push(CircuitGate::create_generic_gadget( - Wire::new(row()), - GenericGateSpec::Pub, - None, - )); - gates.push(CircuitGate::create_generic_gadget( - Wire::new(row()), - GenericGateSpec::Pub, - None, - )); - - // hash a private input - let poseidon_params = oracle::pasta::fp_kimchi::params(); - let round_constants = &poseidon_params.round_constants; - let row = row(); - let (g, final_row) = CircuitGate::::create_poseidon_gadget( - row, - [Wire::new(row), Wire::new(row + 11)], // TODO: this argument should be deleted from the fn - round_constants, - ); - gates.extend(g); - - // wire the output to the public input - // TODO: it'd be nice if we had functions that would do this for us, - // and panic if a permutation is already in place - let last_row = gates.iter_mut().last().unwrap(); - last_row.wires[0] = Wire { row: 0, col: 0 }; - last_row.wires[1] = Wire { row: 0, col: 1 }; - last_row.wires[2] = Wire { row: 0, col: 2 }; - - gates[0].wires[0] = Wire { - row: final_row, - col: 0, - }; - gates[0].wires[1] = Wire { - row: final_row, - col: 1, - }; - gates[0].wires[2] = Wire { - row: final_row, - col: 2, - }; - - gates -} - -/* -fn create_witness(gates: &Vec>) -> [Vec; COLUMNS] { - // TODO -} - -fn verify_proof(gates: Vec>, witness: [Vec; COLUMNS], public: &[Fp]) { - // TODO -} -*/ - -fn test_example() { - // first define the circuit - let gates = create_circuit(); - - // then compute the witness for the circuit and the public input - /* - let public = /*the output of the hash function*/ - // TODO: we need simple witness generators for each gate - let mut witness: [Vec; COLUMNS] = create_witness(&gates, &public); - - // generate and verify a proof - verify_proof(gates, witness, &public); - */ - -} - -``` \ No newline at end of file diff --git a/kimchi/README.md b/kimchi/README.md index b9cfca5ba5..8f4c0980ab 100644 --- a/kimchi/README.md +++ b/kimchi/README.md @@ -54,9 +54,6 @@ To obtain a flamegraph: Note: lots of good advice on system performance in the [flamegraph repo](https://github.com/flamegraph-rs/flamegraph#systems-performance-work-guided-by-flamegraphs). -## Contributing - -Check [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in contributing to this project. ## Guidelines From c8135c6a4b2d7abbb94a1e5bf14219f9a541749f Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 13 Jun 2022 21:38:28 +0200 Subject: [PATCH 19/21] exporting what is used by the circuit example directly in the root --- kimchi/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 6789f620db..47b957b488 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -10,6 +10,14 @@ pub use mina_curves; pub use o1_utils; pub use oracle; +pub use commitment_dlog::{commitment::CommitmentCurve, srs::SRS}; +pub use groupmap::GroupMap; +pub use oracle::{ + constants::*, + poseidon::{ArithmeticSponge, Sponge}, + sponge::{DefaultFqSponge, DefaultFrSponge}, +}; + pub mod alphas; pub mod bench; pub mod circuits; From 3924bb560e4c3cf604b9d6db49b6dedcc7dd22d0 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 13 Jun 2022 21:43:17 +0200 Subject: [PATCH 20/21] delete unneded exports --- kimchi/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 47b957b488..6789f620db 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -10,14 +10,6 @@ pub use mina_curves; pub use o1_utils; pub use oracle; -pub use commitment_dlog::{commitment::CommitmentCurve, srs::SRS}; -pub use groupmap::GroupMap; -pub use oracle::{ - constants::*, - poseidon::{ArithmeticSponge, Sponge}, - sponge::{DefaultFqSponge, DefaultFrSponge}, -}; - pub mod alphas; pub mod bench; pub mod circuits; From 675dfbf4f8fa9c5d54a6d65ebaad8e640e8de6bd Mon Sep 17 00:00:00 2001 From: querolita Date: Tue, 14 Jun 2022 13:40:11 +0200 Subject: [PATCH 21/21] update kombucha reference for the readme --- README.md | 13 +++++++++++++ kimchi/README.md | 9 --------- kimchi/src/lib.rs | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a35b29ea2a..946d444c79 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,19 @@ You can read more about this project on the [Kimchi book](https://o1-labs.github [See here for the rust documentation](https://o1-labs.github.io/proof-systems/rustdoc). +# Kombucha + +This repository contains **kombucha**, the Kimchi circuit constructor for external users. + +## Guidelines + +When using this library, make sure to include in your Cargo.toml the following dependency: + +```toml +[dependencies] +circuit-construction = { git = "https://github.com/o1-labs/proof-systems" } +``` + ## Example The following is an example to demonstrate a full cycle workflow using circuit-construction: diff --git a/kimchi/README.md b/kimchi/README.md index 8f4c0980ab..76a71006cc 100644 --- a/kimchi/README.md +++ b/kimchi/README.md @@ -54,12 +54,3 @@ To obtain a flamegraph: Note: lots of good advice on system performance in the [flamegraph repo](https://github.com/flamegraph-rs/flamegraph#systems-performance-work-guided-by-flamegraphs). - -## Guidelines - -When using this library, make sure to include in your Cargo.toml the following dependency: - -` -[dependencies] -kimchi = { git = "https://github.com/o1-labs/proof-systems" } -` diff --git a/kimchi/src/lib.rs b/kimchi/src/lib.rs index 6789f620db..bfe27fb55a 100644 --- a/kimchi/src/lib.rs +++ b/kimchi/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../../README.md")] +#![doc = include_str!("../README.md")] #[macro_use] extern crate num_derive;