update everything https://github.com/ethereum/eth2.0-specs/releases/tag/v0.7.1 leaves unchanged from v0.7.0 to v0.7.1 (#290)

This commit is contained in:
Dustin Brody 2019-06-18 15:34:30 +00:00 committed by GitHub
parent 7293c6a420
commit 13381c8fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 102 additions and 102 deletions

View File

@ -11,7 +11,7 @@ import
./bitfield, ./crypto, ./datatypes, ./digest, ./helpers, ./validator, ./bitfield, ./crypto, ./datatypes, ./digest, ./helpers, ./validator,
tables tables
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#verify_merkle_branch # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#verify_merkle_branch
func verify_merkle_branch(leaf: Eth2Digest, proof: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool = func verify_merkle_branch(leaf: Eth2Digest, proof: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool =
## Verify that the given ``leaf`` is on the merkle branch ``proof`` ## Verify that the given ``leaf`` is on the merkle branch ``proof``
## starting with the given ``root``. ## starting with the given ``root``.
@ -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.7.0/specs/core/0_beacon-chain.md#increase_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#decrease_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.
@ -45,7 +45,7 @@ func decrease_balance*(
else: else:
state.balances[index] - delta state.balances[index] - delta
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#deposits # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#deposits
func process_deposit*( func process_deposit*(
state: var BeaconState, deposit: Deposit, flags: UpdateFlags = {}): bool = state: var BeaconState, deposit: Deposit, flags: UpdateFlags = {}): bool =
# Process an Eth1 deposit, registering a validator or increasing its balance. # Process an Eth1 deposit, registering a validator or increasing its balance.
@ -102,13 +102,13 @@ func process_deposit*(
true true
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_delayed_activation_exit_epoch # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#get_churn_limit # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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,
@ -116,7 +116,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.7.0/specs/core/0_beacon-chain.md#initiate_validator_exit # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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``.
@ -147,7 +147,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.7.0/specs/core/0_beacon-chain.md#slash_validator # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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)
@ -297,7 +297,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.7.0/specs/core/0_beacon-chain.md#get_block_root_at_slot # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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``.
@ -306,12 +306,12 @@ 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.7.0/specs/core/0_beacon-chain.md#get_block_root # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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))
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_total_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_total_balance
func get_total_balance*(state: BeaconState, validators: auto): Gwei = func get_total_balance*(state: BeaconState, validators: auto): Gwei =
## Return the combined effective balance of the ``indices``. (1 Gwei minimum ## Return the combined effective balance of the ``indices``. (1 Gwei minimum
## to avoid divisions by zero.) ## to avoid divisions by zero.)
@ -319,7 +319,7 @@ func get_total_balance*(state: BeaconState, validators: auto): Gwei =
foldl(validators, a + state.validator_registry[b].effective_balance, 0'u64) foldl(validators, a + state.validator_registry[b].effective_balance, 0'u64)
) )
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#registry-updates # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#registry-updates
func process_registry_updates*(state: var BeaconState) = func process_registry_updates*(state: var BeaconState) =
# Process activation eligibility and ejections # Process activation eligibility and ejections
for index, validator in state.validator_registry: for index, validator in state.validator_registry:
@ -357,7 +357,7 @@ func process_registry_updates*(state: var BeaconState) =
validator.activation_epoch = validator.activation_epoch =
get_delayed_activation_exit_epoch(get_current_epoch(state)) get_delayed_activation_exit_epoch(get_current_epoch(state))
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#validate_indexed_attestation # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#validate_indexed_attestation
func validate_indexed_attestation*( func validate_indexed_attestation*(
state: BeaconState, indexed_attestation: IndexedAttestation): bool = state: BeaconState, indexed_attestation: IndexedAttestation): bool =
# Verify validity of ``indexed_attestation`` fields. # Verify validity of ``indexed_attestation`` fields.
@ -408,7 +408,7 @@ func validate_indexed_attestation*(
), ),
) )
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_attesting_indices # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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] =
@ -439,7 +439,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.7.0/specs/core/0_beacon-chain.md#convert_to_indexed # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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

View File

@ -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.7.0/specs/core/0_beacon-chain.md#get_bitfield_bit # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#verify_bitfield # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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:

View File

@ -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.7.0/specs/bls_signature.md#bls_aggregate_pubkeys # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/bls_signature.md#bls_verify # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/bls_signature.md#bls_verify_multiple # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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 =

View File

