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

Implement Plonky3 frontend adaptor #306

Merged
merged 27 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
acdbdf3
feat: copy symbolic from Plonky3
ed255 Mar 27, 2024
dc46c17
feat: copy fibo_air test from Plonky3
ed255 Mar 27, 2024
38a5f02
checkpoint
ed255 Mar 27, 2024
0664b54
checkpoint
ed255 Mar 28, 2024
4d2882e
feat: complete p3 frontend PoC
ed255 Mar 31, 2024
6208ca2
chore: clean up
ed255 Apr 2, 2024
4f9f19f
chore: revert changes in middleware
ed255 Apr 2, 2024
b7bf734
fix: clippy warnings
ed255 Apr 2, 2024
4812248
feat: add keccak test and fixes
ed255 Apr 3, 2024
500b773
chore: clean up
ed255 Apr 8, 2024
7cd356b
fix: clippy warnings
ed255 Apr 9, 2024
6beb646
chore: clean up tests
ed255 Apr 9, 2024
bf69b4a
fix: clippy warnings
ed255 Apr 9, 2024
95a7601
fix: remove debug print
ed255 Apr 9, 2024
4a686e8
chore: comment about transition constraints
ed255 May 17, 2024
4fc156b
chore: extend comment about PrimeField64 impl
ed255 May 17, 2024
552043c
Merge branch 'main' into feat/p3-frontend
ed255 May 17, 2024
c043d86
fix: merge renamings
ed255 May 17, 2024
c850856
chore: add unit tests
ed255 May 21, 2024
6304585
fix: clippy complaints
ed255 May 21, 2024
8eea66f
chore: extend unit test
ed255 May 21, 2024
80c1d47
Merge branch 'main' into feat/p3-frontend
ed255 May 22, 2024
998992b
chore: replace no coverage directives
ed255 May 22, 2024
8e1d5d3
chore: remove no coverage directives
ed255 May 22, 2024
622f6ad
chore: apply feedback from @adria0
ed255 May 27, 2024
be40a51
Merge branch 'main' into feat/p3-frontend
ed255 May 27, 2024
37c916f
fix: clippy warnings and PCS API update
ed255 May 27, 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ members = [
"halo2_frontend",
"halo2_middleware",
"halo2_backend",
"p3_frontend",
]
resolver = "2"
1 change: 1 addition & 0 deletions halo2_backend/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use halo2curves::{CurveAffine, CurveExt};
/// This represents an element of a group with basic operations that can be
/// performed. This allows an FFT implementation (for example) to operate
/// generically over either a field or elliptic curve group.
#[allow(dead_code)]
pub(crate) trait FftGroup<Scalar: Field>:
Copy + Send + Sync + 'static + GroupOpsOwned + ScalarMulOwned<Scalar>
{
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ pub(crate) fn write_polynomial_slice<W: io::Write, F: SerdePrimeField, B>(
/// Gets the total number of bytes of a slice of polynomials, assuming all polynomials are the same length
pub(crate) fn polynomial_slice_byte_length<F: PrimeField, B>(slice: &[Polynomial<F, B>]) -> usize {
let field_len = F::default().to_repr().as_ref().len();
4 + slice.len() * (4 + field_len * slice.get(0).map(|poly| poly.len()).unwrap_or(0))
4 + slice.len() * (4 + field_len * slice.first().map(|poly| poly.len()).unwrap_or(0))
}
2 changes: 1 addition & 1 deletion halo2_backend/src/poly/ipa/multiopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where
let mut point_index_set = BTreeSet::new();
for (commitment, point_idx_set) in commitment_set_map.iter() {
if query.get_commitment() == *commitment {
point_index_set = point_idx_set.clone();
point_index_set.clone_from(point_idx_set);
}
}
assert!(!point_index_set.is_empty());
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/poly/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub enum CommitmentReference<'r, C: CurveAffine, M: MSM<C>> {
impl<'r, C: CurveAffine, M: MSM<C>> Copy for CommitmentReference<'r, C, M> {}

impl<'r, C: CurveAffine, M: MSM<C>> PartialEq for CommitmentReference<'r, C, M> {
#![allow(clippy::vtable_address_comparisons)]
#![allow(ambiguous_wide_pointer_comparisons)]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(&CommitmentReference::Commitment(a), &CommitmentReference::Commitment(b)) => {
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ fn batch_invert_assigned<F: Field>(assigned: Vec<Vec<Assigned<F>>>) -> Vec<Vec<F
// `Assigned<F>`.
fn poly_invert<F: Field>(
poly: &[Assigned<F>],
inv_denoms: impl Iterator<Item = F> + ExactSizeIterator,
inv_denoms: impl ExactSizeIterator<Item = F>,
) -> Vec<F> {
assert_eq!(inv_denoms.len(), poly.len());
poly.iter()
Expand Down
1 change: 1 addition & 0 deletions halo2_frontend/src/plonk/circuit/constraint_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::fmt::Debug;
/// Represents an index into a vector where each entry corresponds to a distinct
/// point that polynomials are queried at.
#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
pub(crate) struct PointIndex(pub usize);

/// A "virtual cell" is a PLONK cell that has been queried at a particular relative offset
Expand Down
1 change: 1 addition & 0 deletions halo2_proofs/benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use criterion::{BenchmarkId, Criterion};
fn criterion_benchmark(c: &mut Criterion) {
/// This represents an advice column at a certain row in the ConstraintSystem
#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
pub struct Variable(Column<Advice>, usize);

#[derive(Clone)]
Expand Down
1 change: 1 addition & 0 deletions halo2_proofs/examples/circuit-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::marker::PhantomData;

/// This represents an advice column at a certain row in the ConstraintSystem
#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
pub struct Variable(Column<Advice>, usize);

#[derive(Clone)]
Expand Down
3 changes: 3 additions & 0 deletions halo2_proofs/tests/compress_selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct MyCircuitConfig {

s_add: Selector,
s_mul: Selector,
#[allow(dead_code)]
s_cubed: Selector,

PI: Column<Instance>,
Expand Down Expand Up @@ -82,6 +83,7 @@ trait MyCircuitComposer<F: Field> {
row: usize,
) -> Result<(), Error>;

#[allow(dead_code)]
fn cube<FM>(&self, layouter: &mut impl Layouter<F>, f: FM) -> Result<(Cell, Cell), Error>
where
FM: FnMut() -> Value<(Assigned<F>, Assigned<F>)>;
Expand Down Expand Up @@ -362,6 +364,7 @@ fn test_mycircuit(
let pk = keygen_pk_custom(&params, vk.clone(), &circuit, pk_keygen_compress_selectors)?;

// Proving
#[allow(clippy::useless_vec)]
let instances = vec![vec![Fr::one(), Fr::from_u128(3)]];
let instances_slice: &[&[Fr]] = &(instances
.iter()
Expand Down
1 change: 1 addition & 0 deletions halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn plonk_api() {

/// This represents an advice column at a certain row in the ConstraintSystem
#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
pub struct Variable(Column<Advice>, usize);

#[derive(Clone)]
Expand Down
37 changes: 37 additions & 0 deletions p3_frontend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "p3_frontend"
version = "0.3.0"
authors = [
"Privacy Scaling Explorations team",
]
edition = "2021"
description = """
Plonky3 frontend implementation. Allows using a circuit defined with the Air trait from plonky3 to be proved with a halo2 backend.
"""
license = "MIT OR Apache-2.0"
categories = ["cryptography"]
keywords = ["halo", "proofs", "zkp", "zkSNARKs", "plonky3"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]

[dependencies]
p3-air = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
p3-util = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
p3-matrix = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
p3-field = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
halo2_middleware = { path = "../halo2_middleware" }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
num-bigint = { version = "0.4.3", default-features = false }

[dev-dependencies]
halo2curves = { version = "0.6.0", default-features = false }
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
halo2_backend = { path = "../halo2_backend" }
serde_test = { version = "1.0" }
p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
p3-keccak = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
p3-util = { git = "https://github.com/Plonky3/Plonky3", rev = "7b5b8a6" }
rand = "0.8.5"
7 changes: 7 additions & 0 deletions p3_frontend/src/air.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Alternative `AirBuilderWithPublicValues` trait that uses `Self::Var` instead of `Self::F`.

use p3_air::AirBuilder;

pub trait AirBuilderWithPublicValues: AirBuilder {
fn public_values(&self) -> &[Self::Var];
}
Loading
Loading