Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cryptographic hashing procedures to crypto folder. #2306

Merged
merged 18 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ members = [
"substrate/client/transaction-pool",
"substrate/client/transaction-pool/api",
"substrate/client/utils",
"substrate/deprecated/hashing",
"substrate/deprecated/hashing/proc-macro",
"substrate/frame",
"substrate/frame/alliance",
"substrate/frame/asset-conversion",
Expand Down Expand Up @@ -406,9 +408,9 @@ members = [
"substrate/primitives/consensus/slots",
"substrate/primitives/core",
"substrate/primitives/core/fuzz",
"substrate/primitives/core/hashing",
"substrate/primitives/core/hashing/proc-macro",
"substrate/primitives/crypto/ec-utils",
"substrate/primitives/crypto/hashing",
"substrate/primitives/crypto/hashing/proc-macro",
"substrate/primitives/database",
"substrate/primitives/debug-derive",
"substrate/primitives/externalities",
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/core/pvf/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sc-executor-common = { path = "../../../../../substrate/client/executor/common"
sc-executor-wasmtime = { path = "../../../../../substrate/client/executor/wasmtime" }

sp-core = { path = "../../../../../substrate/primitives/core" }
sp-crypto-hashing = { path = "../../../../../substrate/primitives/crypto/hashing" }
sp-externalities = { path = "../../../../../substrate/primitives/externalities" }
sp-io = { path = "../../../../../substrate/primitives/io" }
sp-tracing = { path = "../../../../../substrate/primitives/tracing" }
Expand Down
3 changes: 1 addition & 2 deletions polkadot/node/core/pvf/common/src/pvf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::prepare::PrepareJobKind;
use parity_scale_codec::{Decode, Encode};
use polkadot_parachain_primitives::primitives::ValidationCodeHash;
use polkadot_primitives::ExecutorParams;
use sp_core::blake2_256;
use std::{
cmp::{Eq, PartialEq},
fmt,
Expand Down Expand Up @@ -53,7 +52,7 @@ impl PvfPrepData {
prep_kind: PrepareJobKind,
) -> Self {
let code = Arc::new(code);
let code_hash = blake2_256(&code).into();
let code_hash = sp_crypto_hashing::blake2_256(&code).into();
let executor_params = Arc::new(executor_params);
Self { code, code_hash, executor_params, prep_timeout, prep_kind }
}
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/network/gossip-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license.workspace = true
sp-application-crypto = { path = "../../../../substrate/primitives/application-crypto" }
sp-keystore = { path = "../../../../substrate/primitives/keystore" }
sp-core = { path = "../../../../substrate/primitives/core" }
sp-crypto-hashing = { path = "../../../../substrate/primitives/crypto/hashing" }
sc-network = { path = "../../../../substrate/client/network" }
sc-network-common = { path = "../../../../substrate/client/network/common" }

Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ async fn update_gossip_topology(
let mut subject = [0u8; 40];
subject[..8].copy_from_slice(b"gossipsu");
subject[8..].copy_from_slice(&randomness);
sp_core::blake2_256(&subject)
sp_crypto_hashing::blake2_256(&subject)
};

// shuffle the validators and create the index mapping
Expand Down
1 change: 1 addition & 0 deletions substrate/client/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sc-network = { path = "../network" }
sc-telemetry = { path = "../telemetry" }
sp-blockchain = { path = "../../primitives/blockchain" }
sp-core = { path = "../../primitives/core" }
sp-crypto-hashing = { path = "../../primitives/crypto/hashing" }
sp-genesis-builder = { path = "../../primitives/genesis-builder" }
sp-runtime = { path = "../../primitives/runtime" }
sp-state-machine = { path = "../../primitives/state-machine" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/chain-spec/src/genesis_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where
pub fn new(code: &'a [u8]) -> Self {
GenesisConfigBuilderRuntimeCaller {
code: code.into(),
code_hash: sp_core::blake2_256(code).to_vec(),
code_hash: sp_crypto_hashing::blake2_256(code).to_vec(),
executor: WasmExecutor::<(sp_io::SubstrateHostFunctions, EHF)>::builder()
.with_allow_missing_host_functions(true)
.build(),
Expand Down
1 change: 1 addition & 0 deletions substrate/client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sp-consensus = { path = "../../../primitives/consensus/common" }
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
sp-consensus-slots = { path = "../../../primitives/consensus/slots" }
sp-core = { path = "../../../primitives/core" }
sp-crypto-hashing = { path = "../../../primitives/crypto/hashing" }
sp-inherents = { path = "../../../primitives/inherents" }
sp-keystore = { path = "../../../primitives/keystore" }
sp-runtime = { path = "../../../primitives/runtime" }
Expand Down
3 changes: 1 addition & 2 deletions substrate/client/consensus/babe/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use sp_consensus_babe::{
make_vrf_sign_data, AuthorityId, BabeAuthorityWeight, Randomness, Slot,
};
use sp_core::{
blake2_256,
crypto::{ByteArray, Wraps},
U256,
};
Expand Down Expand Up @@ -109,7 +108,7 @@ pub(super) fn secondary_slot_author(
return None
}

let rand = U256::from((randomness, slot).using_encoded(blake2_256));
let rand = U256::from((randomness, slot).using_encoded(sp_crypto_hashing::blake2_256));

let authorities_len = U256::from(authorities.len());
let idx = rand % authorities_len;
Expand Down
1 change: 1 addition & 0 deletions substrate/client/consensus/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sp-blockchain = { path = "../../../primitives/blockchain" }
sp-consensus = { path = "../../../primitives/consensus/common" }
sp-consensus-beefy = { path = "../../../primitives/consensus/beefy" }
sp-core = { path = "../../../primitives/core" }
sp-crypto-hashing = { path = "../../../primitives/crypto/hashing" }
sp-keystore = { path = "../../../primitives/keystore" }
sp-mmr-primitives = { path = "../../../primitives/merkle-mountain-range" }
sp-runtime = { path = "../../../primitives/runtime" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/beefy/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use sp_application_crypto::{key_types::BEEFY as BEEFY_KEY_TYPE, RuntimeAppPublic};
use sp_core::keccak_256;
use sp_crypto_hashing::keccak_256;
use sp_keystore::KeystorePtr;

use log::warn;
Expand Down
1 change: 1 addition & 0 deletions substrate/client/consensus/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sp-arithmetic = { path = "../../../primitives/arithmetic" }
sp-blockchain = { path = "../../../primitives/blockchain" }
sp-consensus = { path = "../../../primitives/consensus/common" }
sp-core = { path = "../../../primitives/core" }
sp-crypto-hashing = { path = "../../../primitives/crypto/hashing" }
sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa" }
sp-keystore = { path = "../../../primitives/keystore" }
sp-runtime = { path = "../../../primitives/runtime" }
Expand Down
7 changes: 5 additions & 2 deletions substrate/client/consensus/grandpa/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use sp_api::{Core, RuntimeApiInfo};
use sp_blockchain::BlockStatus;
use sp_consensus::{BlockOrigin, Error as ConsensusError, SelectChain};
use sp_consensus_grandpa::{ConsensusLog, GrandpaApi, ScheduledChange, SetId, GRANDPA_ENGINE_ID};
use sp_core::hashing::twox_128;
use sp_runtime::{
generic::OpaqueDigestItemId,
traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero},
Expand Down Expand Up @@ -438,7 +437,11 @@ where
// The new API is not supported in this runtime. Try reading directly from storage.
// This code may be removed once warp sync to an old runtime is no longer needed.
for prefix in ["GrandpaFinality", "Grandpa"] {
let k = [twox_128(prefix.as_bytes()), twox_128(b"CurrentSetId")].concat();
let k = [
sp_crypto_hashing::twox_128(prefix.as_bytes()),
sp_crypto_hashing::twox_128(b"CurrentSetId"),
]
.concat();
davxy marked this conversation as resolved.
Show resolved Hide resolved
if let Ok(Some(id)) =
self.inner.storage(hash, &sc_client_api::StorageKey(k.to_vec()))
{
Expand Down
1 change: 1 addition & 0 deletions substrate/client/sysinfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.108"
sc-telemetry = { path = "../telemetry" }
sp-core = { path = "../../primitives/core" }
sp-crypto-hashing = { path = "../../primitives/crypto/hashing" }
sp-io = { path = "../../primitives/io" }
sp-std = { path = "../../primitives/std" }

Expand Down
2 changes: 1 addition & 1 deletion substrate/client/sysinfo/src/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub fn benchmark_cpu(limit: ExecutionLimit) -> Throughput {

let run = || -> Result<(), ()> {
clobber_slice(&mut buffer);
hash = sp_core::hashing::blake2_256(&buffer);
hash = sp_crypto_hashing::blake2_256(&buffer);
clobber_slice(&mut hash);

Ok(())
Expand Down
23 changes: 23 additions & 0 deletions substrate/deprecated/hashing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "sp-core-hashing"
version = "9.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.io"
repository.workspace = true
description = "Hashing primitives (deprecated: use sp-crypto-hashing for new applications)"
documentation = "https://docs.rs/sp-crypto-hashing"

[badges]
maintenance = { status = "deprecated" }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sp-crypto-hashing = { path = "../../primitives/crypto/hashing" }

[features]
default = [ "std" ]
std = [ "sp-crypto-hashing/std" ]
3 changes: 3 additions & 0 deletions substrate/deprecated/hashing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hashing

This package has been deprecated. Please use `sp-crypto-hashing`.
Loading