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 Clone trait for CircuitBuilder #26

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
[workspace]
members = ["field", "maybe_rayon", "plonky2", "starky", "util", "gen"]
members = ["field", "maybe_rayon", "plonky2", "starky", "util", "gen"]
resolver = "2"

[workspace.dependencies]
ahash = { version = "0.8.7", default-features = false, features = ["compile-time-rng"] } # NOTE: Be sure to keep this version the same as the dependency in `hashbrown`.
cryptography_cuda = { git = "ssh://[email protected]/okx/cryptography_cuda.git", rev = "173510160183f3299f4765b30bd4f2c1685353f9", features = [
"no_cuda",
] }
ahash = { version = "0.8.7", default-features = false, features = [
"compile-time-rng",
] } # NOTE: Be sure to keep this version the same as the dependency in `hashbrown`.
anyhow = { version = "1.0.40", default-features = false }
hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "serde"] } # NOTE: When upgrading, see `ahash` dependency.
hashbrown = { version = "0.14.3", default-features = false, features = [
"ahash",
"serde",
] } # NOTE: When upgrading, see `ahash` dependency.
itertools = { version = "0.11.0", default-features = false }
log = { version = "0.4.14", default-features = false }
num = { version = "0.4", default-features = false, features = ["rand"] }
Expand Down
9 changes: 7 additions & 2 deletions field/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
name = "plonky2_field"
description = "Finite field arithmetic"
version = "0.2.0"
authors = ["Daniel Lubarov <[email protected]>", "William Borgeaud <[email protected]>", "Jacqueline Nabaglo <[email protected]>", "Hamish Ivey-Law <[email protected]>"]
authors = [
"Daniel Lubarov <[email protected]>",
"William Borgeaud <[email protected]>",
"Jacqueline Nabaglo <[email protected]>",
"Hamish Ivey-Law <[email protected]>",
]
edition.workspace = true
license.workspace = true
homepage.workspace = true
Expand All @@ -23,7 +28,7 @@ rand = { workspace = true, features = ["getrandom"] }
serde = { workspace = true, features = ["alloc"] }
static_assertions = { workspace = true }
unroll = { workspace = true }
cryptography_cuda = { git = "ssh://[email protected]/okx/cryptography_cuda.git", rev = "173510160183f3299f4765b30bd4f2c1685353f9", optional = true }
cryptography_cuda = { workspace = true, optional = true }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["getrandom"] }
Expand Down
7 changes: 3 additions & 4 deletions field/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::env;
use std::fs::write;
use std::path::{Path};
#[cfg(feature = "precompile")]
use std::Path::{PathBuf};
use std::path::Path;
use std::process::Command;
#[cfg(feature = "precompile")]
use std::str::FromStr;
#[cfg(feature = "precompile")]
use std::Path::PathBuf;

use anyhow::Context;
#[cfg(feature = "precompile")]
Expand All @@ -29,7 +29,6 @@ fn build_precompile() {
_ = write_generated_file(token_stream, "goldilock_root_of_unity.rs");
}
fn main() {

#[cfg(feature = "precompile")]
build_precompile();
}
Expand Down
2 changes: 0 additions & 2 deletions field/examples/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use plonky2_field::fft::fft;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_field::types::Field;


use rand::random;

fn random_fr() -> u64 {
Expand Down
5 changes: 2 additions & 3 deletions field/src/goldilocks_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ use core::iter::{Product, Sum};
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};

use num::{BigUint, Integer, ToPrimitive};
#[cfg(feature = "precompile")]
use plonky2_util::log2_strict;
use plonky2_util::{assume, branch_hint};
use serde::{Deserialize, Serialize};
#[cfg(feature = "precompile")]
use plonky2_util::{log2_strict};

#[cfg(feature = "precompile")]
use crate::fft::FftRootTable;
use crate::ops::Square;
use crate::types::{Field, Field64, PrimeField, PrimeField64, Sample};

#[cfg(feature = "precompile")]
use crate::PRE_COMPUTE_ROOT_TABLES;

Expand Down
2 changes: 1 addition & 1 deletion field/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include!(concat!(env!("OUT_DIR"), "/goldilock_root_of_unity.rs"));

#[cfg(feature = "precompile")]
use std::collections::HashMap;

