Skip to content

Commit a6b46ab

Browse files
andresilvabkchr
andauthored
sp-core: Rename VrfOutput to VrfPreOutput (paritytech#2534)
This will make more sense after paritytech#2524 since the schnorrkel type for VRF outputs is also renamed in the latest version. Can be reviewed independently though. Can be merged after paritytech#1577 so that there is less pain for @davxy. --------- Co-authored-by: Bastian Köcher <[email protected]>
1 parent 24d089f commit a6b46ab

14 files changed

Lines changed: 150 additions & 141 deletions

File tree

substrate/client/consensus/babe/src/authorship.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn claim_primary_slot(
249249
.make_bytes::<AUTHORING_SCORE_LENGTH>(
250250
AUTHORING_SCORE_VRF_CONTEXT,
251251
&data.as_ref(),
252-
&vrf_signature.output,
252+
&vrf_signature.pre_output,
253253
)
254254
.map(|bytes| u128::from_le_bytes(bytes) < threshold)
255255
.unwrap_or_default();

substrate/client/consensus/babe/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ fn claim_vrf_check() {
580580
};
581581
let data = make_vrf_sign_data(&epoch.randomness.clone(), 0.into(), epoch.epoch_index);
582582
let sign = keystore.sr25519_vrf_sign(AuthorityId::ID, &public, &data).unwrap().unwrap();
583-
assert_eq!(pre_digest.vrf_signature.output, sign.output);
583+
assert_eq!(pre_digest.vrf_signature.pre_output, sign.pre_output);
584584

585585
// We expect a SecondaryVRF claim for slot 1
586586
let pre_digest = match claim_slot(1.into(), &epoch, &keystore).unwrap().0 {
@@ -589,7 +589,7 @@ fn claim_vrf_check() {
589589
};
590590
let data = make_vrf_sign_data(&epoch.randomness.clone(), 1.into(), epoch.epoch_index);
591591
let sign = keystore.sr25519_vrf_sign(AuthorityId::ID, &public, &data).unwrap().unwrap();
592-
assert_eq!(pre_digest.vrf_signature.output, sign.output);
592+
assert_eq!(pre_digest.vrf_signature.pre_output, sign.pre_output);
593593

594594
// Check that correct epoch index has been used if epochs are skipped (primary VRF)
595595
let slot = Slot::from(103);
@@ -601,7 +601,7 @@ fn claim_vrf_check() {
601601
let data = make_vrf_sign_data(&epoch.randomness.clone(), slot, fixed_epoch.epoch_index);
602602
let sign = keystore.sr25519_vrf_sign(AuthorityId::ID, &public, &data).unwrap().unwrap();
603603
assert_eq!(fixed_epoch.epoch_index, 11);
604-
assert_eq!(claim.vrf_signature.output, sign.output);
604+
assert_eq!(claim.vrf_signature.pre_output, sign.pre_output);
605605

606606
// Check that correct epoch index has been used if epochs are skipped (secondary VRF)
607607
let slot = Slot::from(100);
@@ -613,7 +613,7 @@ fn claim_vrf_check() {
613613
let data = make_vrf_sign_data(&epoch.randomness.clone(), slot, fixed_epoch.epoch_index);
614614
let sign = keystore.sr25519_vrf_sign(AuthorityId::ID, &public, &data).unwrap().unwrap();
615615
assert_eq!(fixed_epoch.epoch_index, 11);
616-
assert_eq!(pre_digest.vrf_signature.output, sign.output);
616+
assert_eq!(pre_digest.vrf_signature.pre_output, sign.pre_output);
617617
}
618618

619619
// Propose and import a new BABE block on top of the given parent.

substrate/client/consensus/babe/src/verification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn check_primary_header<B: BlockT + Sized>(
185185
.make_bytes::<AUTHORING_SCORE_LENGTH>(
186186
AUTHORING_SCORE_VRF_CONTEXT,
187187
&data.as_ref(),
188-
&pre_digest.vrf_signature.output,
188+
&pre_digest.vrf_signature.pre_output,
189189
)
190190
.map(u128::from_le_bytes)
191191
.map_err(|_| babe_err(Error::VrfVerificationFailed))?;

substrate/client/keystore/src/local.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ impl LocalKeystore {
120120
Ok(sig)
121121
}
122122

123-
fn vrf_output<T: CorePair + VrfSecret>(
123+
fn vrf_pre_output<T: CorePair + VrfSecret>(
124124
&self,
125125
key_type: KeyTypeId,
126126
public: &T::Public,
127127
input: &T::VrfInput,
128-
) -> std::result::Result<Option<T::VrfOutput>, TraitError> {
129-
let preout = self
128+
) -> std::result::Result<Option<T::VrfPreOutput>, TraitError> {
129+
let pre_output = self
130130
.0
131131
.read()
132132
.key_pair_by_type::<T>(public, key_type)?
133-
.map(|pair| pair.vrf_output(input));
134-
Ok(preout)
133+
.map(|pair| pair.vrf_pre_output(input));
134+
Ok(pre_output)
135135
}
136136
}
137137

@@ -188,13 +188,13 @@ impl Keystore for LocalKeystore {
188188
self.vrf_sign::<sr25519::Pair>(key_type, public, data)
189189
}
190190

191-
fn sr25519_vrf_output(
191+
fn sr25519_vrf_pre_output(
192192
&self,
193193
key_type: KeyTypeId,
194194
public: &sr25519::Public,
195195
input: &sr25519::vrf::VrfInput,
196-
) -> std::result::Result<Option<sr25519::vrf::VrfOutput>, TraitError> {
197-
self.vrf_output::<sr25519::Pair>(key_type, public, input)
196+
) -> std::result::Result<Option<sr25519::vrf::VrfPreOutput>, TraitError> {
197+
self.vrf_pre_output::<sr25519::Pair>(key_type, public, input)
198198
}
199199

200200
fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public> {
@@ -293,13 +293,13 @@ impl Keystore for LocalKeystore {
293293
self.vrf_sign::<bandersnatch::Pair>(key_type, public, data)
294294
}
295295

296-
fn bandersnatch_vrf_output(
296+
fn bandersnatch_vrf_pre_output(
297297
&self,
298298
key_type: KeyTypeId,
299299
public: &bandersnatch::Public,
300300
input: &bandersnatch::vrf::VrfInput,
301-
) -> std::result::Result<Option<bandersnatch::vrf::VrfOutput>, TraitError> {
302-
self.vrf_output::<bandersnatch::Pair>(key_type, public, input)
301+
) -> std::result::Result<Option<bandersnatch::vrf::VrfPreOutput>, TraitError> {
302+
self.vrf_pre_output::<bandersnatch::Pair>(key_type, public, input)
303303
}
304304

305305
fn bandersnatch_ring_vrf_sign(

substrate/frame/babe/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,11 @@ pub mod pallet {
384384
});
385385

386386
public
387-
.make_bytes(RANDOMNESS_VRF_CONTEXT, &transcript, &signature.output)
387+
.make_bytes(
388+
RANDOMNESS_VRF_CONTEXT,
389+
&transcript,
390+
&signature.pre_output,
391+
)
388392
.ok()
389393
});
390394

substrate/frame/sassafras/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ pub mod pallet {
272272
#[pallet::storage]
273273
pub type RingVerifierData<T: Config> = StorageValue<_, vrf::RingVerifierData>;
274274

275-
/// Slot claim vrf-preoutput used to generate per-slot randomness.
275+
/// Slot claim VRF pre-output used to generate per-slot randomness.
276276
///
277277
/// The value is ephemeral and is cleared on block finalization.
278278
#[pallet::storage]
279-
pub(crate) type ClaimTemporaryData<T> = StorageValue<_, vrf::VrfOutput>;
279+
pub(crate) type ClaimTemporaryData<T> = StorageValue<_, vrf::VrfPreOutput>;
280280

281281
/// Genesis configuration for Sassafras protocol.
282282
#[pallet::genesis_config]
@@ -324,12 +324,12 @@ pub mod pallet {
324324
Self::post_genesis_initialize(claim.slot);
325325
}
326326

327-
let randomness_output = claim
327+
let randomness_pre_output = claim
328328
.vrf_signature
329-
.outputs
329+
.pre_outputs
330330
.get(0)
331-
.expect("Valid claim must have vrf signature; qed");
332-
ClaimTemporaryData::<T>::put(randomness_output);
331+
.expect("Valid claim must have VRF signature; qed");
332+
ClaimTemporaryData::<T>::put(randomness_pre_output);
333333

334334
let trigger_weight = T::EpochChangeTrigger::trigger::<T>(block_num);
335335

@@ -346,9 +346,9 @@ pub mod pallet {
346346
CurrentSlot::<T>::get(),
347347
EpochIndex::<T>::get(),
348348
);
349-
let randomness_output = ClaimTemporaryData::<T>::take()
349+
let randomness_pre_output = ClaimTemporaryData::<T>::take()
350350
.expect("Unconditionally populated in `on_initialize`; `on_finalize` is always called after; qed");
351-
let randomness = randomness_output
351+
let randomness = randomness_pre_output
352352
.make_bytes::<RANDOMNESS_LENGTH>(RANDOMNESS_VRF_CONTEXT, &randomness_input);
353353
Self::deposit_slot_randomness(&randomness);
354354

@@ -422,15 +422,15 @@ pub mod pallet {
422422
for ticket in tickets {
423423
debug!(target: LOG_TARGET, "Checking ring proof");
424424

425-
let Some(ticket_id_output) = ticket.signature.outputs.get(0) else {
426-
debug!(target: LOG_TARGET, "Missing ticket vrf output from ring signature");
425+
let Some(ticket_id_pre_output) = ticket.signature.pre_outputs.get(0) else {
426+
debug!(target: LOG_TARGET, "Missing ticket VRF pre-output from ring signature");
427427
continue
428428
};
429429
let ticket_id_input =
430430
vrf::ticket_id_input(&randomness, ticket.body.attempt_idx, epoch_idx);
431431

432432
// Check threshold constraint
433-
let ticket_id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_output);
433+
let ticket_id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_pre_output);
434434
if ticket_id >= ticket_threshold {
435435
debug!(target: LOG_TARGET, "Ignoring ticket over threshold ({:032x} >= {:032x})", ticket_id, ticket_threshold);
436436
continue

substrate/frame/sassafras/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ pub fn make_ticket_body(attempt_idx: u32, pair: &AuthorityPair) -> (TicketId, Ti
190190
let randomness = Sassafras::next_randomness();
191191

192192
let ticket_id_input = vrf::ticket_id_input(&randomness, attempt_idx, epoch);
193-
let ticket_id_output = pair.as_inner_ref().vrf_output(&ticket_id_input);
193+
let ticket_id_pre_output = pair.as_inner_ref().vrf_pre_output(&ticket_id_input);
194194

195-
let id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_output);
195+
let id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_pre_output);
196196

197197
// Make a dummy ephemeral public that hopefully is unique within one test instance.
198198
// In the tests, the values within the erased public are just used to compare

substrate/primitives/consensus/babe/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sp_std::vec::Vec;
3333
use crate::digests::{NextConfigDescriptor, NextEpochDescriptor};
3434

3535
pub use sp_core::sr25519::vrf::{
36-
VrfInput, VrfOutput, VrfProof, VrfSignData, VrfSignature, VrfTranscript,
36+
VrfInput, VrfPreOutput, VrfProof, VrfSignData, VrfSignature, VrfTranscript,
3737
};
3838

3939
/// Key type for BABE module.

substrate/primitives/consensus/sassafras/src/vrf.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
//! Utilities related to VRF input, output and signatures.
18+
//! Utilities related to VRF input, pre-output and signatures.
1919
2020
use crate::{Randomness, TicketBody, TicketId};
2121
use scale_codec::Encode;
@@ -24,7 +24,7 @@ use sp_std::vec::Vec;
2424

2525
pub use sp_core::bandersnatch::{
2626
ring_vrf::{RingProver, RingVerifier, RingVerifierData, RingVrfSignature},
27-
vrf::{VrfInput, VrfOutput, VrfSignData, VrfSignature},
27+
vrf::{VrfInput, VrfPreOutput, VrfSignData, VrfSignature},
2828
};
2929

3030
/// Ring VRF domain size for Sassafras consensus.
@@ -90,21 +90,21 @@ pub fn ticket_body_sign_data(ticket_body: &TicketBody, ticket_id_input: VrfInput
9090
)
9191
}
9292

93-
/// Make ticket-id from the given VRF input and output.
93+
/// Make ticket-id from the given VRF input and pre-output.
9494
///
9595
/// Input should have been obtained via [`ticket_id_input`].
96-
/// Output should have been obtained from the input directly using the vrf secret key
97-
/// or from the vrf signature outputs.
98-
pub fn make_ticket_id(input: &VrfInput, output: &VrfOutput) -> TicketId {
99-
let bytes = output.make_bytes::<16>(b"ticket-id", input);
96+
/// Pre-output should have been obtained from the input directly using the vrf
97+
/// secret key or from the vrf signature pre-outputs.
98+
pub fn make_ticket_id(input: &VrfInput, pre_output: &VrfPreOutput) -> TicketId {
99+
let bytes = pre_output.make_bytes::<16>(b"ticket-id", input);
100100
u128::from_le_bytes(bytes)
101101
}
102102

103-
/// Make revealed key seed from a given VRF input and ouput.
103+
/// Make revealed key seed from a given VRF input and pre-ouput.
104104
///
105105
/// Input should have been obtained via [`revealed_key_input`].
106-
/// Output should have been obtained from the input directly using the vrf secret key
107-
/// or from the vrf signature outputs.
108-
pub fn make_revealed_key_seed(input: &VrfInput, output: &VrfOutput) -> [u8; 32] {
109-
output.make_bytes::<32>(b"revealed-seed", input)
106+
/// Pre-output should have been obtained from the input directly using the vrf
107+
/// secret key or from the vrf signature pre-outputs.
108+
pub fn make_revealed_key_seed(input: &VrfInput, pre_output: &VrfPreOutput) -> [u8; 32] {
109+
pre_output.make_bytes::<32>(b"revealed-seed", input)
110110
}

0 commit comments

Comments
 (0)