Skip to content

Commit

Permalink
consensus specs v1.2.0-rc.1 (#3661)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored May 25, 2022
1 parent dfd8cd2 commit bf1763f
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 68 deletions.
14 changes: 9 additions & 5 deletions ConsensusSpecPreset-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - add_to_activation_queue [Preset: mainnet] OK
+ Registry updates - ejection [Preset: mainnet] OK
+ Registry updates - ejection_past_churn_limit_min [Preset: mainnet] OK
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 10/10 Fail: 0/10 Skip: 0/10
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Altair - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
Expand Down Expand Up @@ -901,8 +902,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - add_to_activation_queue [Preset: mainnet] OK
+ Registry updates - ejection [Preset: mainnet] OK
+ Registry updates - ejection_past_churn_limit_min [Preset: mainnet] OK
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 10/10 Fail: 0/10 Skip: 0/10
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Bellatrix - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
Expand Down Expand Up @@ -962,6 +964,7 @@ OK: 38/38 Fail: 0/38 Skip: 0/38
## EF - ForkChoice [Preset: mainnet]
```diff
+ ForkChoice - mainnet/phase0/fork_choice/get_head/pyspec_tests/chain_no_attestations OK
ForkChoice - mainnet/phase0/fork_choice/get_head/pyspec_tests/discard_equivocations Skip
+ ForkChoice - mainnet/phase0/fork_choice/get_head/pyspec_tests/genesis OK
+ ForkChoice - mainnet/phase0/fork_choice/get_head/pyspec_tests/proposer_boost_correct_head OK
+ ForkChoice - mainnet/phase0/fork_choice/get_head/pyspec_tests/shorter_chain_but_heavier_we OK
Expand All @@ -972,7 +975,7 @@ OK: 38/38 Fail: 0/38 Skip: 0/38
+ ForkChoice - mainnet/phase0/fork_choice/on_block/pyspec_tests/proposer_boost OK
+ ForkChoice - mainnet/phase0/fork_choice/on_block/pyspec_tests/proposer_boost_root_same_slo OK
```
OK: 9/10 Fail: 0/10 Skip: 1/10
OK: 9/11 Fail: 0/11 Skip: 2/11
## EF - Phase 0 - Epoch Processing - Effective balance updates [Preset: mainnet]
```diff
+ Effective balance updates - effective_balance_hysteresis [Preset: mainnet] OK
Expand Down Expand Up @@ -1025,8 +1028,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - add_to_activation_queue [Preset: mainnet] OK
+ Registry updates - ejection [Preset: mainnet] OK
+ Registry updates - ejection_past_churn_limit_min [Preset: mainnet] OK
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 10/10 Fail: 0/10 Skip: 0/10
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Phase 0 - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
Expand Down Expand Up @@ -1220,4 +1224,4 @@ OK: 44/44 Fail: 0/44 Skip: 0/44
OK: 27/27 Fail: 0/27 Skip: 0/27

---TOTAL---
OK: 1035/1038 Fail: 0/1038 Skip: 3/1038
OK: 1038/1042 Fail: 0/1042 Skip: 4/1042
14 changes: 9 additions & 5 deletions ConsensusSpecPreset-minimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - ejection [Preset: minimal] OK
+ Registry updates - ejection_past_churn_limit_min [Preset: minimal] OK
+ Registry updates - ejection_past_churn_limit_scaled [Preset: minimal] OK
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 14/14 Fail: 0/14 Skip: 0/14
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Altair - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
Expand Down Expand Up @@ -948,8 +949,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - ejection [Preset: minimal] OK
+ Registry updates - ejection_past_churn_limit_min [Preset: minimal] OK
+ Registry updates - ejection_past_churn_limit_scaled [Preset: minimal] OK
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 14/14 Fail: 0/14 Skip: 0/14
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Bellatrix - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
Expand Down Expand Up @@ -1018,6 +1020,7 @@ OK: 38/38 Fail: 0/38 Skip: 0/38
## EF - ForkChoice [Preset: minimal]
```diff
ForkChoice - minimal/phase0/fork_choice/get_head/pyspec_tests/chain_no_attestations Skip
ForkChoice - minimal/phase0/fork_choice/get_head/pyspec_tests/discard_equivocations Skip
ForkChoice - minimal/phase0/fork_choice/get_head/pyspec_tests/filtered_block_tree Skip
ForkChoice - minimal/phase0/fork_choice/get_head/pyspec_tests/genesis Skip
ForkChoice - minimal/phase0/fork_choice/get_head/pyspec_tests/proposer_boost_correct_head Skip
Expand All @@ -1038,7 +1041,7 @@ OK: 38/38 Fail: 0/38 Skip: 0/38
ForkChoice - minimal/phase0/fork_choice/on_block/pyspec_tests/proposer_boost Skip
ForkChoice - minimal/phase0/fork_choice/on_block/pyspec_tests/proposer_boost_root_same_slo Skip
```
OK: 0/20 Fail: 0/20 Skip: 20/20
OK: 0/21 Fail: 0/21 Skip: 21/21
## EF - Phase 0 - Epoch Processing - Effective balance updates [Preset: minimal]
```diff
+ Effective balance updates - effective_balance_hysteresis [Preset: minimal] OK
Expand Down Expand Up @@ -1095,8 +1098,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - ejection [Preset: minimal] OK
+ Registry updates - ejection_past_churn_limit_min [Preset: minimal] OK
+ Registry updates - ejection_past_churn_limit_scaled [Preset: minimal] OK
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 14/14 Fail: 0/14 Skip: 0/14
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Phase 0 - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
Expand Down Expand Up @@ -1297,4 +1301,4 @@ OK: 48/48 Fail: 0/48 Skip: 0/48
OK: 30/30 Fail: 0/30 Skip: 0/30

---TOTAL---
OK: 1085/1107 Fail: 0/1107 Skip: 22/1107
OK: 1088/1111 Fail: 0/1111 Skip: 23/1111
2 changes: 1 addition & 1 deletion beacon_chain/fork_choice/proto_array.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func init*(T: type ProtoArray,

# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#configuration
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#get_latest_attesting_balance
const PROPOSER_SCORE_BOOST* = 70
const PROPOSER_SCORE_BOOST* = 40
func calculateProposerBoost(validatorBalances: openArray[Gwei]): int64 =
var
total_balance: uint64
Expand Down
23 changes: 17 additions & 6 deletions beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ func get_validator_churn_limit*(
state, state.get_current_epoch(), cache) div cfg.CHURN_LIMIT_QUOTIENT)

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#initiate_validator_exit
func initiate_validator_exit*(cfg: RuntimeConfig, state: var ForkyBeaconState,
index: ValidatorIndex, cache: var StateCache) =
func initiate_validator_exit*(
cfg: RuntimeConfig, state: var ForkyBeaconState,
index: ValidatorIndex, cache: var StateCache): Result[void, cstring] =
## Initiate the exit of the validator with index ``index``.

if state.validators.asSeq()[index].exit_epoch != FAR_FUTURE_EPOCH:
return # Before touching cache
return ok() # Before touching cache

# Return if validator already initiated exit
let validator = addr state.validators[index]
Expand Down Expand Up @@ -116,9 +117,16 @@ func initiate_validator_exit*(cfg: RuntimeConfig, state: var ForkyBeaconState,

# Set validator exit epoch and withdrawable epoch
validator.exit_epoch = exit_queue_epoch

if validator.exit_epoch + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY <
validator.exit_epoch:
return err("initiate_validator_exit: exit_epoch overflowed")

validator.withdrawable_epoch =
validator.exit_epoch + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY

ok()

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#modified-slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
Expand Down Expand Up @@ -157,10 +165,11 @@ func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): G
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#modified-slash_validator
proc slash_validator*(
cfg: RuntimeConfig, state: var ForkyBeaconState,
slashed_index: ValidatorIndex, cache: var StateCache) =
slashed_index: ValidatorIndex, cache: var StateCache):
Result[void, cstring] =
## Slash the validator with index ``index``.
let epoch = get_current_epoch(state)
initiate_validator_exit(cfg, state, slashed_index, cache)
? initiate_validator_exit(cfg, state, slashed_index, cache)
let validator = addr state.validators[slashed_index]