#[cfg(feature = "precompile")]
use fft::FftRootTable;
#[cfg(feature = "precompile")]
Expand Down Expand Up @@ -79,7 +80,6 @@ lazy_static! {

#[cfg(test)]
mod test {


#[cfg(feature = "precompile")]
#[test]
Expand Down
2 changes: 1 addition & 1 deletion field/src/polynomial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};

use crate::extension::{Extendable, FieldExtension};
use crate::fft::{fft, fft_with_options, ifft, FftRootTable};
use crate::types::{Field};
use crate::types::Field;

/// A polynomial in point-value form.
///
Expand Down
1 change: 1 addition & 0 deletions field/src/secp256k1_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use itertools::Itertools;
use num::bigint::BigUint;
use num::{Integer, One};
use serde::{Deserialize, Serialize};

use crate::types::{Field, PrimeField, Sample};

/// The base field of the secp256k1 elliptic curve.
Expand Down
9 changes: 2 additions & 7 deletions field/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAss

use num::bigint::BigUint;
use num::{Integer, One, ToPrimitive, Zero};
use plonky2_util::{bits_u64};
use plonky2_util::bits_u64;
use rand::rngs::OsRng;
use serde::de::DeserializeOwned;
use serde::Serialize;
Expand All @@ -16,8 +16,6 @@ use crate::extension::Frobenius;
use crate::fft::FftRootTable;
use crate::ops::Square;



/// Sampling
pub trait Sample: Sized {
/// Samples a single value using `rng`.
Expand Down Expand Up @@ -277,10 +275,7 @@ pub trait Field:
base.exp_power_of_2(Self::TWO_ADICITY - n_log)
}

fn pre_compute_fft_root_table(
_: usize,
) -> Option<&'static FftRootTable<Self>>
{
fn pre_compute_fft_root_table(_: usize) -> Option<&'static FftRootTable<Self>> {
None
}

Expand Down
6 changes: 4 additions & 2 deletions gen/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(incomplete_features)]

#![feature(generic_const_exprs)]

use std::fs::File;
Expand Down Expand Up @@ -84,7 +83,10 @@ where
}

