0.7.0 updates which don't change semantics; mostly comment changes (#281)
* 0.7.0 updates which don't change semantics; mostly comment changes * mark get_attesting_indices, bls_verify, ProposerSlashing, BeaconBlockBody, deposit contract constants, state list length constants, compute_committee, get_crosslink_committee, is_slashable_attestation_data, processAttesterSlashings as 0.7.0; rename BASE_REWARD_QUOTIENT to BASE_REWARD_FACTOR * complete marking unchanged-in-0.7.0 datatypes as such; a few more have trivial field renamings, etc
This commit is contained in:
parent
d400650eeb
commit
6357bc2a98
|
@ -29,13 +29,13 @@ func verify_merkle_branch(leaf: Eth2Digest, proof: openarray[Eth2Digest], depth:
|
||||||
value = eth2hash(buf)
|
value = eth2hash(buf)
|
||||||
value == root
|
value == root
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#increase_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#increase_balance
|
||||||
func increase_balance*(
|
func increase_balance*(
|
||||||
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||||
# Increase validator balance by ``delta``.
|
# Increase validator balance by ``delta``.
|
||||||
state.balances[index] += delta
|
state.balances[index] += delta
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#decrease_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#decrease_balance
|
||||||
func decrease_balance*(
|
func decrease_balance*(
|
||||||
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||||
# Decrease validator balance by ``delta`` with underflow protection.
|
# Decrease validator balance by ``delta`` with underflow protection.
|
||||||
|
@ -108,13 +108,13 @@ func process_deposit*(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_delayed_activation_exit_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_delayed_activation_exit_epoch
|
||||||
func get_delayed_activation_exit_epoch*(epoch: Epoch): Epoch =
|
func get_delayed_activation_exit_epoch*(epoch: Epoch): Epoch =
|
||||||
## Return the epoch at which an activation or exit triggered in ``epoch``
|
## Return the epoch at which an activation or exit triggered in ``epoch``
|
||||||
## takes effect.
|
## takes effect.
|
||||||
epoch + 1 + ACTIVATION_EXIT_DELAY
|
epoch + 1 + ACTIVATION_EXIT_DELAY
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_churn_limit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_churn_limit
|
||||||
func get_churn_limit(state: BeaconState): uint64 =
|
func get_churn_limit(state: BeaconState): uint64 =
|
||||||
max(
|
max(
|
||||||
MIN_PER_EPOCH_CHURN_LIMIT,
|
MIN_PER_EPOCH_CHURN_LIMIT,
|
||||||
|
@ -122,7 +122,7 @@ func get_churn_limit(state: BeaconState): uint64 =
|
||||||
CHURN_LIMIT_QUOTIENT
|
CHURN_LIMIT_QUOTIENT
|
||||||
).uint64
|
).uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#initiate_validator_exit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#initiate_validator_exit
|
||||||
func initiate_validator_exit*(state: var BeaconState,
|
func initiate_validator_exit*(state: var BeaconState,
|
||||||
index: ValidatorIndex) =
|
index: ValidatorIndex) =
|
||||||
# Initiate the validator of the given ``index``.
|
# Initiate the validator of the given ``index``.
|
||||||
|
@ -153,7 +153,7 @@ func initiate_validator_exit*(state: var BeaconState,
|
||||||
validator.withdrawable_epoch =
|
validator.withdrawable_epoch =
|
||||||
validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#slash_validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#slash_validator
|
||||||
func slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex) =
|
func slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex) =
|
||||||
# Slash the validator with index ``index``.
|
# Slash the validator with index ``index``.
|
||||||
let current_epoch = get_current_epoch(state)
|
let current_epoch = get_current_epoch(state)
|
||||||
|
@ -303,7 +303,7 @@ func get_attestation_slot*(state: BeaconState,
|
||||||
get_attestation_slot(
|
get_attestation_slot(
|
||||||
state, attestation, get_epoch_committee_count(state, epoch))
|
state, attestation, get_epoch_committee_count(state, epoch))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_block_root_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_block_root_at_slot
|
||||||
func get_block_root_at_slot*(state: BeaconState,
|
func get_block_root_at_slot*(state: BeaconState,
|
||||||
slot: Slot): Eth2Digest =
|
slot: Slot): Eth2Digest =
|
||||||
# Return the block root at a recent ``slot``.
|
# Return the block root at a recent ``slot``.
|
||||||
|
@ -312,7 +312,7 @@ func get_block_root_at_slot*(state: BeaconState,
|
||||||
doAssert slot < state.slot
|
doAssert slot < state.slot
|
||||||
state.latest_block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
|
state.latest_block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_block_root
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_block_root
|
||||||
func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
||||||
# Return the block root at a recent ``epoch``.
|
# Return the block root at a recent ``epoch``.
|
||||||
get_block_root_at_slot(state, get_epoch_start_slot(epoch))
|
get_block_root_at_slot(state, get_epoch_start_slot(epoch))
|
||||||
|
@ -407,7 +407,7 @@ func verify_indexed_attestation*(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_attesting_indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_attesting_indices
|
||||||
func get_attesting_indices*(state: BeaconState,
|
func get_attesting_indices*(state: BeaconState,
|
||||||
attestation_data: AttestationData,
|
attestation_data: AttestationData,
|
||||||
bitfield: BitField): HashSet[ValidatorIndex] =
|
bitfield: BitField): HashSet[ValidatorIndex] =
|
||||||
|
@ -438,7 +438,7 @@ iterator get_attestation_participants_cached*(
|
||||||
for participant in get_attesting_indices(state, attestation_data, bitfield):
|
for participant in get_attesting_indices(state, attestation_data, bitfield):
|
||||||
yield participant
|
yield participant
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#convert_to_indexed
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#convert_to_indexed
|
||||||
func convert_to_indexed(state: BeaconState, attestation: Attestation): IndexedAttestation =
|
func convert_to_indexed(state: BeaconState, attestation: Attestation): IndexedAttestation =
|
||||||
# Convert ``attestation`` to (almost) indexed-verifiable form.
|
# Convert ``attestation`` to (almost) indexed-verifiable form.
|
||||||
let
|
let
|
||||||
|
|
|
@ -17,14 +17,14 @@ func init*(T: type BitField, bits: int): BitField =
|
||||||
#proc readValue*(r: var JsonReader, a: var BitField) {.inline.} =
|
#proc readValue*(r: var JsonReader, a: var BitField) {.inline.} =
|
||||||
# a.bits = r.readValue(string).hexToSeqByte()
|
# a.bits = r.readValue(string).hexToSeqByte()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_bitfield_bit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_bitfield_bit
|
||||||
func get_bitfield_bit*(bitfield: BitField, i: int): bool =
|
func get_bitfield_bit*(bitfield: BitField, i: int): bool =
|
||||||
# Extract the bit in ``bitfield`` at position ``i``.
|
# Extract the bit in ``bitfield`` at position ``i``.
|
||||||
doAssert 0 <= i div 8, "i: " & $i & " i div 8: " & $(i div 8)
|
doAssert 0 <= i div 8, "i: " & $i & " i div 8: " & $(i div 8)
|
||||||
doAssert i div 8 < bitfield.bits.len, "i: " & $i & " i div 8: " & $(i div 8)
|
doAssert i div 8 < bitfield.bits.len, "i: " & $i & " i div 8: " & $(i div 8)
|
||||||
((bitfield.bits[i div 8] shr (i mod 8)) mod 2) > 0'u8
|
((bitfield.bits[i div 8] shr (i mod 8)) mod 2) > 0'u8
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#verify_bitfield
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#verify_bitfield
|
||||||
func verify_bitfield*(bitfield: BitField, committee_size: int): bool =
|
func verify_bitfield*(bitfield: BitField, committee_size: int): bool =
|
||||||
# Verify ``bitfield`` against the ``committee_size``.
|
# Verify ``bitfield`` against the ``committee_size``.
|
||||||
if len(bitfield.bits) != (committee_size + 7) div 8:
|
if len(bitfield.bits) != (committee_size + 7) div 8:
|
||||||
|
|
|
@ -69,7 +69,7 @@ template hash*(k: ValidatorPubKey|ValidatorPrivKey): Hash =
|
||||||
|
|
||||||
func pubKey*(pk: ValidatorPrivKey): ValidatorPubKey = pk.getKey()
|
func pubKey*(pk: ValidatorPrivKey): ValidatorPubKey = pk.getKey()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/bls_signature.md#bls_aggregate_pubkeys
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/bls_signature.md#bls_aggregate_pubkeys
|
||||||
func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey =
|
func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey =
|
||||||
var empty = true
|
var empty = true
|
||||||
for key in keys:
|
for key in keys:
|
||||||
|
@ -79,14 +79,14 @@ func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey =
|
||||||
else:
|
else:
|
||||||
result.combine(key)
|
result.combine(key)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/bls_signature.md#bls_verify
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/bls_signature.md#bls_verify
|
||||||
func bls_verify*(
|
func bls_verify*(
|
||||||
pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig,
|
pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig,
|
||||||
domain: uint64): bool =
|
domain: uint64): bool =
|
||||||
# name from spec!
|
# name from spec!
|
||||||
sig.verify(msg, domain, pubkey)
|
sig.verify(msg, domain, pubkey)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/bls_signature.md#bls_verify_multiple
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/bls_signature.md#bls_verify_multiple
|
||||||
func bls_verify_multiple*(
|
func bls_verify_multiple*(
|
||||||
pubkeys: seq[ValidatorPubKey], message_hashes: openArray[Eth2Digest],
|
pubkeys: seq[ValidatorPubKey], message_hashes: openArray[Eth2Digest],
|
||||||
sig: ValidatorSig, domain: uint64): bool =
|
sig: ValidatorSig, domain: uint64): bool =
|
||||||
|
|
|
@ -62,7 +62,7 @@ const
|
||||||
|
|
||||||
# Initial values
|
# Initial values
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#initial-values
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#initial-values
|
||||||
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
||||||
## slot_to_epoch(GENESIS_SLOT)
|
## slot_to_epoch(GENESIS_SLOT)
|
||||||
ZERO_HASH* = Eth2Digest()
|
ZERO_HASH* = Eth2Digest()
|
||||||
|
@ -73,7 +73,7 @@ type
|
||||||
Shard* = uint64
|
Shard* = uint64
|
||||||
Gwei* = uint64
|
Gwei* = uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#proposerslashing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#proposerslashing
|
||||||
ProposerSlashing* = object
|
ProposerSlashing* = object
|
||||||
proposer_index*: uint64 ##\
|
proposer_index*: uint64 ##\
|
||||||
## Proposer index
|
## Proposer index
|
||||||
|
@ -84,14 +84,14 @@ type
|
||||||
header_2*: BeaconBlockHeader ##\
|
header_2*: BeaconBlockHeader ##\
|
||||||
# Second block header
|
# Second block header
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#attesterslashing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#attesterslashing
|
||||||
AttesterSlashing* = object
|
AttesterSlashing* = object
|
||||||
attestation_1*: IndexedAttestation ## \
|
attestation_1*: IndexedAttestation ## \
|
||||||
## First attestation
|
## First attestation
|
||||||
attestation_2*: IndexedAttestation ## \
|
attestation_2*: IndexedAttestation ## \
|
||||||
## Second attestation
|
## Second attestation
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#indexedattestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#indexedattestation
|
||||||
IndexedAttestation* = object
|
IndexedAttestation* = object
|
||||||
# These probably should be seq[ValidatorIndex], but that throws RLP errors
|
# These probably should be seq[ValidatorIndex], but that throws RLP errors
|
||||||
custody_bit_0_indices*: seq[uint64]
|
custody_bit_0_indices*: seq[uint64]
|
||||||
|
@ -103,7 +103,7 @@ type
|
||||||
signature*: ValidatorSig ## \
|
signature*: ValidatorSig ## \
|
||||||
## Aggregate signature
|
## Aggregate signature
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#attestation
|
||||||
Attestation* = object
|
Attestation* = object
|
||||||
aggregation_bitfield*: BitField ##\
|
aggregation_bitfield*: BitField ##\
|
||||||
## Attester aggregation bitfield
|
## Attester aggregation bitfield
|
||||||
|
@ -134,7 +134,7 @@ type
|
||||||
previous_crosslink_root*: Eth2Digest
|
previous_crosslink_root*: Eth2Digest
|
||||||
crosslink_data_root*: Eth2Digest
|
crosslink_data_root*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#attestationdataandcustodybit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#attestationdataandcustodybit
|
||||||
AttestationDataAndCustodyBit* = object
|
AttestationDataAndCustodyBit* = object
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
custody_bit*: bool
|
custody_bit*: bool
|
||||||
|
@ -150,7 +150,7 @@ type
|
||||||
data*: DepositData ##\
|
data*: DepositData ##\
|
||||||
## Data
|
## Data
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#depositdata
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#depositdata
|
||||||
DepositData* = object
|
DepositData* = object
|
||||||
pubkey*: ValidatorPubKey ##\
|
pubkey*: ValidatorPubKey ##\
|
||||||
## BLS pubkey
|
## BLS pubkey
|
||||||
|
@ -166,7 +166,7 @@ type
|
||||||
signature*: ValidatorSig ##\
|
signature*: ValidatorSig ##\
|
||||||
## Container self-signature
|
## Container self-signature
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#voluntaryexit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#voluntaryexit
|
||||||
VoluntaryExit* = object
|
VoluntaryExit* = object
|
||||||
# Minimum epoch for processing exit
|
# Minimum epoch for processing exit
|
||||||
epoch*: Epoch
|
epoch*: Epoch
|
||||||
|
@ -175,7 +175,7 @@ type
|
||||||
# Validator signature
|
# Validator signature
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#transfer
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#transfer
|
||||||
Transfer* = object
|
Transfer* = object
|
||||||
sender*: uint64 ##\
|
sender*: uint64 ##\
|
||||||
## Sender index
|
## Sender index
|
||||||
|
@ -227,7 +227,7 @@ type
|
||||||
block_body_root*: Eth2Digest
|
block_body_root*: Eth2Digest
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#beaconblockbody
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beaconblockbody
|
||||||
BeaconBlockBody* = object
|
BeaconBlockBody* = object
|
||||||
randao_reveal*: ValidatorSig
|
randao_reveal*: ValidatorSig
|
||||||
eth1_data*: Eth1Data
|
eth1_data*: Eth1Data
|
||||||
|
@ -239,7 +239,7 @@ type
|
||||||
voluntary_exits*: seq[VoluntaryExit]
|
voluntary_exits*: seq[VoluntaryExit]
|
||||||
transfers*: seq[Transfer]
|
transfers*: seq[Transfer]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#beaconstate
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
genesis_time*: uint64
|
genesis_time*: uint64
|
||||||
|
@ -286,7 +286,7 @@ type
|
||||||
eth1_data_votes*: seq[Eth1Data]
|
eth1_data_votes*: seq[Eth1Data]
|
||||||
deposit_index*: uint64
|
deposit_index*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#validator
|
||||||
Validator* = object
|
Validator* = object
|
||||||
pubkey*: ValidatorPubKey ##\
|
pubkey*: ValidatorPubKey ##\
|
||||||
## BLS public key
|
## BLS public key
|
||||||
|
@ -323,14 +323,14 @@ type
|
||||||
crosslink_data_root*: Eth2Digest ##\
|
crosslink_data_root*: Eth2Digest ##\
|
||||||
## Shard data since the previous crosslink
|
## Shard data since the previous crosslink
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#pendingattestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#pendingattestation
|
||||||
PendingAttestation* = object
|
PendingAttestation* = object
|
||||||
aggregation_bitfield*: BitField ## Attester participation bitfield
|
aggregation_bitfield*: BitField ## Attester participation bitfield
|
||||||
data*: AttestationData ## Attestation data
|
data*: AttestationData ## Attestation data
|
||||||
inclusion_delay*: uint64 ## Inclusion delay
|
inclusion_delay*: uint64 ## Inclusion delay
|
||||||
proposer_index*: ValidatorIndex ## Proposer index
|
proposer_index*: ValidatorIndex ## Proposer index
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#historicalbatch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#historicalbatch
|
||||||
HistoricalBatch* = object
|
HistoricalBatch* = object
|
||||||
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
||||||
## Block roots
|
## Block roots
|
||||||
|
@ -338,7 +338,7 @@ type
|
||||||
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
||||||
## State roots
|
## State roots
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#fork
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#fork
|
||||||
Fork* = object
|
Fork* = object
|
||||||
previous_version*: array[4, byte] ##\
|
previous_version*: array[4, byte] ##\
|
||||||
## Previous fork version
|
## Previous fork version
|
||||||
|
@ -349,7 +349,7 @@ type
|
||||||
epoch*: Epoch ##\
|
epoch*: Epoch ##\
|
||||||
## Fork epoch number
|
## Fork epoch number
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#eth1data
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#eth1data
|
||||||
Eth1Data* = object
|
Eth1Data* = object
|
||||||
deposit_root*: Eth2Digest ##\
|
deposit_root*: Eth2Digest ##\
|
||||||
## Root of the deposit tree
|
## Root of the deposit tree
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
# Serenity hash function / digest
|
# Serenity hash function / digest
|
||||||
#
|
#
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#hash
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#hash
|
||||||
#
|
#
|
||||||
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
||||||
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import ./datatypes, ./digest, sequtils, math
|
import ./datatypes, ./digest, sequtils, math
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#integer_squareroot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#integer_squareroot
|
||||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
## The largest integer ``x`` such that ``x**2`` is less than or equal to
|
## The largest integer ``x`` such that ``x**2`` is less than or equal to
|
||||||
## ``n``.
|
## ``n``.
|
||||||
|
@ -58,30 +58,30 @@ func merkle_root*(values: openArray[Eth2Digest]): Eth2Digest =
|
||||||
|
|
||||||
o[1]
|
o[1]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#slot_to_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#slot_to_epoch
|
||||||
func slot_to_epoch*(slot: Slot|uint64): Epoch =
|
func slot_to_epoch*(slot: Slot|uint64): Epoch =
|
||||||
# Return the epoch number of the given ``slot``.
|
# Return the epoch number of the given ``slot``.
|
||||||
(slot div SLOTS_PER_EPOCH).Epoch
|
(slot div SLOTS_PER_EPOCH).Epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_epoch_start_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_epoch_start_slot
|
||||||
func get_epoch_start_slot*(epoch: Epoch): Slot =
|
func get_epoch_start_slot*(epoch: Epoch): Slot =
|
||||||
# Return the starting slot of the given ``epoch``.
|
# Return the starting slot of the given ``epoch``.
|
||||||
(epoch * SLOTS_PER_EPOCH).Slot
|
(epoch * SLOTS_PER_EPOCH).Slot
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#is_active_validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#is_active_validator
|
||||||
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
||||||
### Check if ``validator`` is active
|
### Check if ``validator`` is active
|
||||||
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_active_validator_indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_active_validator_indices
|
||||||
func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
||||||
seq[ValidatorIndex] =
|
seq[ValidatorIndex] =
|
||||||
## Gets indices of active validators from validators
|
# Get active validator indices at ``epoch``.
|
||||||
for idx, val in state.validator_registry:
|
for idx, val in state.validator_registry:
|
||||||
if is_active_validator(val, epoch):
|
if is_active_validator(val, epoch):
|
||||||
result.add idx.ValidatorIndex
|
result.add idx.ValidatorIndex
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_epoch_committee_count
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_epoch_committee_count
|
||||||
func get_epoch_committee_count*(state: BeaconState, epoch: Epoch): uint64 =
|
func get_epoch_committee_count*(state: BeaconState, epoch: Epoch): uint64 =
|
||||||
# Return the number of committees at ``epoch``.
|
# Return the number of committees at ``epoch``.
|
||||||
let active_validator_indices = get_active_validator_indices(state, epoch)
|
let active_validator_indices = get_active_validator_indices(state, epoch)
|
||||||
|
@ -89,7 +89,7 @@ func get_epoch_committee_count*(state: BeaconState, epoch: Epoch): uint64 =
|
||||||
len(active_validator_indices) div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
len(active_validator_indices) div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
||||||
1, SHARD_COUNT div SLOTS_PER_EPOCH).uint64 * SLOTS_PER_EPOCH
|
1, SHARD_COUNT div SLOTS_PER_EPOCH).uint64 * SLOTS_PER_EPOCH
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_current_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_current_epoch
|
||||||
func get_current_epoch*(state: BeaconState): Epoch =
|
func get_current_epoch*(state: BeaconState): Epoch =
|
||||||
# Return the current epoch of the given ``state``.
|
# Return the current epoch of the given ``state``.
|
||||||
doAssert state.slot >= GENESIS_SLOT, $state.slot
|
doAssert state.slot >= GENESIS_SLOT, $state.slot
|
||||||
|
@ -103,7 +103,7 @@ func get_randao_mix*(state: BeaconState,
|
||||||
## LATEST_RANDAO_MIXES_LENGTH, current_epoch].
|
## LATEST_RANDAO_MIXES_LENGTH, current_epoch].
|
||||||
state.latest_randao_mixes[epoch mod LATEST_RANDAO_MIXES_LENGTH]
|
state.latest_randao_mixes[epoch mod LATEST_RANDAO_MIXES_LENGTH]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_active_index_root
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_active_index_root
|
||||||
func get_active_index_root(state: BeaconState, epoch: Epoch): Eth2Digest =
|
func get_active_index_root(state: BeaconState, epoch: Epoch): Eth2Digest =
|
||||||
# Returns the index root at a recent ``epoch``.
|
# Returns the index root at a recent ``epoch``.
|
||||||
## ``epoch`` expected to be between
|
## ``epoch`` expected to be between
|
||||||
|
|
|
@ -26,7 +26,7 @@ type
|
||||||
const
|
const
|
||||||
# Misc
|
# Misc
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#misc
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#misc
|
||||||
|
|
||||||
SHARD_COUNT* {.intdefine.} = 1024 ##\
|
SHARD_COUNT* {.intdefine.} = 1024 ##\
|
||||||
## Number of shards supported by the network - validators will jump around
|
## Number of shards supported by the network - validators will jump around
|
||||||
|
@ -57,7 +57,7 @@ const
|
||||||
|
|
||||||
# Deposit contract
|
# Deposit contract
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#deposit-contract
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/configs/constant_presets/mainnet.yaml#L24
|
||||||
|
|
||||||
DEPOSIT_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890"
|
DEPOSIT_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890"
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -66,7 +66,7 @@ const
|
||||||
|
|
||||||
# Gwei values
|
# Gwei values
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#gwei-values
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#gwei-values
|
||||||
|
|
||||||
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
|
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
|
||||||
## Minimum amounth of ETH that can be deposited in one call - deposits can
|
## Minimum amounth of ETH that can be deposited in one call - deposits can
|
||||||
|
@ -92,7 +92,7 @@ const
|
||||||
|
|
||||||
# Time parameters
|
# Time parameters
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_fork-choice.md#time-parameters
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_fork-choice.md#time-parameters
|
||||||
|
|
||||||
SECONDS_PER_SLOT*{.intdefine.} = 6'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 6x faster slots
|
SECONDS_PER_SLOT*{.intdefine.} = 6'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 6x faster slots
|
||||||
## TODO consistent time unit across projects, similar to C++ chrono?
|
## TODO consistent time unit across projects, similar to C++ chrono?
|
||||||
|
@ -141,15 +141,15 @@ const
|
||||||
|
|
||||||
# State list lengths
|
# State list lengths
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#state-list-lengths
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#state-list-lengths
|
||||||
LATEST_RANDAO_MIXES_LENGTH* = 8192
|
LATEST_RANDAO_MIXES_LENGTH* = 8192
|
||||||
LATEST_ACTIVE_INDEX_ROOTS_LENGTH* = 8192 # 2'u64^13, epochs
|
LATEST_ACTIVE_INDEX_ROOTS_LENGTH* = 8192 # 2'u64^13, epochs
|
||||||
LATEST_SLASHED_EXIT_LENGTH* = 8192 # epochs
|
LATEST_SLASHED_EXIT_LENGTH* = 8192 # epochs
|
||||||
|
|
||||||
# Reward and penalty quotients
|
# Reward and penalty quotients
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties
|
||||||
BASE_REWARD_QUOTIENT* = 2'u64^5
|
BASE_REWARD_FACTOR* = 2'u64^5
|
||||||
WHISTLEBLOWING_REWARD_QUOTIENT* = 2'u64^9
|
WHISTLEBLOWING_REWARD_QUOTIENT* = 2'u64^9
|
||||||
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
||||||
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
|
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
|
||||||
|
@ -157,7 +157,7 @@ const
|
||||||
|
|
||||||
# Max operations per block
|
# Max operations per block
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#max-operations-per-block
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#max-operations-per-block
|
||||||
MAX_PROPOSER_SLASHINGS* = 2^4
|
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||||
MAX_ATTESTER_SLASHINGS* = 2^0
|
MAX_ATTESTER_SLASHINGS* = 2^0
|
||||||
MAX_ATTESTATIONS* = 2^7
|
MAX_ATTESTATIONS* = 2^7
|
||||||
|
@ -168,7 +168,7 @@ const
|
||||||
type
|
type
|
||||||
# Signature domains
|
# Signature domains
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#signature-domains
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#signature-domains
|
||||||
SignatureDomain* {.pure.} = enum
|
SignatureDomain* {.pure.} = enum
|
||||||
DOMAIN_BEACON_PROPOSER = 0
|
DOMAIN_BEACON_PROPOSER = 0
|
||||||
DOMAIN_RANDAO = 1
|
DOMAIN_RANDAO = 1
|
||||||
|
|
|
@ -26,7 +26,7 @@ type
|
||||||
const
|
const
|
||||||
# Misc
|
# Misc
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#misc
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#misc
|
||||||
|
|
||||||
# Changed
|
# Changed
|
||||||
SHARD_COUNT* {.intdefine.} = 8
|
SHARD_COUNT* {.intdefine.} = 8
|
||||||
|
@ -43,15 +43,14 @@ const
|
||||||
|
|
||||||
# Deposit contract
|
# Deposit contract
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#deposit-contract
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#deposit-contract
|
||||||
|
|
||||||
# Unchanged
|
# Unchanged
|
||||||
DEPOSIT_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890"
|
|
||||||
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
|
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
|
||||||
|
|
||||||
# Gwei values
|
# Gwei values
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#gwei-values
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#gwei-values
|
||||||
|
|
||||||
# Unchanged
|
# Unchanged
|
||||||
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9
|
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9
|
||||||
|
@ -61,7 +60,7 @@ const
|
||||||
|
|
||||||
# Initial values
|
# Initial values
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/configs/constant_presets/minimal.yaml#L43
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/configs/constant_presets/minimal.yaml#L43
|
||||||
|
|
||||||
# Unchanged
|
# Unchanged
|
||||||
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
|
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
|
||||||
|
@ -71,12 +70,12 @@ const
|
||||||
|
|
||||||
# Time parameters
|
# Time parameters
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_fork-choice.md#time-parameters
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_fork-choice.md#time-parameters
|
||||||
|
|
||||||
# Unchanged
|
# Unchanged
|
||||||
SECONDS_PER_SLOT*{.intdefine.} = 6'u64
|
SECONDS_PER_SLOT*{.intdefine.} = 6'u64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#time-parameters
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#time-parameters
|
||||||
# Unchanged
|
# Unchanged
|
||||||
MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2
|
MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ const
|
||||||
|
|
||||||
# State list lengths
|
# State list lengths
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#state-list-lengths
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#state-list-lengths
|
||||||
|
|
||||||
# Changed
|
# Changed
|
||||||
LATEST_RANDAO_MIXES_LENGTH* = 64
|
LATEST_RANDAO_MIXES_LENGTH* = 64
|
||||||
|
@ -108,10 +107,10 @@ const
|
||||||
|
|
||||||
# Reward and penalty quotients
|
# Reward and penalty quotients
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties
|
||||||
|
|
||||||
# Unchanged
|
# Unchanged
|
||||||
BASE_REWARD_QUOTIENT* = 2'u64^5
|
BASE_REWARD_FACTOR* = 2'u64^5
|
||||||
WHISTLEBLOWING_REWARD_QUOTIENT* = 2'u64^9
|
WHISTLEBLOWING_REWARD_QUOTIENT* = 2'u64^9
|
||||||
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
||||||
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
|
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
|
||||||
|
@ -119,7 +118,7 @@ const
|
||||||
|
|
||||||
# Max operations per block
|
# Max operations per block
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#max-operations-per-block
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#max-operations-per-block
|
||||||
|
|
||||||
# Unchanged
|
# Unchanged
|
||||||
MAX_PROPOSER_SLASHINGS* = 2^4
|
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||||
|
@ -132,7 +131,7 @@ const
|
||||||
type
|
type
|
||||||
# Signature domains
|
# Signature domains
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#signature-domains
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#signature-domains
|
||||||
SignatureDomain* {.pure.} = enum
|
SignatureDomain* {.pure.} = enum
|
||||||
DOMAIN_BEACON_PROPOSER = 0
|
DOMAIN_BEACON_PROPOSER = 0
|
||||||
DOMAIN_RANDAO = 1
|
DOMAIN_RANDAO = 1
|
||||||
|
|
|
@ -13,8 +13,8 @@ import
|
||||||
./crypto, ./datatypes, ./digest, ./helpers
|
./crypto, ./datatypes, ./digest, ./helpers
|
||||||
|
|
||||||
# TODO: Proceed to renaming and signature changes
|
# TODO: Proceed to renaming and signature changes
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_shuffled_index
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_shuffled_index
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#compute_committee
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#compute_committee
|
||||||
func get_shuffled_seq*(seed: Eth2Digest,
|
func get_shuffled_seq*(seed: Eth2Digest,
|
||||||
list_size: uint64,
|
list_size: uint64,
|
||||||
): seq[ValidatorIndex] =
|
): seq[ValidatorIndex] =
|
||||||
|
@ -128,14 +128,14 @@ func get_previous_epoch*(state: BeaconState): Epoch =
|
||||||
else:
|
else:
|
||||||
current_epoch
|
current_epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_shard_delta
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_shard_delta
|
||||||
func get_shard_delta(state: BeaconState, epoch: Epoch): uint64 =
|
func get_shard_delta*(state: BeaconState, epoch: Epoch): uint64 =
|
||||||
## Return the number of shards to increment ``state.latest_start_shard``
|
## Return the number of shards to increment ``state.latest_start_shard``
|
||||||
## during ``epoch``.
|
## during ``epoch``.
|
||||||
min(get_epoch_committee_count(state, epoch),
|
min(get_epoch_committee_count(state, epoch),
|
||||||
(SHARD_COUNT - SHARD_COUNT div SLOTS_PER_EPOCH).uint64)
|
(SHARD_COUNT - SHARD_COUNT div SLOTS_PER_EPOCH).uint64)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_epoch_start_shard
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_epoch_start_shard
|
||||||
func get_epoch_start_shard*(state: BeaconState, epoch: Epoch): Shard =
|
func get_epoch_start_shard*(state: BeaconState, epoch: Epoch): Shard =
|
||||||
doAssert epoch <= get_current_epoch(state) + 1
|
doAssert epoch <= get_current_epoch(state) + 1
|
||||||
var
|
var
|
||||||
|
@ -149,7 +149,7 @@ func get_epoch_start_shard*(state: BeaconState, epoch: Epoch): Shard =
|
||||||
SHARD_COUNT
|
SHARD_COUNT
|
||||||
return shard
|
return shard
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#compute_committee
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#compute_committee
|
||||||
func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest,
|
func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest,
|
||||||
index: uint64, count: uint64): seq[ValidatorIndex] =
|
index: uint64, count: uint64): seq[ValidatorIndex] =
|
||||||
let
|
let
|
||||||
|
@ -161,7 +161,7 @@ func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest,
|
||||||
indices[
|
indices[
|
||||||
get_shuffled_index(it.ValidatorIndex, len(indices).uint64, seed).int])
|
get_shuffled_index(it.ValidatorIndex, len(indices).uint64, seed).int])
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_crosslink_committee
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_crosslink_committee
|
||||||
func get_crosslink_committee*(state: BeaconState, epoch: Epoch, shard: Shard):
|
func get_crosslink_committee*(state: BeaconState, epoch: Epoch, shard: Shard):
|
||||||
seq[ValidatorIndex] =
|
seq[ValidatorIndex] =
|
||||||
compute_committee(
|
compute_committee(
|
||||||
|
@ -212,7 +212,7 @@ iterator get_crosslink_committees_at_slot_cached*(
|
||||||
cache.crosslink_committee_cache[key] = result
|
cache.crosslink_committee_cache[key] = result
|
||||||
for v in result: yield v
|
for v in result: yield v
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_beacon_proposer_index
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_beacon_proposer_index
|
||||||
func get_beacon_proposer_index*(state: BeaconState): ValidatorIndex =
|
func get_beacon_proposer_index*(state: BeaconState): ValidatorIndex =
|
||||||
# Return the current beacon proposer index.
|
# Return the current beacon proposer index.
|
||||||
const
|
const
|
||||||
|
@ -239,6 +239,7 @@ func get_beacon_proposer_index*(state: BeaconState): ValidatorIndex =
|
||||||
random_byte = (eth2hash(buffer).data)[i mod 32]
|
random_byte = (eth2hash(buffer).data)[i mod 32]
|
||||||
effective_balance =
|
effective_balance =
|
||||||
state.validator_registry[candidate_index].effective_balance
|
state.validator_registry[candidate_index].effective_balance
|
||||||
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
if effective_balance * MAX_RANDOM_BYTE >=
|
||||||
|
MAX_EFFECTIVE_BALANCE * random_byte:
|
||||||
return candidate_index
|
return candidate_index
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
@ -120,7 +120,7 @@ func processEth1Data(state: var BeaconState, blck: BeaconBlock) =
|
||||||
SLOTS_PER_ETH1_VOTING_PERIOD:
|
SLOTS_PER_ETH1_VOTING_PERIOD:
|
||||||
state.latest_eth1_data = blck.body.eth1_data
|
state.latest_eth1_data = blck.body.eth1_data
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#is_slashable_validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#is_slashable_validator
|
||||||
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
||||||
# Check if ``validator`` is slashable.
|
# Check if ``validator`` is slashable.
|
||||||
(not validator.slashed) and
|
(not validator.slashed) and
|
||||||
|
@ -171,7 +171,7 @@ proc processProposerSlashings(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#is_slashable_attestation_data
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#is_slashable_attestation_data
|
||||||
func is_slashable_attestation_data(
|
func is_slashable_attestation_data(
|
||||||
data_1: AttestationData, data_2: AttestationData): bool =
|
data_1: AttestationData, data_2: AttestationData): bool =
|
||||||
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
||||||
|
@ -183,7 +183,7 @@ func is_slashable_attestation_data(
|
||||||
(data_1.source_epoch < data_2.source_epoch and
|
(data_1.source_epoch < data_2.source_epoch and
|
||||||
data_2.target_epoch < data_1.target_epoch)
|
data_2.target_epoch < data_1.target_epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#attester-slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#attester-slashings
|
||||||
proc processAttesterSlashings(state: var BeaconState, blck: BeaconBlock): bool =
|
proc processAttesterSlashings(state: var BeaconState, blck: BeaconBlock): bool =
|
||||||
# Process ``AttesterSlashing`` operation.
|
# Process ``AttesterSlashing`` operation.
|
||||||
if len(blck.body.attester_slashings) > MAX_ATTESTER_SLASHINGS:
|
if len(blck.body.attester_slashings) > MAX_ATTESTER_SLASHINGS:
|
||||||
|
@ -333,7 +333,7 @@ proc processVoluntaryExits(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#transfers
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#transfers
|
||||||
proc processTransfers(state: var BeaconState, blck: BeaconBlock,
|
proc processTransfers(state: var BeaconState, blck: BeaconBlock,
|
||||||
flags: UpdateFlags): bool =
|
flags: UpdateFlags): bool =
|
||||||
if not (len(blck.body.transfers) <= MAX_TRANSFERS):
|
if not (len(blck.body.transfers) <= MAX_TRANSFERS):
|
||||||
|
@ -681,7 +681,7 @@ func process_justification_and_finalization(state: var BeaconState) =
|
||||||
state.finalized_epoch = old_current_justified_epoch
|
state.finalized_epoch = old_current_justified_epoch
|
||||||
state.finalized_root = get_block_root(state, state.finalized_epoch)
|
state.finalized_root = get_block_root(state, state.finalized_epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#crosslinks
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#crosslinks
|
||||||
func process_crosslinks(state: var BeaconState, per_epoch_cache: var StateCache) =
|
func process_crosslinks(state: var BeaconState, per_epoch_cache: var StateCache) =
|
||||||
## TODO is there a semantic reason for this, or is this just a way to force
|
## TODO is there a semantic reason for this, or is this just a way to force
|
||||||
## copying? If so, why not just `list(foo)` or similar? This is strange. In
|
## copying? If so, why not just `list(foo)` or similar? This is strange. In
|
||||||
|
@ -711,7 +711,7 @@ func process_crosslinks(state: var BeaconState, per_epoch_cache: var StateCache)
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#rewards-and-penalties
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#rewards-and-penalties
|
||||||
func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei =
|
func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei =
|
||||||
let adjusted_quotient =
|
let adjusted_quotient =
|
||||||
integer_squareroot(get_total_active_balance(state)) div BASE_REWARD_QUOTIENT
|
integer_squareroot(get_total_active_balance(state)) div BASE_REWARD_FACTOR
|
||||||
if adjusted_quotient == 0:
|
if adjusted_quotient == 0:
|
||||||
return 0
|
return 0
|
||||||
state.validator_registry[index].effective_balance div adjusted_quotient div
|
state.validator_registry[index].effective_balance div adjusted_quotient div
|
||||||
|
@ -851,12 +851,6 @@ func process_slashings(state: var BeaconState) =
|
||||||
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT)
|
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT)
|
||||||
decrease_balance(state, index.ValidatorIndex, penalty)
|
decrease_balance(state, index.ValidatorIndex, penalty)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_shard_delta
|
|
||||||
func get_shard_delta(state: BeaconState, epoch: Epoch): uint64 =
|
|
||||||
# Return the number of shards to increment ``state.latest_start_shard`` during ``epoch``.
|
|
||||||
min(get_epoch_committee_count(state, epoch),
|
|
||||||
(SHARD_COUNT - SHARD_COUNT div SLOTS_PER_EPOCH).uint64)
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#final-updates
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#final-updates
|
||||||
func process_final_updates(state: var BeaconState) =
|
func process_final_updates(state: var BeaconState) =
|
||||||
let
|
let
|
||||||
|
|
|
@ -51,7 +51,7 @@ type
|
||||||
LATEST_RANDAO_MIXES_LENGTH*: int
|
LATEST_RANDAO_MIXES_LENGTH*: int
|
||||||
LATEST_ACTIVE_INDEX_ROOTS_LENGTH*: int
|
LATEST_ACTIVE_INDEX_ROOTS_LENGTH*: int
|
||||||
LATEST_SLASHED_EXIT_LENGTH*: int
|
LATEST_SLASHED_EXIT_LENGTH*: int
|
||||||
BASE_REWARD_QUOTIENT*: uint64
|
BASE_REWARD_FACTOR*: uint64
|
||||||
WHISTLEBLOWING_REWARD_QUOTIENT*: uint64
|
WHISTLEBLOWING_REWARD_QUOTIENT*: uint64
|
||||||
PROPOSER_REWARD_QUOTIENT*: uint64
|
PROPOSER_REWARD_QUOTIENT*: uint64
|
||||||
INACTIVITY_PENALTY_QUOTIENT*: uint64
|
INACTIVITY_PENALTY_QUOTIENT*: uint64
|
||||||
|
|
Loading…
Reference in New Issue