diff --git a/Cargo.lock b/Cargo.lock index 6baf7f37f1..f0c7372cff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3154,6 +3154,7 @@ dependencies = [ "tari_core", "tari_crypto", "tari_features", + "tari_hash_domains", "tari_key_manager", "tari_libtor", "tari_p2p", @@ -5879,6 +5880,7 @@ dependencies = [ "tari_comms_dht", "tari_comms_rpc_macros", "tari_crypto", + "tari_hash_domains", "tari_key_manager", "tari_metrics", "tari_mmr", @@ -5924,6 +5926,13 @@ dependencies = [ name = "tari_features" version = "1.0.0-pre.5" +[[package]] +name = "tari_hash_domains" +version = "0.1.0" +dependencies = [ + "tari_crypto", +] + [[package]] name = "tari_integration_tests" version = "0.35.1" diff --git a/Cargo.toml b/Cargo.toml index e9c531bbf9..2ee6313ef9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,8 @@ members = [ "applications/minotari_app_utilities", "applications/minotari_merge_mining_proxy", "applications/minotari_miner", - "integration_tests" + "integration_tests", + "hash_domains", ] # Add here until we move to edition=2021 diff --git a/applications/minotari_console_wallet/Cargo.toml b/applications/minotari_console_wallet/Cargo.toml index 42500b8d95..ea5e2190c1 100644 --- a/applications/minotari_console_wallet/Cargo.toml +++ b/applications/minotari_console_wallet/Cargo.toml @@ -20,7 +20,10 @@ tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } tari_script = { path = "../../infrastructure/tari_script" } tari_shutdown = { path = "../../infrastructure/shutdown" } tari_utilities = { version = "0.7" } -minotari_wallet = { path = "../../base_layer/wallet", features = ["bundled_sqlite"] } +minotari_wallet = { path = "../../base_layer/wallet", features = [ + "bundled_sqlite", +] } +tari_hash_domains = { path = "../../hash_domains" } # Uncomment for tokio tracing via tokio-console (needs "tracing" featurs) console-subscriber = "0.1.8" @@ -33,8 +36,20 @@ clap = { version = "3.2", features = ["derive", "env"] } config = "0.13.0" crossterm = { version = "0.25.0" } digest = "0.10" -futures = { version = "^0.3.16", default-features = false, features = ["alloc"] } -log4rs = { git = "https://github.com/tari-project/log4rs.git", default_features = false, features = ["config_parsing", "threshold_filter", "yaml_format", "console_appender", "rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller", "delete_roller"] } +futures = { version = "^0.3.16", default-features = false, features = [ + "alloc", +] } +log4rs = { git = "https://github.com/tari-project/log4rs.git", default_features = false, features = [ + "config_parsing", + "threshold_filter", + "yaml_format", + "console_appender", + "rolling_file_appender", + "compound_policy", + "size_trigger", + "fixed_window_roller", + "delete_roller", +] } log = { version = "0.4.8", features = ["std"] } qrcode = { version = "0.12" } rand = "0.8" @@ -67,7 +82,7 @@ default-features = false features = ["crossterm"] [build-dependencies] -tari_features = { path = "../../common/tari_features"} +tari_features = { path = "../../common/tari_features" } [features] default = ["libtor"] diff --git a/applications/minotari_console_wallet/src/ui/components/register_template_tab.rs b/applications/minotari_console_wallet/src/ui/components/register_template_tab.rs index a1e73c769b..edc91d5892 100644 --- a/applications/minotari_console_wallet/src/ui/components/register_template_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/register_template_tab.rs @@ -10,7 +10,8 @@ use minotari_wallet::output_manager_service::UtxoSelectionCriteria; use regex::Regex; use reqwest::StatusCode; use tari_core::transactions::{tari_amount::MicroMinotari, transaction_components::TemplateType}; -use tari_crypto::{hash_domain, hashing::DomainSeparation}; +use tari_crypto::hashing::DomainSeparation; +use tari_hash_domains::TariEngineHashDomain; use tari_utilities::hex::Hex; use tokio::{ runtime::{Handle, Runtime}, @@ -537,7 +538,6 @@ impl RegisterTemplateTab { StatusCode::OK => match data.bytes().await { Ok(bytes) => { let mut hasher = Blake2b::::default(); - hash_domain!(TariEngineHashDomain, "com.tari.dan.engine", 0); TariEngineHashDomain::add_domain_separation_tag(&mut hasher, "Template"); let hash: [u8; 32] = hasher.chain_update(bytes).finalize().into(); hex_string = hash.to_hex(); diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 61a268c298..abe499530f 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -13,31 +13,41 @@ edition = "2018" default = ["base_node"] transactions = [] mempool_proto = [] -base_node = ["tari_mmr", "transactions", "mempool_proto", "base_node_proto", "monero", "randomx-rs"] +base_node = [ + "tari_mmr", + "transactions", + "mempool_proto", + "base_node_proto", + "monero", + "randomx-rs", +] base_node_proto = [] benches = ["base_node"] metrics = ["tari_metrics"] [dependencies] -tari_common = { path = "../../common" } -tari_common_types = { path = "../../base_layer/common_types" } -tari_comms = { path = "../../comms/core" } -tari_comms_dht = { path = "../../comms/dht" } -tari_comms_rpc_macros = { path = "../../comms/rpc_macros" } +tari_common = { path = "../../common" } +tari_common_types = { path = "../../base_layer/common_types" } +tari_comms = { path = "../../comms/core" } +tari_comms_dht = { path = "../../comms/dht" } +tari_comms_rpc_macros = { path = "../../comms/rpc_macros" } tari_crypto = { version = "0.20", features = ["borsh"] } tari_metrics = { path = "../../infrastructure/metrics", optional = true } -tari_mmr = { path = "../../base_layer/mmr", optional = true} -tari_p2p = { path = "../../base_layer/p2p" } +tari_mmr = { path = "../../base_layer/mmr", optional = true } +tari_p2p = { path = "../../base_layer/p2p" } tari_script = { path = "../../infrastructure/tari_script" } -tari_service_framework = { path = "../service_framework" } -tari_shutdown = { path = "../../infrastructure/shutdown" } -tari_storage = { path = "../../infrastructure/storage" } -tari_test_utils = { path = "../../infrastructure/test_utils" } +tari_service_framework = { path = "../service_framework" } +tari_shutdown = { path = "../../infrastructure/shutdown" } +tari_storage = { path = "../../infrastructure/storage" } +tari_test_utils = { path = "../../infrastructure/test_utils" } tari_utilities = { version = "0.7", features = ["borsh"] } -tari_key_manager = { path = "../key_manager", features = ["key_manager_service"] } +tari_key_manager = { path = "../key_manager", features = [ + "key_manager_service", +] } tari_common_sqlite = { path = "../../common_sqlite" } +tari_hash_domains = { path = "../../hash_domains" } -async-trait = {version = "0.1.50"} +async-trait = { version = "0.1.50" } bincode = "1.1.4" bitflags = { version = "2.4", features = ["serde"] } blake2 = "0.10" @@ -76,12 +86,14 @@ tokio = { version = "1.23", features = ["time", "sync", "macros"] } tracing = "0.1.26" zeroize = "1" primitive-types = { version = "0.12", features = ["serde"] } -tiny-keccak = { git = "https://github.com/tari-project/tiny-keccak", rev = "bcddc65530d8646de7282cd8d18d891dc434b643",features = ["keccak"] } +tiny-keccak = { git = "https://github.com/tari-project/tiny-keccak", rev = "bcddc65530d8646de7282cd8d18d891dc434b643", features = [ + "keccak", +] } [dev-dependencies] criterion = { version = "0.4.0" } -tari_p2p = { path = "../../base_layer/p2p", features = ["test-mocks"] } -tari_test_utils = { path = "../../infrastructure/test_utils" } +tari_p2p = { path = "../../base_layer/p2p", features = ["test-mocks"] } +tari_test_utils = { path = "../../infrastructure/test_utils" } curve25519-dalek = { package = "tari-curve25519-dalek", version = "4.0.3" } # SQLite required for the integration tests libsqlite3-sys = { version = "0.25.1", features = ["bundled"] } @@ -92,7 +104,7 @@ toml = { version = "0.5" } quickcheck = "1.0" [build-dependencies] -tari_common = { path = "../../common", features = ["build"] } +tari_common = { path = "../../common", features = ["build"] } [[bench]] name = "mempool" diff --git a/base_layer/core/src/common/mod.rs b/base_layer/core/src/common/mod.rs index 9eefcc7b0b..c6b7d1b293 100644 --- a/base_layer/core/src/common/mod.rs +++ b/base_layer/core/src/common/mod.rs @@ -22,7 +22,7 @@ use blake2::Blake2b; use digest::consts::U64; -use tari_crypto::hash_domain; +use tari_hash_domains::ConfidentialOutputHashDomain; use crate::consensus::DomainSeparatedConsensusHasher; @@ -35,7 +35,6 @@ pub mod rolling_avg; #[cfg(feature = "base_node")] pub mod rolling_vec; -hash_domain!(ConfidentialOutputHashDomain, "com.tari.dan.confidential_output", 1); /// Hasher used in the DAN to derive masks and encrypted value keys pub type ConfidentialOutputHasher = DomainSeparatedConsensusHasher>; diff --git a/base_layer/core/src/common/one_sided.rs b/base_layer/core/src/common/one_sided.rs index b89f1e7d3e..fcb9e734cb 100644 --- a/base_layer/core/src/common/one_sided.rs +++ b/base_layer/core/src/common/one_sided.rs @@ -31,6 +31,7 @@ use tari_crypto::{ hashing::{DomainSeparatedHash, DomainSeparatedHasher}, keys::{PublicKey as PKtrait, SecretKey as SKtrait}, }; +use tari_hash_domains::WalletOutputEncryptionKeysDomain; use tari_utilities::byte_array::ByteArrayError; hash_domain!( @@ -39,12 +40,6 @@ hash_domain!( 1 ); -hash_domain!( - WalletOutputEncryptionKeysDomain, - "com.tari.base_layer.wallet.output_encryption_keys", - 1 -); - hash_domain!( WalletOutputSpendingKeysDomain, "com.tari.base_layer.wallet.output_spending_keys", diff --git a/base_layer/core/src/lib.rs b/base_layer/core/src/lib.rs index 95033dee32..d9ebf079c5 100644 --- a/base_layer/core/src/lib.rs +++ b/base_layer/core/src/lib.rs @@ -57,6 +57,7 @@ mod domain_hashing { use blake2::Blake2b; use digest::consts::U32; use tari_crypto::{hash_domain, hashing::DomainSeparatedHasher}; + use tari_hash_domains::ValidatorNodeBmtHashDomain; use tari_mmr::{ pruned_hashset::PrunedHashSet, sparse_merkle_tree::SparseMerkleTree, @@ -80,11 +81,6 @@ mod domain_hashing { pub type OutputSmt = SparseMerkleTree; - hash_domain!( - ValidatorNodeBmtHashDomain, - "com.tari.base_layer.core.validator_node_mmr", - 1 - ); pub type ValidatorNodeBmtHasherBlake256 = DomainSeparatedHasher, ValidatorNodeBmtHashDomain>; pub type ValidatorNodeBMT = BalancedBinaryMerkleTree; } diff --git a/base_layer/core/src/transactions/mod.rs b/base_layer/core/src/transactions/mod.rs index 632aaefd22..1dab9c0911 100644 --- a/base_layer/core/src/transactions/mod.rs +++ b/base_layer/core/src/transactions/mod.rs @@ -37,10 +37,3 @@ pub mod test_helpers; // Hash domain for all transaction-related hashes, including the script signature challenge, transaction hash and kernel // signature challenge hash_domain!(TransactionHashDomain, "com.tari.base_layer.core.transactions", 0); - -// Hash domain used to derive the final AEAD encryption key for encrypted data in UTXOs -hash_domain!( - TransactionSecureNonceKdfDomain, - "com.tari.base_layer.core.transactions.secure_nonce_kdf", - 0 -); diff --git a/base_layer/core/src/transactions/transaction_components/encrypted_data.rs b/base_layer/core/src/transactions/transaction_components/encrypted_data.rs index fb39d3e37b..1c29b35a7d 100644 --- a/base_layer/core/src/transactions/transaction_components/encrypted_data.rs +++ b/base_layer/core/src/transactions/transaction_components/encrypted_data.rs @@ -40,6 +40,7 @@ use digest::{consts::U32, generic_array::GenericArray, FixedOutput}; use serde::{Deserialize, Serialize}; use tari_common_types::types::{Commitment, PrivateKey}; use tari_crypto::{hashing::DomainSeparatedHasher, keys::SecretKey}; +use tari_hash_domains::TransactionSecureNonceKdfDomain; use tari_utilities::{ hex::{from_hex, to_hex, Hex, HexError}, safe_array::SafeArray, @@ -50,7 +51,7 @@ use thiserror::Error; use zeroize::{Zeroize, Zeroizing}; use super::EncryptedDataKey; -use crate::transactions::{tari_amount::MicroMinotari, TransactionSecureNonceKdfDomain}; +use crate::transactions::tari_amount::MicroMinotari; // Useful size constants, each in bytes const SIZE_NONCE: usize = size_of::(); diff --git a/hash_domains/Cargo.toml b/hash_domains/Cargo.toml new file mode 100644 index 0000000000..28b7a1f3d8 --- /dev/null +++ b/hash_domains/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "tari_hash_domains" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tari_crypto = "0.20.0" diff --git a/hash_domains/src/lib.rs b/hash_domains/src/lib.rs new file mode 100644 index 0000000000..a88f9b4519 --- /dev/null +++ b/hash_domains/src/lib.rs @@ -0,0 +1,45 @@ +// Copyright 2023. The Tari Project +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +// following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the +// following disclaimer in the documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote +// products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +use tari_crypto::hash_domain; + +// These are the hash domains that are also used in tari-dan. + +hash_domain!(ConfidentialOutputHashDomain, "com.tari.dan.confidential_output", 1); +hash_domain!(TariEngineHashDomain, "com.tari.dan.engine", 0); + +// Hash domain used to derive the final AEAD encryption key for encrypted data in UTXOs +hash_domain!( + TransactionSecureNonceKdfDomain, + "com.tari.base_layer.core.transactions.secure_nonce_kdf", + 0 +); +hash_domain!( + ValidatorNodeBmtHashDomain, + "com.tari.base_layer.core.validator_node_mmr", + 1 +); +hash_domain!( + WalletOutputEncryptionKeysDomain, + "com.tari.base_layer.wallet.output_encryption_keys", + 1 +);