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

execution-core: Re-expose zk types under zk-feature #2068

Merged
merged 10 commits into from
Aug 5, 2024
1 change: 0 additions & 1 deletion contracts/host_fn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
3 changes: 1 addition & 2 deletions contracts/license/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
3 changes: 1 addition & 2 deletions contracts/license/src/license_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions contracts/license/tests/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions contracts/stake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions contracts/stake/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
3 changes: 1 addition & 2 deletions contracts/transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions contracts/transfer/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
28 changes: 27 additions & 1 deletion execution-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ signatures::{
PublicKey,
SecretKey,
Signature,
APK as AggPublicKey,
MutlisigPublicKey,
MultisigSignature
};
schnorr::{
PublicKey,
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions execution-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
14 changes: 12 additions & 2 deletions execution-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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,
Signature,
};
}

/// 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,
Expand All @@ -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];
Expand Down
5 changes: 4 additions & 1 deletion execution-core/src/transfer/phoenix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
}

Expand Down
4 changes: 1 addition & 3 deletions rusk-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion rusk-abi/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
7 changes: 5 additions & 2 deletions rusk-abi/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions rusk-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
]
6 changes: 2 additions & 4 deletions rusk-prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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;

Expand All @@ -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)]
Expand Down
9 changes: 6 additions & 3 deletions rusk-prover/src/prover/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading