Skip to content

Commit

Permalink
Update schnorrkel/merlin
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Apr 8, 2023
1 parent 0a14d9a commit 638c672
Show file tree
Hide file tree
Showing 24 changed files with 249 additions and 311 deletions.
246 changes: 92 additions & 154 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = "0.1.57"
async-trait = "0.1"
scale-info = { version = "2.1.1", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.2.2", features = ["derive"] }
futures = "0.3.21"
log = "0.4.17"
merlin = "2.0"
num-bigint = "0.4.3"
num-rational = "0.4.1"
num-traits = "0.2.8"
parking_lot = "0.12.1"
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated"] }
thiserror = "1.0"
fork-tree = { version = "3.0.0", path = "../../../utils/fork-tree" }
futures = "0.3"
log = "0.4"
merlin = "3"
num-bigint = "0.4"
num-rational = "0.4"
num-traits = "0.2"
parking_lot = "0.12"
schnorrkel = { version = "0.10", features = ["preaudit_deprecated"] }
thiserror = "1"
fork-tree = { version = "3", path = "../../../utils/fork-tree" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" }
sc-client-api = { version = "4.0.0-dev", path = "../../api" }
sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" }
Expand All @@ -35,25 +35,25 @@ sc-consensus-slots = { version = "0.10.0-dev", path = "../slots" }
sc-keystore = { version = "4.0.0-dev", path = "../../keystore" }
sc-telemetry = { version = "4.0.0-dev", path = "../../telemetry" }
sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" }
sp-application-crypto = { version = "7.0.0", path = "../../../primitives/application-crypto" }
sp-application-crypto = { version = "7", path = "../../../primitives/application-crypto" }
sp-block-builder = { version = "4.0.0-dev", path = "../../../primitives/block-builder" }
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" }
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
sp-consensus-slots = { version = "0.10.0-dev", path = "../../../primitives/consensus/slots" }
sp-consensus-vrf = { version = "0.10.0-dev", path = "../../../primitives/consensus/vrf" }
sp-core = { version = "7.0.0", path = "../../../primitives/core" }
sp-core = { version = "7", path = "../../../primitives/core" }
sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" }
sp-keystore = { version = "0.13.0", path = "../../../primitives/keystore" }
sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" }
sp-keystore = { version = "0.13", path = "../../../primitives/keystore" }
sp-runtime = { version = "7", path = "../../../primitives/runtime" }

[dev-dependencies]
rand_chacha = "0.2.2"
rand_chacha = "0.3"
sc-block-builder = { version = "0.10.0-dev", path = "../../block-builder" }
sp-keyring = { version = "7.0.0", path = "../../../primitives/keyring" }
sc-network = { version = "0.10.0-dev", path = "../../network" }
sc-network-test = { version = "0.8.0", path = "../../network/test" }
sp-timestamp = { version = "4.0.0-dev", path = "../../../primitives/timestamp" }
sp-tracing = { version = "6.0.0", path = "../../../primitives/tracing" }
substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" }
tokio = "1.22.0"
tokio = "1"
6 changes: 3 additions & 3 deletions client/consensus/babe/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_consensus_babe::{
digests::{PreDigest, PrimaryPreDigest, SecondaryPlainPreDigest, SecondaryVRFPreDigest},
make_transcript, make_transcript_data, AuthorityId, BabeAuthorityWeight, Slot, BABE_VRF_PREFIX,
};
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
use sp_consensus_vrf::schnorrkel::{VRFPreOut, VRFProof};
use sp_core::{blake2_256, crypto::ByteArray, U256};
use sp_keystore::KeystorePtr;

Expand Down Expand Up @@ -161,7 +161,7 @@ fn claim_secondary_slot(
if let Ok(Some(signature)) = result {
Some(PreDigest::SecondaryVRF(SecondaryVRFPreDigest {
slot,
vrf_output: VRFOutput(signature.output),
vrf_output: VRFPreOut(signature.output),
vrf_proof: VRFProof(signature.proof),
authority_index: *authority_index as u32,
}))
Expand Down Expand Up @@ -263,7 +263,7 @@ fn claim_primary_slot(
if check_primary_threshold(&inout, threshold) {
let pre_digest = PreDigest::Primary(PrimaryPreDigest {
slot,
vrf_output: VRFOutput(signature.output),
vrf_output: VRFPreOut(signature.output),
vrf_proof: VRFProof(signature.proof),
authority_index: *authority_index as u32,
});
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub use sp_consensus_babe::{
PrimaryPreDigest, SecondaryPlainPreDigest,
},
AuthorityId, AuthorityPair, AuthoritySignature, BabeApi, BabeAuthorityWeight, BabeBlockWeight,
BabeConfiguration, BabeEpochConfiguration, ConsensusLog, BABE_ENGINE_ID, VRF_OUTPUT_LENGTH,
BabeConfiguration, BabeEpochConfiguration, ConsensusLog, BABE_ENGINE_ID, VRF_PREOUT_LENGTH,
};

pub use aux_schema::load_block_weight as block_weight;
Expand All @@ -161,7 +161,7 @@ pub struct Epoch {
/// The authorities and their weights.
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
/// Randomness for this epoch.
pub randomness: [u8; VRF_OUTPUT_LENGTH],
pub randomness: [u8; VRF_PREOUT_LENGTH],
/// Configuration of the epoch.
pub config: BabeEpochConfiguration,
}
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/babe/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::{
AuthorityId, BabeAuthorityWeight, BabeConfiguration, BabeEpochConfiguration, Epoch,
NextEpochDescriptor, VRF_OUTPUT_LENGTH,
NextEpochDescriptor, VRF_PREOUT_LENGTH,
};
use codec::{Decode, Encode};
use sc_consensus_epochs::Epoch as EpochT;
Expand All @@ -36,7 +36,7 @@ pub struct EpochV0 {
/// The authorities and their weights.
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
/// Randomness for this epoch.
pub randomness: [u8; VRF_OUTPUT_LENGTH],
pub randomness: [u8; VRF_PREOUT_LENGTH],
}

impl EpochT for EpochV0 {
Expand Down
10 changes: 5 additions & 5 deletions client/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use sp_consensus_babe::{
AuthorityId, AuthorityPair, Slot,
};
use sp_consensus_slots::SlotDuration;
use sp_consensus_vrf::schnorrkel::VRFOutput;
use sp_consensus_vrf::schnorrkel::VRFPreOut;
use sp_core::crypto::Pair;
use sp_keyring::Sr25519Keyring;
use sp_keystore::{
Expand Down Expand Up @@ -642,7 +642,7 @@ fn claim_vrf_check() {
.sr25519_vrf_sign(AuthorityId::ID, &public, transcript)
.unwrap()
.unwrap();
assert_eq!(pre_digest.vrf_output, VRFOutput(sign.output));
assert_eq!(pre_digest.vrf_output, VRFPreOut(sign.output));

// We expect a SecondaryVRF claim for slot 1
let pre_digest = match claim_slot(1.into(), &epoch, &keystore).unwrap().0 {
Expand All @@ -654,7 +654,7 @@ fn claim_vrf_check() {
.sr25519_vrf_sign(AuthorityId::ID, &public, transcript)
.unwrap()
.unwrap();
assert_eq!(pre_digest.vrf_output, VRFOutput(sign.output));
assert_eq!(pre_digest.vrf_output, VRFPreOut(sign.output));

// Check that correct epoch index has been used if epochs are skipped (primary VRF)
let slot = Slot::from(103);
Expand All @@ -669,7 +669,7 @@ fn claim_vrf_check() {
.unwrap()
.unwrap();
assert_eq!(fixed_epoch.epoch_index, 11);
assert_eq!(claim.vrf_output, VRFOutput(sign.output));
assert_eq!(claim.vrf_output, VRFPreOut(sign.output));

// Check that correct epoch index has been used if epochs are skipped (secondary VRF)
let slot = Slot::from(100);
Expand All @@ -684,7 +684,7 @@ fn claim_vrf_check() {
.unwrap()
.unwrap();
assert_eq!(fixed_epoch.epoch_index, 11);
assert_eq!(pre_digest.vrf_output, VRFOutput(sign.output));
assert_eq!(pre_digest.vrf_output, VRFPreOut(sign.output));
}

// Propose and import a new BABE block on top of the given parent.
Expand Down
18 changes: 9 additions & 9 deletions client/keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
array-bytes = "4.1"
async-trait = "0.1.57"
parking_lot = "0.12.1"
serde_json = "1.0.85"
thiserror = "1.0"
sp-application-crypto = { version = "7.0.0", path = "../../primitives/application-crypto" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-keystore = { version = "0.13.0", path = "../../primitives/keystore" }
array-bytes = "4"
async-trait = "0.1"
parking_lot = "0.12"
serde_json = "1"
thiserror = "1"
sp-application-crypto = { version = "7", path = "../../primitives/application-crypto" }
sp-core = { version = "7", path = "../../primitives/core" }
sp-keystore = { version = "0.13", path = "../../primitives/keystore" }

[dev-dependencies]
tempfile = "3.1.0"
tempfile = "3"
2 changes: 1 addition & 1 deletion client/keystore/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Keystore for LocalKeystore {
let sig = self.0.read().key_pair_by_type::<sr25519::Pair>(public, key_type)?.map(|pair| {
let transcript = make_transcript(transcript_data);
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
VRFSignature { output: inout.to_output(), proof }
VRFSignature { output: inout.to_preout(), proof }
});
Ok(sig)
}
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use sp_session::{GetSessionNumber, GetValidatorCount};
use sp_staking::{offence::OffenceReportSystem, SessionIndex};
use sp_std::prelude::*;

pub use sp_consensus_babe::{AuthorityId, PUBLIC_KEY_LENGTH, RANDOMNESS_LENGTH, VRF_OUTPUT_LENGTH};
pub use sp_consensus_babe::{AuthorityId, PUBLIC_KEY_LENGTH, RANDOMNESS_LENGTH, VRF_PREOUT_LENGTH};

const LOG_TARGET: &str = "runtime::babe";

Expand Down Expand Up @@ -995,7 +995,7 @@ fn compute_randomness(
rho: impl Iterator<Item = schnorrkel::Randomness>,
rho_size_hint: Option<usize>,
) -> schnorrkel::Randomness {
let mut s = Vec::with_capacity(40 + rho_size_hint.unwrap_or(0) * VRF_OUTPUT_LENGTH);
let mut s = Vec::with_capacity(40 + rho_size_hint.unwrap_or(0) * VRF_PREOUT_LENGTH);
s.extend_from_slice(&last_epoch_randomness);
s.extend_from_slice(&epoch_index.to_le_bytes());

Expand Down
10 changes: 5 additions & 5 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
};
use pallet_session::historical as pallet_session_historical;
use sp_consensus_babe::{AuthorityId, AuthorityPair, Slot};
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
use sp_consensus_vrf::schnorrkel::{VRFPreOut, VRFProof};
use sp_core::{
crypto::{IsWrappedBy, KeyTypeId, Pair},
H256, U256,
Expand Down Expand Up @@ -283,7 +283,7 @@ pub fn start_era(era_index: EraIndex) {
pub fn make_primary_pre_digest(
authority_index: sp_consensus_babe::AuthorityIndex,
slot: sp_consensus_babe::Slot,
vrf_output: VRFOutput,
vrf_output: VRFPreOut,
vrf_proof: VRFProof,
) -> Digest {
let digest_data = sp_consensus_babe::digests::PreDigest::Primary(
Expand Down Expand Up @@ -312,7 +312,7 @@ pub fn make_secondary_plain_pre_digest(
pub fn make_secondary_vrf_pre_digest(
authority_index: sp_consensus_babe::AuthorityIndex,
slot: sp_consensus_babe::Slot,
vrf_output: VRFOutput,
vrf_output: VRFPreOut,
vrf_proof: VRFProof,
) -> Digest {
let digest_data = sp_consensus_babe::digests::PreDigest::SecondaryVRF(
Expand All @@ -330,13 +330,13 @@ pub fn make_secondary_vrf_pre_digest(
pub fn make_vrf_output(
slot: Slot,
pair: &sp_consensus_babe::AuthorityPair,
) -> (VRFOutput, VRFProof, [u8; 32]) {
) -> (VRFPreOut, VRFProof, [u8; 32]) {
let pair = sp_core::sr25519::Pair::from_ref(pair).as_ref();
let transcript = sp_consensus_babe::make_transcript(&Babe::randomness(), slot, 0);
let vrf_inout = pair.vrf_sign(transcript);
let vrf_randomness: sp_consensus_vrf::schnorrkel::Randomness =
vrf_inout.0.make_bytes::<[u8; 32]>(&sp_consensus_babe::BABE_VRF_INOUT_CONTEXT);
let vrf_output = VRFOutput(vrf_inout.0.to_output());
let vrf_output = VRFPreOut(vrf_inout.0.to_preout());
let vrf_proof = VRFProof(vrf_inout.1);

(vrf_output, vrf_proof, vrf_randomness)
Expand Down
8 changes: 4 additions & 4 deletions frame/babe/src/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! randomness collected from VRF outputs.

use super::{
AuthorVrfRandomness, Config, EpochStart, NextRandomness, Randomness, VRF_OUTPUT_LENGTH,
AuthorVrfRandomness, Config, EpochStart, NextRandomness, Randomness, VRF_PREOUT_LENGTH,
};
use frame_support::traits::Randomness as RandomnessT;
use sp_runtime::traits::{Hash, One, Saturating};
Expand Down Expand Up @@ -132,7 +132,7 @@ pub struct CurrentBlockRandomness<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromTwoEpochsAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, T::BlockNumber) {
let mut subject = subject.to_vec();
subject.reserve(VRF_OUTPUT_LENGTH);
subject.reserve(VRF_PREOUT_LENGTH);
subject.extend_from_slice(&Randomness::<T>::get()[..]);

(T::Hashing::hash(&subject[..]), EpochStart::<T>::get().0)
Expand All @@ -142,7 +142,7 @@ impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromTwoEpochs
impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromOneEpochAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, T::BlockNumber) {
let mut subject = subject.to_vec();
subject.reserve(VRF_OUTPUT_LENGTH);
subject.reserve(VRF_PREOUT_LENGTH);
subject.extend_from_slice(&NextRandomness::<T>::get()[..]);

(T::Hashing::hash(&subject[..]), EpochStart::<T>::get().1)
Expand All @@ -153,7 +153,7 @@ impl<T: Config> RandomnessT<Option<T::Hash>, T::BlockNumber> for ParentBlockRand
fn random(subject: &[u8]) -> (Option<T::Hash>, T::BlockNumber) {
let random = AuthorVrfRandomness::<T>::get().map(|random| {
let mut subject = subject.to_vec();
subject.reserve(VRF_OUTPUT_LENGTH);
subject.reserve(VRF_PREOUT_LENGTH);
subject.extend_from_slice(&random);

T::Hashing::hash(&subject[..])
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
use mock::*;
use pallet_session::ShouldEndSession;
use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot};
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
use sp_consensus_vrf::schnorrkel::{VRFPreOut, VRFProof};
use sp_core::crypto::Pair;

const EMPTY_RANDOMNESS: [u8; 32] = [
Expand Down Expand Up @@ -134,7 +134,7 @@ fn current_slot_is_processed_on_initialization() {

fn test_author_vrf_output<F>(make_pre_digest: F)
where
F: Fn(sp_consensus_babe::AuthorityIndex, Slot, VRFOutput, VRFProof) -> sp_runtime::Digest,
F: Fn(sp_consensus_babe::AuthorityIndex, Slot, VRFPreOut, VRFProof) -> sp_runtime::Digest,
{
let (pairs, mut ext) = new_test_ext_with_pairs(1);

Expand Down
12 changes: 6 additions & 6 deletions frame/society/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] }
rand_chacha = { version = "0.2", default-features = false }
rand_chacha = { version = "0.3", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-runtime = { version = "7", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "5", default-features = false, path = "../../primitives/std" }

[dev-dependencies]
frame-support-test = { version = "3.0.0", path = "../support/test" }
frame-support-test = { version = "3", path = "../support/test" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
sp-core = { version = "7", path = "../../primitives/core" }
sp-io = { version = "7", path = "../../primitives/io" }

[features]
default = ["std"]
Expand Down
20 changes: 10 additions & 10 deletions frame/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.136", optional = true }
serde = { version = "1", optional = true }
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "5", default-features = false, path = "../../primitives/std" }
sp-io = { version = "7", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "7", default-features = false, path = "../../primitives/runtime" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
pallet-session = { version = "4.0.0-dev", default-features = false, features = [
"historical",
], path = "../session" }
pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" }
sp-application-crypto = { version = "7.0.0", default-features = false, path = "../../primitives/application-crypto" }
sp-application-crypto = { version = "7", default-features = false, path = "../../primitives/application-crypto" }
frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" }
log = { version = "0.4.17", default-features = false }
log = { version = "0.4", default-features = false }

# Optional imports for benchmarking
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
rand_chacha = { version = "0.2", default-features = false, optional = true }
rand_chacha = { version = "0.3", default-features = false, optional = true }

[dev-dependencies]
sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-tracing = { version = "6", path = "../../primitives/tracing" }
sp-core = { version = "7", path = "../../primitives/core" }
sp-npos-elections = { version = "4.0.0-dev", path = "../../primitives/npos-elections" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
pallet-timestamp = { version = "4.0.0-dev", path = "../timestamp" }
Expand All @@ -47,7 +47,7 @@ pallet-bags-list = { version = "4.0.0-dev", path = "../bags-list" }
substrate-test-utils = { version = "4.0.0-dev", path = "../../test-utils" }
frame-benchmarking = { version = "4.0.0-dev", path = "../benchmarking" }
frame-election-provider-support = { version = "4.0.0-dev", path = "../election-provider-support" }
rand_chacha = { version = "0.2" }
rand_chacha = { version = "0.3" }

[features]
default = ["std"]
Expand Down
Loading

0 comments on commit 638c672

Please sign in to comment.