trace "slash_validator: ejecting validator via slashing (validator_leaving)",
Expand All @@ -185,7 +194,7 @@ proc slash_validator*(
let proposer_index = get_beacon_proposer_index(state, cache)
if proposer_index.isNone:
debug "No beacon proposer index and probably no active validators"
return
return ok()

# Apply proposer and whistleblower rewards
let
Expand All @@ -200,6 +209,8 @@ proc slash_validator*(
increase_balance(
state, whistleblower_index, whistleblower_reward - proposer_reward)

ok()

func genesis_time_from_eth1_timestamp*(cfg: RuntimeConfig, eth1_timestamp: uint64): uint64 =
eth1_timestamp + cfg.GENESIS_DELAY

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/datatypes/base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export
tables, results, json_serialization, timer, sszTypes, beacon_time, crypto,
digest, presets

const SPEC_VERSION* = "1.1.10"
const SPEC_VERSION* = "1.2.0-rc.1"
## Spec version we're aiming to be compatible with, right now

const
Expand Down
10 changes: 6 additions & 4 deletions beacon_chain/spec/state_transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func clear_epoch_from_cache(cache: var StateCache, epoch: Epoch) =
proc advance_slot(
cfg: RuntimeConfig,
state: var ForkyBeaconState, previous_slot_state_root: Eth2Digest,
flags: UpdateFlags, cache: var StateCache, info: var ForkyEpochInfo) =
flags: UpdateFlags, cache: var StateCache, info: var ForkyEpochInfo):
Result[void, cstring] =
# Do the per-slot and potentially the per-epoch processing, then bump the
# slot number - we've now arrived at the slot state on top of which a block
# optionally can be applied.
Expand All @@ -137,11 +138,13 @@ proc advance_slot(
let is_epoch_transition = (state.slot + 1).is_epoch
if is_epoch_transition:
# Note: Genesis epoch = 0, no need to test if before Genesis
process_epoch(cfg, state, flags, cache, info)
? process_epoch(cfg, state, flags, cache, info)
clear_epoch_from_cache(cache, (state.slot + 1).epoch)

state.slot += 1

ok()

func noRollback*(state: var phase0.HashedBeaconState) =
trace "Skipping rollback of broken phase 0 state"

Expand Down Expand Up @@ -192,8 +195,7 @@ proc process_slots*(
while getStateField(state, slot) < slot:
withState(state):
withEpochInfo(state.data, info):
advance_slot(
cfg, state.data, state.root, flags, cache, info)
? advance_slot(cfg, state.data, state.root, flags, cache, info)

if skipLastStateRootCalculation notin flags or
state.data.slot < slot:
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ proc process_proposer_slashing*(
cache: var StateCache):
Result[void, cstring] =
let proposer_index = ? check_proposer_slashing(state, proposer_slashing, flags)
slash_validator(cfg, state, proposer_index, cache)
? slash_validator(cfg, state, proposer_index, cache)
ok()

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_slashable_attestation_data
Expand Down Expand Up @@ -247,7 +247,7 @@ proc process_attester_slashing*(
? check_attester_slashing(state, attester_slashing, flags)

for index in slashed_attesters:
slash_validator(cfg, state, index, cache)
? slash_validator(cfg, state, index, cache)

ok()

Expand Down Expand Up @@ -376,7 +376,7 @@ proc process_voluntary_exit*(
cache: var StateCache): Result[void, cstring] =
let exited_validator =
? check_voluntary_exit(cfg, state, signed_voluntary_exit, flags)
initiate_validator_exit(cfg, state, exited_validator, cache)
? initiate_validator_exit(cfg, state, exited_validator, cache)
ok()

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#operations
Expand Down
27 changes: 14 additions & 13 deletions beacon_chain/spec/state_transition_epoch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ func process_rewards_and_penalties(

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#registry-updates
func process_registry_updates*(
cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache) =
cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache):
Result[void, cstring] =
## Process activation eligibility and ejections

# Make visible, e.g.,
Expand All @@ -823,7 +824,7 @@ func process_registry_updates*(

if is_active_validator(state.validators.asSeq()[vidx], get_current_epoch(state)) and
state.validators.asSeq()[vidx].effective_balance <= cfg.EJECTION_BALANCE:
initiate_validator_exit(cfg, state, vidx, cache)
? initiate_validator_exit(cfg, state, vidx, cache)

## Queue validators eligible for activation and not dequeued for activation
var activation_queue : seq[tuple[a: Epoch, b: ValidatorIndex]] = @[]
Expand All @@ -846,6 +847,8 @@ func process_registry_updates*(
state.validators[vidx].activation_epoch =
compute_activation_exit_epoch(get_current_epoch(state))

ok()

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#slashings
Expand Down Expand Up @@ -1034,7 +1037,7 @@ func process_inactivity_updates*(
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#epoch-processing
proc process_epoch*(
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
cache: var StateCache, info: var phase0.EpochInfo) =
cache: var StateCache, info: var phase0.EpochInfo): Result[void, cstring] =
let currentEpoch = get_current_epoch(state)
trace "process_epoch",
current_epoch = currentEpoch
Expand All @@ -1054,7 +1057,7 @@ proc process_epoch*(
doAssert state.finalized_checkpoint.epoch + 3 >= currentEpoch

process_rewards_and_penalties(state, info)
process_registry_updates(cfg, state, cache)
? process_registry_updates(cfg, state, cache)
process_slashings(state, info.balances.current_epoch)
process_eth1_data_reset(state)
process_effective_balance_updates(state)
Expand All @@ -1063,6 +1066,8 @@ proc process_epoch*(
process_historical_roots_update(state)
process_participation_record_updates(state)

ok()

func init*(
info: var altair.EpochInfo,
state: altair.BeaconState | bellatrix.BeaconState) =
Expand All @@ -1087,8 +1092,8 @@ func init*(
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#epoch-processing
proc process_epoch*(
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState),
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo)
=
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo):
Result[void, cstring] =
let currentEpoch = get_current_epoch(state)
trace "process_epoch",
current_epoch = currentEpoch
Expand All @@ -1114,21 +1119,17 @@ proc process_epoch*(
process_rewards_and_penalties(cfg, state, info)

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#registry-updates
process_registry_updates(cfg, state, cache)
? process_registry_updates(cfg, state, cache)

# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#slashings
process_slashings(state, info.balances.current_epoch)

process_eth1_data_reset(state)

process_effective_balance_updates(state)

process_slashings_reset(state)

process_randao_mixes_reset(state)

process_historical_roots_update(state)

process_participation_flag_updates(state) # [New in Altair]

process_sync_committee_updates(state) # [New in Altair]

ok()
Loading

0 comments on commit bf1763f

Please sign in to comment.