v0.12.2 beacon chain protocol update (#1378)

This commit is contained in:
tersec 2020-07-27 10:59:57 +00:00 committed by GitHub
parent 90708a8287
commit 20a2525390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 107 additions and 186 deletions

View File

@ -107,30 +107,23 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ BASE_REWARD_FACTOR 64 [Preset: mainnet] OK
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: mainnet] OK
+ CHURN_LIMIT_QUOTIENT 65536 [Preset: mainnet] OK
CUSTODY_PERIOD_TO_RANDAO_PADDING 2048 [Preset: mainnet] Skip
+ DEPOSIT_CHAIN_ID 1 [Preset: mainnet] OK
DEPOSIT_CONTRACT_ADDRESS "0x1234567890123456789012345678901234567 Skip
+ DEPOSIT_NETWORK_ID 1 [Preset: mainnet] OK
+ DOMAIN_AGGREGATE_AND_PROOF "0x06000000" [Preset: mainnet] OK
+ DOMAIN_BEACON_ATTESTER "0x01000000" [Preset: mainnet] OK
+ DOMAIN_BEACON_PROPOSER "0x00000000" [Preset: mainnet] OK
+ DOMAIN_CUSTODY_BIT_SLASHING "0x83000000" [Preset: mainnet] OK
+ DOMAIN_DEPOSIT "0x03000000" [Preset: mainnet] OK
+ DOMAIN_LIGHT_CLIENT "0x82000000" [Preset: mainnet] OK
+ DOMAIN_RANDAO "0x02000000" [Preset: mainnet] OK
+ DOMAIN_SELECTION_PROOF "0x05000000" [Preset: mainnet] OK
+ DOMAIN_SHARD_COMMITTEE "0x81000000" [Preset: mainnet] OK
+ DOMAIN_SHARD_PROPOSAL "0x80000000" [Preset: mainnet] OK
+ DOMAIN_VOLUNTARY_EXIT "0x04000000" [Preset: mainnet] OK
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS 16384 [Preset: mainnet] Skip
+ EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE 2 [Preset: mainnet] OK
+ EFFECTIVE_BALANCE_INCREMENT 1000000000 [Preset: mainnet] OK
+ EJECTION_BALANCE 16000000000 [Preset: mainnet] OK
+ EPOCHS_PER_CUSTODY_PERIOD 2048 [Preset: mainnet] OK
+ EPOCHS_PER_ETH1_VOTING_PERIOD 32 [Preset: mainnet] OK
+ EPOCHS_PER_HISTORICAL_VECTOR 65536 [Preset: mainnet] OK
+ EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION 256 [Preset: mainnet] OK
+ EPOCHS_PER_SLASHINGS_VECTOR 8192 [Preset: mainnet] OK
+ ETH1_FOLLOW_DISTANCE 1024 [Preset: mainnet] OK
+ GASPRICE_ADJUSTMENT_COEFFICIENT 8 [Preset: mainnet] OK
GENESIS_DELAY 172800 [Preset: mainnet] Skip
GENESIS_FORK_VERSION "0x00000000" [Preset: mainnet] Skip
+ HISTORICAL_ROOTS_LIMIT 16777216 [Preset: mainnet] OK
@ -138,60 +131,40 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ HYSTERESIS_QUOTIENT 4 [Preset: mainnet] OK
+ HYSTERESIS_UPWARD_MULTIPLIER 5 [Preset: mainnet] OK
+ INACTIVITY_PENALTY_QUOTIENT 16777216 [Preset: mainnet] OK
+ INITIAL_ACTIVE_SHARDS 64 [Preset: mainnet] OK
+ LIGHT_CLIENT_COMMITTEE_PERIOD 256 [Preset: mainnet] OK
+ LIGHT_CLIENT_COMMITTEE_SIZE 128 [Preset: mainnet] OK
+ MAX_ATTESTATIONS 128 [Preset: mainnet] OK
+ MAX_ATTESTER_SLASHINGS 2 [Preset: mainnet] OK
+ MAX_COMMITTEES_PER_SLOT 64 [Preset: mainnet] OK
+ MAX_CUSTODY_KEY_REVEALS 256 [Preset: mainnet] OK
+ MAX_CUSTODY_SLASHINGS 1 [Preset: mainnet] OK
+ MAX_DEPOSITS 16 [Preset: mainnet] OK
+ MAX_EARLY_DERIVED_SECRET_REVEALS 1 [Preset: mainnet] OK
+ MAX_EFFECTIVE_BALANCE 32000000000 [Preset: mainnet] OK
+ MAX_EPOCHS_PER_CROSSLINK 64 [Preset: mainnet] OK
+ MAX_GASPRICE 16384 [Preset: mainnet] OK
+ MAX_PROPOSER_SLASHINGS 16 [Preset: mainnet] OK
+ MAX_REVEAL_LATENESS_DECREMENT 128 [Preset: mainnet] OK
+ MAX_SEED_LOOKAHEAD 4 [Preset: mainnet] OK
+ MAX_SHARDS 1024 [Preset: mainnet] OK
+ MAX_SHARD_BLOCKS_PER_ATTESTATION 12 [Preset: mainnet] OK
+ MAX_SHARD_BLOCK_CHUNKS 4 [Preset: mainnet] OK
+ MAX_VALIDATORS_PER_COMMITTEE 2048 [Preset: mainnet] OK
+ MAX_VOLUNTARY_EXITS 16 [Preset: mainnet] OK
+ MINOR_REWARD_QUOTIENT 256 [Preset: mainnet] OK
+ MIN_ATTESTATION_INCLUSION_DELAY 1 [Preset: mainnet] OK
+ MIN_DEPOSIT_AMOUNT 1000000000 [Preset: mainnet] OK
+ MIN_EPOCHS_TO_INACTIVITY_PENALTY 4 [Preset: mainnet] OK
+ MIN_GASPRICE 8 [Preset: mainnet] OK
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT 16384 [Preset: mainnet] Skip
MIN_GENESIS_TIME 1578009600 [Preset: mainnet] Skip
+ MIN_PER_EPOCH_CHURN_LIMIT 4 [Preset: mainnet] OK
+ MIN_SEED_LOOKAHEAD 1 [Preset: mainnet] OK
+ MIN_SLASHING_PENALTY_QUOTIENT 32 [Preset: mainnet] OK
+ MIN_VALIDATOR_WITHDRAWABILITY_DELAY 256 [Preset: mainnet] OK
+ ONLINE_PERIOD 8 [Preset: mainnet] OK
+ PHASE_1_FORK_VERSION "0x01000000" [Preset: mainnet] OK
+ PHASE_1_GENESIS_SLOT 32 [Preset: mainnet] OK
+ PROPOSER_REWARD_QUOTIENT 8 [Preset: mainnet] OK
+ RANDAO_PENALTY_EPOCHS 2 [Preset: mainnet] OK
+ RANDOM_SUBNETS_PER_VALIDATOR 1 [Preset: mainnet] OK
+ SAFE_SLOTS_TO_UPDATE_JUSTIFIED 8 [Preset: mainnet] OK
+ SECONDS_PER_ETH1_BLOCK 14 [Preset: mainnet] OK
+ SECONDS_PER_SLOT 12 [Preset: mainnet] OK
+ SHARD_BLOCK_CHUNK_SIZE 262144 [Preset: mainnet] OK
SHARD_BLOCK_OFFSETS [1,2,3,5,8,13,21,34,55,89,144,233] [Pres Skip
+ SHARD_COMMITTEE_PERIOD 256 [Preset: mainnet] OK
+ SHUFFLE_ROUND_COUNT 90 [Preset: mainnet] OK
+ SLOTS_PER_EPOCH 32 [Preset: mainnet] OK
+ SLOTS_PER_HISTORICAL_ROOT 8192 [Preset: mainnet] OK
+ TARGET_AGGREGATORS_PER_COMMITTEE 16 [Preset: mainnet] OK
+ TARGET_COMMITTEE_SIZE 128 [Preset: mainnet] OK
+ TARGET_SHARD_BLOCK_SIZE 196608 [Preset: mainnet] OK
+ VALIDATOR_REGISTRY_LIMIT 1099511627776 [Preset: mainnet] OK
+ WHISTLEBLOWER_REWARD_QUOTIENT 512 [Preset: mainnet] OK
```
OK: 78/86 Fail: 0/86 Skip: 8/86
OK: 54/59 Fail: 0/59 Skip: 5/59
## PeerPool testing suite
```diff
+ Access peers by key test OK
@ -272,4 +245,4 @@ OK: 8/8 Fail: 0/8 Skip: 0/8
OK: 1/1 Fail: 0/1 Skip: 0/1
---TOTAL---
OK: 158/166 Fail: 0/166 Skip: 8/166
OK: 134/139 Fail: 0/139 Skip: 5/139

View File

@ -67,14 +67,19 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
OK: 21/21 Fail: 0/21 Skip: 0/21
## Official - Operations - Attester slashing [Preset: mainnet]
```diff
+ [Invalid] all_empty_indices OK
+ [Invalid] att1_bad_extra_index OK
+ [Invalid] att1_bad_replaced_index OK
+ [Invalid] att1_duplicate_index_double_signed OK
+ [Invalid] att1_duplicate_index_normal_signed OK
+ [Invalid] att1_empty_indices OK
+ [Invalid] att1_high_index OK
+ [Invalid] att2_bad_extra_index OK
+ [Invalid] att2_bad_replaced_index OK
+ [Invalid] att2_duplicate_index_double_signed OK
+ [Invalid] att2_duplicate_index_normal_signed OK
+ [Invalid] att2_empty_indices OK
+ [Invalid] att2_high_index OK
+ [Invalid] invalid_sig_1 OK
+ [Invalid] invalid_sig_1_and_2 OK
+ [Invalid] invalid_sig_2 OK
@ -88,7 +93,7 @@ OK: 21/21 Fail: 0/21 Skip: 0/21
+ [Valid] success_double OK
+ [Valid] success_surround OK
```
OK: 20/20 Fail: 0/20 Skip: 0/20
OK: 25/25 Fail: 0/25 Skip: 0/25
## Official - Operations - Block header [Preset: mainnet]
```diff
+ [Invalid] invalid_multiple_blocks_single_slot OK
@ -163,11 +168,12 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ [Valid] multiple_different_proposer_slashings_same_block OK
+ [Valid] multiple_different_validator_exits_same_block OK
+ [Valid] proposer_after_inactive_index OK
+ [Valid] proposer_self_slashing OK
+ [Valid] proposer_slashing OK
+ [Valid] skipped_slots OK
+ [Valid] voluntary_exit OK
```
OK: 31/31 Fail: 0/31 Skip: 0/31
OK: 32/32 Fail: 0/32 Skip: 0/32
## Official - Sanity - Slots [Preset: mainnet]
```diff
+ Slots - double_empty_epoch OK
@ -179,4 +185,4 @@ OK: 31/31 Fail: 0/31 Skip: 0/31
OK: 5/5 Fail: 0/5 Skip: 0/5
---TOTAL---
OK: 129/129 Fail: 0/129 Skip: 0/129
OK: 135/135 Fail: 0/135 Skip: 0/135

View File

@ -24,7 +24,7 @@ func is_aggregator(state: BeaconState, slot: Slot, index: CommitteeIndex,
let
committee = get_beacon_committee(state, slot, index, cache)
modulo = max(1'u64, len(committee).uint64 div TARGET_AGGREGATORS_PER_COMMITTEE)
bytes_to_int(eth2digest(slot_signature.toRaw()).data[0..7]) mod modulo == 0
bytes_to_uint64(eth2digest(slot_signature.toRaw()).data[0..7]) mod modulo == 0
proc aggregate_attestations*(
pool: AttestationPool, state: BeaconState, index: CommitteeIndex,
@ -44,7 +44,7 @@ proc aggregate_attestations*(
var cache = StateCache()
# TODO performance issue for future, via get_active_validator_indices(...)
doAssert index.uint64 < get_committee_count_per_slot(state, slot, cache)
doAssert index.uint64 < get_committee_count_per_slot(state, slot.epoch, cache)
# TODO for testing purposes, refactor this into the condition check
# and just calculation

View File

@ -369,7 +369,7 @@ proc readJsonDeposits(depositsList: JsonNode): seq[Eth1Block] =
data: DepositData(
pubkey: ValidatorPubKey.init(array[48, byte](pubkey)),
withdrawal_credentials: Eth2Digest(data: array[32, byte](withdrawalCredentials)),
amount: bytes_to_int(array[8, byte](amount)),
amount: bytes_to_uint64(array[8, byte](amount)),
signature: ValidatorSig.init(array[96, byte](signature))))
method fetchDepositData*(p: Web3DataProviderRef,
@ -390,7 +390,7 @@ method fetchBlockDetails(p: Web3DataProviderRef, blk: Eth1Block) {.async.} =
discard await depositRoot
discard await rawCount
let depositCount = bytes_to_int(array[8, byte](rawCount.read))
let depositCount = bytes_to_uint64(array[8, byte](rawCount.read))
blk.timestamp = Eth1BlockTimestamp(web3Block.read.timestamp)
blk.voteData.deposit_count = depositCount

View File

@ -94,7 +94,7 @@ func attachMerkleProofs*(deposits: var openarray[Deposit]) =
for val_idx in 0 ..< deposits.len:
let merkle_tree = merkleTreeFromLeaves(deposit_data_roots[0..val_idx])
deposits[val_idx].proof[0..31] = merkle_tree.getMerkleProof(val_idx)
deposits[val_idx].proof[32].data[0..7] = int_to_bytes8((val_idx + 1).uint64)
deposits[val_idx].proof[32].data[0..7] = uint_to_bytes8((val_idx + 1).uint64)
doAssert is_valid_merkle_branch(
deposit_data_roots[val_idx], deposits[val_idx].proof,

View File

@ -50,6 +50,23 @@ func decrease_balance*(
state.balances[index] - delta
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#deposits
func get_validator_from_deposit(state: BeaconState, deposit: Deposit):
Validator =
let
amount = deposit.data.amount
effective_balance = min(
amount - amount mod EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
Validator(
pubkey: deposit.data.pubkey,
withdrawal_credentials: deposit.data.withdrawal_credentials,
activation_eligibility_epoch: FAR_FUTURE_EPOCH,
activation_epoch: FAR_FUTURE_EPOCH,
exit_epoch: FAR_FUTURE_EPOCH,
withdrawable_epoch: FAR_FUTURE_EPOCH,
effective_balance: effective_balance
)
proc process_deposit*(preset: RuntimePreset,
state: var BeaconState,
deposit: Deposit,
@ -89,16 +106,7 @@ proc process_deposit*(preset: RuntimePreset,
return ok()
# Add validator and balance entries
state.validators.add(Validator(
pubkey: pubkey,
withdrawal_credentials: deposit.data.withdrawal_credentials,
activation_eligibility_epoch: FAR_FUTURE_EPOCH,
activation_epoch: FAR_FUTURE_EPOCH,
exit_epoch: FAR_FUTURE_EPOCH,
withdrawable_epoch: FAR_FUTURE_EPOCH,
effective_balance: min(amount - amount mod EFFECTIVE_BALANCE_INCREMENT,
MAX_EFFECTIVE_BALANCE)
))
state.validators.add(get_validator_from_deposit(state, deposit))
state.balances.add(amount)
else:
# Increase balance by deposit amount
@ -590,13 +598,6 @@ proc check_attestation*(
attestation = shortLog(attestation)
trace "process_attestation: beginning"
let committees_per_slot =
get_committee_count_per_slot(state, data.slot, stateCache)
if not (data.index < committees_per_slot):
warn "Data index exceeds committee count",
committee_count = committees_per_slot
return
if not isValidAttestationTargetEpoch(state.get_current_epoch(), data):
# Logging in isValidAttestationTargetEpoch
return
@ -605,6 +606,22 @@ proc check_attestation*(
# Logging in isValidAttestationSlot
return
let committees_per_slot =
get_committee_count_per_slot(
state, data.target.epoch, stateCache)
if not (data.index < committees_per_slot):
warn "Data index exceeds committee count",
committee_count = committees_per_slot
return
if not (data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot):
warn "Attestation too new"
return
if not (state.slot <= data.slot + SLOTS_PER_EPOCH):
warn "Attestation too old"
return
let committee = get_beacon_committee(
state, data.slot, data.index.CommitteeIndex, stateCache)
if attestation.aggregation_bits.len != committee.len:

View File

@ -47,7 +47,7 @@ export
# internal state that's gone through sanity checks already.
const
SPEC_VERSION* = "0.12.1" ## \
SPEC_VERSION* = "0.12.2" ## \
## Spec version we're aiming to be compatible with, right now
GENESIS_SLOT* = Slot(0)
@ -87,14 +87,6 @@ type
DOMAIN_VOLUNTARY_EXIT = 4
DOMAIN_SELECTION_PROOF = 5
DOMAIN_AGGREGATE_AND_PROOF = 6
# Phase 1 - Sharding
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase1/beacon-chain.md#misc
DOMAIN_SHARD_PROPOSAL = 128
DOMAIN_SHARD_COMMITTEE = 129
DOMAIN_LIGHT_CLIENT = 130
# Phase 1 - Custody game
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase1/custody-game.md#signature-domain-types
DOMAIN_CUSTODY_BIT_SLASHING = 0x83
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#custom-types
Domain* = array[32, byte]

View File

@ -98,11 +98,6 @@ func get_committee_count_per_slot*(state: BeaconState,
# Otherwise, get_beacon_committee(...) cannot access some committees.
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT) >= uint64(result)
func get_committee_count_per_slot*(state: BeaconState,
slot: Slot,
cache: StateCache): uint64 =
get_committee_count_per_slot(state, slot.compute_epoch_at_slot, cache)
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_current_epoch
func get_current_epoch*(state: BeaconState): Epoch =
# Return the current epoch.
@ -115,7 +110,7 @@ func get_randao_mix*(state: BeaconState,
## Returns the randao mix at a recent ``epoch``.
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR]
func bytes_to_int*(data: openarray[byte]): uint64 =
func bytes_to_uint64*(data: openarray[byte]): uint64 =
doAssert data.len == 8
# Little-endian data representation
@ -123,15 +118,9 @@ func bytes_to_int*(data: openarray[byte]): uint64 =
for i in countdown(7, 0):
result = result * 256 + data[i]
# Have 1, 4, 8, and 32-byte versions. 1+ more and maybe worth metaprogramming.
func int_to_bytes32*(x: uint64): array[32, byte] =
## Little-endian data representation
## TODO remove uint64 when those callers fade away
result[0..<7] = x.toBytesLE()
func int_to_bytes32*(x: Epoch): array[32, byte] {.borrow.}
func int_to_bytes8*(x: uint64): array[8, byte] =
# Have 1, 4, and 8-byte versions. Spec only defines 8-byte version, but useful
# to check invariants on rest.
func uint_to_bytes8*(x: uint64): array[8, byte] =
x.toBytesLE()
func int_to_bytes1*(x: int): array[1, byte] =
@ -140,8 +129,7 @@ func int_to_bytes1*(x: int): array[1, byte] =
result[0] = x.byte
func int_to_bytes4*(x: uint64): array[4, byte] =
doAssert x >= 0'u64
func uint_to_bytes4*(x: uint64): array[4, byte] =
doAssert x < 2'u64^32
# Little-endian data representation
@ -181,7 +169,7 @@ func compute_domain*(
# Return the domain for the ``domain_type`` and ``fork_version``.
let fork_data_root =
compute_fork_data_root(fork_version, genesis_validators_root)
result[0..3] = int_to_bytes4(domain_type.uint64)
result[0..3] = uint_to_bytes4(domain_type.uint64)
result[4..31] = fork_data_root.data[0..27]
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_domain
@ -222,8 +210,8 @@ func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2D
static:
doAssert EPOCHS_PER_HISTORICAL_VECTOR > MIN_SEED_LOOKAHEAD
seed_input[0..3] = int_to_bytes4(domain_type.uint64)
seed_input[4..11] = int_to_bytes8(epoch.uint64)
seed_input[0..3] = uint_to_bytes4(domain_type.uint64)
seed_input[4..11] = uint_to_bytes8(epoch.uint64)
seed_input[12..43] =
get_randao_mix(state, # Avoid underflow
epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1).data

View File

@ -3,7 +3,9 @@ type
BASE_REWARD_FACTOR
BLS_WITHDRAWAL_PREFIX
CHURN_LIMIT_QUOTIENT
DEPOSIT_CHAIN_ID
DEPOSIT_CONTRACT_ADDRESS
DEPOSIT_NETWORK_ID
DOMAIN_AGGREGATE_AND_PROOF
DOMAIN_BEACON_ATTESTER
DOMAIN_BEACON_PROPOSER

View File

@ -134,12 +134,12 @@ const
when const_preset == "mainnet":
template defaultRuntimePreset*: auto = mainnetRuntimePreset
import ./presets/v0_12_1/mainnet
import ./presets/v0_12_2/mainnet
export mainnet
elif const_preset == "minimal":
template defaultRuntimePreset*: auto = minimalRuntimePreset
import ./presets/v0_12_1/minimal
import ./presets/v0_12_2/minimal
export minimal
else:

View File

@ -158,42 +158,10 @@ const
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64 = 256 # epochs ~ 27 hours
SECONDS_PER_ETH1_BLOCK* {.intdefine.}: uint64 = 14 # (estimate from Eth1 mainnet)
# Phase 1: Upgrade from Phase 0
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L161
PHASE_1_FORK_VERSION*: uint64 = 1
PHASE_1_GENESIS_SLOT*: uint64 = 32 # [STUB]
INITIAL_ACTIVE_SHARDS*: uint64 = 64
# Phase 1: General
# Deposit contract
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L168
MAX_SHARDS*: uint64 = 1024
ONLINE_PERIOD*: uint64 = 8 # epochs (~51 min)
LIGHT_CLIENT_COMMITTEE_SIZE*: uint64 = 128
LIGHT_CLIENT_COMMITTEE_PERIOD*: uint64 = 256 # epochs (~27 hours)
SHARD_BLOCK_CHUNK_SIZE*: uint64 = 262144
MAX_SHARD_BLOCK_CHUNKS*: uint64 = 4
TARGET_SHARD_BLOCK_SIZE*: uint64 = 196608
MAX_SHARD_BLOCKS_PER_ATTESTATION*: uint64 = 12
MAX_GASPRICE*: uint64 = 16384 # Gwei
MIN_GASPRICE*: uint64 = 8 # Gwei
GASPRICE_ADJUSTMENT_COEFFICIENT*: uint64 = 8
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/configs/mainnet/phase0.yaml#L52
# Phase 1: Custody game
# ---------------------------------------------------------------
# Time parameters
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L199
RANDAO_PENALTY_EPOCHS*: uint64 = 2 # epochs (12.8 minutes)
EPOCHS_PER_CUSTODY_PERIOD*: uint64 = 2048 # epochs (~9 days)
MAX_REVEAL_LATENESS_DECREMENT*: uint64 = 128 # epochs (~14 hours)
# Max operations
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L211
MAX_CUSTODY_KEY_REVEALS*: uint64 = 256
MAX_EARLY_DERIVED_SECRET_REVEALS*: uint64 = 1
MAX_CUSTODY_SLASHINGS*: uint64 = 1
# Reward and penalty quotients
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L217
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE*: uint64 = 2
MINOR_REWARD_QUOTIENT*: uint64 = 256
# Ethereum PoW Mainnet
DEPOSIT_CHAIN_ID* = 1
DEPOSIT_NETWORK_ID* = 1

View File

@ -117,6 +117,14 @@ const
MAX_DEPOSITS*: uint64 = 2'u64 ^ 4
MAX_VOLUNTARY_EXITS*: uint64 = 2'u64 ^ 4
# Deposit contract
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/configs/minimal/phase0.yaml#L52
# Ethereum Goerli testnet
DEPOSIT_CHAIN_ID* = 5
DEPOSIT_NETWORK_ID* = 5
# Fork choice
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L32
@ -136,44 +144,3 @@ const
RANDOM_SUBNETS_PER_VALIDATOR*: uint64 = 1 # subnet
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64 = 256 # epochs ~ 27 hours
SECONDS_PER_ETH1_BLOCK* {.intdefine.}: uint64 = 14 # estimate from Eth1 mainnet)
# Phase 1: Upgrade from Phase 0
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L161
PHASE_1_FORK_VERSION*: uint64 = 16777217
PHASE_1_GENESIS_SLOT*: uint64 = 8
INITIAL_ACTIVE_SHARDS*: uint64 = 4
# Phase 1: General
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L171
MAX_SHARDS*: uint64 = 8
ONLINE_PERIOD*: uint64 = 8 # epochs ~ 51 minutes
LIGHT_CLIENT_COMMITTEE_SIZE*: uint64 = 128
LIGHT_CLIENT_COMMITTEE_PERIOD*: uint64 = 256 # epochs
SHARD_BLOCK_CHUNK_SIZE*: uint64 = 262144
MAX_SHARD_BLOCK_CHUNKS*: uint64 = 4
TARGET_SHARD_BLOCK_SIZE*: uint64 = 196608
MAX_SHARD_BLOCKS_PER_ATTESTATION*: uint64 = 12
MAX_GASPRICE*: uint64 = 16384 # Gwei
MIN_GASPRICE*: uint64 = 8 # Gwei
GASPRICE_ADJUSTMENT_COEFFICIENT*: uint64 = 8
# Phase 1 - Custody game
# ---------------------------------------------------------------
# Time parameters
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L202
RANDAO_PENALTY_EPOCHS*: uint64 = 2
EPOCHS_PER_CUSTODY_PERIOD*: uint64 = 2048
MAX_REVEAL_LATENESS_DECREMENT*: uint64 = 128
# Max operations
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L214
MAX_CUSTODY_KEY_REVEALS*: uint64 = 256
MAX_EARLY_DERIVED_SECRET_REVEALS*: uint64 = 1
MAX_CUSTODY_SLASHINGS*: uint64 = 1
# Reward and penalty quotients
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L220
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE*: uint64 = 2
MINOR_REWARD_QUOTIENT*: uint64 = 256

View File

@ -52,13 +52,15 @@ func get_shuffled_seq*(seed: Eth2Digest,
source_buffer[32] = round_bytes1
# Only one pivot per round.
let pivot = bytes_to_int(eth2digest(pivot_buffer).data.toOpenArray(0, 7)) mod list_size
let pivot =
bytes_to_uint64(eth2digest(pivot_buffer).data.toOpenArray(0, 7)) mod
list_size
## Only need to run, per round, position div 256 hashes, so precalculate
## them. This consumes memory, but for low-memory devices, it's possible
## to mitigate by some light LRU caching and similar.
for reduced_position in 0 ..< sources.len:
source_buffer[33..36] = int_to_bytes4(reduced_position.uint64)
source_buffer[33..36] = uint_to_bytes4(reduced_position.uint64)
sources[reduced_position] = eth2digest(source_buffer)
## Iterate over all the indices. This was in get_permuted_index, but large
@ -190,12 +192,12 @@ func compute_shuffled_index(
let
# If using multiple indices, can amortize this
pivot =
bytes_to_int(eth2digest(pivot_buffer).data.toOpenArray(0, 7)) mod
bytes_to_uint64(eth2digest(pivot_buffer).data.toOpenArray(0, 7)) mod
index_count
flip = ((index_count + pivot) - cur_idx_permuted) mod index_count
position = max(cur_idx_permuted.int, flip.int)
source_buffer[33..36] = int_to_bytes4((position div 256).uint64)
source_buffer[33..36] = uint_to_bytes4((position div 256).uint64)
let
source = eth2digest(source_buffer).data
byte_value = source[(position mod 256) div 8]
@ -221,7 +223,7 @@ func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
buffer: array[32+8, byte]
buffer[0..31] = seed.data
while true:
buffer[32..39] = int_to_bytes8(i div 32)
buffer[32..39] = uint_to_bytes8(i div 32)
let
candidate_index =
indices[compute_shuffled_index(i mod seq_len, seq_len, seed)]
@ -246,7 +248,7 @@ func get_beacon_proposer_index*(state: BeaconState, cache: var StateCache, slot:
var buffer: array[32 + 8, byte]
buffer[0..31] = get_seed(state, epoch, DOMAIN_BEACON_PROPOSER).data
buffer[32..39] = int_to_bytes8(slot.uint64)
buffer[32..39] = uint_to_bytes8(slot.uint64)
# TODO fixme; should only be run once per slot and cached
# There's exactly one beacon proposer per slot.
@ -287,9 +289,12 @@ func get_committee_assignment*(
var cache = StateCache()
let start_slot = compute_start_slot_at_epoch(epoch)
let
start_slot = compute_start_slot_at_epoch(epoch)
committee_count_per_slot =
get_committee_count_per_slot(state, epoch, cache)
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
for index in 0'u64 ..< get_committee_count_per_slot(state, slot, cache):
for index in 0'u64 ..< committee_count_per_slot:
let idx = index.CommitteeIndex
let committee = get_beacon_committee(state, slot, idx, cache)
if validator_index in committee:
@ -306,9 +311,8 @@ func get_committee_assignments*(
var cache = StateCache()
let start_slot = compute_start_slot_at_epoch(epoch)
# get_committee_count_per_slot is constant throughout an epoch
let committees_per_slot =
get_committee_count_per_slot(state, start_slot, cache)
get_committee_count_per_slot(state, epoch, cache)
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
for index in 0'u64 ..< committees_per_slot:

View File

@ -237,7 +237,8 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
proc forSlot(slot: Slot, res: var seq[BeaconStatesCommitteesTuple]) =
if index == 0: # TODO this means if the parameter is missing (its optional)
let committees_per_slot = get_committee_count_per_slot(state, slot, cache)
let committees_per_slot =
get_committee_count_per_slot(state, slot.epoch, cache)
for committee_index in 0'u64..<committees_per_slot:
res.add(getCommittee(slot, committee_index.CommitteeIndex))
else:

View File

@ -333,7 +333,8 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
node.blockPool.withState(node.blockPool.tmpState, attestationHead):
var cache = getEpochCache(attestationHead.blck, state)
let
committees_per_slot = get_committee_count_per_slot(state, slot, cache)
committees_per_slot =
get_committee_count_per_slot(state, slot.epoch, cache)
num_active_validators =
count_active_validators(state, slot.compute_epoch_at_slot, cache)
@ -395,7 +396,7 @@ proc broadcastAggregatedAttestations(
var cache = getEpochCache(aggregationHead, state)
let
committees_per_slot =
get_committee_count_per_slot(state, aggregationSlot, cache)
get_committee_count_per_slot(state, aggregationSlot.epoch, cache)
for committee_index in 0'u64..<committees_per_slot:
let committee = get_beacon_committee(
state, aggregationSlot, committee_index.CommitteeIndex, cache)

View File

@ -69,7 +69,8 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
blockPool.withState(blockPool.tmpState, attestationHead):
var cache = getEpochCache(attestationHead.blck, state)
let committees_per_slot = get_committee_count_per_slot(state, slot, cache)
let committees_per_slot =
get_committee_count_per_slot(state, slot.epoch, cache)
for committee_index in 0'u64..<committees_per_slot:
let committee = get_beacon_committee(

View File

@ -107,7 +107,8 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
# some variation
let
target_slot = state[].data.slot + MIN_ATTESTATION_INCLUSION_DELAY - 1
committees_per_slot = get_committee_count_per_slot(state[].data, target_slot, cache)
committees_per_slot =
get_committee_count_per_slot(state[].data, target_slot.epoch, cache)
let
scass = withTimerRet(timers[tShuffle]):

View File

@ -4,7 +4,7 @@ import testutils/fuzzing_engines
const
gitRoot = thisDir() / ".."
fixturesDir = gitRoot / "vendor" / "nim-eth2-scenarios" / "tests-v0.12.1" / "mainnet" / "phase0" / "ssz_static"
fixturesDir = gitRoot / "vendor" / "nim-eth2-scenarios" / "tests-v0.12.2" / "mainnet" / "phase0" / "ssz_static"
fuzzingTestsDir = gitRoot / "tests" / "fuzzing"
fuzzingCorpusesDir = fuzzingTestsDir / "corpus"

View File

@ -19,7 +19,7 @@ import
const
SpecDir = currentSourcePath.rsplit(DirSep, 1)[0] /
".."/".."/"beacon_chain"/"spec"
Config = SszTestsDir/const_preset/"config.yaml"
Config = SszTestsDir/const_preset/"config"/"phase0.yaml"
type
CheckedType = SomeInteger or Slot or Epoch

View File

@ -305,7 +305,7 @@ suiteReport "Attestation pool processing" & preset():
for epoch in 0 ..< 5:
let start_slot = compute_start_slot_at_epoch(Epoch epoch)
let committees_per_slot =
get_committee_count_per_slot(state.data.data, start_slot, cache)
get_committee_count_per_slot(state.data.data, Epoch epoch, cache)
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
let new_block = makeTestBlock(
state.data, block_root, cache, attestations = attestations)

View File

@ -215,8 +215,8 @@ proc makeFullAttestations*(
flags: UpdateFlags = {}): seq[Attestation] =
# Create attestations in which the full committee participates for each shard
# that should be attested to during a particular slot
let
committees_per_slot = get_committee_count_per_slot(state, slot, cache)
let committees_per_slot =
get_committee_count_per_slot(state, slot.epoch, cache)
for index in 0'u64..<committees_per_slot:
let

@ -1 +1 @@
Subproject commit d22fabdb91521df5f1d4392be39fc3569145229c
Subproject commit 83f67f3f6730077e3cd537ef638394543315bb2a