@ -53,7 +53,7 @@ else:
{.fatal: "Preset \"" & const_preset ".nim\" is not supported.".} {.fatal: "Preset \"" & const_preset ".nim\" is not supported.".}
const const
SPEC_VERSION* = "0.7.0" ## \ SPEC_VERSION* = "0.7.1" ## \
## Spec version we're aiming to be compatible with, right now ## Spec version we're aiming to be compatible with, right now
## TODO: improve this scheme once we can negotiate versions in protocol ## TODO: improve this scheme once we can negotiate versions in protocol
@ -62,7 +62,7 @@ const
# Initial values # Initial values
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#initial-values # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#proposerslashing # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#attesterslashing # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#indexedattestation # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#attestation # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#attestation
Attestation* = object Attestation* = object
aggregation_bitfield*: BitField ##\ aggregation_bitfield*: BitField ##\
## Attester aggregation bitfield ## Attester aggregation bitfield
@ -134,12 +134,12 @@ 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.7.0/specs/core/0_beacon-chain.md#attestationdataandcustodybit # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#attestationdataandcustodybit
AttestationDataAndCustodyBit* = object AttestationDataAndCustodyBit* = object
data*: AttestationData data*: AttestationData
custody_bit*: bool custody_bit*: bool
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#deposit # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#deposit
Deposit* = object Deposit* = object
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest] ##\ proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest] ##\
## Branch in the deposit tree ## Branch in the deposit tree
@ -147,7 +147,7 @@ type
data*: DepositData ##\ data*: DepositData ##\
## Data ## Data
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#depositdata # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#depositdata
DepositData* = object DepositData* = object
pubkey*: ValidatorPubKey ##\ pubkey*: ValidatorPubKey ##\
## BLS pubkey ## BLS pubkey
@ -163,7 +163,7 @@ type
signature*: ValidatorSig ##\ signature*: ValidatorSig ##\
## Container self-signature ## Container self-signature
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#voluntaryexit # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -172,7 +172,7 @@ type
# Validator signature # Validator signature
signature*: ValidatorSig signature*: ValidatorSig
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#transfer # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#transfer
Transfer* = object Transfer* = object
sender*: uint64 ##\ sender*: uint64 ##\
## Sender index ## Sender index
@ -195,7 +195,7 @@ type
signature*: ValidatorSig ##\ signature*: ValidatorSig ##\
## Sender signature ## Sender signature
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beaconblock # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beaconblock
BeaconBlock* = object BeaconBlock* = object
## For each slot, a proposer is chosen from the validator pool to propose ## For each slot, a proposer is chosen from the validator pool to propose
## a new block. Once the block as been proposed, it is transmitted to ## a new block. Once the block as been proposed, it is transmitted to
@ -216,7 +216,7 @@ type
signature*: ValidatorSig ##\ signature*: ValidatorSig ##\
## Proposer signature ## Proposer signature
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beaconblockheader # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beaconblockheader
BeaconBlockHeader* = object BeaconBlockHeader* = object
slot*: Slot slot*: Slot
parent_root*: Eth2Digest parent_root*: Eth2Digest
@ -224,7 +224,7 @@ type
body_root*: Eth2Digest body_root*: Eth2Digest
signature*: ValidatorSig signature*: ValidatorSig
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beaconblockbody # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beaconblockbody
BeaconBlockBody* = object BeaconBlockBody* = object
randao_reveal*: ValidatorSig randao_reveal*: ValidatorSig
eth1_data*: Eth1Data eth1_data*: Eth1Data
@ -236,7 +236,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.7.0/specs/core/0_beacon-chain.md#beaconstate # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beaconstate
BeaconState* = object BeaconState* = object
slot*: Slot slot*: Slot
genesis_time*: uint64 genesis_time*: uint64
@ -283,7 +283,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.7.0/specs/core/0_beacon-chain.md#validator # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#validator
Validator* = object Validator* = object
pubkey*: ValidatorPubKey ##\ pubkey*: ValidatorPubKey ##\
## BLS public key ## BLS public key
@ -320,14 +320,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.7.0/specs/core/0_beacon-chain.md#pendingattestation # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#historicalbatch # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -335,7 +335,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.7.0/specs/core/0_beacon-chain.md#fork # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -346,7 +346,7 @@ type
epoch*: Epoch ##\ epoch*: Epoch ##\
## Fork epoch number ## Fork epoch number
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#eth1data # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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