pub fn generate_to(file: &mut File) -> Result<(), Error> {
println!("generate for start {:?}, end {:?}", PRE_COMPUTE_START, PRE_COMPUTE_END);
println!(
"generate for start {:?}, end {:?}",
PRE_COMPUTE_START, PRE_COMPUTE_END
);
let context = RouContext::<PRE_COMPUTE_START, PRE_COMPUTE_END>::new_boxed();
let pre_g = context.inspect_raw().as_ref();

Expand Down
1 change: 1 addition & 0 deletions gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 7 additions & 2 deletions plonky2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
name = "plonky2"
description = "Recursive SNARKs based on PLONK and FRI"
version = "0.2.0"
authors = ["Daniel Lubarov <[email protected]>", "William Borgeaud <[email protected]>", "Nicholas Ward <[email protected]>"]
authors = [
"Daniel Lubarov <[email protected]>",
"William Borgeaud <[email protected]>",
"Nicholas Ward <[email protected]>",
]
readme = "README.md"
edition.workspace = true
license.workspace = true
Expand Down Expand Up @@ -42,7 +46,8 @@ once_cell = { version = "1.18.0" }
plonky2_field = { version = "0.2.0", 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 = { git = "ssh://[email protected]/okx/cryptography_cuda.git", rev = "173510160183f3299f4765b30bd4f2c1685353f9", optional = true }
cryptography_cuda = { workspace = true, optional = true }
dyn-clone = "1.0.17"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", default-features = false, features = ["js"] }
Expand Down
2 changes: 1 addition & 1 deletion plonky2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ fn main() {

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
.expect("Couldn't write bindings!");
}
2 changes: 1 addition & 1 deletion plonky2/examples/bench_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use core::str::FromStr;

use anyhow::{anyhow, Context as _, Result};
use log::{info, Level, LevelFilter};
use plonky2_maybe_rayon::rayon;
use plonky2::gates::noop::NoopGate;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::witness::{PartialWitness, WitnessWrite};
Expand All @@ -27,6 +26,7 @@ use plonky2::plonk::proof::{CompressedProofWithPublicInputs, ProofWithPublicInpu
use plonky2::plonk::prover::prove;
use plonky2::util::timing::TimingTree;
use plonky2_field::extension::Extendable;
use plonky2_maybe_rayon::rayon;
use rand::rngs::OsRng;
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
Expand Down
2 changes: 1 addition & 1 deletion plonky2/examples/square_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use plonky2_field::extension::Extendable;

/// A generator used by the prover to calculate the square root (`x`) of a given value
/// (`x_squared`), outside of the circuit, in order to supply it as an additional public input.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
struct SquareRootGenerator<F: RichField + Extendable<D>, const D: usize> {
x: Target,
x_squared: Target,
Expand Down
1 change: 0 additions & 1 deletion plonky2/src/fri/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use cryptography_cuda::{
device::memory::HostOrDeviceSlice, lde_batch, lde_batch_multi_gpu, transpose_rev_batch,
types::*,
};

use itertools::Itertools;
use plonky2_field::types::Field;
use plonky2_maybe_rayon::*;
Expand Down
3 changes: 2 additions & 1 deletion plonky2/src/fri/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ fn fri_committed_trees<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>,
.par_chunks(arity)
.map(|chunk: &[F::Extension]| flatten(chunk))
.collect();
let tree = MerkleTree::<F, C::Hasher>::new_from_2d(chunked_values, fri_params.config.cap_height);
let tree =
MerkleTree::<F, C::Hasher>::new_from_2d(chunked_values, fri_params.config.cap_height);

challenger.observe_cap(&tree.cap);
trees.push(tree);
Expand Down
5 changes: 2 additions & 3 deletions plonky2/src/fri/recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::fri::proof::{
};
use crate::fri::structure::{FriBatchInfoTarget, FriInstanceInfoTarget, FriOpeningsTarget};
use crate::fri::{FriConfig, FriParams};

use crate::gates::gate::Gate;
use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate;
use crate::gates::interpolation::InterpolationGate;
Expand Down Expand Up @@ -50,7 +49,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
let start = self.exp_from_bits_const_base(g_inv, x_index_within_coset_bits.iter().rev());
let coset_start = self.mul(start, x);

// NOTE: circom_compatability
// NOTE: circom_compatability
// // The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta.
// let interpolation_gate = <CosetInterpolationGate<F, D>>::with_max_degree(
// arity_bits,
Expand Down Expand Up @@ -275,7 +274,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}

// sum
// NOTE: circom_compatability
// NOTE: circom_compatability
// Multiply the final polynomial by `X`, so that `final_poly` has the maximum degree for
// which the LDT will pass. See github.com/mir-protocol/plonky2/pull/436 for details.
self.mul_extension(sum, subgroup_x)
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/fri/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub(crate) fn fri_combine_initial<
}

// sum
// NOTE: circom_compatability
// NOTE: circom_compatability
// Multiply the final polynomial by `X`, so that `final_poly` has the maximum degree for
// which the LDT will pass. See github.com/mir-protocol/plonky2/pull/436 for details.
sum * subgroup_x
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gadgets/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct EqualityGenerator {
x: Target,
y: Target,
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gadgets/arithmetic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct QuotientGeneratorExtension<const D: usize> {
numerator: ExtensionTarget<D>,
denominator: ExtensionTarget<D>,
Expand Down
2 changes: 0 additions & 2 deletions plonky2/src/gadgets/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use alloc::vec;

use plonky2_field::extension::Extendable;


use crate::gates::interpolation::InterpolationGate;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
Expand Down Expand Up @@ -72,7 +71,6 @@ mod tests {
use crate::field::extension::FieldExtension;
use crate::field::interpolation::interpolant;
use crate::field::types::{Field, Sample};

use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate;
use crate::gates::low_degree_interpolation::LowDegreeInterpolationGate;
use crate::iop::witness::PartialWitness;
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gadgets/range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct LowHighGenerator {
integer: Target,
n_log: usize,
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gadgets/split_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct BaseSumGenerator<const B: usize> {
row: usize,
limbs: Vec<BoolTarget>,
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gadgets/split_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct SplitGenerator {
integer: Target,
bits: Vec<Target>,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D> for Spl
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct WireSplitGenerator {
integer: Target,
gates: Vec<usize>,
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gates/base_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<F: RichField + Extendable<D>, const D: usize, const B: usize> PackedEvaluab
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct BaseSplitGenerator<const B: usize> {
row: usize,
num_limbs: usize,
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gates/coset_interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for CosetInterpola
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct InterpolationGenerator<F: RichField + Extendable<D>, const D: usize> {
row: usize,
gate: CosetInterpolationGate<F, D>,
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gates/exponentiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct ExponentiationGenerator<F: RichField + Extendable<D>, const D: usize> {
row: usize,
gate: ExponentiationGate<F, D>,
Expand Down
Loading
Loading