diff --git a/Cargo.toml b/Cargo.toml index 7ab23041bb..e0b1aa5c3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,11 @@ members = [ "contracts/alice", "contracts/bob", "contracts/stake", - "contracts/stake-types", "contracts/transfer", - "contracts/transfer-types", "contracts/license", + "execution-core", + "rusk-prover", "rusk-recovery", diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index 99b2fba0be..38c9bdb03f 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -18,7 +18,6 @@ rand = { version = "0.8", default-features = false, features = ["std_rng"] } tokio = { version = "1", features = ["full"] } tracing-subscriber = "0.2" tracing = "0.1" -bls12_381-bls = { version = "0.2" } sha3 = { version = "0.10" } num-bigint = { version = "0.4.3", default-features = false } hex = { version = "0.4.3" } @@ -29,6 +28,7 @@ async-channel = "1.7.1" async-trait = "0.1" anyhow = "1.0" node-data = { version = "0.1", path = "../node-data" } +execution-core = { version = "0.1.0", path = "../execution-core" } dusk-merkle = { version = "0.5", features = ["size_32"] } thiserror = "1" time-util = { version = "0.3", features = ["chrono"] } diff --git a/consensus/src/aggregator.rs b/consensus/src/aggregator.rs index d944508bd2..f6f80e1af8 100644 --- a/consensus/src/aggregator.rs +++ b/consensus/src/aggregator.rs @@ -7,6 +7,7 @@ use crate::user::cluster::Cluster; use crate::user::committee::Committee; use dusk_bytes::Serializable; +use execution_core::{BlsSigError, BlsSignature}; use node_data::bls::PublicKey; use node_data::ledger::{to_str, StepVotes}; use node_data::message::payload::Vote; @@ -31,11 +32,11 @@ pub enum AggregatorError { #[error("Vote from member not in the committee")] NotCommitteeMember, #[error("Invalid signature to aggregate {0}")] - InvalidSignature(bls12_381_bls::Error), + InvalidSignature(BlsSigError), } -impl From for AggregatorError { - fn from(value: bls12_381_bls::Error) -> Self { +impl From for AggregatorError { + fn from(value: BlsSigError) -> Self { Self::InvalidSignature(value) } } @@ -152,12 +153,12 @@ impl fmt::Display for Aggregator { #[derive(Default)] pub(super) struct AggrSignature { - data: Option, + data: Option, } impl AggrSignature { - pub fn add(&mut self, data: &[u8; 48]) -> Result<(), bls12_381_bls::Error> { - let sig = bls12_381_bls::Signature::from_bytes(data)?; + pub fn add(&mut self, data: &[u8; 48]) -> Result<(), BlsSigError> { + let sig = BlsSignature::from_bytes(data)?; let aggr_sig = match self.data { Some(data) => data.aggregate(&[sig]), @@ -182,8 +183,8 @@ mod tests { use crate::user::committee::Committee; use crate::user::provisioners::{Provisioners, DUSK}; use crate::user::sortition::Config; - use bls12_381_bls::{PublicKey, SecretKey}; use dusk_bytes::DeserializableSlice; + use execution_core::{StakePublicKey, StakeSecretKey}; use hex::FromHex; use node_data::ledger::{Header, Seed}; use node_data::message::StepMessage; @@ -216,7 +217,7 @@ mod tests { .iter() .map(|hex| hex::decode(hex).expect("valid hex")) .map(|data| { - SecretKey::from_slice(&data[..]).expect("valid secret key") + StakeSecretKey::from_slice(&data[..]).expect("valid secret key") }) .collect(); @@ -237,8 +238,9 @@ mod tests { mrb_header.height = 0; for secret_key in sks { - let pubkey_bls = - node_data::bls::PublicKey::new(PublicKey::from(&secret_key)); + let pubkey_bls = node_data::bls::PublicKey::new( + StakePublicKey::from(&secret_key), + ); p.add_member_with_value(pubkey_bls.clone(), 1000 * DUSK); diff --git a/consensus/src/commons.rs b/consensus/src/commons.rs index b54409a4cb..e94a18a839 100644 --- a/consensus/src/commons.rs +++ b/consensus/src/commons.rs @@ -14,7 +14,7 @@ use std::collections::HashMap; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use thiserror::Error; -use bls12_381_bls::SecretKey; +use execution_core::{BlsSigError, StakeSecretKey}; use node_data::bls::PublicKey; use node_data::message::{AsyncQueue, Message, Payload}; use node_data::StepName; @@ -29,7 +29,7 @@ pub struct RoundUpdate { // This provisioner consensus keys pub pubkey_bls: PublicKey, - pub secret_key: SecretKey, + pub secret_key: StakeSecretKey, seed: Seed, hash: [u8; 32], @@ -41,7 +41,7 @@ pub struct RoundUpdate { impl RoundUpdate { pub fn new( pubkey_bls: PublicKey, - secret_key: SecretKey, + secret_key: StakeSecretKey, mrb_header: &Header, base_timeouts: TimeoutSet, ) -> Self { @@ -75,15 +75,15 @@ pub enum StepSigError { #[error("Failed to reach a quorum")] VoteSetTooSmall, #[error("Verification error {0}")] - VerificationFailed(bls12_381_bls::Error), + VerificationFailed(BlsSigError), #[error("Empty Apk instance")] EmptyApk, #[error("Invalid Type")] InvalidType, } -impl From for StepSigError { - fn from(inner: bls12_381_bls::Error) -> Self { +impl From for StepSigError { + fn from(inner: BlsSigError) -> Self { Self::VerificationFailed(inner) } } @@ -92,7 +92,7 @@ impl From for StepSigError { pub enum ConsensusError { InvalidBlock, InvalidBlockHash, - InvalidSignature(bls12_381_bls::Error), + InvalidSignature(BlsSigError), InvalidMsgType, InvalidValidationStepVotes(StepSigError), InvalidValidation(QuorumType), @@ -116,8 +116,8 @@ impl From for ConsensusError { Self::InvalidValidationStepVotes(e) } } -impl From for ConsensusError { - fn from(e: bls12_381_bls::Error) -> Self { +impl From for ConsensusError { + fn from(e: BlsSigError) -> Self { Self::InvalidSignature(e) } } diff --git a/consensus/src/operations.rs b/consensus/src/operations.rs index 1376be315c..698ae17a56 100644 --- a/consensus/src/operations.rs +++ b/consensus/src/operations.rs @@ -7,7 +7,7 @@ use std::fmt; use std::time::Duration; -use bls12_381_bls::PublicKey; +use execution_core::StakePublicKey; use node_data::ledger::{Block, Header, SpentTransaction, Transaction}; use node_data::StepName; @@ -25,7 +25,7 @@ pub struct CallParams { pub round: u64, pub block_gas_limit: u64, pub generator_pubkey: node_data::bls::PublicKey, - pub missed_generators: Vec, + pub missed_generators: Vec, } #[derive(Default)] diff --git a/consensus/src/quorum/verifiers.rs b/consensus/src/quorum/verifiers.rs index 34ed7eec89..c180c3a045 100644 --- a/consensus/src/quorum/verifiers.rs +++ b/consensus/src/quorum/verifiers.rs @@ -16,6 +16,7 @@ use crate::user::committee::{Committee, CommitteeSet}; use crate::user::sortition; use dusk_bytes::Serializable as BytesSerializable; +use execution_core::{StakeAggPublicKey, StakeSignature}; use tokio::sync::RwLock; use tracing::error; @@ -161,13 +162,13 @@ pub fn verify_votes( } impl Cluster { - fn aggregate_pks(&self) -> Result { + fn aggregate_pks(&self) -> Result { let pks: Vec<_> = self.iter().map(|(pubkey, _)| *pubkey.inner()).collect(); match pks.split_first() { Some((first, rest)) => { - let mut apk = bls12_381_bls::APK::from(first); + let mut apk = StakeAggPublicKey::from(first); apk.aggregate(rest); Ok(apk) } @@ -180,7 +181,7 @@ fn verify_step_signature( header: &ConsensusHeader, step: StepName, vote: &Vote, - apk: bls12_381_bls::APK, + apk: StakeAggPublicKey, signature: &[u8; 48], ) -> Result<(), StepSigError> { // Compile message to verify @@ -190,7 +191,7 @@ fn verify_step_signature( StepName::Proposal => Err(StepSigError::InvalidType)?, }; - let sig = bls12_381_bls::Signature::from_bytes(signature)?; + let sig = StakeSignature::from_bytes(signature)?; let mut msg = header.signable(); msg.extend_from_slice(sign_seed); vote.write(&mut msg).expect("Writing to vec should succeed"); diff --git a/consensus/src/user/sortition.rs b/consensus/src/user/sortition.rs index 2f4920f23b..06e5be7161 100644 --- a/consensus/src/user/sortition.rs +++ b/consensus/src/user/sortition.rs @@ -99,10 +99,8 @@ mod tests { use crate::user::committee::Committee; use crate::user::provisioners::{Provisioners, DUSK}; use crate::user::sortition::Config; - use bls12_381_bls::{ - PublicKey as StakePublicKey, SecretKey as StakeSecretKey, - }; use dusk_bytes::DeserializableSlice; + use execution_core::{StakePublicKey, StakeSecretKey}; use node_data::ledger::Seed; diff --git a/contracts/Makefile b/contracts/Makefile index 570bfd7330..a0c56ff7c5 100644 --- a/contracts/Makefile +++ b/contracts/Makefile @@ -1,4 +1,4 @@ -SUBDIRS := stake-types transfer-types alice bob transfer stake license +SUBDIRS := alice bob license transfer stake all: $(SUBDIRS) ## Build all the contracts diff --git a/contracts/alice/Cargo.toml b/contracts/alice/Cargo.toml index c754f0fc25..601552c052 100644 --- a/contracts/alice/Cargo.toml +++ b/contracts/alice/Cargo.toml @@ -8,5 +8,5 @@ resolver = "2" crate-type = ["cdylib", "rlib"] [dependencies] -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } +execution-core = { version = "0.1.0", path = "../../execution-core" } rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", features = ["dlmalloc"] } diff --git a/contracts/alice/src/state.rs b/contracts/alice/src/state.rs index dabdfdca5a..b784374754 100644 --- a/contracts/alice/src/state.rs +++ b/contracts/alice/src/state.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use phoenix_core::transaction::*; +use execution_core::transfer::{Wfct, Wfctc}; use rusk_abi::TRANSFER_CONTRACT; /// Alice contract. diff --git a/contracts/license/Cargo.toml b/contracts/license/Cargo.toml index edb7ce5c8a..a373a85261 100644 --- a/contracts/license/Cargo.toml +++ b/contracts/license/Cargo.toml @@ -7,15 +7,13 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } +execution-core = { version = "0.1.0", path = "../../execution-core" } dusk-bytes = "0.1" -dusk-jubjub = { version = "0.14", default-features = false, features = ["rkyv-impl"] } dusk-poseidon = { version = "0.33", default-features = false, features = ["rkyv-impl", "alloc"] } poseidon-merkle = { version = "0.5", 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 } -jubjub-schnorr = { version = "0.2", default-features = false, features = ["rkyv-impl"] } [target.'cfg(target_family = "wasm")'.dependencies] rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" } @@ -28,7 +26,6 @@ rkyv = { version = "0.7", default-features = false, features = ["size_32"] } hex = "0.4" rand = "0.8" zk-citadel = "0.11" -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl"] } ff = { version = "0.13", default-features = false } [build-dependencies] diff --git a/contracts/license/src/license_types.rs b/contracts/license/src/license_types.rs index f45121f1d4..2e34a1db1e 100644 --- a/contracts/license/src/license_types.rs +++ b/contracts/license/src/license_types.rs @@ -9,7 +9,8 @@ use alloc::vec::Vec; use bytecheck::CheckBytes; use rkyv::{Archive, Deserialize, Serialize}; -use dusk_bls12_381::BlsScalar; +use execution_core::BlsScalar; + use dusk_plonk::prelude::Proof; use poseidon_merkle::Item; diff --git a/contracts/license/src/state.rs b/contracts/license/src/state.rs index 0c43c740d1..ec776a535b 100644 --- a/contracts/license/src/state.rs +++ b/contracts/license/src/state.rs @@ -4,15 +4,18 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::error::Error; -use alloc::vec::Vec; use core::ops::Range; -use dusk_bls12_381::BlsScalar; + +use alloc::vec::Vec; + use dusk_bytes::Serializable; use poseidon_merkle::{Opening, Tree}; + +use execution_core::BlsScalar; use rusk_abi::PublicInput; use crate::collection::Map; +use crate::error::Error; use crate::license_types::{ LicenseSession, LicenseSessionId, PoseidonItem, UseLicenseArg, }; diff --git a/contracts/license/tests/license.rs b/contracts/license/tests/license.rs index 8a193b97f0..bb654c6b83 100644 --- a/contracts/license/tests/license.rs +++ b/contracts/license/tests/license.rs @@ -6,18 +6,25 @@ extern crate alloc; -use dusk_bls12_381::BlsScalar; -use dusk_jubjub::{JubJubAffine, GENERATOR_EXTENDED}; -use dusk_plonk::prelude::*; -use dusk_poseidon::sponge; -use phoenix_core::{PublicKey, SecretKey, StealthAddress, ViewKey}; use std::ops::Range; use std::sync::mpsc; +use dusk_plonk::prelude::*; +use dusk_poseidon::sponge; +use ff::Field; use poseidon_merkle::Opening; use rand::rngs::StdRng; use rand::{CryptoRng, RngCore, SeedableRng}; use rkyv::{check_archived_root, Deserialize, Infallible}; +use zk_citadel::license::{License, Request}; +use zk_citadel::utils::CitadelUtils; + +use execution_core::{ + BlsScalar, JubJubAffine, PublicKey, SecretKey, StealthAddress, ViewKey, + GENERATOR_EXTENDED, +}; +use rusk_abi::{ContractData, ContractId, Session}; +use rusk_profile::get_common_reference_string; #[path = "../src/license_types.rs"] mod license_types; @@ -25,12 +32,6 @@ use license_types::*; use license_circuits::LicenseCircuit; -use ff::Field; -use rusk_abi::{ContractData, ContractId, Session}; -use rusk_profile::get_common_reference_string; -use zk_citadel::license::{License, Request}; -use zk_citadel::utils::CitadelUtils; - const LICENSE_CONTRACT_ID: ContractId = { let mut bytes = [0u8; 32]; bytes[0] = 0xf8; diff --git a/contracts/stake-types/Cargo.toml b/contracts/stake-types/Cargo.toml deleted file mode 100644 index 60a7e07f32..0000000000 --- a/contracts/stake-types/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "stake-contract-types" -description = "Stake contract types for the Dusk Network." -version = "0.1.0-rc.0" -edition = "2021" -license = "MPL-2.0" - -[dependencies] -dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } -bls12_381-bls = { version = "0.2", default-features = false, features = ["rkyv-impl"] } -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl"] } -dusk-bytes = "0.1" - -rkyv = { version = "0.7", default-features = false, features = ["size_32"] } -bytecheck = { version = "0.6", default-features = false } diff --git a/contracts/stake-types/LICENSE b/contracts/stake-types/LICENSE deleted file mode 100644 index a612ad9813..0000000000 --- a/contracts/stake-types/LICENSE +++ /dev/null @@ -1,373 +0,0 @@ -Mozilla Public License Version 2.0 -================================== - -1. Definitions --------------- - -1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - -1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - -1.6. "Executable Form" - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - -1.8. "License" - means this document. - -1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - -1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - -1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - -1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - -1.13. "Source Code Form" - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - -2. License Grants and Conditions --------------------------------- - -2.1. Grants - -Each Contributor hereby grants You a world-wide, royalty-free, -non-exclusive license: - -(a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - -(b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - -The licenses granted in Section 2.1 with respect to any Contribution -become effective for each Contribution on the date the Contributor first -distributes such Contribution. - -2.3. Limitations on Grant Scope - -The licenses granted in this Section 2 are the only rights granted under -this License. No additional rights or licenses will be implied from the -distribution or licensing of Covered Software under this License. -Notwithstanding Section 2.1(b) above, no patent license is granted by a -Contributor: - -(a) for any code that a Contributor has removed from Covered Software; - or - -(b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - -(c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - -This License does not grant any rights in the trademarks, service marks, -or logos of any Contributor (except as may be necessary to comply with -the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - -No Contributor makes additional grants as a result of Your choice to -distribute the Covered Software under a subsequent version of this -License (see Section 10.2) or under the terms of a Secondary License (if -permitted under the terms of Section 3.3). - -2.5. Representation - -Each Contributor represents that the Contributor believes its -Contributions are its original creation(s) or it has sufficient rights -to grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - -This License is not intended to limit any rights You have under -applicable copyright doctrines of fair use, fair dealing, or other -equivalents. - -2.7. Conditions - -Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted -in Section 2.1. - -3. Responsibilities -------------------- - -3.1. Distribution of Source Form - -All distribution of Covered Software in Source Code Form, including any -Modifications that You create or to which You contribute, must be under -the terms of this License. You must inform recipients that the Source -Code Form of the Covered Software is governed by the terms of this -License, and how they can obtain a copy of this License. You may not -attempt to alter or restrict the recipients' rights in the Source Code -Form. - -3.2. Distribution of Executable Form - -If You distribute Covered Software in Executable Form then: - -(a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - -(b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - -You may create and distribute a Larger Work under terms of Your choice, -provided that You also comply with the requirements of this License for -the Covered Software. If the Larger Work is a combination of Covered -Software with a work governed by one or more Secondary Licenses, and the -Covered Software is not Incompatible With Secondary Licenses, this -License permits You to additionally distribute such Covered Software -under the terms of such Secondary License(s), so that the recipient of -the Larger Work may, at their option, further distribute the Covered -Software under the terms of either this License or such Secondary -License(s). - -3.4. Notices - -You may not remove or alter the substance of any license notices -(including copyright notices, patent notices, disclaimers of warranty, -or limitations of liability) contained within the Source Code Form of -the Covered Software, except that You may alter any license notices to -the extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - -You may choose to offer, and to charge a fee for, warranty, support, -indemnity or liability obligations to one or more recipients of Covered -Software. However, You may do so only on Your own behalf, and not on -behalf of any Contributor. You must make it absolutely clear that any -such warranty, support, indemnity, or liability obligation is offered by -You alone, and You hereby agree to indemnify every Contributor for any -liability incurred by such Contributor as a result of warranty, support, -indemnity or liability terms You offer. You may include additional -disclaimers of warranty and limitations of liability specific to any -jurisdiction. - -4. Inability to Comply Due to Statute or Regulation ---------------------------------------------------- - -If it is impossible for You to comply with any of the terms of this -License with respect to some or all of the Covered Software due to -statute, judicial order, or regulation then You must: (a) comply with -the terms of this License to the maximum extent possible; and (b) -describe the limitations and the code they affect. Such description must -be placed in a text file included with all distributions of the Covered -Software under this License. Except to the extent prohibited by statute -or regulation, such description must be sufficiently detailed for a -recipient of ordinary skill to be able to understand it. - -5. Termination --------------- - -5.1. The rights granted under this License will terminate automatically -if You fail to comply with any of its terms. However, if You become -compliant, then the rights granted under this License from a particular -Contributor are reinstated (a) provisionally, unless and until such -Contributor explicitly and finally terminates Your grants, and (b) on an -ongoing basis, if such Contributor fails to notify You of the -non-compliance by some reasonable means prior to 60 days after You have -come back into compliance. Moreover, Your grants from a particular -Contributor are reinstated on an ongoing basis if such Contributor -notifies You of the non-compliance by some reasonable means, this is the -first time You have received notice of non-compliance with this License -from such Contributor, and You become compliant prior to 30 days after -Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all -end user license agreements (excluding distributors and resellers) which -have been validly granted by You or Your distributors under this License -prior to termination shall survive termination. - -************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * -************************************************************************ - -************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * -************************************************************************ - -8. Litigation -------------- - -Any litigation relating to this License may be brought only in the -courts of a jurisdiction where the defendant maintains its principal -place of business and such litigation shall be governed by laws of that -jurisdiction, without reference to its conflict-of-law provisions. -Nothing in this Section shall prevent a party's ability to bring -cross-claims or counter-claims. - -9. Miscellaneous ----------------- - -This License represents the complete agreement concerning the subject -matter hereof. If any provision of this License is held to be -unenforceable, such provision shall be reformed only to the extent -necessary to make it enforceable. Any law or regulation which provides -that the language of a contract shall be construed against the drafter -shall not be used to construe this License against a Contributor. - -10. Versions of the License ---------------------------- - -10.1. New Versions - -Mozilla Foundation is the license steward. Except as provided in Section -10.3, no one other than the license steward has the right to modify or -publish new versions of this License. Each version will be given a -distinguishing version number. - -10.2. Effect of New Versions - -You may distribute the Covered Software under the terms of the version -of the License under which You originally received the Covered Software, -or under the terms of any subsequent version published by the license -steward. - -10.3. Modified Versions - -If you create software not governed by this License, and you want to -create a new license for such software, you may create and use a -modified version of this License if you rename the license and remove -any references to the name of the license steward (except to note that -such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses - -If You choose to distribute Source Code Form that is Incompatible With -Secondary Licenses under the terms of this version of the License, the -notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice -------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular -file, then You may include the notice in a location (such as a LICENSE -file in a relevant directory) where a recipient would be likely to look -for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice ---------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. diff --git a/contracts/stake-types/Makefile b/contracts/stake-types/Makefile deleted file mode 100644 index ab50914d0b..0000000000 --- a/contracts/stake-types/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -all: ## Build the transfer contract - @cargo build --release - -help: ## Display this help screen - @grep -h \ - -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ - awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -check: wasm ## Run the Rust check on the project features - @cargo check --target wasm32-unknown-unknown - @cargo check - -test: ## Perform the contract tests defined in the host module - @cargo test --release - -wasm: ## Build the WASM files - @RUSTFLAGS="$(RUSTFLAGS) --remap-path-prefix $(HOME)= -C link-args=-zstack-size=65536" \ - cargo +dusk build \ - --release \ - --color=always \ - -Z build-std=core,alloc \ - --target wasm64-unknown-unknown - -clippy: ## Run clippy - @cargo clippy --all-features --release -- -D warnings - @cargo clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings - -.PHONY: all check test wasm help diff --git a/contracts/stake-types/README.md b/contracts/stake-types/README.md deleted file mode 100644 index 20c11cb6a5..0000000000 --- a/contracts/stake-types/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# stake-contract-types - -Provides types which are needed for the interaction with the Dusk Network Stake Contract: - -- Stake -- Unstake -- Withdraw -- Allow - -It also provides staking-related message signing functions as well as the StakeData object - a representation of a public key's stake. diff --git a/contracts/stake-types/src/lib.rs b/contracts/stake-types/src/lib.rs deleted file mode 100644 index 37a2ad7db6..0000000000 --- a/contracts/stake-types/src/lib.rs +++ /dev/null @@ -1,86 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -//! Types used for transactions with Dusk's stake contract. - -#![no_std] -#![deny(missing_docs)] -#![deny(clippy::pedantic)] - -extern crate alloc; -use alloc::vec::Vec; - -mod sig; -mod stake; - -pub use sig::{ - stake_signature_message, unstake_signature_message, - withdraw_signature_message, -}; -pub use stake::{next_epoch, BlockHeight, StakeData, EPOCH}; - -use bls12_381_bls::{PublicKey as StakePublicKey, Signature as StakeSignature}; -use dusk_bls12_381::BlsScalar; -use phoenix_core::StealthAddress; - -use bytecheck::CheckBytes; -use rkyv::{Archive, Deserialize, Serialize}; - -/// Stake a value on the stake contract. -#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)] -#[archive_attr(derive(bytecheck::CheckBytes))] -pub struct Stake { - /// Public key to which the stake will belong. - pub public_key: StakePublicKey, - /// Signature belonging to the given public key. - pub signature: StakeSignature, - /// Value to stake. - pub value: u64, - /// Proof of the `STCT` circuit. - pub proof: Vec, -} - -/// Unstake a value from the stake contract. -#[derive(Debug, Clone, PartialEq, Eq, Archive, Deserialize, Serialize)] -#[archive_attr(derive(CheckBytes))] -pub struct Unstake { - /// Public key to unstake. - pub public_key: StakePublicKey, - /// Signature belonging to the given public key. - pub signature: StakeSignature, - /// Note to withdraw to. - pub note: Vec, // todo: not sure it will stay as Vec - /// A proof of the `WFCT` circuit. - pub proof: Vec, -} - -/// Withdraw the accumulated reward. -#[derive(Debug, Clone, Archive, Deserialize, Serialize)] -#[archive_attr(derive(CheckBytes))] -pub struct Withdraw { - /// Public key to withdraw the rewards. - pub public_key: StakePublicKey, - /// Signature belonging to the given public key. - pub signature: StakeSignature, - /// The address to mint to. - pub address: StealthAddress, - /// A nonce to prevent replay. - pub nonce: BlsScalar, -} - -/// -/// Events - -/// Event emitted after a stake contract operation is performed. -#[derive(Debug, Clone, Archive, Deserialize, Serialize)] -#[archive_attr(derive(CheckBytes))] -pub struct StakingEvent { - /// Public key which is relevant to the event. - pub public_key: StakePublicKey, - /// Value of the relevant operation, be it stake, unstake, withdrawal, - /// reward, or slash. - pub value: u64, -} diff --git a/contracts/stake-types/src/sig.rs b/contracts/stake-types/src/sig.rs deleted file mode 100644 index ddca0590ba..0000000000 --- a/contracts/stake-types/src/sig.rs +++ /dev/null @@ -1,63 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -//! Signatures messages used in the stake contract. - -use alloc::vec::Vec; - -use dusk_bls12_381::BlsScalar; -use dusk_bytes::Serializable; -use phoenix_core::StealthAddress; - -const STAKE_MESSAGE_SIZE: usize = u64::SIZE + u64::SIZE; -const WITHDRAW_MESSAGE_SIZE: usize = - u64::SIZE + StealthAddress::SIZE + BlsScalar::SIZE; - -/// Return the digest to be signed in the `stake` function of the stake -/// contract. -#[must_use] -pub fn stake_signature_message( - counter: u64, - value: u64, -) -> [u8; STAKE_MESSAGE_SIZE] { - let mut bytes = [0u8; STAKE_MESSAGE_SIZE]; - - bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes()); - bytes[u64::SIZE..].copy_from_slice(&value.to_bytes()); - - bytes -} - -/// Signature message used for [`Unstake`]. -pub fn unstake_signature_message(counter: u64, note: T) -> Vec -where - T: AsRef<[u8]>, -{ - let mut vec = Vec::new(); - - vec.extend_from_slice(&counter.to_bytes()); - vec.extend_from_slice(note.as_ref()); - - vec -} - -/// Signature message used for [`Withdraw`]. -#[must_use] -pub fn withdraw_signature_message( - counter: u64, - address: StealthAddress, - nonce: BlsScalar, -) -> [u8; WITHDRAW_MESSAGE_SIZE] { - let mut bytes = [0u8; WITHDRAW_MESSAGE_SIZE]; - - bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes()); - bytes[u64::SIZE..u64::SIZE + StealthAddress::SIZE] - .copy_from_slice(&address.to_bytes()); - bytes[u64::SIZE + StealthAddress::SIZE..] - .copy_from_slice(&nonce.to_bytes()); - - bytes -} diff --git a/contracts/stake/Cargo.toml b/contracts/stake/Cargo.toml index 4c0565b182..9e24ffb0df 100644 --- a/contracts/stake/Cargo.toml +++ b/contracts/stake/Cargo.toml @@ -7,21 +7,16 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } -bls12_381-bls = { version = "0.2", default-features = false, features = ["rkyv-impl"] } +execution-core = { version = "0.1.0", path = "../../execution-core" } dusk-bytes = "0.1" -dusk-jubjub = { version = "0.14", default-features = false, 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"] } -transfer-contract-types = { version = "0.1.0", path = "../transfer-types", default-features = false } -stake-contract-types = { version = "0.1.0-rc", path = "../stake-types", default-features = false } [target.'cfg(target_family = "wasm")'.dependencies] rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" } [dev-dependencies] rusk-profile = { version = "0.6", path = "../../rusk-profile" } -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", default-features = false, features = ["host"] } transfer-circuits = { version = "0.5", path = "../../circuits/transfer" } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } diff --git a/contracts/stake/benches/get_provisioners.rs b/contracts/stake/benches/get_provisioners.rs index 3eaa9496de..04c2bbc3cf 100644 --- a/contracts/stake/benches/get_provisioners.rs +++ b/contracts/stake/benches/get_provisioners.rs @@ -4,14 +4,13 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use bls12_381_bls::{PublicKey, SecretKey}; use criterion::{criterion_group, criterion_main, Criterion}; +use execution_core::{stake::StakeData, StakePublicKey, StakeSecretKey}; use rand::rngs::StdRng; use rand::{CryptoRng, RngCore, SeedableRng}; use rusk_abi::{ ContractData, Error, Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM, }; -use stake_contract_types::StakeData; use std::sync::mpsc; const SAMPLE_SIZE: usize = 10; @@ -67,7 +66,7 @@ fn instantiate(vm: &VM) -> Session { fn do_get_provisioners( session: &mut Session, -) -> Result, Error> { +) -> Result, Error> { let (sender, receiver) = mpsc::channel(); session.feeder_call::<_, ()>( STAKE_CONTRACT, @@ -77,7 +76,7 @@ fn do_get_provisioners( sender, )?; Ok(receiver.into_iter().map(|bytes| { - rkyv::from_bytes::<(PublicKey, StakeData)>(&bytes) + rkyv::from_bytes::<(StakePublicKey, StakeData)>(&bytes) .expect("The contract should only return (pk, stake_data) tuples") })) } @@ -91,8 +90,8 @@ fn do_insert_stake( counter: 1, reward: 0, }; - let sk = SecretKey::random(rng); - let pk = PublicKey::from(&sk); + let sk = StakeSecretKey::random(rng); + let pk = StakePublicKey::from(&sk); session.call::<_, ()>( STAKE_CONTRACT, "insert_stake", @@ -117,7 +116,7 @@ fn get_provisioners(c: &mut Criterion) { c.bench_function("get_provisioners", |b| { b.iter(|| { - let _: Vec<(PublicKey, StakeData)> = + let _: Vec<(StakePublicKey, StakeData)> = do_get_provisioners(&mut session) .expect("getting provisioners should succeed") .collect(); diff --git a/contracts/stake/src/lib.rs b/contracts/stake/src/lib.rs index 312270c94a..3064023652 100644 --- a/contracts/stake/src/lib.rs +++ b/contracts/stake/src/lib.rs @@ -18,7 +18,7 @@ use state::StakeState; /// The minimum amount of Dusk one can stake. pub const MINIMUM_STAKE: Dusk = dusk(1_000.0); -use bls12_381_bls::PublicKey as BlsPublicKey; +use execution_core::StakePublicKey; use rusk_abi::{ContractId, PaymentInfo}; #[no_mangle] @@ -56,7 +56,7 @@ unsafe fn withdraw(arg_len: u32) -> u32 { #[no_mangle] unsafe fn get_stake(arg_len: u32) -> u32 { - rusk_abi::wrap_call(arg_len, |pk: BlsPublicKey| { + rusk_abi::wrap_call(arg_len, |pk: StakePublicKey| { STATE.get_stake(&pk).cloned() }) } diff --git a/contracts/stake/src/state.rs b/contracts/stake/src/state.rs index 0fb8a75e71..b9c0602a2f 100644 --- a/contracts/stake/src/state.rs +++ b/contracts/stake/src/state.rs @@ -4,18 +4,21 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use core::cmp::min; - -use crate::*; - use alloc::collections::BTreeMap; +use core::cmp::min; -use bls12_381_bls::PublicKey as StakePublicKey; use dusk_bytes::Serializable; +use execution_core::{ + stake::{ + next_epoch, Stake, StakeData, StakingEvent, Unstake, Withdraw, EPOCH, + }, + transfer::{Mint, Stct, WfctRaw}, + StakePublicKey, +}; use rusk_abi::{STAKE_CONTRACT, TRANSFER_CONTRACT}; -use stake_contract_types::*; -use transfer_contract_types::*; + +use crate::*; /// Contract keeping track of each public key's stake. /// @@ -79,7 +82,7 @@ impl StakeState { loaded_stake.insert_amount(stake.value, rusk_abi::block_height()); // verify the signature is over the correct digest - let digest = stake_signature_message(counter, stake.value).to_vec(); + let digest = Stake::signature_message(counter, stake.value).to_vec(); if !rusk_abi::verify_bls(digest, stake.public_key, stake.signature) { panic!("Invalid signature!"); @@ -129,7 +132,7 @@ impl StakeState { // verify signature let digest = - unstake_signature_message(counter, unstake.note.as_slice()); + Unstake::signature_message(counter, unstake.note.as_slice()); if !rusk_abi::verify_bls(digest, unstake.public_key, unstake.signature) { @@ -180,7 +183,7 @@ impl StakeState { loaded_stake.increment_counter(); // verify signature - let digest = withdraw_signature_message( + let digest = Withdraw::signature_message( counter, withdraw.address, withdraw.nonce, diff --git a/contracts/stake/tests/common/assert.rs b/contracts/stake/tests/common/assert.rs index 987df3cb05..c369d117aa 100644 --- a/contracts/stake/tests/common/assert.rs +++ b/contracts/stake/tests/common/assert.rs @@ -4,16 +4,16 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use bls12_381_bls::PublicKey; use dusk_bytes::Serializable; use rkyv::{check_archived_root, Deserialize, Infallible}; + +use execution_core::{stake::StakingEvent, StakePublicKey}; use rusk_abi::Event; -use stake_contract_types::StakingEvent; pub fn assert_event( events: &Vec, topic: S, - should_pk: &PublicKey, + should_pk: &StakePublicKey, should_amount: u64, ) where S: AsRef, diff --git a/contracts/stake/tests/common/init.rs b/contracts/stake/tests/common/init.rs index b209c9ed0d..50ea604f21 100644 --- a/contracts/stake/tests/common/init.rs +++ b/contracts/stake/tests/common/init.rs @@ -4,11 +4,13 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::common::utils::update_root; -use phoenix_core::{Note, PublicKey}; use rand::{CryptoRng, RngCore}; + +use execution_core::{Note, PublicKey}; use rusk_abi::{ContractData, Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM}; +use crate::common::utils::update_root; + const OWNER: [u8; 32] = [0; 32]; const POINT_LIMIT: u64 = 0x100_000_000; diff --git a/contracts/stake/tests/common/utils.rs b/contracts/stake/tests/common/utils.rs index a7e82c8c96..2e752dd2e2 100644 --- a/contracts/stake/tests/common/utils.rs +++ b/contracts/stake/tests/common/utils.rs @@ -7,9 +7,12 @@ use std::sync::mpsc; use dusk_plonk::prelude::*; -use phoenix_core::transaction::{TreeLeaf, TRANSFER_TREE_DEPTH}; -use phoenix_core::{Note, Transaction, ViewKey}; use poseidon_merkle::Opening as PoseidonOpening; + +use execution_core::{ + transfer::{TreeLeaf, TRANSFER_TREE_DEPTH}, + Note, Transaction, ViewKey, +}; use rusk_abi::{CallReceipt, ContractError, Error, Session, TRANSFER_CONTRACT}; const POINT_LIMIT: u64 = 0x100000000; diff --git a/contracts/stake/tests/events.rs b/contracts/stake/tests/events.rs index 5b1ef8ef31..33e99bdb22 100644 --- a/contracts/stake/tests/events.rs +++ b/contracts/stake/tests/events.rs @@ -6,14 +6,14 @@ pub mod common; -use bls12_381_bls::{PublicKey as StakePublicKey, SecretKey as StakeSecretKey}; -use phoenix_core::{PublicKey, SecretKey}; use rand::rngs::StdRng; use rand::SeedableRng; + +use execution_core::{ + stake::StakeData, PublicKey, SecretKey, StakePublicKey, StakeSecretKey, +}; use rusk_abi::dusk::dusk; -use rusk_abi::Error; -use rusk_abi::{STAKE_CONTRACT, TRANSFER_CONTRACT}; -use stake_contract_types::StakeData; +use rusk_abi::{Error, STAKE_CONTRACT, TRANSFER_CONTRACT}; use crate::common::assert::assert_event; use crate::common::init::instantiate; diff --git a/contracts/stake/tests/stake.rs b/contracts/stake/tests/stake.rs index 6cd85fd267..b9272242b6 100644 --- a/contracts/stake/tests/stake.rs +++ b/contracts/stake/tests/stake.rs @@ -6,31 +6,29 @@ pub mod common; -use crate::common::assert::assert_event; -use crate::common::init::instantiate; -use crate::common::utils::*; -use bls12_381_bls::{PublicKey as StakePublicKey, SecretKey as StakeSecretKey}; -use dusk_bls12_381::BlsScalar; use dusk_bytes::Serializable; -use dusk_jubjub::{JubJubScalar, GENERATOR_NUMS_EXTENDED}; use ff::Field; -use phoenix_core::{ - Fee, Note, Ownable, PublicKey, SecretKey, Transaction, ViewKey, -}; use rand::rngs::StdRng; use rand::SeedableRng; + +use execution_core::stake::{Stake, StakeData, Unstake, Withdraw}; +use execution_core::{ + BlsScalar, Fee, JubJubScalar, Note, Ownable, PublicKey, SecretKey, + StakePublicKey, StakeSecretKey, Transaction, ViewKey, + GENERATOR_NUMS_EXTENDED, +}; use rusk_abi::dusk::{dusk, LUX}; use rusk_abi::STAKE_CONTRACT; -use stake_contract_types::{ - stake_signature_message, unstake_signature_message, - withdraw_signature_message, Stake, StakeData, Unstake, Withdraw, -}; use transfer_circuits::{ CircuitInput, CircuitInputSignature, ExecuteCircuitOneTwo, ExecuteCircuitThreeTwo, ExecuteCircuitTwoTwo, SendToContractTransparentCircuit, WithdrawFromTransparentCircuit, }; +use crate::common::assert::assert_event; +use crate::common::init::instantiate; +use crate::common::utils::*; + const GENESIS_VALUE: u64 = dusk(1_000_000.0); const POINT_LIMIT: u64 = 0x100_000_000; @@ -116,7 +114,7 @@ fn stake_withdraw_unstake() { .prove(rng, &stct_circuit) .expect("Proving STCT circuit should succeed"); - let stake_digest = stake_signature_message(0, crossover_value); + let stake_digest = Stake::signature_message(0, crossover_value); let stake_sig = stake_sk.sign(&stake_pk, &stake_digest); // Fashion a Stake struct @@ -314,7 +312,7 @@ fn stake_withdraw_unstake() { let withdraw_nonce = BlsScalar::random(&mut *rng); - let withdraw_digest = withdraw_signature_message( + let withdraw_digest = Withdraw::signature_message( stake_data.counter, withdraw_address, withdraw_nonce, @@ -519,8 +517,10 @@ fn stake_withdraw_unstake() { .prove(rng, &wfct_circuit) .expect("Proving WFCT circuit should succeed"); - let unstake_digest = - unstake_signature_message(stake_data.counter, withdraw_note.to_bytes()); + let unstake_digest = Unstake::signature_message( + stake_data.counter, + withdraw_note.to_bytes(), + ); let unstake_sig = stake_sk.sign(&stake_pk, unstake_digest.as_slice()); let unstake = Unstake { diff --git a/contracts/transfer-types/Makefile b/contracts/transfer-types/Makefile deleted file mode 100644 index ab50914d0b..0000000000 --- a/contracts/transfer-types/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -all: ## Build the transfer contract - @cargo build --release - -help: ## Display this help screen - @grep -h \ - -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ - awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -check: wasm ## Run the Rust check on the project features - @cargo check --target wasm32-unknown-unknown - @cargo check - -test: ## Perform the contract tests defined in the host module - @cargo test --release - -wasm: ## Build the WASM files - @RUSTFLAGS="$(RUSTFLAGS) --remap-path-prefix $(HOME)= -C link-args=-zstack-size=65536" \ - cargo +dusk build \ - --release \ - --color=always \ - -Z build-std=core,alloc \ - --target wasm64-unknown-unknown - -clippy: ## Run clippy - @cargo clippy --all-features --release -- -D warnings - @cargo clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings - -.PHONY: all check test wasm help diff --git a/contracts/transfer/Cargo.toml b/contracts/transfer/Cargo.toml index 5c4b7d0ce9..d4dd63bad6 100644 --- a/contracts/transfer/Cargo.toml +++ b/contracts/transfer/Cargo.toml @@ -7,16 +7,12 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } +execution-core = { version = "0.1.0", path = "../../execution-core" } dusk-bytes = "0.1" -dusk-jubjub = { version = "0.14", default-features = false, features = ["rkyv-impl"] } -jubjub-schnorr = { version = "0.2", default-features = false, features = ["rkyv-impl"] } dusk-poseidon = { version = "0.33", default-features = false, features = ["alloc"] } poseidon-merkle = { version = "0.5", features = ["rkyv-impl"] } -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } -transfer-contract-types = { version = "0.1.0", path = "../transfer-types", default-features = false } ringbuffer = "0.15" diff --git a/contracts/transfer/src/error.rs b/contracts/transfer/src/error.rs index 61bf05ce67..d6d2212c3c 100644 --- a/contracts/transfer/src/error.rs +++ b/contracts/transfer/src/error.rs @@ -5,7 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use core::fmt; -use phoenix_core::Error as PhoenixError; +use execution_core::PhoenixError; #[derive(Debug, Clone)] pub enum Error { diff --git a/contracts/transfer/src/state.rs b/contracts/transfer/src/state.rs index 825a2759e8..cac1b642f7 100644 --- a/contracts/transfer/src/state.rs +++ b/contracts/transfer/src/state.rs @@ -12,17 +12,21 @@ use alloc::collections::btree_map::Entry; use alloc::collections::{BTreeMap, BTreeSet}; use alloc::vec::Vec; -use dusk_bls12_381::BlsScalar; use dusk_bytes::DeserializableSlice; -use dusk_jubjub::JubJubAffine; -use phoenix_core::transaction::*; -use phoenix_core::{Crossover, Fee, Note, Ownable, StealthAddress}; use poseidon_merkle::Opening as PoseidonOpening; use ringbuffer::{ConstGenericRingBuffer, RingBuffer}; use rusk_abi::{ ContractError, ContractId, PaymentInfo, PublicInput, STAKE_CONTRACT, }; -use transfer_contract_types::{Mint, Stct, Wfct, Wfctc}; + +use execution_core::{ + stct_signature_message, + transfer::{ + Mint, Stct, TreeLeaf, Wfct, WfctRaw, Wfctc, TRANSFER_TREE_DEPTH, + }, + BlsScalar, Crossover, Fee, JubJubAffine, Note, Ownable, StealthAddress, + Transaction, +}; /// Arity of the transfer tree. pub const A: usize = 4; @@ -139,7 +143,7 @@ impl TransferState { pub fn withdraw_from_contract_transparent_raw( &mut self, - wfct_raw: transfer_contract_types::WfctRaw, + wfct_raw: WfctRaw, ) -> bool { let note = Note::from_slice(wfct_raw.note.as_slice()) .expect("Failed to deserialize note"); diff --git a/contracts/transfer/src/tree.rs b/contracts/transfer/src/tree.rs index 6df8a2f86f..52c74a70bd 100644 --- a/contracts/transfer/src/tree.rs +++ b/contracts/transfer/src/tree.rs @@ -6,14 +6,15 @@ use alloc::vec::Vec; -use dusk_bls12_381::BlsScalar; -use phoenix_core::transaction::*; -use phoenix_core::Note; - use poseidon_merkle::{ Item as PoseidonItem, Opening as PoseidonOpening, Tree as PoseidonTree, }; +use execution_core::{ + transfer::{TreeLeaf, TRANSFER_TREE_DEPTH}, + BlsScalar, Note, +}; + use crate::state::A; pub struct Tree { diff --git a/contracts/transfer/tests/transfer.rs b/contracts/transfer/tests/transfer.rs index 868c246f38..48359cd5cb 100644 --- a/contracts/transfer/tests/transfer.rs +++ b/contracts/transfer/tests/transfer.rs @@ -6,13 +6,9 @@ use std::sync::mpsc; -use dusk_bls12_381::BlsScalar; use dusk_bytes::Serializable; -use dusk_jubjub::{JubJubScalar, GENERATOR_NUMS_EXTENDED}; use dusk_plonk::prelude::*; use ff::Field; -use phoenix_core::transaction::*; -use phoenix_core::{Fee, Note, Ownable, PublicKey, SecretKey, ViewKey}; use poseidon_merkle::Opening as PoseidonOpening; use rand::rngs::StdRng; use rand::{CryptoRng, RngCore, SeedableRng}; @@ -27,6 +23,12 @@ use transfer_circuits::{ WithdrawFromTransparentCircuit, }; +use execution_core::{ + transfer::{Stct, TreeLeaf, Wfct, TRANSFER_TREE_DEPTH}, + BlsScalar, Fee, JubJubScalar, Note, Ownable, PublicKey, SecretKey, + Transaction, ViewKey, GENERATOR_NUMS_EXTENDED, +}; + const GENESIS_VALUE: u64 = dusk(1_000.0); const POINT_LIMIT: u64 = 0x10000000; diff --git a/contracts/transfer-types/Cargo.toml b/execution-core/Cargo.toml similarity index 72% rename from contracts/transfer-types/Cargo.toml rename to execution-core/Cargo.toml index 2e1a6d8916..5d0846c45f 100644 --- a/contracts/transfer-types/Cargo.toml +++ b/execution-core/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "transfer-contract-types" +name = "execution-core" version = "0.1.0" edition = "2021" @@ -7,6 +7,9 @@ edition = "2021" dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } dusk-jubjub = { version = "0.14", default-features = false, features = ["rkyv-impl"] } dusk-poseidon = { version = "0.33", default-features = false, features = ["rkyv-impl", "alloc"] } +bls12_381-bls = { version = "0.2", default-features = false, features = ["rkyv-impl"] } +jubjub-schnorr = { version = "0.2", default-features = false, features = ["rkyv-impl"] } phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } +dusk-bytes = "0.1" rkyv = { version = "0.7", default-features = false, features = ["size_32"] } bytecheck = { version = "0.6", default-features = false } diff --git a/execution-core/src/lib.rs b/execution-core/src/lib.rs new file mode 100644 index 0000000000..b73b1ab4e7 --- /dev/null +++ b/execution-core/src/lib.rs @@ -0,0 +1,57 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// Copyright (c) DUSK NETWORK. All rights reserved. + +//! Types used for interacting with Dusk's transfer and stake contracts. + +#![no_std] +#![deny(missing_docs)] +#![deny(clippy::pedantic)] + +/// Block height type alias +pub type BlockHeight = u64; + +pub mod stake; +pub mod transfer; + +// elliptic curve types +pub use dusk_bls12_381::BlsScalar; +pub use dusk_jubjub::{ + JubJubAffine, JubJubExtended, JubJubScalar, GENERATOR_EXTENDED, + GENERATOR_NUMS_EXTENDED, +}; + +// signature types +pub use bls12_381_bls::{ + Error as BlsSigError, PublicKey as BlsPublicKey, SecretKey as BlsSecretKey, + Signature as BlsSignature, APK as BlsAggPublicKey, +}; + +/// Secret key associated to a stake. +pub type StakeSecretKey = BlsSecretKey; +/// Public key associated to a stake. +pub type StakePublicKey = BlsPublicKey; +/// Signature associated with a stake. +pub type StakeSignature = BlsSignature; +/// Aggregated public key for multisignatures +pub type StakeAggPublicKey = BlsAggPublicKey; + +pub use jubjub_schnorr::{ + PublicKey as SchnorrPublicKey, SecretKey as SchnorrSecretKey, + Signature as SchnorrSignature, +}; +/// Secret key associated with a note. +pub type NoteSecretKey = SchnorrSecretKey; +/// Public key associated with a note. +pub type NotePublicKey = SchnorrPublicKey; +/// Signature to prove ownership of the note +pub type NoteSignature = SchnorrSignature; + +// phoenix types +pub use phoenix_core::{ + transaction::stct_signature_message, Crossover, Error as PhoenixError, Fee, + Message, Note, Ownable, PublicKey, Remainder, SecretKey, StealthAddress, + Transaction, ViewKey, +}; diff --git a/contracts/stake-types/src/stake.rs b/execution-core/src/stake.rs similarity index 58% rename from contracts/stake-types/src/stake.rs rename to execution-core/src/stake.rs index a3f9908625..c19b7dadec 100644 --- a/contracts/stake-types/src/stake.rs +++ b/execution-core/src/stake.rs @@ -4,11 +4,18 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +//! Types used by Dusk's stake contract. + +extern crate alloc; +use alloc::vec::Vec; + use bytecheck::CheckBytes; +use dusk_bytes::Serializable; use rkyv::{Archive, Deserialize, Serialize}; -/// Block height type alias -pub type BlockHeight = u64; +use crate::{ + BlockHeight, BlsScalar, StakePublicKey, StakeSignature, StealthAddress, +}; /// Epoch used for stake operations pub const EPOCH: u64 = 2160; @@ -20,6 +27,115 @@ pub const fn next_epoch(block_height: BlockHeight) -> u64 { block_height + to_next_epoch } +/// Stake a value on the stake contract. +#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)] +#[archive_attr(derive(bytecheck::CheckBytes))] +pub struct Stake { + /// Public key to which the stake will belong. + pub public_key: StakePublicKey, + /// Signature belonging to the given public key. + pub signature: StakeSignature, + /// Value to stake. + pub value: u64, + /// Proof of the `STCT` circuit. + pub proof: Vec, +} + +impl Stake { + const MESSAGE_SIZE: usize = u64::SIZE + u64::SIZE; + /// Return the digest to be signed in the `stake` function of the stake + /// contract. + #[must_use] + pub fn signature_message( + counter: u64, + value: u64, + ) -> [u8; Self::MESSAGE_SIZE] { + let mut bytes = [0u8; Self::MESSAGE_SIZE]; + + bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes()); + bytes[u64::SIZE..].copy_from_slice(&value.to_bytes()); + + bytes + } +} + +/// Unstake a value from the stake contract. +#[derive(Debug, Clone, PartialEq, Eq, Archive, Deserialize, Serialize)] +#[archive_attr(derive(CheckBytes))] +pub struct Unstake { + /// Public key to unstake. + pub public_key: StakePublicKey, + /// Signature belonging to the given public key. + pub signature: StakeSignature, + /// Note to withdraw to. + pub note: Vec, // todo: not sure it will stay as Vec + /// A proof of the `WFCT` circuit. + pub proof: Vec, +} + +impl Unstake { + /// Signature message used for [`Unstake`]. + pub fn signature_message(counter: u64, note: T) -> Vec + where + T: AsRef<[u8]>, + { + let mut vec = Vec::new(); + + vec.extend_from_slice(&counter.to_bytes()); + vec.extend_from_slice(note.as_ref()); + + vec + } +} + +/// Withdraw the accumulated reward. +#[derive(Debug, Clone, Archive, Deserialize, Serialize)] +#[archive_attr(derive(CheckBytes))] +pub struct Withdraw { + /// Public key to withdraw the rewards. + pub public_key: StakePublicKey, + /// Signature belonging to the given public key. + pub signature: StakeSignature, + /// The address to mint to. + pub address: StealthAddress, + /// A nonce to prevent replay. + pub nonce: BlsScalar, +} + +impl Withdraw { + const MESSAGE_SIZE: usize = + u64::SIZE + StealthAddress::SIZE + BlsScalar::SIZE; + + /// Signature message used for [`Withdraw`]. + #[must_use] + pub fn signature_message( + counter: u64, + address: StealthAddress, + nonce: BlsScalar, + ) -> [u8; Self::MESSAGE_SIZE] { + let mut bytes = [0u8; Self::MESSAGE_SIZE]; + + bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes()); + bytes[u64::SIZE..u64::SIZE + StealthAddress::SIZE] + .copy_from_slice(&address.to_bytes()); + bytes[u64::SIZE + StealthAddress::SIZE..] + .copy_from_slice(&nonce.to_bytes()); + + bytes + } +} + +/// Event emitted after a stake contract operation is performed. +#[derive(Debug, Clone, Archive, Deserialize, Serialize)] +#[archive_attr(derive(CheckBytes))] +pub struct StakingEvent { + /// Public key which is relevant to the event. + pub public_key: StakePublicKey, + /// Value of the relevant operation, be it stake, unstake, withdrawal, + /// reward, or slash. + pub value: u64, +} + /// The representation of a public key's stake. /// /// A user can stake for a particular `amount` larger in value than the diff --git a/contracts/transfer-types/src/lib.rs b/execution-core/src/transfer.rs similarity index 92% rename from contracts/transfer-types/src/lib.rs rename to execution-core/src/transfer.rs index 28e8e34e03..e492e8b0be 100644 --- a/contracts/transfer-types/src/lib.rs +++ b/execution-core/src/transfer.rs @@ -4,24 +4,22 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -//! Types used for transactions with Dusk's transfer contract. - -#![no_std] -#![deny(missing_docs)] -#![deny(clippy::pedantic)] +//! Types used by Dusk's transfer contract. extern crate alloc; use alloc::vec::Vec; -use dusk_bls12_381::BlsScalar; - use bytecheck::CheckBytes; -use phoenix_core::{Note, StealthAddress}; use rkyv::{Archive, Deserialize, Serialize}; +use crate::{BlsScalar, Note, StealthAddress}; + /// Module Id pub type ModuleId = [u8; 32]; +/// The depth of the transfer tree. +pub const TRANSFER_TREE_DEPTH: usize = 17; + /// A leaf of the transfer tree. #[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)] #[archive_attr(derive(CheckBytes))] diff --git a/node-data/Cargo.toml b/node-data/Cargo.toml index 43a84cb6a2..2587bc4c8b 100644 --- a/node-data/Cargo.toml +++ b/node-data/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } dusk-bytes = "^0.1" bytes = "0.6" sha3 = "0.10" @@ -12,8 +11,8 @@ sha2 = "0.10" fake = { version = "2.5", features = ['derive'], optional = true } rand = { version = "0.8", optional = true } hex = { version = "0.4", optional = true } -bls12_381-bls = { version = "0.2", default-features = false } rusk-abi = { version = "0.13.0-rc", path = "../rusk-abi", default-features = false } +execution-core = { version = "0.1.0", path = "../execution-core" } rand_core = { version = "0.6", default-features = false } blake3 = "1.3" diff --git a/node-data/src/bls.rs b/node-data/src/bls.rs index 6834507094..c46a208217 100644 --- a/node-data/src/bls.rs +++ b/node-data/src/bls.rs @@ -18,28 +18,29 @@ use std::fs; use std::path::PathBuf; use tracing::warn; -pub const PUBLIC_BLS_SIZE: usize = bls12_381_bls::PublicKey::SIZE; +use execution_core::{BlsPublicKey, BlsSecretKey}; +pub const PUBLIC_BLS_SIZE: usize = BlsPublicKey::SIZE; -/// Extends bls12_381_bls::PublicKey by implementing a few traits +/// Extends BlsPublicKey by implementing a few traits /// /// See also PublicKey::bytes(&self) #[derive(Default, Eq, PartialEq, Clone)] pub struct PublicKey { - inner: bls12_381_bls::PublicKey, + inner: BlsPublicKey, as_bytes: PublicKeyBytes, } impl TryFrom<[u8; 96]> for PublicKey { - type Error = bls12_381_bls::Error; + type Error = dusk_bytes::Error; fn try_from(bytes: [u8; 96]) -> Result { - let inner = bls12_381_bls::PublicKey::from_slice(&bytes)?; + let inner = BlsPublicKey::from_slice(&bytes)?; let as_bytes = PublicKeyBytes(bytes); Ok(Self { as_bytes, inner }) } } impl PublicKey { - pub fn new(inner: bls12_381_bls::PublicKey) -> Self { + pub fn new(inner: BlsPublicKey) -> Self { let b = inner.to_bytes(); Self { inner, @@ -51,9 +52,9 @@ impl PublicKey { /// associated public key pub fn from_sk_seed_u64(state: u64) -> Self { let rng = &mut StdRng::seed_from_u64(state); - let sk = bls12_381_bls::SecretKey::random(rng); + let sk = BlsSecretKey::random(rng); - Self::new(bls12_381_bls::PublicKey::from(&sk)) + Self::new(BlsPublicKey::from(&sk)) } /// `bytes` returns a reference to the pk.to_bytes() initialized on @@ -63,7 +64,7 @@ impl PublicKey { &self.as_bytes } - pub fn inner(&self) -> &bls12_381_bls::PublicKey { + pub fn inner(&self) -> &BlsPublicKey { &self.inner } @@ -136,7 +137,7 @@ impl Debug for PublicKeyBytes { pub fn load_keys( path: String, pwd: String, -) -> anyhow::Result<(bls12_381_bls::SecretKey, PublicKey)> { +) -> anyhow::Result<(BlsSecretKey, PublicKey)> { let path_buf = PathBuf::from(path); let (pk, sk) = read_from_file(path_buf, &pwd)?; @@ -149,7 +150,7 @@ pub fn load_keys( fn read_from_file( path: PathBuf, pwd: &str, -) -> anyhow::Result<(bls12_381_bls::PublicKey, bls12_381_bls::SecretKey)> { +) -> anyhow::Result<(BlsPublicKey, BlsSecretKey)> { use serde::Deserialize; /// Bls key pair helper structure @@ -190,10 +191,10 @@ fn read_from_file( let sk_bytes = base64::decode(keys.secret_key_bls) .map_err(|e| anyhow::anyhow!("sk should be base64 {e}"))?; - let sk = bls12_381_bls::SecretKey::from_slice(&sk_bytes) + let sk = BlsSecretKey::from_slice(&sk_bytes) .map_err(|e| anyhow::anyhow!("sk should be valid {e:?}"))?; - let pk = bls12_381_bls::PublicKey::from_slice( + let pk = BlsPublicKey::from_slice( &base64::decode(keys.public_key_bls) .map_err(|e| anyhow::anyhow!("pk should be base64 {e}"))?[..], ) @@ -215,9 +216,7 @@ fn decrypt(data: &[u8], pwd: &[u8]) -> Result, BlockModeError> { /// consensus keys. /// /// It reads RUSK_WALLET_PWD var to unlock wallet files. -pub fn load_provisioners_keys( - n: usize, -) -> Vec<(bls12_381_bls::SecretKey, PublicKey)> { +pub fn load_provisioners_keys(n: usize) -> Vec<(BlsSecretKey, PublicKey)> { let mut keys = vec![]; let dir = std::env::var("DUSK_WALLET_DIR").unwrap(); diff --git a/node-data/src/encoding.rs b/node-data/src/encoding.rs index c82b1bc294..2cfb7f8133 100644 --- a/node-data/src/encoding.rs +++ b/node-data/src/encoding.rs @@ -4,6 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use std::io::{self, Read, Write}; + +use execution_core::Transaction as PhoenixTransaction; + use crate::bls::PublicKeyBytes; use crate::ledger::{ Block, Certificate, Header, IterationsInfo, Label, SpentTransaction, @@ -14,7 +18,6 @@ use crate::message::payload::{ }; use crate::message::{ConsensusHeader, SignInfo}; use crate::Serializable; -use std::io::{self, Read, Write}; impl Serializable for Block { fn write(&self, w: &mut W) -> io::Result<()> { @@ -71,7 +74,7 @@ impl Serializable for Transaction { let tx_type = Self::read_u32_le(r)?; let tx_payload = Self::read_var_le_bytes32(r)?; - let inner = phoenix_core::Transaction::from_slice(&tx_payload[..]) + let inner = PhoenixTransaction::from_slice(&tx_payload[..]) .map_err(|_| io::Error::from(io::ErrorKind::InvalidData))?; Ok(Self { diff --git a/node-data/src/ledger.rs b/node-data/src/ledger.rs index efdc69e56b..3c0eccaf9c 100644 --- a/node-data/src/ledger.rs +++ b/node-data/src/ledger.rs @@ -13,6 +13,8 @@ use rusk_abi::hash::Hasher; use sha3::Digest; use std::io::{self, Read, Write}; +use execution_core::{BlsPublicKey, Transaction as PhoenixTransaction}; + #[cfg(any(feature = "faker", test))] use fake::{Dummy, Fake, Faker}; @@ -76,11 +78,11 @@ impl std::fmt::Debug for Header { pub struct Transaction { pub version: u32, pub r#type: u32, - pub inner: phoenix_core::Transaction, + pub inner: PhoenixTransaction, } -impl From for Transaction { - fn from(value: phoenix_core::Transaction) -> Self { +impl From for Transaction { + fn from(value: PhoenixTransaction) -> Self { Self { inner: value, r#type: 1, @@ -371,11 +373,9 @@ impl IterationsInfo { } } - pub fn to_missed_generators( - &self, - ) -> Result, io::Error> { + pub fn to_missed_generators(&self) -> Result, io::Error> { self.to_missed_generators_bytes() - .map(|pk| bls12_381_bls::PublicKey::from_slice(pk.inner()).map_err(|e|{ + .map(|pk| BlsPublicKey::from_slice(pk.inner()).map_err(|e|{ tracing::error!("Unable to generate missing generators from failed_iterations: {e:?}"); io::Error::new(io::ErrorKind::InvalidData, "Error in deserialize") })) @@ -500,7 +500,7 @@ pub mod faker { )) .expect("decodable data"); - let inner = phoenix_core::Transaction::from_slice(&utx_bytes) + let inner = PhoenixTransaction::from_slice(&utx_bytes) .expect("should be valid"); inner.into() } diff --git a/node-data/src/message.rs b/node-data/src/message.rs index f5758e2f1c..63bb1d336d 100644 --- a/node-data/src/message.rs +++ b/node-data/src/message.rs @@ -5,6 +5,9 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_bytes::Serializable as DuskSerializable; +use execution_core::{ + BlsAggPublicKey, BlsPublicKey, BlsSecretKey, BlsSigError, BlsSignature, +}; use tracing::warn; use crate::bls::PublicKey; @@ -1010,19 +1013,15 @@ pub trait StepMessage { Self::STEP_NAME.to_step(self.header().iteration) } - fn verify_signature(&self) -> Result<(), bls12_381_bls::Error> { + fn verify_signature(&self) -> Result<(), BlsSigError> { let signature = self.sign_info().signature.inner(); - let sig = bls12_381_bls::Signature::from_bytes(signature)?; - let pk = bls12_381_bls::APK::from(self.sign_info().signer.inner()); + let sig = BlsSignature::from_bytes(signature)?; + let pk = BlsAggPublicKey::from(self.sign_info().signer.inner()); let msg = self.signable(); pk.verify(&sig, &msg) } - fn sign( - &mut self, - sk: &bls12_381_bls::SecretKey, - pk: &bls12_381_bls::PublicKey, - ) { + fn sign(&mut self, sk: &BlsSecretKey, pk: &BlsPublicKey) { let msg = self.signable(); let sign_info = self.sign_info_mut(); let signature = sk.sign(pk, &msg).to_bytes(); diff --git a/node/Cargo.toml b/node/Cargo.toml index 94670a2e45..1a0cbc6300 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -24,15 +24,14 @@ tracing-subscriber = { version = "0.3", features = [ ] } async-channel = "1.7" -stake-contract-types = { version = "0.1.0-rc", path = "../contracts/stake-types" } rkyv = "0.7" rocksdb_lib = { package = "rocksdb", version = "0.22", default-features = false } dusk-bytes = "^0.1" node-data = { version = "0.1", path = "../node-data" } +execution-core = { version = "0.1.0", path = "../execution-core" } rustc_tools_util = "=0.2.0" blake2 = "0.10.5" -bls12_381-bls = { version = "0.2", default-features = false } console-subscriber = { version = "0.1.8", optional = true } smallvec = "1.10.0" diff --git a/node/benches/accept.rs b/node/benches/accept.rs index 2e73ecc305..698c3e7a67 100644 --- a/node/benches/accept.rs +++ b/node/benches/accept.rs @@ -16,15 +16,12 @@ use criterion::{ criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, }; -use bls12_381_bls::{ - PublicKey as StakePublicKey, SecretKey as StakeSecretKey, - Signature as StakeSignature, -}; use dusk_bytes::Serializable; use dusk_consensus::user::{ cluster::Cluster, committee::Committee, provisioners::Provisioners, sortition::Config as SortitionConfig, }; +use execution_core::{StakePublicKey, StakeSecretKey, StakeSignature}; use node_data::ledger::{Certificate, StepVotes}; use node_data::message::payload::{ QuorumType, RatificationResult, ValidationResult, Vote, diff --git a/node/src/chain/acceptor.rs b/node/src/chain/acceptor.rs index cff5a1b13f..fa21103b96 100644 --- a/node/src/chain/acceptor.rs +++ b/node/src/chain/acceptor.rs @@ -19,10 +19,10 @@ use node_data::ledger::{ use node_data::message::AsyncQueue; use node_data::message::Payload; +use execution_core::stake::Unstake; use metrics::{counter, gauge, histogram}; use node_data::message::payload::Vote; use node_data::{Serializable, StepName}; -use stake_contract_types::Unstake; use std::sync::{Arc, LazyLock}; use std::time::Duration; use tokio::sync::RwLock; @@ -326,7 +326,7 @@ impl Acceptor { ProvisionerChange::Unstake(PublicKey::new(unstake.public_key)) } STAKE => { - let stake: stake_contract_types::Stake = + let stake: execution_core::stake::Stake = rkyv::from_bytes(calldata).map_err(|e| { anyhow::anyhow!("Cannot deserialize stake rkyv {e:?}") })?; diff --git a/node/src/chain/consensus.rs b/node/src/chain/consensus.rs index 793e0f9ba1..c7f60d8ba0 100644 --- a/node/src/chain/consensus.rs +++ b/node/src/chain/consensus.rs @@ -53,7 +53,7 @@ pub(crate) struct Task { task_id: u64, /// Loaded Consensus keys - pub keys: (bls12_381_bls::SecretKey, node_data::bls::PublicKey), + pub keys: (execution_core::StakeSecretKey, node_data::bls::PublicKey), } impl Task { diff --git a/node/src/chain/header_validation.rs b/node/src/chain/header_validation.rs index 4a0ad51672..b37e8e03df 100644 --- a/node/src/chain/header_validation.rs +++ b/node/src/chain/header_validation.rs @@ -120,13 +120,13 @@ impl<'a, DB: database::DB> Validator<'a, DB> { seed: &[u8; 48], pk_bytes: &[u8; 96], ) -> anyhow::Result<()> { - let pk = bls12_381_bls::PublicKey::from_bytes(pk_bytes) + let pk = execution_core::StakePublicKey::from_bytes(pk_bytes) .map_err(|err| anyhow!("invalid pk bytes: {:?}", err))?; - let signature = bls12_381_bls::Signature::from_bytes(seed) + let signature = execution_core::StakeSignature::from_bytes(seed) .map_err(|err| anyhow!("invalid signature bytes: {}", err))?; - bls12_381_bls::APK::from(&pk) + execution_core::StakeAggPublicKey::from(&pk) .verify(&signature, &self.prev_header.seed.inner()[..]) .map_err(|err| anyhow!("invalid seed: {:?}", err))?; diff --git a/node/src/vm.rs b/node/src/vm.rs index 3126d3c2ea..c9d3954456 100644 --- a/node/src/vm.rs +++ b/node/src/vm.rs @@ -4,11 +4,11 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use bls12_381_bls::PublicKey; use dusk_consensus::{ operations::{CallParams, VerificationOutput}, user::{provisioners::Provisioners, stake::Stake}, }; +use execution_core::StakePublicKey; use node_data::ledger::{Block, SpentTransaction, Transaction}; #[derive(Default)] @@ -49,7 +49,10 @@ pub trait VMExecution: Send + Sync + 'static { base_commit: [u8; 32], ) -> anyhow::Result)>>; - fn get_provisioner(&self, pk: &PublicKey) -> anyhow::Result>; + fn get_provisioner( + &self, + pk: &StakePublicKey, + ) -> anyhow::Result>; fn get_state_root(&self) -> anyhow::Result<[u8; 32]>; diff --git a/rusk-abi/Cargo.toml b/rusk-abi/Cargo.toml index 11ba771e56..0d07e4fe13 100644 --- a/rusk-abi/Cargo.toml +++ b/rusk-abi/Cargo.toml @@ -13,11 +13,6 @@ blake2b_simd = { version = "1", default-features = false } cfg-if = "1" dusk-poseidon = { version = "0.33", default-features = false } -dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } -bls12_381-bls = { version = "0.2", features = ["rkyv-impl"] } -jubjub-schnorr = { version = "0.2", default-features = false, features = ["rkyv-impl"] } -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl"] } -dusk-jubjub = { version = "0.14", default-features = false, features = ["rkyv-impl"] } dusk-bytes = "0.1" bytecheck = { version = "0.6", default-features = false } dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] } @@ -25,6 +20,8 @@ dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-imp piecrust-uplink = { version = "0.11" } piecrust = { version = "0.18", optional = true } +execution-core = { version = "0.1.0", path = "../execution-core" } + # 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/abi.rs b/rusk-abi/src/abi.rs index 46080b2bb8..870220eb2c 100644 --- a/rusk-abi/src/abi.rs +++ b/rusk-abi/src/abi.rs @@ -7,23 +7,24 @@ #[cfg(feature = "abi")] use dusk_bytes::Serializable; #[cfg(feature = "abi")] -use phoenix_core::PublicKey; +use execution_core::{ + BlsPublicKey, BlsScalar, BlsSignature, PublicKey, SchnorrPublicKey, + SchnorrSignature, +}; pub use piecrust_uplink::*; /// Compute the blake2b hash of the given bytes, returning the resulting scalar. /// The output of the hasher is truncated (last nibble) to fit onto a scalar. #[cfg(feature = "abi")] -pub fn hash(bytes: alloc::vec::Vec) -> dusk_bls12_381::BlsScalar { +pub fn hash(bytes: alloc::vec::Vec) -> BlsScalar { use crate::Query; host_query(Query::HASH, bytes) } /// Compute the poseidon hash of the given scalars #[cfg(feature = "abi")] -pub fn poseidon_hash( - scalars: alloc::vec::Vec, -) -> dusk_bls12_381::BlsScalar { +pub fn poseidon_hash(scalars: alloc::vec::Vec) -> BlsScalar { use crate::Query; host_query(Query::POSEIDON_HASH, scalars) } @@ -42,9 +43,9 @@ pub fn verify_proof( /// Verify a schnorr signature is valid for the given public key and message #[cfg(feature = "abi")] pub fn verify_schnorr( - msg: dusk_bls12_381::BlsScalar, - pk: jubjub_schnorr::PublicKey, - sig: jubjub_schnorr::Signature, + msg: BlsScalar, + pk: SchnorrPublicKey, + sig: SchnorrSignature, ) -> bool { use crate::Query; host_query(Query::VERIFY_SCHNORR, (msg, pk, sig)) @@ -54,8 +55,8 @@ pub fn verify_schnorr( #[cfg(feature = "abi")] pub fn verify_bls( msg: alloc::vec::Vec, - pk: bls12_381_bls::PublicKey, - sig: bls12_381_bls::Signature, + pk: BlsPublicKey, + sig: BlsSignature, ) -> bool { use crate::Query; host_query(Query::VERIFY_BLS, (msg, pk, sig)) diff --git a/rusk-abi/src/hash.rs b/rusk-abi/src/hash.rs index c3dc059961..bf2b9db8b3 100644 --- a/rusk-abi/src/hash.rs +++ b/rusk-abi/src/hash.rs @@ -5,8 +5,8 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use blake2b_simd::{Params, State}; -use dusk_bls12_381::BlsScalar; use dusk_bytes::Serializable; +use execution_core::BlsScalar; /// Hashes scalars and arbitrary slices of bytes using Blake2b-256, returning /// a valid [`BlsScalar`]. diff --git a/rusk-abi/src/host.rs b/rusk-abi/src/host.rs index 3b6a356992..d731a6203a 100644 --- a/rusk-abi/src/host.rs +++ b/rusk-abi/src/host.rs @@ -11,13 +11,12 @@ use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use std::sync::{Mutex, MutexGuard, OnceLock}; -use bls12_381_bls::{ - PublicKey as BlsPublicKey, Signature as BlsSignature, APK, -}; -use dusk_bls12_381::BlsScalar; use dusk_bytes::DeserializableSlice; use dusk_plonk::prelude::{Proof, Verifier}; -use jubjub_schnorr::{PublicKey as NotePublicKey, Signature}; +use execution_core::{ + BlsAggPublicKey, BlsPublicKey, BlsScalar, BlsSignature, SchnorrPublicKey, + SchnorrSignature, +}; use lru::LruCache; use rkyv::ser::serializers::AllocSerializer; use rkyv::{Archive, Deserialize, Serialize}; @@ -237,14 +236,14 @@ pub fn verify_proof( /// Verify a schnorr signature is valid for the given public key and message pub fn verify_schnorr( msg: BlsScalar, - pk: NotePublicKey, - sig: Signature, + pk: SchnorrPublicKey, + sig: SchnorrSignature, ) -> bool { pk.verify(&sig, msg) } /// Verify a BLS signature is valid for the given public key and message pub fn verify_bls(msg: Vec, pk: BlsPublicKey, sig: BlsSignature) -> bool { - let apk = APK::from(&pk); + let apk = BlsAggPublicKey::from(&pk); apk.verify(&sig, &msg).is_ok() } diff --git a/rusk-abi/src/lib.rs b/rusk-abi/src/lib.rs index 7d667aff78..32814f37c8 100644 --- a/rusk-abi/src/lib.rs +++ b/rusk-abi/src/lib.rs @@ -39,8 +39,8 @@ pub mod hash; use hash::Hasher; -use dusk_bls12_381::BlsScalar; use dusk_bytes::DeserializableSlice; +use execution_core::BlsScalar; /// Constant depth of the merkle tree that provides the opening proofs. pub const POSEIDON_TREE_DEPTH: usize = 17; diff --git a/rusk-abi/src/types.rs b/rusk-abi/src/types.rs index 58c650ab73..92ba1f9ded 100644 --- a/rusk-abi/src/types.rs +++ b/rusk-abi/src/types.rs @@ -6,9 +6,9 @@ #![allow(dead_code)] -use dusk_bls12_381::BlsScalar; -use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar}; -use phoenix_core::PublicKey; +use execution_core::{ + BlsScalar, JubJubAffine, JubJubExtended, JubJubScalar, PublicKey, +}; use bytecheck::CheckBytes; use rkyv::{Archive, Deserialize, Serialize}; diff --git a/rusk-abi/tests/contracts/host_fn/Cargo.toml b/rusk-abi/tests/contracts/host_fn/Cargo.toml index d43ed2a70e..fec60d940d 100644 --- a/rusk-abi/tests/contracts/host_fn/Cargo.toml +++ b/rusk-abi/tests/contracts/host_fn/Cargo.toml @@ -7,11 +7,7 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] } -bls12_381-bls = { version = "0.2", default-features = false, features = ["rkyv-impl"] } -dusk-jubjub = { version = "0.14", default-features = false, features = ["rkyv-impl"] } -jubjub-schnorr = { version = "0.2", default-features = false, features = ["rkyv-impl"] } -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl"] } +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 = "../../.." } diff --git a/rusk-abi/tests/contracts/host_fn/src/lib.rs b/rusk-abi/tests/contracts/host_fn/src/lib.rs index f4e1254f59..e078f06f26 100644 --- a/rusk-abi/tests/contracts/host_fn/src/lib.rs +++ b/rusk-abi/tests/contracts/host_fn/src/lib.rs @@ -11,13 +11,11 @@ extern crate alloc; use alloc::vec::Vec; -use bls12_381_bls::{PublicKey as BlsPublicKey, Signature as BlsSignature}; -use dusk_bls12_381::BlsScalar; use dusk_bytes::Serializable; -use jubjub_schnorr::{ - PublicKey as SchnorrPublicKey, Signature as SchnorrSignature, +use execution_core::{ + BlsPublicKey, BlsScalar, BlsSignature, PublicKey, SchnorrPublicKey, + SchnorrSignature, }; -use phoenix_core::PublicKey; use rusk_abi::{ContractId, PaymentInfo, PublicInput}; #[no_mangle] diff --git a/rusk-abi/tests/lib.rs b/rusk-abi/tests/lib.rs index 0c37b7a8cc..5f08b87f18 100644 --- a/rusk-abi/tests/lib.rs +++ b/rusk-abi/tests/lib.rs @@ -11,13 +11,13 @@ use std::sync::OnceLock; use rand_core::OsRng; -use bls12_381_bls::{PublicKey as StakePublicKey, SecretKey as StakeSecretKey}; -use dusk_bls12_381::BlsScalar; use dusk_bytes::{ParseHexStr, Serializable}; use dusk_plonk::prelude::*; +use execution_core::{ + BlsScalar, NotePublicKey, NoteSecretKey, PublicKey, SecretKey, + StakePublicKey, StakeSecretKey, +}; use ff::Field; -use jubjub_schnorr::{PublicKey as NotePublicKey, SecretKey as NoteSecretKey}; -use phoenix_core::{PublicKey, SecretKey}; use rusk_abi::hash::Hasher; use rusk_abi::PublicInput; use rusk_abi::{ContractData, ContractId, Session, VM}; diff --git a/rusk-prover/Cargo.toml b/rusk-prover/Cargo.toml index 2aa9b6dcad..1c7b8ff6b1 100644 --- a/rusk-prover/Cargo.toml +++ b/rusk-prover/Cargo.toml @@ -12,11 +12,10 @@ dusk-wallet-core = { version = "0.25.0-phoenix.0.26", default-features = false } ## feature local_prover once_cell = { version = "1.9", optional = true } dusk-plonk = { version = "0.19", optional = true } -phoenix-core = { version = "0.26", features = ["alloc"], optional = true } -jubjub-schnorr = { version = "0.2", optional = true } rand = { version = "0.8", optional = true } rusk-profile = { version = "0.6", path = "../rusk-profile", optional = true } transfer-circuits = { version = "0.5", path = "../circuits/transfer", optional = true } +execution-core = { version = "0.1.0", path = "../execution-core", optional = true } [dev-dependencies] hex = "0.4" @@ -27,10 +26,9 @@ default = ["local_prover"] local_prover = [ "once_cell", "dusk-plonk", - "phoenix-core", - "jubjub-schnorr", "rand", "rusk-profile", "transfer-circuits", + "execution-core", ] no_random = [] diff --git a/rusk-prover/src/prover.rs b/rusk-prover/src/prover.rs index 6df33a66db..ec23d9556a 100644 --- a/rusk-prover/src/prover.rs +++ b/rusk-prover/src/prover.rs @@ -21,8 +21,7 @@ use rand::rngs::OsRng; use rand::{rngs::StdRng, SeedableRng}; use dusk_plonk::prelude::*; -use jubjub_schnorr::Signature; -use phoenix_core::{Crossover, Fee}; +use execution_core::{Crossover, Fee, SchnorrSignature}; use transfer_circuits::{ CircuitInput, CircuitInputSignature, ExecuteCircuit, diff --git a/rusk-prover/src/prover/execute.rs b/rusk-prover/src/prover/execute.rs index cf93c22e8e..e42eacb8c4 100644 --- a/rusk-prover/src/prover/execute.rs +++ b/rusk-prover/src/prover/execute.rs @@ -7,7 +7,7 @@ use super::*; use crate::prover::fetch_prover; use dusk_wallet_core::UnprovenTransaction; -use phoenix_core::transaction::TRANSFER_TREE_DEPTH; +use execution_core::transfer::TRANSFER_TREE_DEPTH; use rand::{CryptoRng, RngCore}; use transfer_circuits::{ ExecuteCircuitFourTwo, ExecuteCircuitOneTwo, ExecuteCircuitThreeTwo, diff --git a/rusk-prover/src/prover/stct.rs b/rusk-prover/src/prover/stct.rs index 5f7eb93680..8c5ed8b262 100644 --- a/rusk-prover/src/prover/stct.rs +++ b/rusk-prover/src/prover/stct.rs @@ -12,7 +12,7 @@ pub const STCT_INPUT_LEN: usize = Fee::SIZE + u64::SIZE + JubJubScalar::SIZE + BlsScalar::SIZE - + Signature::SIZE; + + SchnorrSignature::SIZE; pub static STCT_PROVER: Lazy = Lazy::new(|| fetch_prover("SendToContractTransparentCircuit")); @@ -42,7 +42,7 @@ impl LocalProver { .map_err(|e| ProverError::invalid_data("crossover_blinder", e))?; let contract_address = BlsScalar::from_reader(&mut reader) .map_err(|e| ProverError::invalid_data("contract_address", e))?; - let signature = Signature::from_reader(&mut reader) + let signature = SchnorrSignature::from_reader(&mut reader) .map_err(|e| ProverError::invalid_data("signature", e))?; let circ = SendToContractTransparentCircuit::new( diff --git a/rusk-recovery/Cargo.toml b/rusk-recovery/Cargo.toml index 1d0ed68a4b..4f343ee311 100644 --- a/rusk-recovery/Cargo.toml +++ b/rusk-recovery/Cargo.toml @@ -11,20 +11,11 @@ path = "src/lib.rs" [dependencies] -hex = "0.4" +dusk-bytes = "0.1" dusk-plonk = { version = "0.19", features = ["rkyv-impl"] } -phoenix-core ="0.26" -stake-contract-types = { version = "0.1.0-rc", path = "../contracts/stake-types", default-features = false } -transfer-contract-types = { version = "0.1.0", path = "../contracts/transfer-types", default-features = false } +hex = "0.4" rand = "0.8" -rusk-profile = { version = "0.6", path = "../rusk-profile" } -rusk-abi = { version = "0.13.0-rc", path = "../rusk-abi", default-features = false, features = ["host"] } once_cell = "1.13" -dusk-bytes = "0.1" -dusk-jubjub = { version = "0.14", default-features = false } -jubjub-schnorr = "0.2" -dusk-bls12_381 = { version = "0.13", default-features = false } -bls12_381-bls = "0.2" ff = { version = "0.13", default-features = false } tracing = { version = "0.1", features = ["log"] } http_req = "0.8" @@ -33,11 +24,14 @@ url = "2.3" flate2 = "1" tar = "0.4" +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" } + serde_derive = { version = "1", optional = true } serde = { version = "1", optional = true } toml = { version = "0.5", optional = true } bs58 = { version = "0.4", optional = true } -tempfile = "3.3" [features] state = ["serde_derive", "serde", "toml", "bs58"] diff --git a/rusk-recovery/src/state.rs b/rusk-recovery/src/state.rs index bb2e5a69dc..5449cb902d 100644 --- a/rusk-recovery/src/state.rs +++ b/rusk-recovery/src/state.rs @@ -4,27 +4,26 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::Theme; +use std::error::Error; +use std::fs; +use std::path::Path; -use dusk_bls12_381::BlsScalar; use dusk_bytes::DeserializableSlice; -use dusk_jubjub::JubJubScalar; use ff::Field; use once_cell::sync::Lazy; -use phoenix_core::PublicKey; use rand::rngs::StdRng; use rand::SeedableRng; -use rusk_abi::{ContractData, ContractId, Session, VM}; -use rusk_abi::{LICENSE_CONTRACT, STAKE_CONTRACT, TRANSFER_CONTRACT}; -use std::error::Error; -use std::fs; -use std::path::Path; use tracing::info; use url::Url; +use execution_core::{ + stake::StakeData, transfer::Mint, BlsScalar, JubJubScalar, PublicKey, +}; +use rusk_abi::{ContractData, ContractId, Session, VM}; +use rusk_abi::{LICENSE_CONTRACT, STAKE_CONTRACT, TRANSFER_CONTRACT}; + +use crate::Theme; pub use snapshot::{Balance, GenesisStake, Snapshot}; -use stake_contract_types::StakeData; -use transfer_contract_types::Mint; mod http; mod snapshot; diff --git a/rusk-recovery/src/state/snapshot.rs b/rusk-recovery/src/state/snapshot.rs index ab1388c13e..14fb4050f1 100644 --- a/rusk-recovery/src/state/snapshot.rs +++ b/rusk-recovery/src/state/snapshot.rs @@ -7,7 +7,7 @@ use std::fmt::Debug; use dusk_bytes::Serializable; -use phoenix_core::PublicKey; +use execution_core::PublicKey; use rusk_abi::dusk::Dusk; use serde_derive::{Deserialize, Serialize}; diff --git a/rusk-recovery/src/state/snapshot/stake.rs b/rusk-recovery/src/state/snapshot/stake.rs index 336e374223..3ffb4f67d8 100644 --- a/rusk-recovery/src/state/snapshot/stake.rs +++ b/rusk-recovery/src/state/snapshot/stake.rs @@ -4,23 +4,24 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use bls12_381_bls::PublicKey as BlsPublicKey; use dusk_bytes::Serializable; -use rusk_abi::dusk::Dusk; use serde_derive::{Deserialize, Serialize}; +use execution_core::StakePublicKey; +use rusk_abi::dusk::Dusk; + use super::wrapper::Wrapper; #[derive(Serialize, Deserialize, PartialEq, Eq)] pub struct GenesisStake { - pub(crate) address: Wrapper, + pub(crate) address: Wrapper, pub amount: Dusk, pub eligibility: Option, pub reward: Option, } impl GenesisStake { - pub fn address(&self) -> &BlsPublicKey { + pub fn address(&self) -> &StakePublicKey { &self.address } } diff --git a/rusk/Cargo.toml b/rusk/Cargo.toml index f6ab262b2e..068e02dba0 100644 --- a/rusk/Cargo.toml +++ b/rusk/Cargo.toml @@ -39,18 +39,13 @@ rkyv = { version = "0.7", default-features = false, features = ["size_32"] } bytecheck = { version = "0.6", default-features = false } dirs = "4" -jubjub-schnorr = "0.2" dusk-poseidon = "0.33" poseidon-merkle = { version = "0.5", features = ["rkyv-impl", "size_32"] } sha3 = "0.10" dusk-plonk = "0.19" -dusk-bls12_381 = "0.13" -bls12_381-bls = "0.2" -dusk-jubjub = "0.14" dusk-bytes = "0.1" kadcast = "0.6.0-rc" dusk-wallet-core = "0.25.0-phoenix.0.26" -phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] } pin-project = "1" tungstenite = "0.21" hyper-tungstenite = "0.13" @@ -64,7 +59,7 @@ tokio-rustls = "0.25" rustls-pemfile = "2" async-trait = "0.1" - +execution-core = { version = "0.1.0", path = "../execution-core" } transfer-circuits = { version = "0.5", path = "../circuits/transfer" } rusk-profile = { version = "0.6", path = "../rusk-profile" } rusk-abi = { version = "0.13.0-rc", path = "../rusk-abi", default-features = false, features = ["host"] } diff --git a/rusk/benches/block_ingestion.rs b/rusk/benches/block_ingestion.rs index deb7c35a1f..0836ca42b5 100644 --- a/rusk/benches/block_ingestion.rs +++ b/rusk/benches/block_ingestion.rs @@ -13,13 +13,14 @@ use std::io::{BufRead, BufReader}; use std::sync::Arc; use std::time::Duration; -use bls12_381_bls::{PublicKey as StakePublicKey, SecretKey as StakeSecretKey}; use criterion::measurement::WallTime; use criterion::{ criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, }; +use execution_core::{ + StakePublicKey, StakeSecretKey, Transaction as PhoenixTransaction, +}; use node_data::ledger::Transaction; -use phoenix_core::Transaction as PhoenixTransaction; use rand::prelude::StdRng; use rand::SeedableRng; use tempfile::tempdir; diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 8686e5d1f1..69523823dd 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -14,13 +14,13 @@ use sha3::{Digest, Sha3_256}; use tokio::task; use tracing::{debug, info, warn}; -use bls12_381_bls::PublicKey as StakePublicKey; -use dusk_bls12_381::BlsScalar; use dusk_bytes::DeserializableSlice; use dusk_consensus::operations::{CallParams, VerificationOutput}; +use execution_core::{ + stake::StakeData, BlsScalar, StakePublicKey, + Transaction as PhoenixTransaction, +}; use node_data::ledger::{SpentTransaction, Transaction}; -use phoenix_core::transaction::StakeData; -use phoenix_core::Transaction as PhoenixTransaction; use rusk_abi::dusk::Dusk; use rusk_abi::{ CallReceipt, ContractError, Error as PiecrustError, Event, Session, diff --git a/rusk/src/lib/chain/vm.rs b/rusk/src/lib/chain/vm.rs index ea548ceb16..486fa8d0d9 100644 --- a/rusk/src/lib/chain/vm.rs +++ b/rusk/src/lib/chain/vm.rs @@ -6,13 +6,13 @@ mod query; -use phoenix_core::transaction::StakeData; use tracing::info; use dusk_bytes::DeserializableSlice; use dusk_consensus::operations::{CallParams, VerificationOutput}; use dusk_consensus::user::provisioners::Provisioners; use dusk_consensus::user::stake::Stake; +use execution_core::{stake::StakeData, StakePublicKey}; use node::vm::VMExecution; use node_data::ledger::{Block, SpentTransaction, Transaction}; @@ -44,7 +44,7 @@ impl VMExecution for Rusk { ) -> anyhow::Result { info!("Received verify_state_transition request"); let generator = blk.header().generator_bls_pubkey; - let generator = bls12_381_bls::PublicKey::from_slice(&generator.0) + let generator = StakePublicKey::from_slice(&generator.0) .map_err(|e| anyhow::anyhow!("Error in from_slice {e:?}"))?; let (_, verification_output) = self @@ -66,7 +66,7 @@ impl VMExecution for Rusk { ) -> anyhow::Result<(Vec, VerificationOutput)> { info!("Received accept request"); let generator = blk.header().generator_bls_pubkey; - let generator = bls12_381_bls::PublicKey::from_slice(&generator.0) + let generator = StakePublicKey::from_slice(&generator.0) .map_err(|e| anyhow::anyhow!("Error in from_slice {e:?}"))?; let (txs, verification_output) = self @@ -126,7 +126,7 @@ impl VMExecution for Rusk { fn get_provisioner( &self, - pk: &bls12_381_bls::PublicKey, + pk: &StakePublicKey, ) -> anyhow::Result> { let stake = self .provisioner(pk) diff --git a/rusk/src/lib/error.rs b/rusk/src/lib/error.rs index 5fb7fafb87..c1cd3fb7cd 100644 --- a/rusk/src/lib/error.rs +++ b/rusk/src/lib/error.rs @@ -6,7 +6,8 @@ use std::{fmt, io}; -use dusk_bls12_381::BlsScalar; +use execution_core::BlsScalar; +use execution_core::PhoenixError; use rusk_abi::dusk::Dusk; #[derive(Debug)] @@ -32,7 +33,7 @@ pub enum Error { /// Bytes Serialization Errors Serialization(dusk_bytes::Error), /// Originating from Phoenix. - Phoenix(phoenix_core::Error), + Phoenix(PhoenixError), /// Piecrust VM internal Errors Vm(rusk_abi::Error), /// IO Errors @@ -80,8 +81,8 @@ impl From for Error { } } -impl From for Error { - fn from(pe: phoenix_core::Error) -> Self { +impl From for Error { + fn from(pe: PhoenixError) -> Self { Self::Phoenix(pe) } } diff --git a/rusk/src/lib/http/chain.rs b/rusk/src/lib/http/chain.rs index 57af84f97d..8814e26798 100644 --- a/rusk/src/lib/http/chain.rs +++ b/rusk/src/lib/http/chain.rs @@ -107,7 +107,7 @@ impl RuskNode { } async fn propagate_tx(&self, tx: &[u8]) -> anyhow::Result { - let tx = phoenix_core::Transaction::from_slice(tx) + let tx = execution_core::Transaction::from_slice(tx) .map_err(|e| anyhow::anyhow!("Invalid Data {e:?}"))? .into(); let tx_message = Message::new_transaction(tx); diff --git a/rusk/src/lib/http/chain/graphql/data.rs b/rusk/src/lib/http/chain/graphql/data.rs index 70612afaa1..c4857a22fe 100644 --- a/rusk/src/lib/http/chain/graphql/data.rs +++ b/rusk/src/lib/http/chain/graphql/data.rs @@ -241,7 +241,7 @@ impl Transaction<'_> { pub async fn json(&self) -> String { use dusk_bytes::Serializable; - use phoenix_core::Ownable; + use execution_core::Ownable; use serde::Serialize; use serde_json::{json, Map, Value}; diff --git a/rusk/src/lib/http/rusk.rs b/rusk/src/lib/http/rusk.rs index 3551b1f74b..6f2f44188f 100644 --- a/rusk/src/lib/http/rusk.rs +++ b/rusk/src/lib/http/rusk.rs @@ -86,7 +86,7 @@ impl Rusk { } fn handle_preverify(&self, data: &[u8]) -> anyhow::Result { - let tx = phoenix_core::Transaction::from_slice(data) + let tx = execution_core::Transaction::from_slice(data) .map_err(|e| anyhow::anyhow!("Invalid Data {e:?}"))?; self.preverify(&tx.into())?; Ok(ResponseData::new(DataType::None)) diff --git a/rusk/src/lib/test_utils.rs b/rusk/src/lib/test_utils.rs index e352bdc51e..e4e74a3fd7 100644 --- a/rusk/src/lib/test_utils.rs +++ b/rusk/src/lib/test_utils.rs @@ -16,11 +16,12 @@ use futures::Stream; use tokio::spawn; use tracing::{error, info}; -use bls12_381_bls::PublicKey as BlsPublicKey; -use dusk_bls12_381::BlsScalar; +use execution_core::stake::StakeData; +use execution_core::transfer::{TreeLeaf, TRANSFER_TREE_DEPTH}; +use execution_core::{ + BlsPublicKey, BlsScalar, Message, Note, PublicKey, ViewKey, +}; use parking_lot::RwLockWriteGuard; -use phoenix_core::transaction::{StakeData, TreeLeaf, TRANSFER_TREE_DEPTH}; -use phoenix_core::{Message, Note, PublicKey, ViewKey}; use poseidon_merkle::Opening as PoseidonOpening; use rusk_abi::{ContractId, STAKE_CONTRACT, TRANSFER_CONTRACT, VM}; diff --git a/rusk/tests/common/keys.rs b/rusk/tests/common/keys.rs index 82665e7039..15374b6c46 100644 --- a/rusk/tests/common/keys.rs +++ b/rusk/tests/common/keys.rs @@ -10,7 +10,7 @@ use rand::prelude::*; use rand::rngs::StdRng; use tracing::info; -use bls12_381_bls::SecretKey as StakeSecretKey; +use execution_core::StakeSecretKey; pub static STAKE_SK: LazyLock = LazyLock::new(|| { info!("Generating StakeSecretKey"); diff --git a/rusk/tests/common/state.rs b/rusk/tests/common/state.rs index b4c13025db..691e344c9c 100644 --- a/rusk/tests/common/state.rs +++ b/rusk/tests/common/state.rs @@ -12,9 +12,9 @@ use node::vm::VMExecution; use rusk::{Result, Rusk}; use rusk_recovery_tools::state::{self, Snapshot}; -use bls12_381_bls::PublicKey as StakePublicKey; use dusk_consensus::operations::CallParams; use dusk_wallet_core::Transaction as PhoenixTransaction; +use execution_core::StakePublicKey; use node_data::{ bls::PublicKeyBytes, ledger::{Block, Certificate, Header, IterationsInfo, SpentTransaction}, diff --git a/rusk/tests/common/wallet.rs b/rusk/tests/common/wallet.rs index 4bacb88fde..ba8cf4f2fd 100644 --- a/rusk/tests/common/wallet.rs +++ b/rusk/tests/common/wallet.rs @@ -10,19 +10,19 @@ use std::io::Write; use std::sync::{Arc, RwLock}; use crate::common::block::Block as BlockAwait; -use bls12_381_bls::PublicKey as BlsPublicKey; -use dusk_bls12_381::BlsScalar; + use dusk_bytes::{DeserializableSlice, Serializable}; -use dusk_jubjub::{JubJubAffine, JubJubScalar}; use dusk_plonk::prelude::Proof; use dusk_wallet_core::{ self as wallet, StakeInfo, Store, Transaction as PhoenixTransaction, UnprovenTransaction, }; +use execution_core::transfer::TRANSFER_TREE_DEPTH; +use execution_core::{ + BlsPublicKey, BlsScalar, Crossover, Fee, JubJubAffine, JubJubScalar, Note, + NoteSignature, ViewKey, +}; use futures::StreamExt; -use jubjub_schnorr::Signature; -use phoenix_core::transaction::TRANSFER_TREE_DEPTH; -use phoenix_core::{Crossover, Fee, Note, ViewKey}; use poseidon_merkle::Opening as PoseidonOpening; use rusk::{Error, Result, Rusk}; use rusk_prover::prover::{A, STCT_INPUT_LEN, WFCT_INPUT_LEN}; @@ -162,7 +162,7 @@ impl wallet::ProverClient for TestProverClient { value: u64, blinder: JubJubScalar, address: BlsScalar, - signature: Signature, + signature: NoteSignature, ) -> Result { let mut buf = [0u8; STCT_INPUT_LEN]; let mut writer = &mut buf[..]; diff --git a/rusk/tests/rusk-state.rs b/rusk/tests/rusk-state.rs index 1b8a730f76..b0372b0161 100644 --- a/rusk/tests/rusk-state.rs +++ b/rusk/tests/rusk-state.rs @@ -10,15 +10,15 @@ pub mod common; use crate::common::*; use std::collections::HashMap; -use dusk_bls12_381::BlsScalar; use std::path::Path; use std::sync::{mpsc, Arc, RwLock}; use dusk_wallet_core::{self as wallet}; +use execution_core::{ + transfer::TreeLeaf, BlsScalar, Note, PublicKey, SecretKey, +}; use ff::Field; use parking_lot::RwLockWriteGuard; -use phoenix_core::transaction::TreeLeaf; -use phoenix_core::{Note, PublicKey, SecretKey}; use rand::prelude::*; use rand::rngs::StdRng; use rusk::chain::{Rusk, RuskTip}; diff --git a/rusk/tests/services/multi_transfer.rs b/rusk/tests/services/multi_transfer.rs index c75678b1f7..1569597fc3 100644 --- a/rusk/tests/services/multi_transfer.rs +++ b/rusk/tests/services/multi_transfer.rs @@ -8,10 +8,9 @@ use std::collections::HashMap; use std::path::Path; use std::sync::{Arc, LazyLock, RwLock}; -use dusk_bls12_381::BlsScalar; use dusk_wallet_core::{self as wallet, Store}; +use execution_core::{BlsScalar, PublicKey, SecretKey}; use ff::Field; -use phoenix_core::{PublicKey, SecretKey}; use rand::prelude::*; use rand::rngs::StdRng; use rusk::{Result, Rusk}; diff --git a/rusk/tests/services/stake.rs b/rusk/tests/services/stake.rs index 80d2e83e85..2573e98e74 100644 --- a/rusk/tests/services/stake.rs +++ b/rusk/tests/services/stake.rs @@ -7,9 +7,8 @@ use std::path::Path; use std::sync::{Arc, LazyLock, RwLock}; -use bls12_381_bls::PublicKey as StakePublicKey; use dusk_wallet_core::{self as wallet, Store}; -use phoenix_core::{PublicKey, SecretKey}; +use execution_core::{PublicKey, SecretKey, StakePublicKey}; use rand::prelude::*; use rand::rngs::StdRng; use rusk::chain::MINIMUM_STAKE; diff --git a/rusk/tests/services/transfer.rs b/rusk/tests/services/transfer.rs index 16091eddcd..f1a69b9207 100644 --- a/rusk/tests/services/transfer.rs +++ b/rusk/tests/services/transfer.rs @@ -8,11 +8,10 @@ use std::collections::HashMap; use std::path::Path; use std::sync::{Arc, LazyLock, RwLock}; -use dusk_bls12_381::BlsScalar; use dusk_wallet_core::{self as wallet, Store}; +use execution_core::{BlsScalar, PublicKey, SecretKey}; use ff::Field; use node_data::ledger::SpentTransaction; -use phoenix_core::{PublicKey, SecretKey}; use rand::prelude::*; use rand::rngs::StdRng; use rusk::{Result, Rusk};