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

Upgrade to a model based on bellatrix #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A modular dynamical-systems model of Ethereum's validator economics, based on the open-source Python library [radCAD](https://github.com/CADLabs/radCAD), an extension to [cadCAD](https://cadcad.org).

* Latest model release version: [Subgraph / v1.1.7](https://github.com/CADLabs/ethereum-economic-model/releases/tag/v1.1.7)
* Implements the official Ethereum [Altair](https://github.com/ethereum/eth2.0-specs#altair) spec updates in the [Blue Loop / v1.1.0-alpha.7](https://github.com/ethereum/eth2.0-specs/releases/tag/v1.1.0-alpha.7) release
* Implements the official Ethereum [Bellatrix](https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix) spec updates in the [Ailuropoda melanoleuca / v1.2.0](https://github.com/ethereum/consensus-specs/releases/tag/v1.2.0) release

## Table of Contents

Expand Down
8 changes: 4 additions & 4 deletions docs/model/parameters.html
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ <h1 class="title">Module <code>model.parameters</code></h1>
Used to calculate the proportion of the effective balance of the slashed validator
distributed between the whistleblower and the proposer.
&#34;&#34;&#34;
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 6])
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 5])
&#34;&#34;&#34;
Used to calculate the penalty applied for a slashable offence.
&#34;&#34;&#34;
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([2])
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([3])
&#34;&#34;&#34;
Scales the slashing penalty proportional to the total slashings for the current epoch

Expand Down Expand Up @@ -635,11 +635,11 @@ <h2 class="section-title" id="header-classes">Classes</h2>
Used to calculate the proportion of the effective balance of the slashed validator
distributed between the whistleblower and the proposer.
&#34;&#34;&#34;
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 6])
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 5])
&#34;&#34;&#34;
Used to calculate the penalty applied for a slashable offence.
&#34;&#34;&#34;
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([2])
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([3])
&#34;&#34;&#34;
Scales the slashing penalty proportional to the total slashings for the current epoch

Expand Down
36 changes: 24 additions & 12 deletions docs/model/parts/incentives.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,13 @@ <h1 id="proof-of-stake-incentives">Proof of Stake Incentives</h1>
params, substep, state_history, previous_state
) -&gt; typing.Dict[str, Gwei]:
&#34;&#34;&#34;Slashing Policy Function
Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator

Extract from spec:
```python
state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
decrease_balance(state, slashed_index, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX # [Modified in Bellatrix]
decrease_balance(state, slashed_index, slashing_penalty)

# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
Expand All @@ -258,14 +259,17 @@ <h1 id="proof-of-stake-incentives">Proof of Stake Incentives</h1>
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
```

Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings

Extract from spec:
```python
def process_slashings(state: BeaconState) -&gt; None:
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR, total_balance)
adjusted_total_slashing_balance = min(
sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, # [Modified in Bellatrix]
total_balance
)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow
Expand Down Expand Up @@ -605,10 +609,11 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</code></dt>
<dd>
<div class="desc"><p>Slashing Policy Function
Derived from <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator</a></p>
Derived from <a href="https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator">https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator</a></p>
<p>Extract from spec:</p>
<pre><code class="language-python">state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
decrease_balance(state, slashed_index, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX # [Modified in Bellatrix]
decrease_balance(state, slashed_index, slashing_penalty)

# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
Expand All @@ -619,12 +624,15 @@ <h2 class="section-title" id="header-functions">Functions</h2>
increase_balance(state, proposer_index, proposer_reward)
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
</code></pre>
<p>Derived from <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings</a></p>
<p>Derived from <a href="https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings">https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings</a></p>
<p>Extract from spec:</p>
<pre><code class="language-python">def process_slashings(state: BeaconState) -&gt; None:
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR, total_balance)
adjusted_total_slashing_balance = min(
sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, # [Modified in Bellatrix]
total_balance
)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow
Expand All @@ -640,12 +648,13 @@ <h2 class="section-title" id="header-functions">Functions</h2>
params, substep, state_history, previous_state
) -&gt; typing.Dict[str, Gwei]:
&#34;&#34;&#34;Slashing Policy Function
Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator

Extract from spec:
```python
state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
decrease_balance(state, slashed_index, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX # [Modified in Bellatrix]
decrease_balance(state, slashed_index, slashing_penalty)

# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
Expand All @@ -657,14 +666,17 @@ <h2 class="section-title" id="header-functions">Functions</h2>
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
```

Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings

Extract from spec:
```python
def process_slashings(state: BeaconState) -&gt; None:
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR, total_balance)
adjusted_total_slashing_balance = min(
sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, # [Modified in Bellatrix]
total_balance
)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow
Expand Down
36 changes: 24 additions & 12 deletions docs/model/parts/pos_incentives.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,13 @@ <h1 id="proof-of-stake-incentives">Proof of Stake Incentives</h1>
) -&gt; typing.Dict[str, Gwei]:
&#34;&#34;&#34;
## Slashing Policy Function
Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator

