Skip to content

Commit

Permalink
fix specs quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jan 10, 2025
1 parent 2c57a2c commit ac3e9b7
Showing 1 changed file with 6 additions and 46 deletions.
52 changes: 6 additions & 46 deletions packages/specs/pages/modules/proof-of-stake/cubic-slashing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,15 @@ The cubic slash rate is a function of all infractions in a given epoch and its n
2. Sum the fractional voting powers (relative to the total voting power of all consensus validators) of the misbehaving validator for each of the collected infractions. {/* The total voting powers include all validators in one of the validator sets and all jailed validators (more on this later). */}
3. The cubic slash rate is then proportional to this sum. Using $\text{vp}_i$ to indicate the validator voting power used to commit the infraction $i$ and $\text{vp}_{\text{tot}}^i$ to indicate the total consensus voting power at the epoch of infraction $i$, the cubic rate is expressed as:

$$ 9*\left(\sum_{i \in \text{infractions}}\frac{\text{vp}_i}{\text{vp}_{\text{tot}}^i}\right)^2. $$
$$
9*\left(\sum_{i \in \text{infractions}}\frac{\text{vp}_i}{\text{vp}_{\text{tot}}^i}\right)^2.
$$

For each individual slash, the rate is ultimately determined as the maximum of the cubic slash rate and some nominal minimum rate that is dependent on the infraction type (see [system parameters](./objects-and-txs.mdx#system-parameters)) and is capped at 1.0. The amount of slashed tokens is the rate multiplied by the stake (voting power) used to commit the infraction. The "cubic" in cubic slashing thus comes from the product of the rate, which is quadratic in the voting power, and the voting power itself.

Expressed in pseudocode:
<Tabs items={['haskell', 'python']}>
<Tab>
```haskell =
calculateSlashRate :: [Slash] -> Float

calculateSlashRate slashes =
let votingPowerFraction = sum [ votingPowerFraction (validator slash) | slash <- slashes]
in max 0.01 (min 1 (votingPowerFraction**2)*9)
-- minimum slash rate is 1%
-- then exponential between 0 & 1/3 voting power
-- we can make this a more complex function later
```
</Tab>
<Tab>
```python
class PoS:
def __init__(self, genesis_validators : list):
self.update_validators(genesis_validators)

def update_validators(self, new_validators):
self.validators = new_validators
self.total_voting_power = sum(validator.voting_power for validator in self.validators)

def slash(self, slashed_validators : list):
for slashed_validator in slashed_validators:
voting_power_fraction = slashed_validator.voting_power / self.total_voting_power
slash_rate = calc_slash_rate(voting_power_fraction)
slashed_validator.voting_power *= (1 - slash_rate)

def get_voting_power(self):
for i in range(min(10, len(self.validators))):
print(self.validators[i])

@staticmethod
def calc_slash_rate(voting_power_fraction):
slash_rate = max(0.01, (voting_power_fraction ** 2) * 9)
return slash_rate
```
</Tab>
</Tabs>


### Rust implementation
Expressed in Rust-like pseudocode:
```rust
// Infraction type, where inner field is the slash rate for the type
enum Infraction {
Expand All @@ -82,7 +43,6 @@ struct Slash {
// Calculate the cubic slash rate for a slash in the current epoch
fn calculate_cubic_slash_rate(
current_epoch: u64,
nominal_slash_rate: Decimal,
cubic_window_width: u64,
slashes: Map<u64, Vec<Slash>>,
total_voting_power: u64
Expand Down

0 comments on commit ac3e9b7

Please sign in to comment.