Safrole State Transition Function

Overview

The Safrole State Transition Function (STF) defines how the protocol state evolves with each block. It handles four main types of transitions: |

1. Timekeeping

Updates the timeslot index (τ) based on the block header timestamp:

\[\tau' \equiv H_t\]

2. Entropy Accumulation

Updates the entropy (η₀) by incorporating VRF outputs from block headers:

\[\eta'_0 \equiv \mathcal{H}(\eta_0 \| \text{VRF}_{\text{output}}(H_v))\]

3. Ticket Processing

Handles ticket extrinsics in each block:

  • Validates ticket entries (entry index, VRF signature)

  • Verifies tickets are not duplicated

  • Ensures proper ordering by VRF output

  • Accumulates valid tickets into state:

\[\gamma'_a \equiv sorted(\gamma_a \cup \{\text{new valid tickets}\})\]

4. Epoch Transitions

Manages state updates at epoch boundaries:

  • Rotates validator keys:

\[(\gamma'_k, \kappa', \lambda') \equiv (\Phi(\iota), \gamma_k, \kappa)\]

where \(\Phi(\iota)\) filters out offenders from the new validator set.

  • Updates entropy values:

\[(\eta'_1, \eta'_2, \eta'_3) \equiv (\eta_0, \eta_1, \eta_2)\]
  • Updates slot sealing keys based on conditions:

\[\begin{split}\gamma'_s \equiv \begin{cases} Z(\gamma_a) & \text{if } e' = e + 1 \text{ and } m \geq Y \\\\ \gamma_s & \text{if } e' = e \\\\ F(\eta'_2, \kappa') & \text{otherwise} \end{cases}\end{split}\]
  • Computes new ring root from validator set:

\[\gamma_z \equiv O(k_b \text{ for } k \in \gamma'_k) \text{ (sorted by } k_b)\]

API Reference

class jam.consensus.safrole.safrole.Safrole[source]

Bases: object

static verify_vrf(message, proof) bool[source]
static compute_ring_root(keys: List[ByteArray32]) ByteArray32[source]
static vrf_output(proof) ByteArray32[source]
static transition(pre_state: State, block: Block) State[source]
static ensure_valid_ticket_extrinsics(block: Block)[source]

Ensures the tickets submitted via the extrinsic are valid.

static ensure_tickets_order(tickets: TicketsExtrinsic)[source]

Ensures the tickets submitted via the extrinsic must already have been placed in order of their implied identifier. https://graypaper.fluffylabs.dev/#/5b732de/0fc7000fc800

static ensure_valid_vrf(ticket: TicketEnvelope)[source]

Signature must be valid Ring-VRF proof

static ensure_valid_attempt(ticket: TicketEnvelope)[source]

Entry index should be a natural number less than N https://graypaper.fluffylabs.dev/#/5b732de/0f22000f2400

static arrange_fallback(entropy: Bytes, validators: Kappa) GammaSFallback[source]

This function is to be called in case the ticketing system fails to accumulate valid tickeys. :param Etn`2 - Upcoming eta2 or current eta1: :param Kappa - List of current validators:

Returns:

GammaSFallback - Set of Bandersnatch keys