View File

@ -7,7 +7,7 @@
# Serenity hash function / digest # Serenity hash function / digest
# #
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#hash # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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)

View File

@ -9,7 +9,7 @@
import ./datatypes, ./digest, sequtils, math import ./datatypes, ./digest, sequtils, math
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#integer_squareroot # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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,22 +58,22 @@ func merkle_root*(values: openArray[Eth2Digest]): Eth2Digest =
o[1] o[1]
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#slot_to_epoch # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#get_epoch_start_slot # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#is_active_validator # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#get_active_validator_indices # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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] =
# Get active validator indices at ``epoch``. # Get active validator indices at ``epoch``.
@ -81,7 +81,7 @@ func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
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.7.0/specs/core/0_beacon-chain.md#get_epoch_committee_count # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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,13 +89,13 @@ 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.7.0/specs/core/0_beacon-chain.md#get_current_epoch # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
slot_to_epoch(state.slot) slot_to_epoch(state.slot)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_randao_mix # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_randao_mix
func get_randao_mix*(state: BeaconState, func get_randao_mix*(state: BeaconState,
epoch: Epoch): Eth2Digest = epoch: Epoch): Eth2Digest =
## Returns the randao mix at a recent ``epoch``. ## Returns the randao mix at a recent ``epoch``.
@ -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.7.0/specs/core/0_beacon-chain.md#get_active_index_root # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -112,7 +112,7 @@ func get_active_index_root(state: BeaconState, epoch: Epoch): Eth2Digest =
## intentional ## intentional
state.latest_active_index_roots[epoch mod LATEST_ACTIVE_INDEX_ROOTS_LENGTH] state.latest_active_index_roots[epoch mod LATEST_ACTIVE_INDEX_ROOTS_LENGTH]
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#bytes_to_int # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#bytes_to_int
func bytes_to_int*(data: openarray[byte]): uint64 = func bytes_to_int*(data: openarray[byte]): uint64 =
doAssert data.len == 8 doAssert data.len == 8
@ -159,7 +159,7 @@ func bls_domain(domain_type: SignatureDomain, fork_version: array[4, byte]):
buf[4..7] = int_to_bytes4(domain_type.uint64) buf[4..7] = int_to_bytes4(domain_type.uint64)
bytes_to_int(buf) bytes_to_int(buf)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_domain # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_domain
func get_domain*( func get_domain*(
state: BeaconState, domain_type: SignatureDomain, message_epoch: Epoch): uint64 = state: BeaconState, domain_type: SignatureDomain, message_epoch: Epoch): uint64 =
## Return the signature domain (fork version concatenated with domain type) ## Return the signature domain (fork version concatenated with domain type)

View File

