Skip to content

Commit

Permalink
Merge pull request #710 from w3f/bnb/babe-definition-fixes
Browse files Browse the repository at this point in the history
reorganised chapter and corrected definition of VRF transcripts
  • Loading branch information
bhargavbh authored Oct 12, 2023
2 parents 54f2ddf + c133ac9 commit 5b74ac9
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions docs/sect-block-production.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,46 @@ The numbers should be treated as 64-bit rational numbers.
:::
### -sec-num- Primary Block Production Lottery {#id-primary-block-production-lottery}

###### Definition -def-num- BABE Slot VRF transcript, output, and proof {#defn-babe-vrf-transcript}
:::definition

The BABE block production lottery requires a specific transcript structure ([Definition -def-num-ref-](id-cryptography-encoding#defn-vrf-transcript)). That structure is used by both primary slots ([Block-Production-Lottery](sect-block-production#algo-block-production-lottery)) and secondary slots ([Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)).

$$
{t}_{{1}}\leftarrow\text{Transcript}{\left(\text{'BABE'}\right)}
$$
$$
{t}_{{2}}\leftarrow\text{append}{\left({t}_{{1}},\text{'slot number'},{s}\right)}
$$
$$
{t}_{{3}}\leftarrow\text{append}{\left({t}_{{2}},\text{'current epoch'},{e}_{{i}}\right)}
$$
$$
{t}_{{4}}\leftarrow\text{append}{\left({t}_{{3}},\text{'chain randomness'},{r}\right)}
$$
$$
{t}_{{5}}\leftarrow\text{append}{\left({t}_{{4}},\text{'vrf-nm-pk'},{p}_{{k}}\right)}
$$
$$
{t}_{{6}}\leftarrow\text{meta-ad}{\left({t}_{{5}},\text{'VRFHash'},\text{False}\right)}
$$
$$
{t}_{{7}}\leftarrow\text{meta-ad}{\left({t}_{{6}},{64}_{\text{le}},\text{True}\right)}
$$
$$
{h}\leftarrow\text{prf}{\left({t}_{{7}},\text{False}\right)}
$$
$$
{d}={s}_{{k}}\cdot{h}
$$
$$
{\pi}\leftarrow\text{dleq\_prove}{\left({t}_{{7}},{h}\right)}
$$

The operators are defined in [Definition -def-num-ref-](id-cryptography-encoding#defn-strobe-operations), $\text{dleq\_prove}$ in [Definition -def-num-ref-](id-cryptography-encoding#defn-vrf-dleq-prove). The computed outputs, ${d}$ and ${\pi}$, are included in the block Pre-Digest ([Definition -def-num-ref-](sect-block-production#defn-babe-header)).

:::

A block producer aiming to produce a block during ${\mathcal{{E}}}_{{n}}$ should run the $\text{Block-Production-Lottery}$ algorithm to identify the slots it is awarded. These are the slots during which the block producer is allowed to build a block. The session secret key, ${s}{k}$, is the block producer lottery secret key, and ${n}$ is the index of the epoch for whose slots the block producer is running the lottery.

###### Algorithm -algo-num- Block Production Lottery {#algo-block-production-lottery}
Expand All @@ -136,7 +176,6 @@ where $\text{Epoch-Randomness}$ is defined in ([Definition -def-num-ref-](sect-b
:::info
The secondary slots ([Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)) are running alongside the primary block production lottery and mainly serve as a fallback to in case no authority was selected in the primary lottery.
:::

###### Definition -def-num- Secondary Slots {#defn-babe-secondary-slots}
:::definition

Expand All @@ -160,46 +199,7 @@ $$

- ${A}_{{l}}$ is the lengths of the authority list ([Definition -def-num-ref-](chap-sync#defn-authority-list)).

If ${i}_{{d}}$ points to the authority, that authority must claim the secondary slot by creating a BABE VRF transcript ([Definition -def-num-ref-](sect-block-production#defn-babe-vrf-transcript)). The resulting values ${o}$ and ${p}$ are then used in the Pre-Digest item ([Definition -def-num-ref-](sect-block-production#defn-babe-header)). In the case of secondary slots with plain outputs, respectively the Pre-Digest being of value *2*, the transcript respectively the VRF is skipped.

:::
###### Definition -def-num- BABE Slot VRF transcript {#defn-babe-vrf-transcript}
:::definition

The BABE block production lottery requires a specific transcript structure ([Definition -def-num-ref-](id-cryptography-encoding#defn-vrf-transcript)). That structure is used by both primary slots ([Block-Production-Lottery](sect-block-production#algo-block-production-lottery)) and secondary slots ([Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)).

$$
{t}_{{1}}\leftarrow\text{Transcript}{\left(\text{'BABE'}\right)}
$$
$$
{t}_{{2}}\leftarrow\text{append}{\left({t}_{{1}},\text{'slot number'},{s}\right)}
$$
$$
{t}_{{3}}\leftarrow\text{append}{\left({t}_{{2}},\text{'current epoch'},{e}_{{i}}\right)}
$$
$$
{t}_{{4}}\leftarrow\text{append}{\left({t}_{{3}},\text{'chain randomness'},{r}\right)}
$$
$$
{t}_{{5}}\leftarrow\text{append}{\left({t}_{{4}},\text{'vrf-nm-pk'},{p}_{{k}}\right)}
$$
$$
{t}_{{6}}\leftarrow\text{meta-ad}{\left({t}_{{5}},\text{'VRFHash'},\text{False}\right)}
$$
$$
{t}_{{7}}\leftarrow\text{meta-ad}{\left({t}_{{6}},{64}_{\text{le}},\text{True}\right)}
$$
$$
{h}\leftarrow\text{prf}{\left({t}_{{7}},\text{False}\right)}
$$
$$
{o}={s}_{{k}}\cdot{h}
$$
$$
{p}\leftarrow\text{dleq\_prove}{\left({t}_{{7}},{h}\right)}
$$

The operators are defined in [Definition -def-num-ref-](id-cryptography-encoding#defn-strobe-operations), $\text{dleq\_prove}$ in [Definition -def-num-ref-](id-cryptography-encoding#defn-vrf-dleq-prove). The computed outputs, ${o}$ and ${p}$, are included in the block Pre-Digest ([Definition -def-num-ref-](sect-block-production#defn-babe-header)).
If ${i}_{{d}}$ points to the authority, that authority must claim the secondary slot by creating a BABE VRF transcript ([Definition -def-num-ref-](sect-block-production#defn-babe-vrf-transcript)). The resulting values ${d}$ and ${\pi}$ are then used in the Pre-Digest item ([Definition -def-num-ref-](sect-block-production#defn-babe-header)). In the case of secondary slots with plain outputs, respectively the Pre-Digest being of value *2*, the transcript respectively the VRF is skipped.

:::
## -sec-num- Slot Number Calculation {#sect-slot-number-calculation}
Expand Down Expand Up @@ -299,7 +299,7 @@ Throughout each epoch, each block producer should run [Invoke-Block-Authoring](s
The **Pre-Digest**, or BABE header, ${P}$, is a varying datatype of the following format:

$$
{P}={\left\lbrace\begin{matrix}{1}&\rightarrow&{\left({a}_{\text{id}},{s},{o},{p}\right)}\\{2}&\rightarrow&{\left({a}_{\text{id}},{s}\right)}\\{3}&\rightarrow&{\left({a}_{\text{id}},{s},{o},{p}\right)}\end{matrix}\right.}
{P}={\left\lbrace\begin{matrix}{1}&\rightarrow&{\left({a}_{\text{id}},{s},{d},{\pi}\right)}\\{2}&\rightarrow&{\left({a}_{\text{id}},{s}\right)}\\{3}&\rightarrow&{\left({a}_{\text{id}},{s},{d},{\pi}\right)}\end{matrix}\right.}
$$

**where**
Expand All @@ -309,9 +309,9 @@ $$

- ${s}$ is the slot number ([Definition -def-num-ref-](sect-block-production#defn-epoch-slot)).

- ${o}$ is VRF output ([Block-Production-Lottery](sect-block-production#algo-block-production-lottery) respectively [Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)).
- ${d}$ is VRF output ([Block-Production-Lottery](sect-block-production#algo-block-production-lottery) respectively [Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)).

- ${p}$ is VRF proof ([Block-Production-Lottery](sect-block-production#algo-block-production-lottery) respectively [Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)).
- ${\pi}$ is VRF proof ([Block-Production-Lottery](sect-block-production#algo-block-production-lottery) respectively [Definition -def-num-ref-](sect-block-production#defn-babe-secondary-slots)).

The Pre-Digest must be included as a digest item of Pre-Runtime type in the header digest ([Definition -def-num-ref-](chap-state#defn-digest)) ${H}_{{d}}{\left({B}\right)}$.
:::
Expand Down

0 comments on commit 5b74ac9

Please sign in to comment.