diff --git a/rusk/benches/block_ingestion.rs b/rusk/benches/block_ingestion.rs index eb70cabf57..84962d803c 100644 --- a/rusk/benches/block_ingestion.rs +++ b/rusk/benches/block_ingestion.rs @@ -17,7 +17,8 @@ use criterion::{ criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, }; use execution_core::{ - transfer::Transaction as ProtocolTransaction, BlsPublicKey, BlsSecretKey, + signatures::bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey}, + transfer::Transaction as ProtocolTransaction, }; use node_data::ledger::Transaction; use rand::prelude::StdRng; diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 4aee486fd2..32cfcc2de3 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -21,12 +21,15 @@ use dusk_consensus::config::{ RATIFICATION_COMMITTEE_CREDITS, VALIDATION_COMMITTEE_CREDITS, }; use dusk_consensus::operations::{CallParams, VerificationOutput, Voter}; -use execution_core::transfer::ContractDeploy; use execution_core::{ - stake::StakeData, - transfer::{AccountData, Transaction as ProtocolTransaction}, - BlsPublicKey, BlsScalar, ContractBytecode, ContractError, Dusk, Event, - STAKE_CONTRACT, TRANSFER_CONTRACT, + signatures::bls::PublicKey as BlsPublicKey, + stake::{StakeData, STAKE_CONTRACT}, + transfer::{ + contract_exec::{ContractBytecode, ContractDeploy}, + moonlight::AccountData, + Transaction as ProtocolTransaction, TRANSFER_CONTRACT, + }, + BlsScalar, ContractError, Dusk, Event, }; use node_data::ledger::{Slash, SpentTransaction, Transaction}; use rusk_abi::{CallReceipt, PiecrustError, Session, VM}; diff --git a/rusk/src/lib/chain/vm.rs b/rusk/src/lib/chain/vm.rs index 9714ca0cdf..d0f8e8139a 100644 --- a/rusk/src/lib/chain/vm.rs +++ b/rusk/src/lib/chain/vm.rs @@ -13,8 +13,8 @@ use dusk_consensus::operations::{CallParams, VerificationOutput, Voter}; use dusk_consensus::user::provisioners::Provisioners; use dusk_consensus::user::stake::Stake; use execution_core::{ - stake::StakeData, transfer::Transaction as ProtocolTransaction, - BlsPublicKey, + signatures::bls::PublicKey as BlsPublicKey, stake::StakeData, + transfer::Transaction as ProtocolTransaction, }; use node::vm::VMExecution; use node_data::ledger::{Block, Slash, SpentTransaction, Transaction}; diff --git a/rusk/src/lib/error.rs b/rusk/src/lib/error.rs index 653fed10ab..57777deda0 100644 --- a/rusk/src/lib/error.rs +++ b/rusk/src/lib/error.rs @@ -7,7 +7,10 @@ use std::{fmt, io}; use dusk_bytes::Serializable; -use execution_core::{BlsPublicKey, BlsScalar, Dusk, PhoenixError}; +use execution_core::{ + signatures::bls::PublicKey as BlsPublicKey, + transfer::phoenix::Error as PhoenixError, BlsScalar, Dusk, +}; use rusk_abi::PiecrustError; #[derive(Debug)] diff --git a/rusk/src/lib/gen_id.rs b/rusk/src/lib/gen_id.rs index bb7f2d6389..82c52fa445 100644 --- a/rusk/src/lib/gen_id.rs +++ b/rusk/src/lib/gen_id.rs @@ -4,8 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::hash::Hasher; -use rusk_abi::ContractId; +use blake2b_simd::Params; +use execution_core::{ContractId, CONTRACT_ID_BYTES}; /// Generate a [`ContractId`] address from: /// - slice of bytes, @@ -16,11 +16,15 @@ pub fn gen_contract_id( nonce: u64, owner: impl AsRef<[u8]>, ) -> ContractId { - let mut hasher = Hasher::new(); + let mut hasher = Params::new().hash_length(CONTRACT_ID_BYTES).to_state(); hasher.update(bytes.as_ref()); - hasher.update(nonce.to_le_bytes()); + hasher.update(&nonce.to_le_bytes()[..]); hasher.update(owner.as_ref()); - let hash_bytes = hasher.finalize(); + let hash_bytes: [u8; CONTRACT_ID_BYTES] = hasher + .finalize() + .as_bytes() + .try_into() + .expect("the hash result is exactly `CONTRACT_ID_BYTES` long"); ContractId::from_bytes(hash_bytes) } @@ -47,7 +51,7 @@ mod tests { assert_eq!( hex::encode(contract_id.as_bytes()), - "a138d3b9c87235dac6f62d1d30b75cffbb94601d9cbe5bd540b3e1e5842c8a7d" + "2da8b6277789a88c7215789e227ef4dd97486db252e554805c7b874a17e07785" ); } } diff --git a/rusk/src/lib/hash.rs b/rusk/src/lib/hash.rs deleted file mode 100644 index 523baf6e9b..0000000000 --- a/rusk/src/lib/hash.rs +++ /dev/null @@ -1,44 +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. - -use blake2b_simd::{Params, State}; - -/// Hashes scalars and arbitrary slices of bytes using Blake2b, returning an -/// array of 32 bytes. -/// -/// This hash cannot be proven inside a circuit, if that is desired, use -/// `poseidon_hash` instead. -pub struct Hasher { - state: State, -} - -impl Default for Hasher { - fn default() -> Self { - Hasher { - state: Params::new().hash_length(64).to_state(), - } - } -} - -impl Hasher { - /// Create new hasher instance. - pub fn new() -> Self { - Self::default() - } - - /// Process data, updating the internal state. - pub fn update(&mut self, data: impl AsRef<[u8]>) { - self.state.update(data.as_ref()); - } - - /// Retrieve result and consume hasher instance. - pub fn finalize(self) -> [u8; 32] { - let hash = self.state.finalize(); - let mut a = [0u8; 32]; - a.clone_from_slice(&hash.as_array()[..32]); - a - } -} diff --git a/rusk/src/lib/http/chain/graphql.rs b/rusk/src/lib/http/chain/graphql.rs index 735ece0655..ed664150de 100644 --- a/rusk/src/lib/http/chain/graphql.rs +++ b/rusk/src/lib/http/chain/graphql.rs @@ -13,7 +13,7 @@ use data::*; use tx::*; use async_graphql::{Context, FieldError, FieldResult, Object}; -use execution_core::{ContractId, TRANSFER_CONTRACT}; +use execution_core::{transfer::TRANSFER_CONTRACT, ContractId}; use node::database::rocksdb::Backend; use node::database::{Ledger, DB}; diff --git a/rusk/src/lib/lib.rs b/rusk/src/lib/lib.rs index a9cdd23505..3cce7b8230 100644 --- a/rusk/src/lib/lib.rs +++ b/rusk/src/lib/lib.rs @@ -10,7 +10,6 @@ pub mod chain; mod error; pub mod gen_id; -mod hash; pub mod http; pub mod verifier; mod version; diff --git a/rusk/src/lib/test_utils.rs b/rusk/src/lib/test_utils.rs index b5c343dc41..5427b50dfd 100644 --- a/rusk/src/lib/test_utils.rs +++ b/rusk/src/lib/test_utils.rs @@ -16,11 +16,14 @@ use futures::Stream; use tokio::spawn; use tracing::{error, info}; -use execution_core::stake::StakeData; -use execution_core::transfer::{TreeLeaf, TRANSFER_TREE_DEPTH}; use execution_core::{ - BlsPublicKey, BlsScalar, ContractId, Note, ViewKey, STAKE_CONTRACT, - TRANSFER_CONTRACT, + signatures::bls::PublicKey as BlsPublicKey, + stake::{StakeData, STAKE_CONTRACT}, + transfer::{ + phoenix::{Note, TreeLeaf, ViewKey, NOTES_TREE_DEPTH}, + TRANSFER_CONTRACT, + }, + BlsScalar, ContractId, }; use parking_lot::RwLockWriteGuard; use poseidon_merkle::Opening as PoseidonOpening; @@ -62,7 +65,7 @@ impl Rusk { pub fn tree_opening( &self, pos: u64, - ) -> Result>> { + ) -> Result>> { self.query(TRANSFER_CONTRACT, "opening", &pos) } diff --git a/rusk/src/lib/verifier.rs b/rusk/src/lib/verifier.rs index 107a57ce36..accca6f4a9 100644 --- a/rusk/src/lib/verifier.rs +++ b/rusk/src/lib/verifier.rs @@ -9,7 +9,10 @@ use crate::error::Error; use crate::Result; -use execution_core::transfer::{MoonlightTransaction, PhoenixTransaction}; +use execution_core::transfer::{ + moonlight::Transaction as MoonlightTransaction, + phoenix::Transaction as PhoenixTransaction, +}; use rusk_profile::Circuit as CircuitProfile; use std::sync::LazyLock; diff --git a/rusk/tests/common/keys.rs b/rusk/tests/common/keys.rs index 73c92e9756..7815d79885 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 execution_core::BlsSecretKey; +use execution_core::signatures::bls::SecretKey as BlsSecretKey; #[allow(dead_code)] pub static STAKE_SK: LazyLock = LazyLock::new(|| { diff --git a/rusk/tests/common/state.rs b/rusk/tests/common/state.rs index ed4b4ef1b7..e4c3965c2a 100644 --- a/rusk/tests/common/state.rs +++ b/rusk/tests/common/state.rs @@ -13,7 +13,9 @@ use rusk::{Result, Rusk}; use rusk_recovery_tools::state::{self, Snapshot}; use dusk_consensus::operations::CallParams; -use execution_core::{transfer::Transaction, BlsPublicKey}; +use execution_core::{ + signatures::bls::PublicKey as BlsPublicKey, transfer::Transaction, +}; use node_data::{ bls::PublicKeyBytes, ledger::{ diff --git a/rusk/tests/common/wallet.rs b/rusk/tests/common/wallet.rs index f5b74c80f5..bd7ad2b9fd 100644 --- a/rusk/tests/common/wallet.rs +++ b/rusk/tests/common/wallet.rs @@ -13,9 +13,14 @@ use crate::common::block::Block as BlockAwait; use dusk_bytes::{DeserializableSlice, Serializable}; use dusk_plonk::prelude::Proof; use execution_core::{ + signatures::bls::PublicKey as BlsPublicKey, stake::StakeData, - transfer::{AccountData, Transaction, TRANSFER_TREE_DEPTH}, - BlsPublicKey, BlsScalar, Note, ViewKey, + transfer::{ + moonlight::AccountData, + phoenix::{Note, ViewKey, NOTES_TREE_DEPTH}, + Transaction, + }, + BlsScalar, }; use futures::StreamExt; use poseidon_merkle::Opening as PoseidonOpening; @@ -101,7 +106,7 @@ impl wallet::StateClient for TestStateClient { fn fetch_opening( &self, note: &Note, - ) -> Result, Self::Error> { + ) -> Result, Self::Error> { self.rusk .tree_opening(*note.pos())? .ok_or(Error::OpeningPositionNotFound(*note.pos())) diff --git a/rusk/tests/rusk-state.rs b/rusk/tests/rusk-state.rs index b46dbe8433..da44e88756 100644 --- a/rusk/tests/rusk-state.rs +++ b/rusk/tests/rusk-state.rs @@ -13,8 +13,14 @@ use std::path::Path; use std::sync::{mpsc, Arc}; use execution_core::{ - transfer::TreeLeaf, JubJubScalar, Note, PublicKey, SecretKey, LUX, - TRANSFER_CONTRACT, + transfer::{ + phoenix::{ + Note, PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey, + TreeLeaf, + }, + TRANSFER_CONTRACT, + }, + JubJubScalar, LUX, }; use ff::Field; use parking_lot::RwLockWriteGuard; @@ -55,9 +61,10 @@ where info!("Generating a note"); let mut rng = StdRng::seed_from_u64(0xdead); - let sender_sk = SecretKey::random(&mut rng); - let sender_pk = PublicKey::from(&sender_sk); - let receiver_pk = PublicKey::from(&SecretKey::random(&mut rng)); + let sender_sk = PhoenixSecretKey::random(&mut rng); + let sender_pk = PhoenixPublicKey::from(&sender_sk); + let receiver_pk = + PhoenixPublicKey::from(&PhoenixSecretKey::random(&mut rng)); let sender_blinder = [ JubJubScalar::random(&mut rng), diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index 8535fe82ec..4cbf3b6035 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -9,8 +9,8 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; use execution_core::{ - transfer::{ContractDeploy, ContractExec}, - ContractBytecode, ContractId, + transfer::contract_exec::{ContractBytecode, ContractDeploy, ContractExec}, + ContractId, }; use rand::prelude::*; use rand::rngs::StdRng; @@ -88,7 +88,7 @@ fn initial_state>(dir: P, deploy_bob: bool) -> Result { )), POINT_LIMIT, ) - .expect("Deploying the alice contract should succeed"); + .expect("Deploying the bob contract should succeed"); } }) .expect("Deploying initial state should succeed"); diff --git a/rusk/tests/services/gas_behavior.rs b/rusk/tests/services/gas_behavior.rs index b856714184..31a0e3678d 100644 --- a/rusk/tests/services/gas_behavior.rs +++ b/rusk/tests/services/gas_behavior.rs @@ -8,8 +8,10 @@ use std::collections::HashMap; use std::path::Path; use std::sync::{Arc, RwLock}; -use execution_core::transfer::{ContractCall, ContractExec}; -use execution_core::TRANSFER_CONTRACT; +use execution_core::transfer::{ + contract_exec::{ContractCall, ContractExec}, + TRANSFER_CONTRACT, +}; 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 42e4301d64..7151dd760f 100644 --- a/rusk/tests/services/stake.rs +++ b/rusk/tests/services/stake.rs @@ -8,8 +8,10 @@ use std::path::Path; use std::sync::{Arc, RwLock}; use execution_core::{ - dusk, stake::StakeAmount, transfer::ContractCall, BlsPublicKey, - STAKE_CONTRACT, + dusk, + signatures::bls::PublicKey as BlsPublicKey, + stake::{StakeAmount, STAKE_CONTRACT}, + transfer::contract_exec::ContractCall, }; use rand::prelude::*; use rand::rngs::StdRng; diff --git a/rusk/tests/services/unspendable.rs b/rusk/tests/services/unspendable.rs index 88cd3d626a..8ffeebe6b6 100644 --- a/rusk/tests/services/unspendable.rs +++ b/rusk/tests/services/unspendable.rs @@ -8,8 +8,8 @@ use std::collections::HashMap; use std::path::Path; use std::sync::{Arc, RwLock}; -use execution_core::{ - transfer::{ContractCall, ContractExec}, +use execution_core::transfer::{ + contract_exec::{ContractCall, ContractExec}, TRANSFER_CONTRACT, }; use rand::prelude::*;