@ -22,11 +22,11 @@ type
{.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec {.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/configs/constant_presets/mainnet.yaml # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/configs/constant_presets/mainnet.yaml
const const
# Misc # Misc
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#misc # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/configs/constant_presets/mainnet.yaml#L24 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#gwei-values # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -83,7 +83,7 @@ const
# Initial values # Initial values
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/configs/constant_presets/mainnet.yaml#L44 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/configs/constant_presets/mainnet.yaml#L44
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8] GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
GENESIS_SLOT* = 0.Slot GENESIS_SLOT* = 0.Slot
@ -92,7 +92,7 @@ const
# Time parameters # Time parameters
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_fork-choice.md#time-parameters # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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,14 +141,14 @@ const
# State list lengths # State list lengths
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#state-list-lengths # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#rewards-and-penalties
BASE_REWARD_FACTOR* = 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
@ -157,7 +157,7 @@ const
# Max operations per block # 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 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#signature-domains # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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

View File

@ -22,11 +22,11 @@ type
{.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec {.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/configs/constant_presets/minimal.yaml # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/configs/constant_presets/minimal.yaml
const const
# Misc # Misc
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#misc # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#misc
# Changed # Changed
SHARD_COUNT* {.intdefine.} = 8 SHARD_COUNT* {.intdefine.} = 8
@ -43,14 +43,14 @@ const
# Deposit contract # Deposit contract
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#deposit-contract # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#deposit-contract
# Unchanged # Unchanged
DEPOSIT_CONTRACT_TREE_DEPTH* = 32 DEPOSIT_CONTRACT_TREE_DEPTH* = 32
# Gwei values # Gwei values
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#gwei-values # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -60,7 +60,7 @@ const
# Initial values # Initial values
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/configs/constant_presets/minimal.yaml#L43 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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]
@ -70,12 +70,12 @@ const
# Time parameters # Time parameters
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_fork-choice.md#time-parameters # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#time-parameters # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#time-parameters
# Unchanged # Unchanged
MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2 MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2
@ -98,7 +98,7 @@ const
# State list lengths # State list lengths
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#state-list-lengths # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#state-list-lengths
# Changed # Changed
LATEST_RANDAO_MIXES_LENGTH* = 64 LATEST_RANDAO_MIXES_LENGTH* = 64
@ -107,7 +107,7 @@ const
# Reward and penalty quotients # Reward and penalty quotients
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#rewards-and-penalties
# Unchanged # Unchanged
BASE_REWARD_FACTOR* = 2'u64^5 BASE_REWARD_FACTOR* = 2'u64^5
@ -118,7 +118,7 @@ const
# Max operations per block # 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 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#max-operations-per-block
# Unchanged # Unchanged
MAX_PROPOSER_SLASHINGS* = 2^4 MAX_PROPOSER_SLASHINGS* = 2^4
@ -131,7 +131,7 @@ const
type type
# Signature domains # Signature domains
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#signature-domains # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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

View File

@ -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.7.0/specs/core/0_beacon-chain.md#get_shuffled_index # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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#compute_committee # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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] =
@ -118,7 +118,7 @@ func get_shuffled_index(index: ValidatorIndex, index_count: uint64, seed: Eth2Di
if bit != 0: if bit != 0:
result = flip result = flip
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_previous_epoch # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_previous_epoch
func get_previous_epoch*(state: BeaconState): Epoch = func get_previous_epoch*(state: BeaconState): Epoch =
## Return the previous epoch of the given ``state``. ## Return the previous epoch of the given ``state``.
## Return the current epoch if it's genesis epoch. ## Return the current epoch if it's genesis epoch.
@ -128,14 +128,14 @@ func get_previous_epoch*(state: BeaconState): Epoch =
else: else:
current_epoch - 1 current_epoch - 1
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_shard_delta # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#get_epoch_start_shard # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#compute_committee # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#get_crosslink_committee # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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.7.0/specs/core/0_beacon-chain.md#get_beacon_proposer_index # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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

View File

@ -35,7 +35,7 @@ import
./extras, ./ssz, ./beacon_node_types, ./extras, ./ssz, ./beacon_node_types,
./spec/[beaconstate, bitfield, crypto, datatypes, digest, helpers, validator] ./spec/[beaconstate, bitfield, crypto, datatypes, digest, helpers, validator]
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#block-header # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#block-header
proc processBlockHeader( proc processBlockHeader(
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags): bool = state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags): bool =
# Verify that the slots match # Verify that the slots match
@ -81,7 +81,7 @@ proc processBlockHeader(
true true
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#randao # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#randao
proc processRandao( proc processRandao(
state: var BeaconState, body: BeaconBlockBody, flags: UpdateFlags): bool = state: var BeaconState, body: BeaconBlockBody, flags: UpdateFlags): bool =
let let
@ -112,14 +112,14 @@ proc processRandao(
true true
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#eth1-data # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#eth1-data
func processEth1Data(state: var BeaconState, body: BeaconBlockBody) = func processEth1Data(state: var BeaconState, body: BeaconBlockBody) =
state.eth1_data_votes.add body.eth1_data state.eth1_data_votes.add body.eth1_data
if state.eth1_data_votes.count(body.eth1_data) * 2 > if state.eth1_data_votes.count(body.eth1_data) * 2 >
SLOTS_PER_ETH1_VOTING_PERIOD: SLOTS_PER_ETH1_VOTING_PERIOD:
state.latest_eth1_data = body.eth1_data state.latest_eth1_data = body.eth1_data
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#is_slashable_validator # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -170,7 +170,7 @@ proc processProposerSlashings(
true true
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#is_slashable_attestation_data # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -182,7 +182,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.7.0/specs/core/0_beacon-chain.md#attester-slashings # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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:
@ -332,7 +332,7 @@ proc processVoluntaryExits(
true true
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#transfers # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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):
@ -413,7 +413,7 @@ func advance_slot(state: var BeaconState) =
state.slot += 1 state.slot += 1
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
func process_slot(state: var BeaconState) = func process_slot(state: var BeaconState) =
# Cache state root # Cache state root
let previous_state_root = hash_tree_root(state) let previous_state_root = hash_tree_root(state)
@ -614,7 +614,7 @@ func get_winning_crosslink_and_attesting_indices(
get_unslashed_attesting_indices(state, get_unslashed_attesting_indices(state,
get_attestations_for(winning_crosslink))) get_attestations_for(winning_crosslink)))
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#justification-and-finalization # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#justification-and-finalization
func process_justification_and_finalization(state: var BeaconState) = func process_justification_and_finalization(state: var BeaconState) =
if get_current_epoch(state) <= GENESIS_EPOCH + 1: if get_current_epoch(state) <= GENESIS_EPOCH + 1:
return return
@ -679,7 +679,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.7.0/specs/core/0_beacon-chain.md#crosslinks # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/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
@ -706,7 +706,7 @@ func process_crosslinks(state: var BeaconState, per_epoch_cache: var StateCache)
2'u64 * get_total_balance(state, crosslink_committee): 2'u64 * get_total_balance(state, crosslink_committee):
state.current_crosslinks[shard] = winning_crosslink state.current_crosslinks[shard] = winning_crosslink
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties-1 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#rewards-and-penalties-1
func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei = func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei =
let let
total_balance = get_total_active_balance(state) total_balance = get_total_active_balance(state)
@ -812,7 +812,7 @@ func get_crosslink_deltas(state: BeaconState, cache: var StateCache):
(rewards, penalties) (rewards, penalties)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties-1 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#rewards-and-penalties-1
func process_rewards_and_penalties( func process_rewards_and_penalties(
state: var BeaconState, cache: var StateCache) = state: var BeaconState, cache: var StateCache) =
if get_current_epoch(state) == GENESIS_EPOCH: if get_current_epoch(state) == GENESIS_EPOCH:
@ -825,7 +825,7 @@ func process_rewards_and_penalties(
increase_balance(state, i.ValidatorIndex, rewards1[i] + rewards2[i]) increase_balance(state, i.ValidatorIndex, rewards1[i] + rewards2[i])
decrease_balance(state, i.ValidatorIndex, penalties1[i] + penalties2[i]) decrease_balance(state, i.ValidatorIndex, penalties1[i] + penalties2[i])
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#slashings # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#slashings
func process_slashings(state: var BeaconState) = func process_slashings(state: var BeaconState) =
let let
current_epoch = get_current_epoch(state) current_epoch = get_current_epoch(state)
@ -908,24 +908,24 @@ func processEpoch(state: var BeaconState) =
(state.slot + 1) mod SLOTS_PER_EPOCH == 0): (state.slot + 1) mod SLOTS_PER_EPOCH == 0):
return return
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#justification-and-finalization # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#justification-and-finalization
process_justification_and_finalization(state) process_justification_and_finalization(state)
var per_epoch_cache = get_empty_per_epoch_cache() var per_epoch_cache = get_empty_per_epoch_cache()
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#crosslinks # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#crosslinks
process_crosslinks(state, per_epoch_cache) process_crosslinks(state, per_epoch_cache)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties-1 # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#rewards-and-penalties-1
process_rewards_and_penalties(state, per_epoch_cache) process_rewards_and_penalties(state, per_epoch_cache)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#registry-updates # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#registry-updates
process_registry_updates(state) process_registry_updates(state)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#slashings # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#slashings
process_slashings(state) process_slashings(state)
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#final-updates # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#final-updates
process_final_updates(state) process_final_updates(state)
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#state-root-verification # https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#state-root-verification
@ -1033,7 +1033,7 @@ proc skipSlots*(state: var BeaconState, slot: Slot,
# TODO hashed versions of above - not in spec # TODO hashed versions of above - not in spec
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
func process_slot(state: var HashedBeaconState) = func process_slot(state: var HashedBeaconState) =
# Cache state root # Cache state root
let previous_slot_state_root = state.root let previous_slot_state_root = state.root

View File

@ -14,7 +14,7 @@ type
## which blocks are valid - in particular, blocks are not valid if they ## which blocks are valid - in particular, blocks are not valid if they
## come from the future as seen from the local clock. ## come from the future as seen from the local clock.
## ##
## https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_fork-choice.md#beacon-chain-processing ## https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_fork-choice.md#beacon-chain-processing
## ##
# TODO replace time in chronos with a proper unit type, then this code can # TODO replace time in chronos with a proper unit type, then this code can
# follow: # follow: