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

Restructure modules internally #806

Merged
merged 1 commit into from
Dec 22, 2023
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Hide all modules except 'prelude' [#782]
- Turn `Composer` trait into a struct [#802]
- Rename `Arithmetization` to `Gate` [#802]
- Change internal module structure [#805]:
- Move compiler module to root
- Move prover and verifier modules under compiler
- Move compress module under composer
- Move constraint_system module under composer
- Move permutation module under composer

### Removed

Expand Down Expand Up @@ -548,6 +554,7 @@ is necessary since `rkyv/validation` was required as a bound.
- Proof system module.

<!-- ISSUES -->
[#805]: https://github.com/dusk-network/plonk/issues/805
[#802]: https://github.com/dusk-network/plonk/issues/802
[#797]: https://github.com/dusk-network/plonk/issues/797
[#796]: https://github.com/dusk-network/plonk/issues/796
Expand Down
18 changes: 11 additions & 7 deletions src/composer/compiler.rs → src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ use alloc::vec::Vec;
use dusk_bls12_381::BlsScalar;

use crate::commitment_scheme::{CommitKey, OpeningKey, PublicParameters};
use crate::constraint_system::{Constraint, Selector, Witness};
use crate::composer::CompressedCircuit;
use crate::error::Error;
use crate::fft::{EvaluationDomain, Evaluations, Polynomial};
use crate::proof_system::preprocess::Polynomials;
use crate::proof_system::{widget, ProverKey};

use super::{Circuit, Composer, Gate, Prover, Verifier};
use crate::prelude::{Circuit, Composer};

#[cfg(feature = "alloc")]
mod compress;
mod prover;
mod verifier;

pub use prover::Prover;
pub use verifier::Verifier;

/// Generate the arguments to prove and verify a circuit
pub struct Compiler;
Expand Down Expand Up @@ -65,7 +68,8 @@ impl Compiler {
where
C: Circuit,
{
compress::CompressedCircuit::from_circuit::<C>(true)
let hades_optimization = true;
CompressedCircuit::from_circuit::<C>(hades_optimization)
}

/// Generates a [Prover] and [Verifier] from a buffer created by
Expand All @@ -75,13 +79,13 @@ impl Compiler {
label: &[u8],
compressed: &[u8],
) -> Result<(Prover, Verifier), Error> {
compress::CompressedCircuit::from_bytes(pp, label, compressed)
CompressedCircuit::from_bytes(pp, label, compressed)
}

/// Create a new arguments set from a given circuit instance
///
/// Use the default implementation of the circuit
fn compile_with_composer(
pub(crate) fn compile_with_composer(
pp: &PublicParameters,
label: &[u8],
composer: &Composer,
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 11 additions & 12 deletions src/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ use dusk_bls12_381::BlsScalar;
use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};

use crate::bit_iterator::BitIterator8;
use crate::constraint_system::ecc::WnafRound;
use crate::constraint_system::{
Constraint, Selector, WiredWitness, Witness, WitnessPoint,
};
use crate::error::Error;
use crate::permutation::Permutation;
use crate::runtime::{Runtime, RuntimeEvent};

mod circuit;
mod compiler;
mod compress;
mod constraint_system;
mod gate;
mod prover;
mod verifier;

pub(crate) mod permutation;

pub use circuit::Circuit;
pub use compiler::Compiler;
use constraint_system::ecc::WnafRound;
pub use constraint_system::{Constraint, Witness, WitnessPoint};
pub use gate::Gate;
pub use prover::Prover;
pub use verifier::Verifier;

pub(crate) use compress::CompressedCircuit;
pub(crate) use constraint_system::{Selector, WireData, WiredWitness};
pub(crate) use permutation::Permutation;

/// Construct and prove circuits
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -173,7 +172,7 @@ impl Composer {
/// Create an empty constraint system.
///
/// This shouldn't be used directly; instead, use [`Self::initialized`]
fn uninitialized() -> Self {
pub(crate) fn uninitialized() -> Self {
Self {
constraints: Vec::new(),
public_inputs: HashMap::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use msgpacker::{MsgPacker, Packable, Unpackable};
use alloc::vec::Vec;

use super::{
BlsScalar, Circuit, Compiler, Composer, Constraint, Error, Gate, Prover,
PublicParameters, Selector, Verifier, Witness,
BlsScalar, Circuit, Composer, Constraint, Error, Gate, Selector, Witness,
};
use crate::prelude::{Compiler, Prover, PublicParameters, Verifier};

mod hades;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::composer::Composer;
use crate::constraint_system::Witness;
use crate::prelude::{Composer, Witness};
use dusk_bls12_381::BlsScalar;

/// Selectors used to address a coefficient inside of a [`Constraint`]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::constraint_system::Witness;
use crate::prelude::Witness;
use dusk_bls12_381::BlsScalar;

/// Represents a JubJub point in the circuit
Expand Down
2 changes: 1 addition & 1 deletion src/composer/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use dusk_bls12_381::BlsScalar;

use crate::constraint_system::Witness;
use crate::prelude::Witness;

/// Represents a gate with its associated wire data
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion src/permutation.rs → src/composer/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::constraint_system::{WireData, Witness};
use crate::composer::{WireData, Witness};
use crate::fft::{EvaluationDomain, Polynomial};
use alloc::vec::Vec;
use constants::{K1, K2, K3};
Expand Down
File renamed without changes.
9 changes: 1 addition & 8 deletions src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use dusk_cdf::{
Encoder, EncoderContextFileProvider, Polynomial, Selectors, WiredWitnesses,
};

use crate::constraint_system::{Constraint, Selector, WiredWitness, Witness};
use crate::composer::{Constraint, Selector, WiredWitness, Witness};
use crate::runtime::RuntimeEvent;

/// PLONK debugger
Expand Down Expand Up @@ -187,13 +187,6 @@ impl Debugger {
}
}

pub(crate) fn with_capacity(capacity: usize) -> Self {
Self {
witnesses: Vec::with_capacity(capacity),
constraints: Vec::with_capacity(capacity),
}
}

pub(crate) fn event(&mut self, event: RuntimeEvent) {
match event {
RuntimeEvent::WitnessAppended { w, v } => {
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ if #[cfg(feature = "alloc")] {
extern crate alloc;

mod bit_iterator;
mod constraint_system;
mod compiler;
mod composer;
mod permutation;
mod runtime;
mod util;
mod transcript;
Expand Down
4 changes: 2 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#[cfg(feature = "alloc")]
pub use crate::{
commitment_scheme::PublicParameters,
composer::{Circuit, Compiler, Composer, Prover, Verifier},
constraint_system::{Constraint, Witness, WitnessPoint},
compiler::{Compiler, Prover, Verifier},
composer::{Circuit, Composer, Constraint, Witness, WitnessPoint},
};

pub use crate::error::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/proof_system/widget/permutation/proverkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::composer::permutation::constants::{K1, K2, K3};
use crate::fft::{EvaluationDomain, Evaluations, Polynomial};
use crate::permutation::constants::{K1, K2, K3};
use dusk_bls12_381::BlsScalar;

#[cfg(feature = "rkyv-impl")]
Expand Down
2 changes: 1 addition & 1 deletion src/proof_system/widget/permutation/verifierkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) struct VerifierKey {
#[cfg(feature = "alloc")]
mod alloc {
use super::*;
use crate::permutation::constants::{K1, K2, K3};
use crate::composer::permutation::constants::{K1, K2, K3};
use crate::proof_system::linearization_poly::ProofEvaluations;
#[rustfmt::skip]
use ::alloc::vec::Vec;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use dusk_bls12_381::BlsScalar;

use crate::constraint_system::{Constraint, Witness};
use crate::prelude::{Constraint, Witness};

#[cfg(feature = "debug")]
use crate::debugger::Debugger;
Expand Down
Loading