diff --git a/contracts/host_fn/Cargo.toml b/contracts/host_fn/Cargo.toml index e6c4bcfb68..ffa5557de9 100644 --- a/contracts/host_fn/Cargo.toml +++ b/contracts/host_fn/Cargo.toml @@ -9,5 +9,4 @@ crate-type = ["cdylib", "rlib"] [dependencies] execution-core = { version = "0.1.0", path = "../../execution-core" } dusk-bytes = "0.1" -dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] } rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" } diff --git a/contracts/license/Cargo.toml b/contracts/license/Cargo.toml index 29f643d2ff..e38842b6aa 100644 --- a/contracts/license/Cargo.toml +++ b/contracts/license/Cargo.toml @@ -7,11 +7,10 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -execution-core = { version = "0.1.0", path = "../../execution-core" } +execution-core = { version = "0.1.0", path = "../../execution-core", features = ["zk"] } dusk-bytes = "0.1" dusk-poseidon = "0.39" poseidon-merkle = { version = "0.6", features = ["rkyv-impl", "zk", "size_32"] } -dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } bytecheck = { version = "0.6", default-features = false } diff --git a/contracts/license/src/license_types.rs b/contracts/license/src/license_types.rs index 2e34a1db1e..1b72090cd3 100644 --- a/contracts/license/src/license_types.rs +++ b/contracts/license/src/license_types.rs @@ -9,9 +9,8 @@ use alloc::vec::Vec; use bytecheck::CheckBytes; use rkyv::{Archive, Deserialize, Serialize}; -use execution_core::BlsScalar; +use execution_core::{plonk::Proof, BlsScalar}; -use dusk_plonk::prelude::Proof; use poseidon_merkle::Item; #[allow(dead_code)] diff --git a/contracts/license/tests/license.rs b/contracts/license/tests/license.rs index 942f1296c0..2a37fe02a4 100644 --- a/contracts/license/tests/license.rs +++ b/contracts/license/tests/license.rs @@ -9,7 +9,6 @@ extern crate alloc; use std::ops::Range; use std::sync::mpsc; -use dusk_plonk::prelude::*; use dusk_poseidon::{Domain, Hash}; use ff::Field; use poseidon_merkle::Opening; @@ -21,8 +20,9 @@ use zk_citadel::license::{ }; use execution_core::{ + plonk::{Compiler, PublicParameters}, transfer::phoenix::{PublicKey, SecretKey, StealthAddress, ViewKey}, - BlsScalar, ContractId, JubJubAffine, GENERATOR_EXTENDED, + BlsScalar, ContractId, JubJubAffine, JubJubScalar, GENERATOR_EXTENDED, }; use rusk_abi::{ContractData, Session}; use rusk_profile::get_common_reference_string; diff --git a/contracts/stake/Cargo.toml b/contracts/stake/Cargo.toml index 7dd5d01c0d..a8e4ab3f32 100644 --- a/contracts/stake/Cargo.toml +++ b/contracts/stake/Cargo.toml @@ -9,7 +9,6 @@ crate-type = ["cdylib", "rlib"] [dependencies] execution-core = { version = "0.1.0", path = "../../execution-core" } dusk-bytes = "0.1" -dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } [target.'cfg(target_family = "wasm")'.dependencies] @@ -18,7 +17,7 @@ rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" } [dev-dependencies] rusk-profile = { version = "0.6", path = "../../rusk-profile" } rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", default-features = false, features = ["host"] } -phoenix-circuits = "0.2.1-rc" +execution-core = { version = "0.1.0", path = "../../execution-core", features = ["zk"] } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } hex = "0.4" rand = "0.8" diff --git a/contracts/stake/tests/common/utils.rs b/contracts/stake/tests/common/utils.rs index 9eb5b78fb5..32d0c8b073 100644 --- a/contracts/stake/tests/common/utils.rs +++ b/contracts/stake/tests/common/utils.rs @@ -7,26 +7,25 @@ use std::sync::mpsc; use dusk_bytes::Serializable; -use dusk_plonk::prelude::*; use ff::Field; -use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote}; use poseidon_merkle::Opening as PoseidonOpening; use rand::rngs::StdRng; use rand::SeedableRng; use execution_core::{ + plonk::{Prover, Verifier}, signatures::schnorr::SecretKey as SchnorrSecretKey, transfer::{ contract_exec::{ContractCall, ContractExec}, phoenix::{ value_commitment, Fee, Note, Payload as PhoenixPayload, PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey, - Sender, TreeLeaf, TxSkeleton, ViewKey as PhoenixViewKey, - NOTES_TREE_DEPTH, + Sender, TreeLeaf, TxCircuit, TxInputNote, TxOutputNote, TxSkeleton, + ViewKey as PhoenixViewKey, NOTES_TREE_DEPTH, }, Transaction, TRANSFER_CONTRACT, }, - ContractError, JubJubScalar, + BlsScalar, ContractError, JubJubAffine, JubJubScalar, }; use rusk_abi::{CallReceipt, PiecrustError, Session}; diff --git a/contracts/transfer/Cargo.toml b/contracts/transfer/Cargo.toml index 640b18edfa..97b4d62ee3 100644 --- a/contracts/transfer/Cargo.toml +++ b/contracts/transfer/Cargo.toml @@ -10,7 +10,6 @@ crate-type = ["cdylib", "rlib"] execution-core = { version = "0.1.0", path = "../../execution-core" } dusk-bytes = "0.1" poseidon-merkle = { version = "0.6", features = ["rkyv-impl"] } -dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } ringbuffer = "0.15" @@ -21,7 +20,7 @@ rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" } [dev-dependencies] rusk-profile = { version = "0.6", path = "../../rusk-profile" } rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", default-features = false, features = ["host"] } -phoenix-circuits = "0.2.1-rc" +execution-core = { version = "0.1.0", path = "../../execution-core", features = ["zk"] } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } bytecheck = { version = "0.6", default-features = false } hex = "0.4" diff --git a/contracts/transfer/tests/common.rs b/contracts/transfer/tests/common.rs index 85a5a99c73..948b0b10b2 100644 --- a/contracts/transfer/tests/common.rs +++ b/contracts/transfer/tests/common.rs @@ -7,6 +7,7 @@ use std::sync::mpsc; use execution_core::{ + plonk::{Prover, Verifier}, signatures::{ bls::{PublicKey as AccountPublicKey, SecretKey as AccountSecretKey}, schnorr::SecretKey as SchnorrSecretKey, @@ -20,18 +21,17 @@ use execution_core::{ phoenix::{ value_commitment, Fee, Note, Payload as PhoenixPayload, PublicKey, SecretKey, Sender, Transaction as PhoenixTransaction, TreeLeaf, - TxSkeleton, ViewKey, NOTES_TREE_DEPTH, + TxCircuit, TxInputNote, TxOutputNote, TxSkeleton, ViewKey, + NOTES_TREE_DEPTH, }, Transaction, TRANSFER_CONTRACT, }, - BlsScalar, ContractError, ContractId, JubJubScalar, + BlsScalar, ContractError, ContractId, JubJubAffine, JubJubScalar, }; use rusk_abi::{CallReceipt, PiecrustError, Session}; use dusk_bytes::Serializable; -use dusk_plonk::prelude::*; use ff::Field; -use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote}; use poseidon_merkle::Opening as PoseidonOpening; use rand::rngs::StdRng; use rand::SeedableRng; diff --git a/execution-core/CHANGELOG.md b/execution-core/CHANGELOG.md index 749cd0f514..6341890004 100644 --- a/execution-core/CHANGELOG.md +++ b/execution-core/CHANGELOG.md @@ -37,7 +37,8 @@ signatures::{ PublicKey, SecretKey, Signature, - APK as AggPublicKey, + MutlisigPublicKey, + MultisigSignature }; schnorr::{ PublicKey, @@ -104,6 +105,31 @@ stake::{ }; licence::LICENSE_CONTRACT; ``` +- under the `"zk"` feature: +```rust +plonk::{ + pub use dusk_plonk::{ + Circuit, + Compiler, + Composer, + Constraint, + Error, + Proof, + Prover, + PublicParameters, + Verifier, + Witness, + WitnessPoint, + } +}; +transfer::phoenix::{ + pub use phoenix_circuits{ + TxCircuit, + TxInputNote, + TxOutputNote, + }; +}; +``` [Unreleased]: https://github.com/dusk-network/rusk/compare/execution-core-0.1.0...HEAD [0.1.0]: https://github.com/dusk-network/dusk-abi/releases/tag/execution-core-0.1.0 diff --git a/execution-core/Cargo.toml b/execution-core/Cargo.toml index 6d3a3b75b5..ffc203aa67 100644 --- a/execution-core/Cargo.toml +++ b/execution-core/Cargo.toml @@ -17,9 +17,19 @@ bytecheck = { version = "0.6", default-features = false } rand = { version = "0.8", default-features = false } ff = { version = "0.13", default-features = false } +# zk-dependencies +dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"], optional = true } +phoenix-circuits = { version = "0.2.1-rc", optional = true } + [dev-dependencies] rand = "0.8" [features] # It enables parallel thread aggregation of BlsPublicKey parallel = ["bls12_381-bls/parallel"] + +# It enables zk-capabilities +zk = ["dusk-plonk", "phoenix-circuits"] + +# Enables std feature for dusk-plonk +std = ["dusk-plonk/std"] diff --git a/execution-core/src/lib.rs b/execution-core/src/lib.rs index 1feccfde40..1847ad9af8 100644 --- a/execution-core/src/lib.rs +++ b/execution-core/src/lib.rs @@ -31,7 +31,7 @@ pub use dusk_jubjub::{ /// Signatures used in the Dusk protocol. pub mod signatures { - /// Types for the bls-signature scheme. + /// Types for the bls-signature scheme operating on the `bls12_381` curve. pub mod bls { pub use bls12_381_bls::{ Error, MultisigPublicKey, MultisigSignature, PublicKey, SecretKey, @@ -39,7 +39,7 @@ pub mod signatures { }; } - /// Types for the schnorr-signature scheme. + /// Types for the schnorr-signature scheme operating on the `jubjub` curve. pub mod schnorr { pub use jubjub_schnorr::{ PublicKey, SecretKey, Signature, SignatureDouble, @@ -52,6 +52,16 @@ pub use piecrust_uplink::{ CONTRACT_ID_BYTES, }; +/// Types and traits to create plonk circuits and generate and verify plonk +/// proofs. +#[cfg(feature = "zk")] +pub mod plonk { + pub use dusk_plonk::prelude::{ + Circuit, Compiler, Composer, Constraint, Error, Proof, Prover, + PublicParameters, Verifier, Witness, WitnessPoint, + }; +} + #[inline] const fn reserved(b: u8) -> ContractId { let mut bytes = [0u8; CONTRACT_ID_BYTES]; diff --git a/execution-core/src/transfer/phoenix.rs b/execution-core/src/transfer/phoenix.rs index 7f5769ba64..011132cc59 100644 --- a/execution-core/src/transfer/phoenix.rs +++ b/execution-core/src/transfer/phoenix.rs @@ -29,6 +29,9 @@ pub use phoenix_core::{ StealthAddress, TxSkeleton, ViewKey, NOTE_VAL_ENC_SIZE, OUTPUT_NOTES, }; +#[cfg(feature = "zk")] +pub use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote}; + /// Label used for the ZK transcript initialization. Must be the same for prover /// and verifier. pub const TRANSCRIPT_LABEL: &[u8] = b"dusk-network"; @@ -46,7 +49,7 @@ pub struct Fee { pub gas_price: u64, /// Address to send the remainder note pub stealth_address: StealthAddress, - /// Sender to use for the remainder + /// Sender to use for the remainder note pub sender: Sender, } diff --git a/rusk-abi/Cargo.toml b/rusk-abi/Cargo.toml index 004a97775a..1f3960e256 100644 --- a/rusk-abi/Cargo.toml +++ b/rusk-abi/Cargo.toml @@ -10,17 +10,15 @@ exclude = [".github/workflows/ci.yml", ".gitignore"] [dependencies] blake2b_simd = { version = "1", default-features = false } -cfg-if = "1" dusk-poseidon = "0.39" dusk-bytes = "0.1" bytecheck = { version = "0.6", default-features = false } -dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] } piecrust-uplink = { version = "0.16" } piecrust = { version = "0.23", optional = true } -execution-core = { version = "0.1.0", path = "../execution-core" } +execution-core = { version = "0.1.0", path = "../execution-core", features = ["zk"] } # These are patches since these crates don't seem to like semver. rkyv = { version = "=0.7.39", default-features = false, features = ["size_32"] } diff --git a/rusk-abi/src/host.rs b/rusk-abi/src/host.rs index ab37cafe6a..a6fb2b4ff4 100644 --- a/rusk-abi/src/host.rs +++ b/rusk-abi/src/host.rs @@ -8,9 +8,9 @@ use alloc::vec::Vec; use std::path::{Path, PathBuf}; use dusk_bytes::DeserializableSlice; -use dusk_plonk::prelude::{Proof, Verifier}; use dusk_poseidon::{Domain, Hash as PoseidonHash}; use execution_core::{ + plonk::{Proof, Verifier}, signatures::{ bls::{PublicKey as BlsPublicKey, Signature as BlsSignature}, schnorr::{ diff --git a/rusk-abi/tests/lib.rs b/rusk-abi/tests/lib.rs index 0a265a2b39..877197aadf 100644 --- a/rusk-abi/tests/lib.rs +++ b/rusk-abi/tests/lib.rs @@ -12,8 +12,11 @@ use std::sync::OnceLock; use rand_core::OsRng; use dusk_bytes::{ParseHexStr, Serializable}; -use dusk_plonk::prelude::*; use execution_core::{ + plonk::{ + Circuit, Compiler, Composer, Constraint, Error as PlonkError, + PublicParameters, + }, signatures::{ bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey}, schnorr::{ @@ -231,7 +234,7 @@ impl TestCircuit { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { + fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> { // append 3 gates that always evaluate to true let a = composer.append_witness(self.a); diff --git a/rusk-prover/Cargo.toml b/rusk-prover/Cargo.toml index 9d65a2d6d0..49a090914b 100644 --- a/rusk-prover/Cargo.toml +++ b/rusk-prover/Cargo.toml @@ -6,20 +6,18 @@ autobins = false [dependencies] dusk-bytes = { version = "0.1" } -dusk-plonk = { version = "0.19", default-features = false } poseidon-merkle = { version = "0.6", features = ["rkyv-impl"] } rand_core = "0.6" rkyv = { version = "0.7", default-features = false, features = ["size_32"] } bytecheck = { version = "0.6", default-features = false } -execution-core = { version = "0.1.0", path = "../execution-core" } +execution-core = { version = "0.1.0", path = "../execution-core", features = ["zk"] } ## feature local_prover once_cell = { version = "1.9", optional = true } rand = { version = "0.8", optional = true } rusk-profile = { version = "0.6", path = "../rusk-profile", optional = true } -phoenix-circuits = { version = "0.2.1-rc", optional = true } [dev-dependencies] hex = "0.4" @@ -30,11 +28,11 @@ rand = "0.8" default = ["local_prover"] local_prover = [ "once_cell", - "dusk-plonk/std", "rand", "rusk-profile", - "phoenix-circuits", "std", ] no_random = [] -std = [] +std = [ + "execution-core/std" +] diff --git a/rusk-prover/src/prover.rs b/rusk-prover/src/prover.rs index 983c3035e2..81e9069c3e 100644 --- a/rusk-prover/src/prover.rs +++ b/rusk-prover/src/prover.rs @@ -9,7 +9,7 @@ mod execute; use crate::{ProverError, ProverResult}; use dusk_bytes::Serializable; -use dusk_plonk::prelude::Prover as PlonkProver; +use execution_core::plonk::Prover as PlonkProver; use once_cell::sync::Lazy; #[cfg(not(feature = "no_random"))] @@ -18,8 +18,6 @@ use rand::rngs::OsRng; #[cfg(feature = "no_random")] use rand::{rngs::StdRng, SeedableRng}; -use dusk_plonk::prelude::*; - #[derive(Debug, Default)] pub struct LocalProver; @@ -38,7 +36,7 @@ pub fn fetch_prover(circuit_name: &str) -> PlonkProver { panic!("there should be a prover key stored for {}", circuit_name) }); - Prover::try_from_bytes(pk).expect("Prover key is expected to by valid") + PlonkProver::try_from_bytes(pk).expect("Prover key is expected to by valid") } #[cfg(test)] diff --git a/rusk-prover/src/prover/execute.rs b/rusk-prover/src/prover/execute.rs index c94b28b6d6..b2ff210076 100644 --- a/rusk-prover/src/prover/execute.rs +++ b/rusk-prover/src/prover/execute.rs @@ -6,10 +6,13 @@ use super::*; -use execution_core::transfer::phoenix::{ - value_commitment, Sender, NOTES_TREE_DEPTH, +use execution_core::{ + transfer::phoenix::{ + value_commitment, Sender, TxCircuit, TxInputNote, TxOutputNote, + NOTES_TREE_DEPTH, + }, + JubJubAffine, }; -use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote}; use rand::{CryptoRng, RngCore}; use crate::prover::fetch_prover; diff --git a/rusk-prover/src/tx.rs b/rusk-prover/src/tx.rs index 13e5c721e1..92f94ccc7c 100644 --- a/rusk-prover/src/tx.rs +++ b/rusk-prover/src/tx.rs @@ -10,8 +10,8 @@ use alloc::vec::Vec; use dusk_bytes::{ DeserializableSlice, Error as BytesError, Serializable, Write, }; -use dusk_plonk::prelude::Proof; use execution_core::{ + plonk::Proof, signatures::schnorr::{ Signature as SchnorrSignature, SignatureDouble as SchnorrSignatureDouble, diff --git a/rusk-recovery/Cargo.toml b/rusk-recovery/Cargo.toml index 755b4a434d..d02cbd857e 100644 --- a/rusk-recovery/Cargo.toml +++ b/rusk-recovery/Cargo.toml @@ -25,12 +25,11 @@ flate2 = "1" tar = "0.4" cargo_toml = "0.15" -phoenix-circuits = "0.2.1-rc" license-circuits = { version = "0.1", path = "../circuits/license" } rusk-profile = { version = "0.6", path = "../rusk-profile" } rusk-abi = { version = "0.13.0-rc", path = "../rusk-abi", default-features = false, features = ["host"] } -execution-core = { version = "0.1.0", path = "../execution-core" } +execution-core = { version = "0.1.0", path = "../execution-core", features = ["zk"] } serde_derive = { version = "1", optional = true } serde = { version = "1", optional = true } diff --git a/rusk-recovery/src/keys.rs b/rusk-recovery/src/keys.rs index 403c4e9fc5..34f4fbf370 100644 --- a/rusk-recovery/src/keys.rs +++ b/rusk-recovery/src/keys.rs @@ -5,8 +5,10 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::Theme; -use dusk_plonk::prelude::{Compiler, PublicParameters}; -use execution_core::transfer::phoenix::TRANSCRIPT_LABEL; +use execution_core::{ + plonk::{Compiler, PublicParameters}, + transfer::phoenix::TRANSCRIPT_LABEL, +}; use once_cell::sync::Lazy; use rand::rngs::StdRng; use rand::SeedableRng; diff --git a/rusk-recovery/src/keys/circuits.rs b/rusk-recovery/src/keys/circuits.rs index 0e21dc367c..5e1aab7dae 100644 --- a/rusk-recovery/src/keys/circuits.rs +++ b/rusk-recovery/src/keys/circuits.rs @@ -7,13 +7,12 @@ use std::io::{self, ErrorKind}; use cargo_toml::{Dependency, Manifest}; -use dusk_plonk::prelude::Circuit; use tracing::info; -use execution_core::transfer::phoenix::NOTES_TREE_DEPTH; +use execution_core::plonk::Circuit; +use execution_core::transfer::phoenix::{TxCircuit, NOTES_TREE_DEPTH}; use license_circuits::LicenseCircuit; -use phoenix_circuits::transaction::TxCircuit; type ExecuteCircuitOneTwo = TxCircuit; type ExecuteCircuitTwoTwo = TxCircuit; diff --git a/rusk/Cargo.toml b/rusk/Cargo.toml index d2d5b6b83e..3caac8609b 100644 --- a/rusk/Cargo.toml +++ b/rusk/Cargo.toml @@ -43,7 +43,6 @@ blake2b_simd = { version = "1", default-features = false } poseidon-merkle = { version = "0.6", features = ["rkyv-impl", "size_32"] } sha3 = "0.10" -dusk-plonk = "0.19" dusk-bytes = "0.1" kadcast = "0.6.0-rc" pin-project = "1" @@ -59,7 +58,7 @@ tokio-rustls = "0.25" rustls-pemfile = "2" async-trait = "0.1" -execution-core = { version = "0.1.0", path = "../execution-core" } +execution-core = { version = "0.1.0", path = "../execution-core", features = ["zk"] } rusk-profile = { version = "0.6", path = "../rusk-profile" } rusk-abi = { version = "0.13.0-rc", path = "../rusk-abi", default-features = false, features = ["host"] } rusk-prover = { version = "0.3", path = "../rusk-prover", optional = true } diff --git a/rusk/tests/common/wallet.rs b/rusk/tests/common/wallet.rs index bd7ad2b9fd..5e514df10b 100644 --- a/rusk/tests/common/wallet.rs +++ b/rusk/tests/common/wallet.rs @@ -11,8 +11,8 @@ use std::sync::{Arc, RwLock}; use crate::common::block::Block as BlockAwait; use dusk_bytes::{DeserializableSlice, Serializable}; -use dusk_plonk::prelude::Proof; use execution_core::{ + plonk::Proof, signatures::bls::PublicKey as BlsPublicKey, stake::StakeData, transfer::{ diff --git a/test-wallet/Cargo.toml b/test-wallet/Cargo.toml index 3220d0cc56..570e82861e 100644 --- a/test-wallet/Cargo.toml +++ b/test-wallet/Cargo.toml @@ -12,7 +12,6 @@ sha2 = { version = "^0.10", default-features = false } dusk-bytes = "^0.1" dusk-poseidon = { version = "0.39", default-features = false } poseidon-merkle = { version = "0.6", features = ["rkyv-impl"] } -dusk-plonk = { version = "0.19", default-features = false } rkyv = { version = "0.7", default-features = false } rusk-prover = { version = "0.3.0", path = "../rusk-prover", default-features = false } ff = { version = "0.13", default-features = false }