mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Refinements to VRF types (#14036)
* Allow extra signing data * Fix tests after renaming * Rename VrfSecret/VrfVerifier to VrfSecret/VrfPublic * Further encrapsulation of 'transcript' type to the sr25519 implementation * Keystore sr25519 pre-output * Leave additional custom input field hidden in the associated VrfInput type * Fix test * More ergonomic output_bytes * Trigger pipeline * Define a separated type for vrf signature data * Fix docs * Fix doc * Remove annotation * Directly use dleq_proove and dleq_verify in sr25519 * Trigger CI * Remove cruft before merge
This commit is contained in:
@@ -357,12 +357,12 @@ pub mod pallet {
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(vrf_signature) = pre_digest.vrf_signature() {
|
||||
if let Some(signature) = pre_digest.vrf_signature() {
|
||||
let randomness: Option<BabeRandomness> = Authorities::<T>::get()
|
||||
.get(authority_index as usize)
|
||||
.and_then(|(authority, _)| {
|
||||
let public = authority.as_inner_ref();
|
||||
let transcript = sp_consensus_babe::make_transcript(
|
||||
let transcript = sp_consensus_babe::make_vrf_transcript(
|
||||
&Self::randomness(),
|
||||
CurrentSlot::<T>::get(),
|
||||
EpochIndex::<T>::get(),
|
||||
@@ -372,16 +372,12 @@ pub mod pallet {
|
||||
// execution. We don't run the verification again here to avoid slowing
|
||||
// down the runtime.
|
||||
debug_assert!({
|
||||
use sp_core::crypto::VrfVerifier;
|
||||
public.vrf_verify(&transcript, &vrf_signature)
|
||||
use sp_core::crypto::VrfPublic;
|
||||
public.vrf_verify(&transcript.clone().into_sign_data(), &signature)
|
||||
});
|
||||
|
||||
public
|
||||
.make_bytes(
|
||||
RANDOMNESS_VRF_CONTEXT,
|
||||
&transcript,
|
||||
&vrf_signature.output,
|
||||
)
|
||||
.make_bytes(RANDOMNESS_VRF_CONTEXT, &transcript, &signature.output)
|
||||
.ok()
|
||||
});
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ use frame_support::{
|
||||
use pallet_session::historical as pallet_session_historical;
|
||||
use sp_consensus_babe::{AuthorityId, AuthorityPair, Randomness, Slot, VrfSignature};
|
||||
use sp_core::{
|
||||
crypto::{KeyTypeId, Pair, VrfSigner},
|
||||
crypto::{KeyTypeId, Pair, VrfSecret},
|
||||
H256, U256,
|
||||
};
|
||||
use sp_io;
|
||||
@@ -314,17 +314,16 @@ pub fn make_secondary_vrf_pre_digest(
|
||||
Digest { logs: vec![log] }
|
||||
}
|
||||
|
||||
pub fn make_vrf_output(
|
||||
pub fn make_vrf_signature_and_randomness(
|
||||
slot: Slot,
|
||||
pair: &sp_consensus_babe::AuthorityPair,
|
||||
) -> (VrfSignature, Randomness) {
|
||||
let transcript = sp_consensus_babe::make_transcript(&Babe::randomness(), slot, 0);
|
||||
let transcript = sp_consensus_babe::make_vrf_transcript(&Babe::randomness(), slot, 0);
|
||||
|
||||
let signature = pair.as_ref().vrf_sign(&transcript);
|
||||
let randomness =
|
||||
pair.as_ref().make_bytes(sp_consensus_babe::RANDOMNESS_VRF_CONTEXT, &transcript);
|
||||
|
||||
let randomness = pair
|
||||
.as_ref()
|
||||
.make_bytes::<Randomness>(sp_consensus_babe::RANDOMNESS_VRF_CONTEXT, &transcript);
|
||||
let signature = pair.as_ref().vrf_sign(&transcript.into());
|
||||
|
||||
(signature, randomness)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ fn first_block_epoch_zero_start() {
|
||||
|
||||
ext.execute_with(|| {
|
||||
let genesis_slot = Slot::from(100);
|
||||
let (vrf_signature, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let (vrf_signature, vrf_randomness) =
|
||||
make_vrf_signature_and_randomness(genesis_slot, &pairs[0]);
|
||||
|
||||
let pre_digest = make_primary_pre_digest(0, genesis_slot, vrf_signature);
|
||||
|
||||
@@ -111,7 +112,8 @@ fn current_slot_is_processed_on_initialization() {
|
||||
|
||||
ext.execute_with(|| {
|
||||
let genesis_slot = Slot::from(10);
|
||||
let (vrf_signature, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let (vrf_signature, vrf_randomness) =
|
||||
make_vrf_signature_and_randomness(genesis_slot, &pairs[0]);
|
||||
let pre_digest = make_primary_pre_digest(0, genesis_slot, vrf_signature);
|
||||
|
||||
System::reset_events();
|
||||
@@ -140,7 +142,8 @@ where
|
||||
|
||||
ext.execute_with(|| {
|
||||
let genesis_slot = Slot::from(10);
|
||||
let (vrf_signature, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let (vrf_signature, vrf_randomness) =
|
||||
make_vrf_signature_and_randomness(genesis_slot, &pairs[0]);
|
||||
let pre_digest = make_pre_digest(0, genesis_slot, vrf_signature);
|
||||
|
||||
System::reset_events();
|
||||
|
||||
Reference in New Issue
Block a user