diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 1796114b8..5e7096752 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -29,13 +29,13 @@ func verify_merkle_branch(leaf: Eth2Digest, proof: openarray[Eth2Digest], depth: value = eth2hash(buf) 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*( state: var BeaconState, index: ValidatorIndex, delta: Gwei) = # Increase validator balance by ``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*( state: var BeaconState, index: ValidatorIndex, delta: Gwei) = # Decrease validator balance by ``delta`` with underflow protection. @@ -108,13 +108,13 @@ func process_deposit*( 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 = ## Return the epoch at which an activation or exit triggered in ``epoch`` ## takes effect. 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 = max( MIN_PER_EPOCH_CHURN_LIMIT, @@ -122,7 +122,7 @@ func get_churn_limit(state: BeaconState): uint64 = CHURN_LIMIT_QUOTIENT ).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, index: ValidatorIndex) = # Initiate the validator of the given ``index``. @@ -153,7 +153,7 @@ func initiate_validator_exit*(state: var BeaconState, validator.withdrawable_epoch = 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) = # Slash the validator with index ``index``. let current_epoch = get_current_epoch(state) @@ -303,7 +303,7 @@ func get_attestation_slot*(state: BeaconState, get_attestation_slot( 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, slot: Slot): Eth2Digest = # Return the block root at a recent ``slot``. @@ -312,7 +312,7 @@ func get_block_root_at_slot*(state: BeaconState, doAssert slot < state.slot 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 = # Return the block root at a recent ``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, attestation_data: AttestationData, bitfield: BitField): HashSet[ValidatorIndex] = @@ -438,7 +438,7 @@ iterator get_attestation_participants_cached*( for participant in get_attesting_indices(state, attestation_data, bitfield): 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 = # Convert ``attestation`` to (almost) indexed-verifiable form. let diff --git a/beacon_chain/spec/bitfield.nim b/beacon_chain/spec/bitfield.nim index af28fecfd..5b4506841 100644 --- a/beacon_chain/spec/bitfield.nim +++ b/beacon_chain/spec/bitfield.nim @@ -17,14 +17,14 @@ func init*(T: type BitField, bits: int): BitField = #proc readValue*(r: var JsonReader, a: var BitField) {.inline.} = # 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 = # Extract the bit in ``bitfield`` at position ``i``. 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) ((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 = # Verify ``bitfield`` against the ``committee_size``. if len(bitfield.bits) != (committee_size + 7) div 8: diff --git a/beacon_chain/spec/crypto.nim b/beacon_chain/spec/crypto.nim index 631c090b6..372b5058b 100644 --- a/beacon_chain/spec/crypto.nim +++ b/beacon_chain/spec/crypto.nim @@ -69,7 +69,7 @@ template hash*(k: ValidatorPubKey|ValidatorPrivKey): Hash = 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 = var empty = true for key in keys: @@ -79,14 +79,14 @@ func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey = else: 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*( pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig, domain: uint64): bool = # name from spec! 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*( pubkeys: seq[ValidatorPubKey], message_hashes: openArray[Eth2Digest], sig: ValidatorSig, domain: uint64): bool = diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index 1e3da1e46..82677d7a1 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -62,7 +62,7 @@ const # 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 ##\ ## slot_to_epoch(GENESIS_SLOT) ZERO_HASH* = Eth2Digest() @@ -73,7 +73,7 @@ type Shard* = 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 proposer_index*: uint64 ##\ ## Proposer index @@ -84,14 +84,14 @@ type header_2*: BeaconBlockHeader ##\ # 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 attestation_1*: IndexedAttestation ## \ ## First attestation attestation_2*: IndexedAttestation ## \ ## 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 # These probably should be seq[ValidatorIndex], but that throws RLP errors custody_bit_0_indices*: seq[uint64] @@ -103,7 +103,7 @@ type signature*: ValidatorSig ## \ ## 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 aggregation_bitfield*: BitField ##\ ## Attester aggregation bitfield @@ -134,7 +134,7 @@ type previous_crosslink_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 data*: AttestationData custody_bit*: bool @@ -150,7 +150,7 @@ type data*: DepositData ##\ ## 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 pubkey*: ValidatorPubKey ##\ ## BLS pubkey @@ -166,7 +166,7 @@ type signature*: ValidatorSig ##\ ## 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 # Minimum epoch for processing exit epoch*: Epoch @@ -175,7 +175,7 @@ type # Validator signature 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 sender*: uint64 ##\ ## Sender index @@ -227,7 +227,7 @@ type block_body_root*: Eth2Digest 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 randao_reveal*: ValidatorSig eth1_data*: Eth1Data @@ -239,7 +239,7 @@ type voluntary_exits*: seq[VoluntaryExit] 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 slot*: Slot genesis_time*: uint64 @@ -286,7 +286,7 @@ type eth1_data_votes*: seq[Eth1Data] 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 pubkey*: ValidatorPubKey ##\ ## BLS public key @@ -323,14 +323,14 @@ type crosslink_data_root*: Eth2Digest ##\ ## 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 aggregation_bitfield*: BitField ## Attester participation bitfield data*: AttestationData ## Attestation data inclusion_delay*: uint64 ## Inclusion delay 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 block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\ ## Block roots @@ -338,7 +338,7 @@ type state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\ ## 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 previous_version*: array[4, byte] ##\ ## Previous fork version @@ -349,7 +349,7 @@ type epoch*: Epoch ##\ ## 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 deposit_root*: Eth2Digest ##\ ## Root of the deposit tree diff --git a/beacon_chain/spec/digest.nim b/beacon_chain/spec/digest.nim index 640f4b040..4f20e4e37 100644 --- a/beacon_chain/spec/digest.nim +++ b/beacon_chain/spec/digest.nim @@ -7,7 +7,7 @@ # 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). # Note that is is different from Keccak256 (often mistakenly called SHA3-256) diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index a2b36110e..d675c350a 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -9,7 +9,7 @@ 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 = ## The largest integer ``x`` such that ``x**2`` is less than or equal to ## ``n``. @@ -58,30 +58,30 @@ func merkle_root*(values: openArray[Eth2Digest]): Eth2Digest = 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 = # Return the epoch number of the given ``slot``. (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 = # Return the starting slot of the given ``epoch``. (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 = ### Check if ``validator`` is active 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): seq[ValidatorIndex] = - ## Gets indices of active validators from validators + # Get active validator indices at ``epoch``. for idx, val in state.validator_registry: if is_active_validator(val, epoch): 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 = # Return the number of committees at ``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, 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 = # Return the current epoch of the given ``state``. doAssert state.slot >= GENESIS_SLOT, $state.slot @@ -103,7 +103,7 @@ func get_randao_mix*(state: BeaconState, ## LATEST_RANDAO_MIXES_LENGTH, current_epoch]. 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 = # Returns the index root at a recent ``epoch``. ## ``epoch`` expected to be between diff --git a/beacon_chain/spec/presets/mainnet.nim b/beacon_chain/spec/presets/mainnet.nim index 25abeb8d3..2e6eab56a 100644 --- a/beacon_chain/spec/presets/mainnet.nim +++ b/beacon_chain/spec/presets/mainnet.nim @@ -26,7 +26,7 @@ type const # 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 ##\ ## Number of shards supported by the network - validators will jump around @@ -57,7 +57,7 @@ const # 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" # TODO @@ -66,7 +66,7 @@ const # 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 ##\ ## Minimum amounth of ETH that can be deposited in one call - deposits can @@ -92,7 +92,7 @@ const # 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 ## TODO consistent time unit across projects, similar to C++ chrono? @@ -141,15 +141,15 @@ const # 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_ACTIVE_INDEX_ROOTS_LENGTH* = 8192 # 2'u64^13, epochs LATEST_SLASHED_EXIT_LENGTH* = 8192 # epochs # 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 - BASE_REWARD_QUOTIENT* = 2'u64^5 + # https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#rewards-and-penalties + BASE_REWARD_FACTOR* = 2'u64^5 WHISTLEBLOWING_REWARD_QUOTIENT* = 2'u64^9 PROPOSER_REWARD_QUOTIENT* = 2'u64^3 INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25 @@ -157,7 +157,7 @@ const # 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_ATTESTER_SLASHINGS* = 2^0 MAX_ATTESTATIONS* = 2^7 @@ -168,7 +168,7 @@ const type # 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 DOMAIN_BEACON_PROPOSER = 0 DOMAIN_RANDAO = 1 diff --git a/beacon_chain/spec/presets/minimal.nim b/beacon_chain/spec/presets/minimal.nim index 72355c037..c97b3720f 100644 --- a/beacon_chain/spec/presets/minimal.nim +++ b/beacon_chain/spec/presets/minimal.nim @@ -26,7 +26,7 @@ type const # 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 SHARD_COUNT* {.intdefine.} = 8 @@ -43,15 +43,14 @@ const # 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 - DEPOSIT_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890" DEPOSIT_CONTRACT_TREE_DEPTH* = 32 # 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 MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 @@ -61,7 +60,7 @@ const # 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 GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8] @@ -71,12 +70,12 @@ const # 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 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 MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2 @@ -99,7 +98,7 @@ const # 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 LATEST_RANDAO_MIXES_LENGTH* = 64 @@ -108,10 +107,10 @@ const # 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 - BASE_REWARD_QUOTIENT* = 2'u64^5 + BASE_REWARD_FACTOR* = 2'u64^5 WHISTLEBLOWING_REWARD_QUOTIENT* = 2'u64^9 PROPOSER_REWARD_QUOTIENT* = 2'u64^3 INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25 @@ -119,7 +118,7 @@ const # 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 MAX_PROPOSER_SLASHINGS* = 2^4 @@ -132,7 +131,7 @@ const type # 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 DOMAIN_BEACON_PROPOSER = 0 DOMAIN_RANDAO = 1 diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index 0ab58eb55..6102255e4 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -13,8 +13,8 @@ import ./crypto, ./datatypes, ./digest, ./helpers # 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.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#get_shuffled_index +# 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, list_size: uint64, ): seq[ValidatorIndex] = @@ -128,14 +128,14 @@ func get_previous_epoch*(state: BeaconState): Epoch = else: current_epoch -# 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 = +# 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 = ## 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#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 = doAssert epoch <= get_current_epoch(state) + 1 var @@ -149,7 +149,7 @@ func get_epoch_start_shard*(state: BeaconState, epoch: Epoch): Shard = SHARD_COUNT 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, index: uint64, count: uint64): seq[ValidatorIndex] = let @@ -161,7 +161,7 @@ func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest, indices[ 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): seq[ValidatorIndex] = compute_committee( @@ -212,7 +212,7 @@ iterator get_crosslink_committees_at_slot_cached*( cache.crosslink_committee_cache[key] = result 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 = # Return the current beacon proposer index. const @@ -239,6 +239,7 @@ func get_beacon_proposer_index*(state: BeaconState): ValidatorIndex = random_byte = (eth2hash(buffer).data)[i mod 32] 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 i += 1 diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 78def2f01..8687fdc02 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -120,7 +120,7 @@ func processEth1Data(state: var BeaconState, blck: BeaconBlock) = SLOTS_PER_ETH1_VOTING_PERIOD: 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 = # Check if ``validator`` is slashable. (not validator.slashed) and @@ -171,7 +171,7 @@ proc processProposerSlashings( 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( data_1: AttestationData, data_2: AttestationData): bool = ## 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_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 = # Process ``AttesterSlashing`` operation. if len(blck.body.attester_slashings) > MAX_ATTESTER_SLASHINGS: @@ -333,7 +333,7 @@ proc processVoluntaryExits( 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, flags: UpdateFlags): bool = 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_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) = ## 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 @@ -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 func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei = 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: return 0 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) 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 func process_final_updates(state: var BeaconState) = let diff --git a/tests/official/fixtures_utils.nim b/tests/official/fixtures_utils.nim index acaf4d879..ae7091bf2 100644 --- a/tests/official/fixtures_utils.nim +++ b/tests/official/fixtures_utils.nim @@ -51,7 +51,7 @@ type LATEST_RANDAO_MIXES_LENGTH*: int LATEST_ACTIVE_INDEX_ROOTS_LENGTH*: int LATEST_SLASHED_EXIT_LENGTH*: int - BASE_REWARD_QUOTIENT*: uint64 + BASE_REWARD_FACTOR*: uint64 WHISTLEBLOWING_REWARD_QUOTIENT*: uint64 PROPOSER_REWARD_QUOTIENT*: uint64 INACTIVITY_PENALTY_QUOTIENT*: uint64