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

sp-core: Rename VrfOutput to VrfPreOutput #2534

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
pallet-sassafras: update vrf pre-output
  • Loading branch information
andresilva committed Dec 4, 2023
commit aeacb5ec906af1c6df031fed25199fe6164cd5a9
22 changes: 11 additions & 11 deletions substrate/frame/sassafras/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ pub mod pallet {
#[pallet::storage]
pub type RingVerifierData<T: Config> = StorageValue<_, vrf::RingVerifierData>;

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

/// Genesis configuration for Sassafras protocol.
#[pallet::genesis_config]
Expand Down Expand Up @@ -324,12 +324,12 @@ pub mod pallet {
Self::post_genesis_initialize(claim.slot);
}

let randomness_output = claim
let randomness_pre_output = claim
.vrf_signature
.outputs
.pre_outputs
.get(0)
.expect("Valid claim must have vrf signature; qed");
ClaimTemporaryData::<T>::put(randomness_output);
.expect("Valid claim must have VRF signature; qed");
ClaimTemporaryData::<T>::put(randomness_pre_output);

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

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

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

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

// Check threshold constraint
let ticket_id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_output);
let ticket_id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_pre_output);
if ticket_id >= ticket_threshold {
debug!(target: LOG_TARGET, "Ignoring ticket over threshold ({:032x} >= {:032x})", ticket_id, ticket_threshold);
continue
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/sassafras/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ pub fn make_ticket_body(attempt_idx: u32, pair: &AuthorityPair) -> (TicketId, Ti
let randomness = Sassafras::next_randomness();

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

let id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_output);
let id = vrf::make_ticket_id(&ticket_id_input, &ticket_id_pre_output);

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