Extract from spec:
```python
state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
decrease_balance(state, slashed_index, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX # [Modified in Bellatrix]
decrease_balance(state, slashed_index, slashing_penalty)

# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
Expand All @@ -296,14 +297,17 @@ <h1 id="proof-of-stake-incentives">Proof of Stake Incentives</h1>
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
```

Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings

Extract from spec:
```python
def process_slashings(state: BeaconState) -&gt; None:
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR, total_balance)
adjusted_total_slashing_balance = min(
sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, # [Modified in Bellatrix]
total_balance
)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow
Expand Down Expand Up @@ -670,10 +674,11 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</code></dt>
<dd>
<div class="desc"><h2 id="slashing-policy-function">Slashing Policy Function</h2>
<p>Derived from <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator</a></p>
<p>Derived from <a href="https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator">https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator</a></p>
<p>Extract from spec:</p>
<pre><code class="language-python">state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
decrease_balance(state, slashed_index, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX # [Modified in Bellatrix]
decrease_balance(state, slashed_index, slashing_penalty)

# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
Expand All @@ -684,12 +689,15 @@ <h2 class="section-title" id="header-functions">Functions</h2>
increase_balance(state, proposer_index, proposer_reward)
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
</code></pre>
<p>Derived from <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings</a></p>
<p>Derived from <a href="https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings">https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings</a></p>
<p>Extract from spec:</p>
<pre><code class="language-python">def process_slashings(state: BeaconState) -&gt; None:
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR, total_balance)
adjusted_total_slashing_balance = min(
sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, # [Modified in Bellatrix]
total_balance
)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow
Expand All @@ -706,12 +714,13 @@ <h2 class="section-title" id="header-functions">Functions</h2>
) -&gt; typing.Dict[str, Gwei]:
&#34;&#34;&#34;
## Slashing Policy Function
Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#modified-slash_validator
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#modified-slash_validator

Extract from spec:
```python
state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
decrease_balance(state, slashed_index, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX # [Modified in Bellatrix]
decrease_balance(state, slashed_index, slashing_penalty)

# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
Expand All @@ -723,14 +732,17 @@ <h2 class="section-title" id="header-functions">Functions</h2>
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
```

Derived from https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#slashings
Derived from https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#slashings

Extract from spec:
```python
def process_slashings(state: BeaconState) -&gt; None:
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR, total_balance)
adjusted_total_slashing_balance = min(
sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX, # [Modified in Bellatrix]
total_balance
)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow
Expand Down
2 changes: 2 additions & 0 deletions docs/model/parts/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h1 id="relevant-eth2-spec-methods">Relevant Eth2 Spec Methods</h1>
<ul>
<li>Phase 0: <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md</a></li>
<li>Altair updates: <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md</a></li>
<li>Bellatrix updates: <a href="https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md">https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md</a></li>
</ul>
<details class="source">
<summary>
Expand All @@ -36,6 +37,7 @@ <h1 id="relevant-eth2-spec-methods">Relevant Eth2 Spec Methods</h1>

* Phase 0: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md
* Altair updates: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md
* Bellatrix updates: https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md
&#34;&#34;&#34;

import math
Expand Down
2 changes: 2 additions & 0 deletions docs/model/parts/utils/ethereum_spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h1 class="title">Module <code>model.parts.utils.ethereum_spec</code></h1>
<ul>
<li>Phase 0: <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md</a></li>
<li>Altair updates: <a href="https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md">https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md</a></li>
<li>Bellatrix updates: <a href="https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md">https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md</a></li>
</ul>
<details class="source">
<summary>
Expand All @@ -36,6 +37,7 @@ <h1 class="title">Module <code>model.parts.utils.ethereum_spec</code></h1>

* Phase 0: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md
* Altair updates: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md
* Bellatrix updates: https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md
&#34;&#34;&#34;

import model.constants as constants
Expand Down
8 changes: 4 additions & 4 deletions docs/model/system_parameters.html
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ <h1 class="title">Module <code>model.system_parameters</code></h1>
Used to calculate the proportion of the effective balance of the slashed validator
distributed between the whistleblower and the proposer.
&#34;&#34;&#34;
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 6])
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 5])
&#34;&#34;&#34;
Used to calculate the penalty applied for a slashable offence.
&#34;&#34;&#34;
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([2])
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([3])
&#34;&#34;&#34;
Scales the slashing penalty proportional to the total slashings for the current epoch

Expand Down Expand Up @@ -596,11 +596,11 @@ <h2 class="section-title" id="header-classes">Classes</h2>
Used to calculate the proportion of the effective balance of the slashed validator
distributed between the whistleblower and the proposer.
&#34;&#34;&#34;
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 6])
MIN_SLASHING_PENALTY_QUOTIENT: List[int] = default([2 ** 5])
&#34;&#34;&#34;
Used to calculate the penalty applied for a slashable offence.
&#34;&#34;&#34;
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([2])
PROPORTIONAL_SLASHING_MULTIPLIER: List[int] = default([3])
&#34;&#34;&#34;
Scales the slashing penalty proportional to the total slashings for the current epoch

Expand Down
Loading