mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 12:41:07 +00:00
VRF refactory (#13889)
* First iteration to encapsulate schnorrkel and merlin usage * Remove schnorkel direct dependency from BABE pallet * Remove schnorrkel direct dependency from BABE client * Trivial renaming for VrfTranscript data and value * Better errors * Expose a function to get a schnorrkel friendly transcript * Keep the vrf signature stuff together (preventing some clones around) * Fix tests * Remove vrf agnostic transcript and define it as an associated type for VrfSigner and VrfVerifier * Fix babe pallet mock * Inner types are required to be public for polkadot * Update client/consensus/babe/src/verification.rs Co-authored-by: Koute <koute@users.noreply.github.com> * Nit * Remove Deref implementations * make_bytes as a method * Trigger CI --------- Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
@@ -25,10 +25,9 @@ use frame_support::{
|
||||
traits::{ConstU128, ConstU32, ConstU64, GenesisBuild, KeyOwnerProofSystem, OnInitialize},
|
||||
};
|
||||
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_babe::{AuthorityId, AuthorityPair, Randomness, Slot, VrfSignature};
|
||||
use sp_core::{
|
||||
crypto::{IsWrappedBy, KeyTypeId, Pair},
|
||||
crypto::{KeyTypeId, Pair, VrfSigner},
|
||||
H256, U256,
|
||||
};
|
||||
use sp_io;
|
||||
@@ -283,16 +282,10 @@ 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_proof: VRFProof,
|
||||
vrf_signature: VrfSignature,
|
||||
) -> Digest {
|
||||
let digest_data = sp_consensus_babe::digests::PreDigest::Primary(
|
||||
sp_consensus_babe::digests::PrimaryPreDigest {
|
||||
authority_index,
|
||||
slot,
|
||||
vrf_output,
|
||||
vrf_proof,
|
||||
},
|
||||
sp_consensus_babe::digests::PrimaryPreDigest { authority_index, slot, vrf_signature },
|
||||
);
|
||||
let log = DigestItem::PreRuntime(sp_consensus_babe::BABE_ENGINE_ID, digest_data.encode());
|
||||
Digest { logs: vec![log] }
|
||||
@@ -312,16 +305,10 @@ 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_proof: VRFProof,
|
||||
vrf_signature: VrfSignature,
|
||||
) -> Digest {
|
||||
let digest_data = sp_consensus_babe::digests::PreDigest::SecondaryVRF(
|
||||
sp_consensus_babe::digests::SecondaryVRFPreDigest {
|
||||
authority_index,
|
||||
slot,
|
||||
vrf_output,
|
||||
vrf_proof,
|
||||
},
|
||||
sp_consensus_babe::digests::SecondaryVRFPreDigest { authority_index, slot, vrf_signature },
|
||||
);
|
||||
let log = DigestItem::PreRuntime(sp_consensus_babe::BABE_ENGINE_ID, digest_data.encode());
|
||||
Digest { logs: vec![log] }
|
||||
@@ -330,16 +317,16 @@ pub fn make_secondary_vrf_pre_digest(
|
||||
pub fn make_vrf_output(
|
||||
slot: Slot,
|
||||
pair: &sp_consensus_babe::AuthorityPair,
|
||||
) -> (VRFOutput, VRFProof, [u8; 32]) {
|
||||
let pair = sp_core::sr25519::Pair::from_ref(pair).as_ref();
|
||||
) -> (VrfSignature, Randomness) {
|
||||
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_proof = VRFProof(vrf_inout.1);
|
||||
|
||||
(vrf_output, vrf_proof, vrf_randomness)
|
||||
let signature = pair.as_ref().vrf_sign(&transcript);
|
||||
|
||||
let randomness = pair
|
||||
.as_ref()
|
||||
.make_bytes::<Randomness>(sp_consensus_babe::RANDOMNESS_VRF_CONTEXT, &transcript);
|
||||
|
||||
(signature, randomness)
|
||||
}
|
||||
|
||||
pub fn new_test_ext(authorities_len: usize) -> sp_io::TestExternalities {
|
||||
|
||||
Reference in New Issue
Block a user