From 9f6b758fd4e5ca8d0564fc342f56243d275ffeda Mon Sep 17 00:00:00 2001 From: moana Date: Thu, 21 Dec 2023 12:31:10 +0100 Subject: [PATCH] Restructure internal modules - 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 --- CHANGELOG.md | 7 ++++++ src/{composer => }/compiler.rs | 18 +++++++++------ src/{composer => compiler}/prover.rs | 0 src/{composer => compiler}/verifier.rs | 0 src/composer.rs | 23 +++++++++---------- src/composer/{compiler => }/compress.rs | 4 ++-- src/composer/{compiler => }/compress/hades.rs | 0 src/{ => composer}/constraint_system.rs | 0 .../constraint_system/constraint.rs | 3 +-- src/{ => composer}/constraint_system/ecc.rs | 2 +- .../constraint_system/witness.rs | 0 src/composer/gate.rs | 2 +- src/{ => composer}/permutation.rs | 2 +- src/{ => composer}/permutation/constants.rs | 0 src/debugger.rs | 9 +------- src/lib.rs | 3 +-- src/prelude.rs | 4 ++-- .../widget/permutation/proverkey.rs | 2 +- .../widget/permutation/verifierkey.rs | 2 +- src/runtime.rs | 2 +- 20 files changed, 42 insertions(+), 41 deletions(-) rename src/{composer => }/compiler.rs (97%) rename src/{composer => compiler}/prover.rs (100%) rename src/{composer => compiler}/verifier.rs (100%) rename src/composer/{compiler => }/compress.rs (98%) rename src/composer/{compiler => }/compress/hades.rs (100%) rename src/{ => composer}/constraint_system.rs (100%) rename src/{ => composer}/constraint_system/constraint.rs (99%) rename src/{ => composer}/constraint_system/ecc.rs (98%) rename src/{ => composer}/constraint_system/witness.rs (100%) rename src/{ => composer}/permutation.rs (99%) rename src/{ => composer}/permutation/constants.rs (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a49a0eee..93b64fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -548,6 +554,7 @@ is necessary since `rkyv/validation` was required as a bound. - Proof system module. +[#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 diff --git a/src/composer/compiler.rs b/src/compiler.rs similarity index 97% rename from src/composer/compiler.rs rename to src/compiler.rs index a87d2a66..4afed7a2 100644 --- a/src/composer/compiler.rs +++ b/src/compiler.rs @@ -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; @@ -65,7 +68,8 @@ impl Compiler { where C: Circuit, { - compress::CompressedCircuit::from_circuit::(true) + let hades_optimization = true; + CompressedCircuit::from_circuit::(hades_optimization) } /// Generates a [Prover] and [Verifier] from a buffer created by @@ -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, diff --git a/src/composer/prover.rs b/src/compiler/prover.rs similarity index 100% rename from src/composer/prover.rs rename to src/compiler/prover.rs diff --git a/src/composer/verifier.rs b/src/compiler/verifier.rs similarity index 100% rename from src/composer/verifier.rs rename to src/compiler/verifier.rs diff --git a/src/composer.rs b/src/composer.rs index 1c61d70e..51611dd3 100644 --- a/src/composer.rs +++ b/src/composer.rs @@ -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)] @@ -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(), diff --git a/src/composer/compiler/compress.rs b/src/composer/compress.rs similarity index 98% rename from src/composer/compiler/compress.rs rename to src/composer/compress.rs index ea8e4d54..12d90e27 100644 --- a/src/composer/compiler/compress.rs +++ b/src/composer/compress.rs @@ -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; diff --git a/src/composer/compiler/compress/hades.rs b/src/composer/compress/hades.rs similarity index 100% rename from src/composer/compiler/compress/hades.rs rename to src/composer/compress/hades.rs diff --git a/src/constraint_system.rs b/src/composer/constraint_system.rs similarity index 100% rename from src/constraint_system.rs rename to src/composer/constraint_system.rs diff --git a/src/constraint_system/constraint.rs b/src/composer/constraint_system/constraint.rs similarity index 99% rename from src/constraint_system/constraint.rs rename to src/composer/constraint_system/constraint.rs index 3ce87b98..11b6e23f 100644 --- a/src/constraint_system/constraint.rs +++ b/src/composer/constraint_system/constraint.rs @@ -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`] diff --git a/src/constraint_system/ecc.rs b/src/composer/constraint_system/ecc.rs similarity index 98% rename from src/constraint_system/ecc.rs rename to src/composer/constraint_system/ecc.rs index 28b52490..f13c6c24 100644 --- a/src/constraint_system/ecc.rs +++ b/src/composer/constraint_system/ecc.rs @@ -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 diff --git a/src/constraint_system/witness.rs b/src/composer/constraint_system/witness.rs similarity index 100% rename from src/constraint_system/witness.rs rename to src/composer/constraint_system/witness.rs diff --git a/src/composer/gate.rs b/src/composer/gate.rs index 41e26178..31d6dab6 100644 --- a/src/composer/gate.rs +++ b/src/composer/gate.rs @@ -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)] diff --git a/src/permutation.rs b/src/composer/permutation.rs similarity index 99% rename from src/permutation.rs rename to src/composer/permutation.rs index 9556322c..32f5fc81 100644 --- a/src/permutation.rs +++ b/src/composer/permutation.rs @@ -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}; diff --git a/src/permutation/constants.rs b/src/composer/permutation/constants.rs similarity index 100% rename from src/permutation/constants.rs rename to src/composer/permutation/constants.rs diff --git a/src/debugger.rs b/src/debugger.rs index b4560825..5131e35d 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -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 @@ -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 } => { diff --git a/src/lib.rs b/src/lib.rs index 30db01b8..89ed518d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/prelude.rs b/src/prelude.rs index f9f538df..f7cc3fe2 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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; diff --git a/src/proof_system/widget/permutation/proverkey.rs b/src/proof_system/widget/permutation/proverkey.rs index 4348b883..8f1d0d3c 100644 --- a/src/proof_system/widget/permutation/proverkey.rs +++ b/src/proof_system/widget/permutation/proverkey.rs @@ -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")] diff --git a/src/proof_system/widget/permutation/verifierkey.rs b/src/proof_system/widget/permutation/verifierkey.rs index 27ac1965..3052aee0 100644 --- a/src/proof_system/widget/permutation/verifierkey.rs +++ b/src/proof_system/widget/permutation/verifierkey.rs @@ -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; diff --git a/src/runtime.rs b/src/runtime.rs index 01905a8b..743a21f6 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -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;