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

RANDAO reveal slashing, custody period staggering and integration of custody and RANDAO reveals #880

Merged
merged 46 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b7c912c
Add RandaoRevealSlashing for early Randao reveals
dankrad Apr 5, 2019
6d047ab
Merge branch 'dev' into dankrad-patch-1
djrtwo Apr 5, 2019
7255ce6
add some randao reveal slashing tests
djrtwo Apr 5, 2019
dd4dc21
Unifying RANDAO reveal slashing and Custody reveal slashing; implemen…
dankrad Apr 10, 2019
a4ac66b
Fix custody reveal domain
dankrad Apr 10, 2019
414a706
Also test exposed_randao_reveals
dankrad Apr 10, 2019
9c3b412
Merge remote-tracking branch 'origin/dev' into dankrad-patch-1
dankrad Apr 15, 2019
cc3c900
Re-add exposed_randao_reveals to validator initialization
dankrad Apr 15, 2019
b42f9aa
Fix tests
dankrad Apr 15, 2019
38c09d7
Unified Randao Reveal slashing mechanism and Custody Reveal,
dankrad Apr 15, 2019
405e8c0
Move exposed_randao_reveals into separate data structure to keep vali…
dankrad Apr 16, 2019
4565b45
new shiny staggered custody periods
CarlBeek Apr 16, 2019
8890926
Fixes style and type hinting
CarlBeek Apr 16, 2019
13e6adf
removes whitespace
CarlBeek Apr 16, 2019
402f8fa
Cleans up multi-line conditionals
CarlBeek Apr 16, 2019
c9d8be0
Make RANDAO key reveal penalties proportional to block rewards
dankrad Apr 16, 2019
0bdd969
Minor typos
CarlBeek Apr 16, 2019
9c5de4d
Minor typos
CarlBeek Apr 16, 2019
1bf310c
Fixes off-by one error
CarlBeek Apr 16, 2019
93611de
Removes unnecicary whitepsace
CarlBeek Apr 16, 2019
92864ef
Merge branch 'dev' into carl-patch-0
CarlBeek Apr 16, 2019
6fc2a7c
Clean up comments; add test for key reveal too far in the future
dankrad Apr 16, 2019
f0edc47
Merge remote-tracking branch 'origin/dev' into dankrad-patch-1
dankrad Apr 16, 2019
35a106d
Reduce the CUSTODY_PERIOD_TO_RANDAO_PADDING again
dankrad Apr 16, 2019
d5b1a00
Fix max_proposer_slot_reward
dankrad Apr 16, 2019
1a42719
Merge remote-tracking branch 'origin/dev' into dankrad-patch-1
dankrad Apr 17, 2019
79b8add
Merge branch 'dev' into dankrad-patch-1
djrtwo Apr 17, 2019
e57bd46
Merge remote-tracking branch 'origin/dev' into dankrad-patch-1
dankrad Apr 27, 2019
2503f7c
Fix types
dankrad Apr 27, 2019
437fea3
Move test
dankrad Apr 27, 2019
e5d0b79
Fix RandaoKeyReveal tests
dankrad Apr 27, 2019
088edc2
Move all RANDAO key reveal to phase 1
dankrad Apr 27, 2019
a410e96
Factor out signature checking
dankrad Apr 27, 2019
4bcf763
Merge remote-tracking branch 'origin/dev' into carl-patch-0
dankrad Apr 29, 2019
d793b07
Merge custody key reveal staggering
dankrad Apr 29, 2019
a7bc5c0
Some fixes
dankrad Apr 29, 2019
a24304a
Update specs/core/1_custody-game.md
vbuterin Apr 30, 2019
8148ce6
Addressing Vitalik's suggestions: Separate RANDAO and Custody key rev…
dankrad Apr 30, 2019
2572171
Remove remnants of verify_custody_key
dankrad Apr 30, 2019
bb0d840
RandaoKeyReveal -> EarlyDerivedSecretReveal
dankrad Apr 30, 2019
ef52ad7
Make penalty proportional to number of secrets already exposed
dankrad Apr 30, 2019
79956a8
Merge remote-tracking branch 'origin/dev' into dankrad-patch-1
dankrad May 3, 2019
33eb63c
Update specs/core/1_custody-game.md
CarlBeek May 3, 2019
a57c476
Update specs/core/1_custody-game.md
CarlBeek May 3, 2019
054128e
Update specs/core/1_custody-game.md
CarlBeek May 3, 2019
ffded82
Merge remote-tracking branch 'origin/dev' into dankrad-patch-1
dankrad May 3, 2019
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
104 changes: 101 additions & 3 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [Beacon operations](#beacon-operations)
- [`ProposerSlashing`](#proposerslashing)
- [`AttesterSlashing`](#attesterslashing)
- [`RandaoKeyReveal`](#RandaoKeyReveal)
dankrad marked this conversation as resolved.
Show resolved Hide resolved
- [`Attestation`](#attestation)
- [`Deposit`](#deposit)
- [`VoluntaryExit`](#voluntaryexit)
Expand Down Expand Up @@ -133,6 +134,7 @@
- [Operations](#operations)
- [Proposer slashings](#proposer-slashings)
- [Attester slashings](#attester-slashings)
- [Randao reveal slashings](#randao-reveal-slashings)
- [Attestations](#attestations)
- [Deposits](#deposits)
- [Voluntary exits](#voluntary-exits)
Expand Down Expand Up @@ -234,6 +236,9 @@ These configurations are updated for releases, but may be out of sync during `de
| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | epochs | ~27 hours |
| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | epochs | 9 days |
| `MAX_CROSSLINK_EPOCHS` | `2**6` (= 64) | epochs | ~7 hours |
| `RANDAO_PENALTY_EPOCHS` | `2` | epochs | 12.8 minutes |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting here is inconsistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now in 1_custody-game -- looks consistent to me? What is the problem?

| `EPOCHS_PER_CUSTODY_PERIOD` | `2**11` (= 2,048) | epochs | ~9 days |
| `CUSTODY_PERIOD_TO_RANDAO_PADDING` | `2**11` (= 2,048) | epochs | ~9 days |

* `MAX_CROSSLINK_EPOCHS` should be a small constant times `SHARD_COUNT // SLOTS_PER_EPOCH`

Expand All @@ -254,6 +259,7 @@ These configurations are updated for releases, but may be out of sync during `de
| `PROPOSER_REWARD_QUOTIENT` | `2**3` (= 8) |
| `INACTIVITY_PENALTY_QUOTIENT` | `2**24` (= 16,777,216) |
| `MIN_PENALTY_QUOTIENT` | `2**5` (= 32) |
| `RANDAO_REVEAL_PENALTY_QUOTIENT` | `2**7` (= 128) |

* The `BASE_REWARD_QUOTIENT` parameter dictates the per-epoch reward. It corresponds to ~2.54% annual interest assuming 10 million participating ETH in every epoch.
* The `INACTIVITY_PENALTY_QUOTIENT` equals `INVERSE_SQRT_E_DROP_TIME**2` where `INVERSE_SQRT_E_DROP_TIME := 2**12 epochs` (~18 days) is the time it takes the inactivity penalty to reduce the balance of non-participating [validators](#dfn-validator) to about `1/sqrt(e) ~= 60.6%`. Indeed, the balance retained by offline [validators](#dfn-validator) after `n` epochs is about `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(n**2/2)` so after `INVERSE_SQRT_E_DROP_TIME` epochs it is roughly `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(INACTIVITY_PENALTY_QUOTIENT/2) ~= 1/sqrt(e)`.
Expand All @@ -264,6 +270,7 @@ These configurations are updated for releases, but may be out of sync during `de
| - | - |
| `MAX_PROPOSER_SLASHINGS` | `2**4` (= 16) |
| `MAX_ATTESTER_SLASHINGS` | `2**0` (= 1) |
| `MAX_RANDAO_KEY_REVEALS` | `2**4` (= 16) |
| `MAX_ATTESTATIONS` | `2**7` (= 128) |
| `MAX_DEPOSITS` | `2**4` (= 16) |
| `MAX_VOLUNTARY_EXITS` | `2**4` (= 16) |
Expand Down Expand Up @@ -426,7 +433,9 @@ The types are defined topologically to aid in facilitating an executable version
# Was the validator slashed
'slashed': 'bool',
# Rounded balance
'high_balance': 'uint64'
'high_balance': 'uint64',
# Future RANDAO reveals already exposed
'exposed_randao_reveals': ['uint64'],
}
```

Expand Down Expand Up @@ -482,6 +491,18 @@ The types are defined topologically to aid in facilitating an executable version
}
```

#### `RandaoKeyReveal`

```python
{
'revealer_index': ValidatorIndex,
'epoch': 'uint64',
'reveal': 'bytes96',
'masker_index': ValidatorIndex,
'mask': 'bytes32',
}
```

#### `Attestation`

```python
Expand Down Expand Up @@ -539,7 +560,7 @@ The types are defined topologically to aid in facilitating an executable version
'slot': 'uint64',
# Sender withdrawal pubkey
'pubkey': 'bytes48',
# Sender signature
# Sender signaturerandao_key_reveals
dankrad marked this conversation as resolved.
Show resolved Hide resolved
'signature': 'bytes96',
}
```
Expand All @@ -554,6 +575,7 @@ The types are defined topologically to aid in facilitating an executable version
'eth1_data': Eth1Data,
'proposer_slashings': [ProposerSlashing],
'attester_slashings': [AttesterSlashing],
'randao_key_reveals': [RandaoKeyReveal],
'attestations': [Attestation],
'deposits': [Deposit],
'voluntary_exits': [VoluntaryExit],
Expand Down Expand Up @@ -1429,6 +1451,7 @@ def get_empty_block() -> BeaconBlock:
),
proposer_slashings=[],
attester_slashings=[],
randao_key_reveals=[],
attestations=[],
deposits=[],
voluntary_exits=[],
Expand Down Expand Up @@ -2021,6 +2044,12 @@ def finish_epoch_update(state: BeaconState) -> None:
# Rotate current/previous epoch attestations
state.previous_epoch_attestations = state.current_epoch_attestations
state.current_epoch_attestations = []

# Clean up exposed RANDAO reveals
for index, validator in enumerate(state.validator_registry):
for reveal_index, reveal_epoch in enumerate(validator.exposed_randao_reveals):
if reveal_epoch <= current_epoch:
del validator.exposed_randao_reveals[reveal_index]
```

### Per-slot processing
Expand Down Expand Up @@ -2161,6 +2190,74 @@ def process_attester_slashing(state: BeaconState,
slash_validator(state, index)
```

##### Custody key reveals

Placeholder for phase 1

dankrad marked this conversation as resolved.
Show resolved Hide resolved

```python
def process_custody_reveal(state: BeaconState,
reveal: RandaoKeyReveal) -> None:
assert False
```

##### Randao key reveals

Verify that `len(block.body.randao_key_reveals) <= MAX_RANDAO_KEY_REVEALS`.

For each `randao_key_reveal` in `block.body.randao_key_reveal`, run the following function:

```python
def process_randao_key_reveal(state: BeaconState,
randao_key_reveal: RandaoKeyReveal) -> None:
"""
Process ``RandaoKeyReveal`` operation.
Note that this function mutates ``state``.
"""
if randao_key_reveal.mask == ZERO_HASH:
process_custody_reveal(state, randao_key_reveal)

revealer = state.validator_registry[randao_key_reveal.revealer_index]
masker = state.validator_registry[randao_key_reveal.masker_index]
pubkeys = [revealer.pubkey, masker.pubkey]
message_hashes = [
hash_tree_root(randao_key_reveal.epoch),
randao_key_reveal.mask,
]

assert randao_key_reveal.epoch >= get_current_epoch(state) + RANDAO_PENALTY_EPOCHS
assert revealer.slashed is False
assert randao_key_reveal.epoch not in state.validator_registry[randao_key_reveal.revealer_index].exposed_randao_reveals

assert bls_verify_multiple(
dankrad marked this conversation as resolved.
Show resolved Hide resolved
pubkeys=pubkeys,
message_hashes=message_hashes,
signature=randao_key_reveal.reveal,
domain=get_domain(
fork=state.fork,
epoch=randao_key_reveal.epoch,
domain_type=DOMAIN_RANDAO,
),
)

if randao_key_reveal.epoch >= get_current_epoch(state) + CUSTODY_PERIOD_TO_RANDAO_PADDING:
# Replacement for custody reveal slashing
slash_validator(state, randao_key_reveal.revealer_index, randao_key_reveal.masker_index)
else:
# Only a small penalty for RANDAO reveal that does not interfere with the custody period
penalty = get_effective_balance(state, randao_key_reveal.revealer_index) // RANDAO_REVEAL_PENALTY_QUOTIENT
proposer_index = get_beacon_proposer_index(state, state.slot)
dankrad marked this conversation as resolved.
Show resolved Hide resolved
whistleblower_index = randao_key_reveal.masker_index
whistleblowing_reward = penalty // WHISTLEBLOWING_REWARD_QUOTIENT
proposer_reward = whistleblowing_reward // PROPOSER_REWARD_QUOTIENT
increase_balance(state, proposer_index, proposer_reward)
increase_balance(state, whistleblower_index, whistleblowing_reward - proposer_reward)
decrease_balance(state, randao_key_reveal.revealer_index, penalty)
state.validator_registry[randao_key_reveal.revealer_index].exposed_randao_reveals.append(randao_key_reveal.epoch)


dankrad marked this conversation as resolved.
Show resolved Hide resolved
```

##### Attestations

Verify that `len(block.body.attestations) <= MAX_ATTESTATIONS`.
Expand Down Expand Up @@ -2272,7 +2369,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
exit_epoch=FAR_FUTURE_EPOCH,
withdrawable_epoch=FAR_FUTURE_EPOCH,
slashed=False,
high_balance=0
high_balance=0,
exposed_randao_reveals=[],
)

# Note: In phase 2 registry indices that have been withdrawn for a long time will be recycled.
Expand Down
73 changes: 23 additions & 50 deletions specs/core/1_custody-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
- [`CustodyChunkChallengeRecord`](#custodychunkchallengerecord)
- [`CustodyBitChallengeRecord`](#custodybitchallengerecord)
- [`CustodyResponse`](#custodyresponse)
- [`CustodyKeyReveal`](#custodykeyreveal)
- [Phase 0 container updates](#phase-0-container-updates)
- [`Validator`](#validator)
- [`BeaconState`](#beaconstate)
Expand Down Expand Up @@ -76,7 +75,6 @@ This document details the beacon chain additions and changes in Phase 1 of Ether
| Name | Value | Unit | Duration |
| - | - | :-: | :-: |
| `MAX_CHUNK_CHALLENGE_DELAY` | `2**11` (= 2,048) | epochs | ~9 days |
| `EPOCHS_PER_CUSTODY_PERIOD` | `2**11` (= 2,048) | epochs | ~9 days |
| `CUSTODY_RESPONSE_DEADLINE` | `2**14` (= 16,384) | epochs | ~73 days |

### Max operations per block
Expand All @@ -92,8 +90,7 @@ This document details the beacon chain additions and changes in Phase 1 of Ether

| Name | Value |
| - | - |
| `DOMAIN_CUSTODY_KEY_REVEAL` | `6` |
| `DOMAIN_CUSTODY_BIT_CHALLENGE` | `7` |
| `DOMAIN_CUSTODY_BIT_CHALLENGE` | `6` |

## Data structures

Expand Down Expand Up @@ -161,18 +158,6 @@ This document details the beacon chain additions and changes in Phase 1 of Ether
}
```

#### `CustodyKeyReveal`

```python
{
'revealer_index': ValidatorIndex,
'period': 'uint64',
'key': BLSSignature,
'masker_index': ValidatorIndex,
dankrad marked this conversation as resolved.
Show resolved Hide resolved
'mask': Hash,
}
```

### Phase 0 container updates

Add the following fields to the end of the specified container objects. Fields with underlying type `uint64` are initialized to `0` and list fields are initialized to `[]`.
Expand All @@ -195,7 +180,6 @@ Add the following fields to the end of the specified container objects. Fields w
#### `BeaconBlockBody`

```python
'custody_key_reveals': [CustodyKeyReveal],
'custody_chunk_challenges': [CustodyChunkChallenge],
'custody_bit_challenges': [CustodyBitChallenge],
'custody_responses': [CustodyResponse],
Expand Down Expand Up @@ -229,30 +213,29 @@ def epoch_to_custody_period(epoch: Epoch) -> int:
return epoch // EPOCHS_PER_CUSTODY_PERIOD
```

### `get_randao_epoch_for_custody_period`

```python
def get_randao_epoch_for_custody_period(period: int) -> Epoch:
return period * EPOCHS_PER_CUSTODY_PERIOD + CUSTODY_PERIOD_TO_RANDAO_PADDING
```

### `verify_custody_key`

```python
def verify_custody_key(state: BeaconState, reveal: CustodyKeyReveal) -> bool:
# Case 1: non-masked non-punitive non-early reveal
def verify_custody_key(state: BeaconState, reveal: RandaoKeyReveal) -> bool:
epoch_to_sign = get_randao_epoch_for_custody_period(reveal.period)
pubkeys = [state.validator_registry[reveal.revealer_index].pubkey]
message_hashes = [hash_tree_root(reveal.period)]

# Case 2: masked punitive early reveal
# Masking prevents proposer stealing the whistleblower reward
# Secure under the aggregate extraction infeasibility assumption
# See pages 11-12 of https://crypto.stanford.edu/~dabo/pubs/papers/aggreg.pdf
if reveal.mask != ZERO_HASH:
pubkeys.append(state.validator_registry[reveal.masker_index].pubkey)
message_hashes.append(reveal.mask)
message_hashes = [hash_tree_root(epoch_to_sign)]

return bls_verify_multiple(
pubkeys=pubkeys,
message_hashes=message_hashes,
signature=reveal.key,
domain=get_domain(
fork=state.fork,
epoch=reveal.period * EPOCHS_PER_CUSTODY_PERIOD,
domain_type=DOMAIN_CUSTODY_KEY_REVEAL,
epoch=epoch_to_sign * EPOCHS_PER_CUSTODY_PERIOD,
domain_type=DOMAIN_RANDAO,
),
)
```
Expand All @@ -265,32 +248,22 @@ Add the following operations to the per-block processing, in order the given bel

#### Custody reveals

Verify that `len(block.body.custody_key_reveals) <= MAX_CUSTODY_KEY_REVEALS`.

For each `reveal` in `block.body.custody_key_reveals`, run the following function:
Replace process_custody_reveal from phase 0 with this function:

```python
def process_custody_reveal(state: BeaconState,
reveal: CustodyKeyReveal) -> None:
reveal: RandaoKeyReveal) -> None:
assert verify_custody_key(state, reveal)
dankrad marked this conversation as resolved.
Show resolved Hide resolved
revealer = state.validator_registry[reveal.revealer_index]
current_custody_period = epoch_to_custody_period(get_current_epoch(state))

# Case 1: non-masked non-punitive non-early reveal
if reveal.mask == ZERO_HASH:
assert reveal.period == epoch_to_custody_period(revealer.activation_epoch) + revealer.custody_reveal_index
# Revealer is active or exited
assert is_active_validator(revealer, get_current_epoch(state)) or revealer.exit_epoch > get_current_epoch(state)
revealer.custody_reveal_index += 1
revealer.max_reveal_lateness = max(revealer.max_reveal_lateness, current_custody_period - reveal.period)
proposer_index = get_beacon_proposer_index(state, state.slot)
increase_balance(state, proposer_index, base_reward(state, index) // MINOR_REWARD_QUOTIENT)

# Case 2: masked punitive early reveal
else:
assert reveal.period > current_custody_period
assert revealer.slashed is False
slash_validator(state, reveal.revealer_index, reveal.masker_index)
assert reveal.period == epoch_to_custody_period(revealer.activation_epoch) + revealer.custody_reveal_index
# Revealer is active or exited
assert is_active_validator(revealer, get_current_epoch(state)) or revealer.exit_epoch > get_current_epoch(state)
revealer.custody_reveal_index += 1
revealer.max_reveal_lateness = max(revealer.max_reveal_lateness, current_custody_period - reveal.period)
proposer_index = get_beacon_proposer_index(state, state.slot)
increase_balance(state, proposer_index, base_reward(state, index) // MINOR_REWARD_QUOTIENT)
```

#### Chunk challenges
Expand Down Expand Up @@ -368,7 +341,7 @@ def process_bit_challenge(state: BeaconState,
assert record.challenger_index != challenge.challenger_index
assert record.responder_index != challenge.responder_index
# Verify the responder key
assert verify_custody_key(state, CustodyKeyReveal(
assert verify_custody_key(state, RandaoKeyReveal(
revealer_index=challenge.responder_index,
period=epoch_to_custody_period(slot_to_epoch(attestation.data.slot)),
key=challenge.responder_key,
Expand Down
Loading