You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/website/contents/for-developers/PreflightGuide.md
+130Lines changed: 130 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,6 +128,124 @@ Use a ledger snapshot of your local node (make sure to add the `_db-analyser` su
128
128
- Comparing the benchmarking results for block validation times, you should see that validating a typical block takes much longer today.
129
129
This is mainly due to larger allowed block sizes and this size being actually used, as well as more complex ledger rules (most prominently, Plutus smart contracts).
130
130
131
+
## Dynamics of the leader schedule
132
+
133
+
This section focuses on high-level statistical properties of the *leader schedule*[^glossary].
134
+
The definitions and most of the basic properties come from the [Ouroboros Praos paper][], eg section 3.3 and 4.4.
135
+
136
+
### Active slots
137
+
138
+
In our context, time is discretized into slots of a specific slot length.
139
+
(For Praos on Cardano mainnet, a slot lasts for one second.)
140
+
Every slot has a specific number of *leaders*, ie stake pools that are allowed to mint a block in this slot.
141
+
The elections for different slots are independent of each other; leading in one slot does not make it more/less likely to lead in another.
142
+
143
+
- Most slots are *inactive*, ie there are no leaders for these slots.[^praos-origin]
144
+
- Some slots are *active*. The probability of a slot to be active is determined by the *active slot coefficient* $f$. On Cardano mainnet, $f = 1/20$.
145
+
- Most active slots are *single leader slots*.
146
+
- Some active slots are *multi leader slots*. As the slot numbers on a chain have to strictly increase, at most one of the blocks minted by the elected stake pools will end up on the honest chain eventually.[^ssle]
147
+
148
+
The leader schedule of Cardano is *private* due to the usage of *verifiable random functions* (VRFs):
149
+
Nodes only know their own leader schedule for one epoch[^glossary] in advance, and nobody can know whether some pool is elected in a slot until they reveal this themselves by minting a block in that slot.
150
+
The advantage of this approach is that eg targeted DoS attacks against slot leaders are impossible.
151
+
However, it also means that it is generally impossible to retroactively distinguish inactive slots from active slots where nobody minted a block for some reason.
152
+
153
+
Let us apply some common probability distributions to this scenario.
154
+
155
+
- The number of active slots out of a number of slots $n$ follows a binomial distribution $\mathop{\mathrm{B}}(n,f)$.
156
+
This number is often of interest as it bounds by how many blocks any chain can grow in that period.
157
+
158
+
For example, consider the number of active slots on Cardano mainnet within 12h (43200 slots), with the probability mass function also depicted below.
159
+
The mean is $43200 \cdot f = 43200 / 20 = 2160$, note that this is the *security parameter*[^glossary] $k$ that comes up in many places.
160
+
Importantly, the number of active slots is rather strongly concentrated around the mean, which justifies common statements like "Usually, there are $k$ active slots within 12h.".
161
+
162
+
- The number of slots until a slot is active (including that slot) follows a geometric distribution $\mathop{\mathrm{Geo}}(f)$.
163
+
164
+
For Cardano mainnet, the probability mass function is again depicted below.
165
+
The mean here is $1/f = 20$ slots, the median however is only $14$ slots, ie in ~50% of all cases, it takes at most 14 slots until a slot is active.
166
+
On the other hand, there is a non-negligible ~0.2% chance that it takes more than 120 slots (2 minutes) until there is an active slot.
167
+
Concretely, this means that an interval of 2 minutes without any blocks on Cardano mainnet does not mean that anything went wrong; the randomness of the leader schedule means that intervals of inactive slots of this or even somewhat larger duration are bound to happen from time to time.
168
+
169
+
As a generalization, the number of slots until a given number (potentially larger than one) of slots have been active follows a negative binomial distribution.
170
+
171
+

172
+
173
+
> A useful library for various calculations in this areas is [scipy.stats][] (in particular available in sagemath).
174
+
> For example, we can calculate the probability that at most 2000 slots are active within 12h
175
+
> ```python
176
+
>from scipy import stats
177
+
> stats.binom(43200,1/20).cdf(2000)
178
+
>```
179
+
> which yields 0.0185%, or the probability that it takes more than one minute until a slot is active
180
+
>```python
181
+
> stats.geom(1/20).sf(60)
182
+
>```
183
+
> which yields 4.6%.
184
+
> Calculate some other probabilities that seem interesting to you, maybe inspired by some of the empirical data gathered via db-analyser.
185
+
186
+
### Multi leader slots
187
+
188
+
The probability that a pool with relative stake $\sigma$ is elected in any specific slot is given by $\phi_f(\sigma) = \phi(\sigma) = 1-{(1-f)}^\sigma$.
189
+
We have $\phi(\sigma) \ge f\sigma$, ie a pool with stake $\sigma$ will be elected in an active slot with probability somewhat higher than $\sigma$.
190
+
For small $\sigma$, $\phi(\sigma) \approx f\sigma$ is a fine approximation.
191
+
192
+
The motivation for choosing $\phi$ like this is the *independent aggregation* property
Intuitively, this means that for a party with$\sum_{\sigma\in S} \sigma$ total relative stake, no matter how they distribute their stake across different pools, they always have the same probability to be elected with at least one pool in any given slot.
198
+
199
+
Unless there is just a single pool withall of the stake (which is heavily disincentivized by the Cardano reward structure), there is a chance that an active slot will in fact have *multiple* slot leaders.
200
+
The exact probabilities depend on the stake distribution.
201
+
In general, the more equally the stake is distributed across many pools, the more likely are slots with more slot leaders.
202
+
In the extreme case, which one can think of as the stake $\sigma$ being distributed evenly across infinitely many pools, the number of slot leaders $L$ of a single slot is given by a Poisson distribution $\mathop{\mathrm{Pois}}(-\sigma\log(1-f))$.
via the definition of the Poisson distribution and$L \sim \mathop{\mathrm{Pois}}(-\sigma\log(1-f))$.
217
+
For $f=1/20$and$\sigma =1$, we get $\mathop{\mathrm{Pr}}(L \ge 2) = 0.00127$, ie 0.127% of all slots are multi leader slots in the worst case.
218
+
In that case, we would expect to see $10k/f \cdot 0.00127 \approx 549$ multi leader slots per epoch.
219
+
220
+
On the community-maintained [pooltool.io](https://pooltool.io/networkhealth), we can observe the number of "slot battles" per epoch, ie the number of times the nodes reporting to pooltool.io observed two blocks in the same slot.
As the stake on mainnet is"only" distributed across a few thousand pools (andnot completely evenly), we are notin the extreme case modeled by the Poisson described above.
225
+
And indeed, we usually see even less than 500 slot battles per epoch.
226
+
227
+
### Grinding
228
+
229
+
The discussion above completely ignored *grinding*.
230
+
In the context of the leader schedule, this refers to an adversarial influence on the nonce that is used as a seed forall of the VRF computations for slot election within a specific epoch.
231
+
The exact mechanism is out-of-scope for this section, but it should be said that such an attack requires both a considerable amount of stake and computational resources, and it allows an adversary to choose the best out of multiple epoch nonces.
232
+
An extremely conservative upper bound for how many nonces an attacker can choose fromis$10^{20}$ (based on the computational resources required to even compute all of these nonces).
233
+
The mainnet parameters of Cardano (in particular the security parameter) were chosen with resistance against grinding in mind.
234
+
235
+
Concretely, an attacker with$\alpha$ stake that can choose out of $N$ epoch nonces can ensure that it leads any specific slot with probability $1-{(1-\phi(\alpha))}^N$, which is a huge advantage compared to $\phi(\alpha)$.
236
+
For example, an attacker with$N=10^{20}$with even a very small amount of stake has a chance of close to 100% to cause themselves to be elected inany single specific slot.
237
+
238
+
Usually, an attacker wants to maximize their total number of active slots within a larger number of slots, like in an entire epoch.
239
+
For this, the impact of grinding is smaller (but still large), as every epoch nonce affects the entire leader schedule of the epoch, and the attacker can not choose different epoch nonces for different slots.
240
+
Calculations in this area make use of the [largest order statistic][order statistic].
241
+
Here, we plot the cumulative distribution function of the number of active slots without andwith different levels of grinding.
242
+
243
+

244
+
245
+
Grinding does *not* impact the number of elections by any honest party, as an attacker can't observe what the leader schedule of honest nodes would be for different nonces (privacy of the leader schedule).
246
+
247
+
Finally, we shall note that there are various ideas of how to eliminate grinding, for example by making the epoch nonce "difficult" to calculate[^nonce-difficult] or by replacing the current source of the nonce with a special protocol[^nonce-protocol].
248
+
131
249
<!-- Footnotes -->
132
250
133
251
[^other-consensus-consumers]: Other important consumers include:
@@ -162,6 +280,15 @@ This means that certain checks (in particular, evaluating smart contracts) are s
162
280
The node itself will create snapshots without a suffix (eg `4492800`), but can also read snapshots withany suffix.
163
281
Crucially, the node won't ever *delete* snapshots with a suffix, as opposed to unsuffixed ones, which are periodically garbage-collected, as well as deleted if the node can't decode them.
164
282
283
+
[^praos-origin]: The fact that most slots are empty (such that there often are periods of "silence"in the network) motivated the name "Praos", meaning "mellow", or"gentle".
284
+
285
+
[^ssle]: With more sophisticated cryptography, one can avoid multi leader slots and the wasted work they cause, see ["Single Secret Leader election" by Boneh et al](https://eprint.iacr.org/2020/025).
286
+
287
+
[^nonce-difficult]: The core idea isfor example described in the abstract of [the paper introducing *Verifiable Delay Functions* (VDF) by Boneh et al](https://eprint.iacr.org/2018/601.pdf).
288
+
289
+
[^nonce-protocol]: See [the paper "Efficient Random Beacons with Adaptive Security
290
+
for Ungrindable Blockchains" by Kiayias et al](https://eprint.iacr.org/2021/1698.pdf).
0 commit comments