mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-24 04:08:32 +00:00
0.11.1 beacon chain spec update (#836)
* initial 0.11.1 spec commit; no test regressions and finalizes in eth2_network_simulation * with BLS 0.10/0.11 available, stop skipping attester slashing, proposer slashing, and voluntary exist operations fixture tests * switch param orders to group state.{fork, genesis_validators_root}; bump spec/datatypes spec version for network purposes * mark attestation construction and broadcast and some minimal/mainnet constants as 0.11.1-compatible; remove phase 1 sharding constants from minimal which don't exist in that preset
This commit is contained in:
parent
b44ba24142
commit
f5f939bd31
@ -51,7 +51,7 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
|||||||
+ Attestation topics OK
|
+ Attestation topics OK
|
||||||
```
|
```
|
||||||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
## Official - 0.11.0 - constants & config [Preset: mainnet]
|
## Official - 0.11.1 - constants & config [Preset: mainnet]
|
||||||
```diff
|
```diff
|
||||||
+ BASE_REWARD_FACTOR 64 [Preset: mainnet] OK
|
+ BASE_REWARD_FACTOR 64 [Preset: mainnet] OK
|
||||||
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: mainnet] OK
|
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: mainnet] OK
|
||||||
|
@ -78,7 +78,7 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
|||||||
+ Attestation topics OK
|
+ Attestation topics OK
|
||||||
```
|
```
|
||||||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
## Official - 0.11.0 - constants & config [Preset: minimal]
|
## Official - 0.11.1 - constants & config [Preset: minimal]
|
||||||
```diff
|
```diff
|
||||||
+ BASE_REWARD_FACTOR 64 [Preset: minimal] OK
|
+ BASE_REWARD_FACTOR 64 [Preset: minimal] OK
|
||||||
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: minimal] OK
|
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: minimal] OK
|
||||||
|
@ -45,6 +45,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||||||
+ [Invalid] after_epoch_slots OK
|
+ [Invalid] after_epoch_slots OK
|
||||||
+ [Invalid] bad_source_root OK
|
+ [Invalid] bad_source_root OK
|
||||||
+ [Invalid] before_inclusion_delay OK
|
+ [Invalid] before_inclusion_delay OK
|
||||||
|
+ [Invalid] empty_aggregation_bits OK
|
||||||
+ [Invalid] future_target_epoch OK
|
+ [Invalid] future_target_epoch OK
|
||||||
+ [Invalid] invalid_attestation_signature OK
|
+ [Invalid] invalid_attestation_signature OK
|
||||||
+ [Invalid] invalid_current_source_root OK
|
+ [Invalid] invalid_current_source_root OK
|
||||||
@ -58,7 +59,6 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||||||
+ [Invalid] too_many_aggregation_bits OK
|
+ [Invalid] too_many_aggregation_bits OK
|
||||||
+ [Invalid] wrong_index_for_committee_signature OK
|
+ [Invalid] wrong_index_for_committee_signature OK
|
||||||
+ [Invalid] wrong_index_for_slot OK
|
+ [Invalid] wrong_index_for_slot OK
|
||||||
+ [Valid] empty_aggregation_bits OK
|
|
||||||
+ [Valid] success OK
|
+ [Valid] success OK
|
||||||
+ [Valid] success_multi_proposer_index_iterations OK
|
+ [Valid] success_multi_proposer_index_iterations OK
|
||||||
+ [Valid] success_previous_epoch OK
|
+ [Valid] success_previous_epoch OK
|
||||||
|
@ -45,6 +45,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||||||
+ [Invalid] after_epoch_slots OK
|
+ [Invalid] after_epoch_slots OK
|
||||||
+ [Invalid] bad_source_root OK
|
+ [Invalid] bad_source_root OK
|
||||||
+ [Invalid] before_inclusion_delay OK
|
+ [Invalid] before_inclusion_delay OK
|
||||||
|
+ [Invalid] empty_aggregation_bits OK
|
||||||
+ [Invalid] future_target_epoch OK
|
+ [Invalid] future_target_epoch OK
|
||||||
+ [Invalid] invalid_attestation_signature OK
|
+ [Invalid] invalid_attestation_signature OK
|
||||||
+ [Invalid] invalid_current_source_root OK
|
+ [Invalid] invalid_current_source_root OK
|
||||||
@ -58,7 +59,6 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||||||
+ [Invalid] too_many_aggregation_bits OK
|
+ [Invalid] too_many_aggregation_bits OK
|
||||||
+ [Invalid] wrong_index_for_committee_signature OK
|
+ [Invalid] wrong_index_for_committee_signature OK
|
||||||
+ [Invalid] wrong_index_for_slot OK
|
+ [Invalid] wrong_index_for_slot OK
|
||||||
+ [Valid] empty_aggregation_bits OK
|
|
||||||
+ [Valid] success OK
|
+ [Valid] success OK
|
||||||
+ [Valid] success_multi_proposer_index_iterations OK
|
+ [Valid] success_multi_proposer_index_iterations OK
|
||||||
+ [Valid] success_previous_epoch OK
|
+ [Valid] success_previous_epoch OK
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
FixtureSSZConsensus-mainnet
|
FixtureSSZConsensus-mainnet
|
||||||
===
|
===
|
||||||
## Official - 0.11.0 - SSZ consensus objects [Preset: mainnet]
|
## Official - 0.11.1 - SSZ consensus objects [Preset: mainnet]
|
||||||
```diff
|
```diff
|
||||||
+ Testing AggregateAndProof OK
|
+ Testing AggregateAndProof OK
|
||||||
+ Testing Attestation OK
|
+ Testing Attestation OK
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
FixtureSSZConsensus-minimal
|
FixtureSSZConsensus-minimal
|
||||||
===
|
===
|
||||||
## Official - 0.11.0 - SSZ consensus objects [Preset: minimal]
|
## Official - 0.11.1 - SSZ consensus objects [Preset: minimal]
|
||||||
```diff
|
```diff
|
||||||
+ Testing AggregateAndProof OK
|
+ Testing AggregateAndProof OK
|
||||||
+ Testing Attestation OK
|
+ Testing Attestation OK
|
||||||
|
@ -308,7 +308,7 @@ proc getAttestationsForBlock*(
|
|||||||
|
|
||||||
for a in slotData.attestations:
|
for a in slotData.attestations:
|
||||||
var
|
var
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#construct-attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#construct-attestation
|
||||||
attestation = Attestation(
|
attestation = Attestation(
|
||||||
aggregation_bits: a.validations[0].aggregation_bits,
|
aggregation_bits: a.validations[0].aggregation_bits,
|
||||||
data: a.data,
|
data: a.data,
|
||||||
|
@ -316,14 +316,15 @@ proc updateHead(node: BeaconNode): BlockRef =
|
|||||||
|
|
||||||
proc sendAttestation(node: BeaconNode,
|
proc sendAttestation(node: BeaconNode,
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
|
genesis_validators_root: Eth2Digest,
|
||||||
validator: AttachedValidator,
|
validator: AttachedValidator,
|
||||||
attestationData: AttestationData,
|
attestationData: AttestationData,
|
||||||
committeeLen: int,
|
committeeLen: int,
|
||||||
indexInCommittee: int) {.async.} =
|
indexInCommittee: int) {.async.} =
|
||||||
logScope: pcs = "send_attestation"
|
logScope: pcs = "send_attestation"
|
||||||
|
|
||||||
let
|
let validatorSignature = await validator.signAttestation(attestationData,
|
||||||
validatorSignature = await validator.signAttestation(attestationData, fork)
|
fork, genesis_validators_root)
|
||||||
|
|
||||||
var aggregationBits = CommitteeValidatorsBits.init(committeeLen)
|
var aggregationBits = CommitteeValidatorsBits.init(committeeLen)
|
||||||
aggregationBits.setBit indexInCommittee
|
aggregationBits.setBit indexInCommittee
|
||||||
@ -334,7 +335,7 @@ proc sendAttestation(node: BeaconNode,
|
|||||||
aggregation_bits: aggregationBits
|
aggregation_bits: aggregationBits
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#broadcast-attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#broadcast-attestation
|
||||||
node.network.broadcast(
|
node.network.broadcast(
|
||||||
getAttestationTopic(attestationData.index), attestation)
|
getAttestationTopic(attestationData.index), attestation)
|
||||||
|
|
||||||
@ -384,7 +385,7 @@ proc proposeBlock(node: BeaconNode,
|
|||||||
let message = makeBeaconBlock(
|
let message = makeBeaconBlock(
|
||||||
state,
|
state,
|
||||||
head.root,
|
head.root,
|
||||||
validator.genRandaoReveal(state.fork, slot),
|
validator.genRandaoReveal(state.fork, state.genesis_validators_root, slot),
|
||||||
eth1data,
|
eth1data,
|
||||||
Eth2Digest(),
|
Eth2Digest(),
|
||||||
node.attestationPool.getAttestationsForBlock(state),
|
node.attestationPool.getAttestationsForBlock(state),
|
||||||
@ -400,8 +401,8 @@ proc proposeBlock(node: BeaconNode,
|
|||||||
let blockRoot = hash_tree_root(newBlock.message)
|
let blockRoot = hash_tree_root(newBlock.message)
|
||||||
|
|
||||||
# Careful, state no longer valid after here because of the await..
|
# Careful, state no longer valid after here because of the await..
|
||||||
newBlock.signature =
|
newBlock.signature = await validator.signBlockProposal(
|
||||||
await validator.signBlockProposal(state.fork, slot, blockRoot)
|
state.fork, state.genesis_validators_root, slot, blockRoot)
|
||||||
|
|
||||||
(blockRoot, newBlock)
|
(blockRoot, newBlock)
|
||||||
|
|
||||||
@ -556,7 +557,8 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
|
|||||||
|
|
||||||
for a in attestations:
|
for a in attestations:
|
||||||
traceAsyncErrors sendAttestation(
|
traceAsyncErrors sendAttestation(
|
||||||
node, state.fork, a.validator, a.data, a.committeeLen, a.indexInCommittee)
|
node, state.fork, state.genesis_validators_root, a.validator, a.data,
|
||||||
|
a.committeeLen, a.indexInCommittee)
|
||||||
|
|
||||||
proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
|
proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
|
||||||
Future[BlockRef] {.async.} =
|
Future[BlockRef] {.async.} =
|
||||||
|
@ -286,12 +286,12 @@ func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
|||||||
# Return the block root at the start of a recent ``epoch``.
|
# Return the block root at the start of a recent ``epoch``.
|
||||||
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/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``.
|
||||||
## to avoid divisions by zero.)
|
## ``EFFECTIVE_BALANCE_INCREMENT`` Gwei minimum to avoid divisions by zero.
|
||||||
## Math safe up to ~10B ETH, afterwhich this overflows uint64.
|
## Math safe up to ~10B ETH, afterwhich this overflows uint64.
|
||||||
max(1'u64,
|
max(EFFECTIVE_BALANCE_INCREMENT,
|
||||||
foldl(validators, a + state.validators[b].effective_balance, 0'u64)
|
foldl(validators, a + state.validators[b].effective_balance, 0'u64)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -365,7 +365,7 @@ proc process_registry_updates*(state: var BeaconState) {.nbench.}=
|
|||||||
validator.activation_epoch =
|
validator.activation_epoch =
|
||||||
compute_activation_exit_epoch(get_current_epoch(state))
|
compute_activation_exit_epoch(get_current_epoch(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_valid_indexed_attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||||
proc is_valid_indexed_attestation*(
|
proc is_valid_indexed_attestation*(
|
||||||
state: BeaconState, indexed_attestation: IndexedAttestation,
|
state: BeaconState, indexed_attestation: IndexedAttestation,
|
||||||
flags: UpdateFlags): bool =
|
flags: UpdateFlags): bool =
|
||||||
@ -381,7 +381,6 @@ proc is_valid_indexed_attestation*(
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
# Verify indices are sorted and unique
|
# Verify indices are sorted and unique
|
||||||
# TODO but why? this is a local artifact
|
|
||||||
if indices != sorted(indices, system.cmp):
|
if indices != sorted(indices, system.cmp):
|
||||||
notice "indexed attestation: indices not sorted"
|
notice "indexed attestation: indices not sorted"
|
||||||
return false
|
return false
|
||||||
@ -436,7 +435,7 @@ func get_indexed_attestation(state: BeaconState, attestation: Attestation,
|
|||||||
signature: attestation.signature
|
signature: attestation.signature
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#attestations
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#attestations
|
||||||
proc check_attestation*(
|
proc check_attestation*(
|
||||||
state: BeaconState, attestation: Attestation, flags: UpdateFlags,
|
state: BeaconState, attestation: Attestation, flags: UpdateFlags,
|
||||||
stateCache: var StateCache): bool =
|
stateCache: var StateCache): bool =
|
||||||
|
@ -57,7 +57,7 @@ else:
|
|||||||
loadCustomPreset const_preset
|
loadCustomPreset const_preset
|
||||||
|
|
||||||
const
|
const
|
||||||
SPEC_VERSION* = "0.11.0" ## \
|
SPEC_VERSION* = "0.11.1" ## \
|
||||||
## Spec version we're aiming to be compatible with, right now
|
## Spec version we're aiming to be compatible with, right now
|
||||||
|
|
||||||
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
||||||
|
@ -149,25 +149,21 @@ func compute_domain*(
|
|||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_domain
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_domain
|
||||||
func get_domain*(
|
func get_domain*(
|
||||||
fork: Fork, domain_type: DomainType, epoch: Epoch): Domain =
|
fork: Fork, domain_type: DomainType, epoch: Epoch, genesis_validators_root: Eth2Digest): Domain =
|
||||||
## Return the signature domain (fork version concatenated with domain type)
|
## Return the signature domain (fork version concatenated with domain type)
|
||||||
## of a message.
|
## of a message.
|
||||||
let
|
let fork_version =
|
||||||
fork_version =
|
if epoch < fork.epoch:
|
||||||
if epoch < fork.epoch:
|
fork.previous_version
|
||||||
fork.previous_version
|
else:
|
||||||
else:
|
fork.current_version
|
||||||
fork.current_version
|
compute_domain(domain_type, fork_version, genesis_validators_root)
|
||||||
compute_domain(domain_type, fork_version)
|
|
||||||
|
|
||||||
func get_domain*(
|
func get_domain*(
|
||||||
state: BeaconState, domain_type: DomainType, message_epoch: Epoch): Domain =
|
state: BeaconState, domain_type: DomainType, epoch: Epoch): Domain =
|
||||||
## Return the signature domain (fork version concatenated with domain type)
|
## Return the signature domain (fork version concatenated with domain type)
|
||||||
## of a message.
|
## of a message.
|
||||||
get_domain(state.fork, domain_type, message_epoch)
|
get_domain(state.fork, domain_type, epoch, state. genesis_validators_root)
|
||||||
|
|
||||||
func get_domain*(state: BeaconState, domain_type: DomainType): Domain =
|
|
||||||
get_domain(state, domain_type, get_current_epoch(state))
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#compute_signing_root
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#compute_signing_root
|
||||||
func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
|
func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
|
||||||
|
@ -56,7 +56,7 @@ const
|
|||||||
|
|
||||||
# Gwei values
|
# Gwei values
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/mainnet.yaml#L52
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/mainnet.yaml#L58
|
||||||
|
|
||||||
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
|
||||||
|
@ -71,7 +71,7 @@ const
|
|||||||
|
|
||||||
# Time parameters
|
# Time parameters
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/minimal.yaml#L71
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L77
|
||||||
# Changed: Faster to spin up testnets, but does not give validator
|
# Changed: Faster to spin up testnets, but does not give validator
|
||||||
# reasonable warning time for genesis
|
# reasonable warning time for genesis
|
||||||
MIN_GENESIS_DELAY* = 300
|
MIN_GENESIS_DELAY* = 300
|
||||||
@ -178,16 +178,6 @@ const
|
|||||||
MIN_GASPRICE* = 32 # Gwei
|
MIN_GASPRICE* = 32 # Gwei
|
||||||
GASPRICE_ADJUSTMENT_COEFFICIENT* = 8
|
GASPRICE_ADJUSTMENT_COEFFICIENT* = 8
|
||||||
|
|
||||||
# Phase 1 - Sharding
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/minimal.yaml#L157
|
|
||||||
# TODO those are included in minimal.yaml but not mainnet.yaml
|
|
||||||
# Why?
|
|
||||||
SHARD_SLOTS_PER_BEACON_SLOT* = 2 # spec: SHARD_SLOTS_PER_EPOCH
|
|
||||||
EPOCHS_PER_SHARD_PERIOD* = 4
|
|
||||||
PHASE_1_FORK_EPOCH* = 8
|
|
||||||
PHASE_1_FORK_SLOT* = 64
|
|
||||||
|
|
||||||
# Phase 1 - Custody game
|
# Phase 1 - Custody game
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase1/custody-game.md#constants
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase1/custody-game.md#constants
|
||||||
|
@ -108,7 +108,8 @@ proc process_randao(
|
|||||||
let proposer = addr state.validators[proposer_index.get]
|
let proposer = addr state.validators[proposer_index.get]
|
||||||
|
|
||||||
# Verify that the provided randao value is valid
|
# Verify that the provided randao value is valid
|
||||||
let signing_root = compute_signing_root(epoch, get_domain(state, DOMAIN_RANDAO))
|
let signing_root = compute_signing_root(
|
||||||
|
epoch, get_domain(state, DOMAIN_RANDAO, get_current_epoch(state)))
|
||||||
if skipBLSValidation notin flags:
|
if skipBLSValidation notin flags:
|
||||||
if not blsVerify(proposer.pubkey, signing_root.data, body.randao_reveal):
|
if not blsVerify(proposer.pubkey, signing_root.data, body.randao_reveal):
|
||||||
notice "Randao mismatch", proposer_pubkey = shortLog(proposer.pubkey),
|
notice "Randao mismatch", proposer_pubkey = shortLog(proposer.pubkey),
|
||||||
@ -481,42 +482,47 @@ proc makeBeaconBlock*(
|
|||||||
|
|
||||||
some(blck)
|
some(blck)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/validator.md
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#aggregation-selection
|
||||||
func get_slot_signature*(
|
func get_slot_signature*(
|
||||||
fork: Fork, slot: Slot, privkey: ValidatorPrivKey): ValidatorSig =
|
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
|
privkey: ValidatorPrivKey): ValidatorSig =
|
||||||
let
|
let
|
||||||
domain =
|
domain = get_domain(fork, DOMAIN_SELECTION_PROOF,
|
||||||
get_domain(fork, DOMAIN_SELECTION_PROOF, compute_epoch_at_slot(slot))
|
compute_epoch_at_slot(slot), genesis_validators_root)
|
||||||
signing_root = compute_signing_root(slot, domain)
|
signing_root = compute_signing_root(slot, domain)
|
||||||
|
|
||||||
blsSign(privKey, signing_root.data)
|
blsSign(privKey, signing_root.data)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/validator.md
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#randao-reveal
|
||||||
func get_epoch_signature*(
|
func get_epoch_signature*(
|
||||||
fork: Fork, slot: Slot, privkey: ValidatorPrivKey): ValidatorSig =
|
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
|
privkey: ValidatorPrivKey): ValidatorSig =
|
||||||
let
|
let
|
||||||
domain =
|
domain = get_domain(fork, DOMAIN_RANDAO, compute_epoch_at_slot(slot),
|
||||||
get_domain(fork, DOMAIN_RANDAO, compute_epoch_at_slot(slot))
|
genesis_validators_root)
|
||||||
signing_root = compute_signing_root(compute_epoch_at_slot(slot), domain)
|
signing_root = compute_signing_root(compute_epoch_at_slot(slot), domain)
|
||||||
|
|
||||||
blsSign(privKey, signing_root.data)
|
blsSign(privKey, signing_root.data)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/validator.md
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#signature
|
||||||
func get_block_signature*(
|
func get_block_signature*(
|
||||||
fork: Fork, slot: Slot, root: Eth2Digest, privkey: ValidatorPrivKey): ValidatorSig =
|
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
|
root: Eth2Digest, privkey: ValidatorPrivKey): ValidatorSig =
|
||||||
let
|
let
|
||||||
domain =
|
domain = get_domain(fork, DOMAIN_BEACON_PROPOSER,
|
||||||
get_domain(fork, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(slot))
|
compute_epoch_at_slot(slot), genesis_validators_root)
|
||||||
signing_root = compute_signing_root(root, domain)
|
signing_root = compute_signing_root(root, domain)
|
||||||
|
|
||||||
blsSign(privKey, signing_root.data)
|
blsSign(privKey, signing_root.data)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/validator.md
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#aggregate-signature
|
||||||
func get_attestation_signature*(
|
func get_attestation_signature*(
|
||||||
fork: Fork, attestation: AttestationData, privkey: ValidatorPrivKey): ValidatorSig =
|
fork: Fork, genesis_validators_root: Eth2Digest, attestation: AttestationData,
|
||||||
|
privkey: ValidatorPrivKey): ValidatorSig =
|
||||||
let
|
let
|
||||||
attestationRoot = hash_tree_root(attestation)
|
attestationRoot = hash_tree_root(attestation)
|
||||||
domain = get_domain(fork, DOMAIN_BEACON_ATTESTER, attestation.target.epoch)
|
domain = get_domain(fork, DOMAIN_BEACON_ATTESTER,
|
||||||
|
attestation.target.epoch, genesis_validators_root)
|
||||||
signing_root = compute_signing_root(attestationRoot, domain)
|
signing_root = compute_signing_root(attestationRoot, domain)
|
||||||
|
|
||||||
blsSign(privKey, signing_root.data)
|
blsSign(privKey, signing_root.data)
|
||||||
|
@ -242,7 +242,7 @@ func get_base_reward(state: BeaconState, index: ValidatorIndex,
|
|||||||
effective_balance * BASE_REWARD_FACTOR div
|
effective_balance * BASE_REWARD_FACTOR div
|
||||||
integer_squareroot(total_balance) div BASE_REWARDS_PER_EPOCH
|
integer_squareroot(total_balance) div BASE_REWARDS_PER_EPOCH
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
|
func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
|
||||||
tuple[a: seq[Gwei], b: seq[Gwei]] {.nbench.}=
|
tuple[a: seq[Gwei], b: seq[Gwei]] {.nbench.}=
|
||||||
let
|
let
|
||||||
@ -280,7 +280,7 @@ func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
|
|||||||
const increment = EFFECTIVE_BALANCE_INCREMENT
|
const increment = EFFECTIVE_BALANCE_INCREMENT
|
||||||
let reward_numerator = get_base_reward(state, index, total_balance) *
|
let reward_numerator = get_base_reward(state, index, total_balance) *
|
||||||
(attesting_balance div increment)
|
(attesting_balance div increment)
|
||||||
rewards[index] = reward_numerator div (total_balance div increment)
|
rewards[index] += reward_numerator div (total_balance div increment)
|
||||||
else:
|
else:
|
||||||
penalties[index] += get_base_reward(state, index, total_balance)
|
penalties[index] += get_base_reward(state, index, total_balance)
|
||||||
|
|
||||||
|
@ -25,7 +25,8 @@ func getValidator*(pool: ValidatorPool,
|
|||||||
pool.validators.getOrDefault(validatorKey)
|
pool.validators.getOrDefault(validatorKey)
|
||||||
|
|
||||||
# TODO: Honest validator - https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md
|
# TODO: Honest validator - https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md
|
||||||
proc signBlockProposal*(v: AttachedValidator, fork: Fork, slot: Slot,
|
proc signBlockProposal*(v: AttachedValidator, fork: Fork,
|
||||||
|
genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
blockRoot: Eth2Digest): Future[ValidatorSig] {.async.} =
|
blockRoot: Eth2Digest): Future[ValidatorSig] {.async.} =
|
||||||
|
|
||||||
if v.kind == inProcess:
|
if v.kind == inProcess:
|
||||||
@ -34,30 +35,33 @@ proc signBlockProposal*(v: AttachedValidator, fork: Fork, slot: Slot,
|
|||||||
# replaced by something more sensible
|
# replaced by something more sensible
|
||||||
await sleepAsync(chronos.milliseconds(1))
|
await sleepAsync(chronos.milliseconds(1))
|
||||||
|
|
||||||
result = get_block_signature(fork, slot, blockRoot, v.privKey)
|
result = get_block_signature(
|
||||||
|
fork, genesis_validators_root, slot, blockRoot, v.privKey)
|
||||||
else:
|
else:
|
||||||
error "Unimplemented"
|
error "Unimplemented"
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
proc signAttestation*(v: AttachedValidator,
|
proc signAttestation*(v: AttachedValidator,
|
||||||
attestation: AttestationData,
|
attestation: AttestationData,
|
||||||
fork: Fork): Future[ValidatorSig] {.async.} =
|
fork: Fork, genesis_validators_root: Eth2Digest):
|
||||||
|
Future[ValidatorSig] {.async.} =
|
||||||
if v.kind == inProcess:
|
if v.kind == inProcess:
|
||||||
# TODO this is an ugly hack to fake a delay and subsequent async reordering
|
# TODO this is an ugly hack to fake a delay and subsequent async reordering
|
||||||
# for the purpose of testing the external validator delay - to be
|
# for the purpose of testing the external validator delay - to be
|
||||||
# replaced by something more sensible
|
# replaced by something more sensible
|
||||||
await sleepAsync(chronos.milliseconds(1))
|
await sleepAsync(chronos.milliseconds(1))
|
||||||
|
|
||||||
result = get_attestation_signature(fork, attestation, v.privKey)
|
result = get_attestation_signature(
|
||||||
|
fork, genesis_validators_root, attestation, v.privKey)
|
||||||
else:
|
else:
|
||||||
error "Unimplemented"
|
error "Unimplemented"
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#randao-reveal
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#randao-reveal
|
||||||
func genRandaoReveal*(k: ValidatorPrivKey, fork: Fork, slot: Slot):
|
func genRandaoReveal*(k: ValidatorPrivKey, fork: Fork,
|
||||||
ValidatorSig =
|
genesis_validators_root: Eth2Digest, slot: Slot): ValidatorSig =
|
||||||
get_epoch_signature(fork, slot, k)
|
get_epoch_signature(fork, genesis_validators_root, slot, k)
|
||||||
|
|
||||||
func genRandaoReveal*(v: AttachedValidator, fork: Fork, slot: Slot):
|
func genRandaoReveal*(v: AttachedValidator, fork: Fork,
|
||||||
ValidatorSig =
|
genesis_validators_root: Eth2Digest, slot: Slot): ValidatorSig =
|
||||||
genRandaoReveal(v.privKey, fork, slot)
|
genRandaoReveal(v.privKey, fork, genesis_validators_root, slot)
|
||||||
|
@ -66,7 +66,8 @@ proc signMockAttestation*(state: BeaconState, attestation: var Attestation) =
|
|||||||
var first_iter = true # Can't do while loop on hashset
|
var first_iter = true # Can't do while loop on hashset
|
||||||
for validator_index in participants:
|
for validator_index in participants:
|
||||||
let sig = get_attestation_signature(
|
let sig = get_attestation_signature(
|
||||||
state.fork, attestation.data, MockPrivKeys[validator_index]
|
state.fork, state.genesis_validators_root, attestation.data,
|
||||||
|
MockPrivKeys[validator_index]
|
||||||
)
|
)
|
||||||
if first_iter:
|
if first_iter:
|
||||||
attestation.signature = sig
|
attestation.signature = sig
|
||||||
|
@ -28,9 +28,10 @@ proc signMockBlockImpl(
|
|||||||
let privkey = MockPrivKeys[proposer_index]
|
let privkey = MockPrivKeys[proposer_index]
|
||||||
|
|
||||||
signedBlock.message.body.randao_reveal = get_epoch_signature(
|
signedBlock.message.body.randao_reveal = get_epoch_signature(
|
||||||
state.fork, block_slot, privkey)
|
state.fork, state.genesis_validators_root, block_slot, privkey)
|
||||||
signedBlock.signature = get_block_signature(
|
signedBlock.signature = get_block_signature(
|
||||||
state.fork, block_slot, hash_tree_root(signedBlock.message), privkey)
|
state.fork, state.genesis_validators_root, block_slot,
|
||||||
|
hash_tree_root(signedBlock.message), privkey)
|
||||||
|
|
||||||
proc signMockBlock*(
|
proc signMockBlock*(
|
||||||
state: BeaconState,
|
state: BeaconState,
|
||||||
|
@ -36,7 +36,7 @@ proc readValue*(r: var JsonReader, a: var seq[byte]) {.inline.} =
|
|||||||
|
|
||||||
const
|
const
|
||||||
FixturesDir* = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
|
FixturesDir* = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
|
||||||
SszTestsDir* = FixturesDir/"tests-v0.11.0"
|
SszTestsDir* = FixturesDir/"tests-v0.11.1"
|
||||||
|
|
||||||
proc parseTest*(path: string, Format: typedesc[Json or SSZ], T: typedesc): T =
|
proc parseTest*(path: string, Format: typedesc[Json or SSZ], T: typedesc): T =
|
||||||
try:
|
try:
|
||||||
|
@ -19,7 +19,7 @@ import
|
|||||||
const
|
const
|
||||||
SpecDir = currentSourcePath.rsplit(DirSep, 1)[0] /
|
SpecDir = currentSourcePath.rsplit(DirSep, 1)[0] /
|
||||||
".."/".."/"beacon_chain"/"spec"
|
".."/".."/"beacon_chain"/"spec"
|
||||||
Config = FixturesDir/"tests-v0.11.0"/const_preset/"config.yaml"
|
Config = FixturesDir/"tests-v0.11.1"/const_preset/"config.yaml"
|
||||||
|
|
||||||
type
|
type
|
||||||
CheckedType = SomeInteger or Slot or Epoch
|
CheckedType = SomeInteger or Slot or Epoch
|
||||||
@ -122,5 +122,5 @@ proc checkConfig() =
|
|||||||
else:
|
else:
|
||||||
check: ConstsToCheck[constant] == value.getBiggestInt().uint64()
|
check: ConstsToCheck[constant] == value.getBiggestInt().uint64()
|
||||||
|
|
||||||
suiteReport "Official - 0.11.0 - constants & config " & preset():
|
suiteReport "Official - 0.11.1 - constants & config " & preset():
|
||||||
checkConfig()
|
checkConfig()
|
||||||
|
@ -32,8 +32,6 @@ proc runTest(identifier: string) =
|
|||||||
|
|
||||||
var flags: UpdateFlags
|
var flags: UpdateFlags
|
||||||
var prefix: string
|
var prefix: string
|
||||||
if not existsFile(testDir/"meta.yaml"):
|
|
||||||
flags.incl skipBlsValidation
|
|
||||||
if existsFile(testDir/"post.ssz"):
|
if existsFile(testDir/"post.ssz"):
|
||||||
prefix = "[Valid] "
|
prefix = "[Valid] "
|
||||||
else:
|
else:
|
||||||
|
@ -32,8 +32,6 @@ proc runTest(identifier: string) =
|
|||||||
|
|
||||||
var flags: UpdateFlags
|
var flags: UpdateFlags
|
||||||
var prefix: string
|
var prefix: string
|
||||||
if not existsFile(testDir/"meta.yaml"):
|
|
||||||
flags.incl skipBlsValidation
|
|
||||||
if existsFile(testDir/"post.ssz"):
|
if existsFile(testDir/"post.ssz"):
|
||||||
prefix = "[Valid] "
|
prefix = "[Valid] "
|
||||||
else:
|
else:
|
||||||
|
@ -32,8 +32,6 @@ proc runTest(identifier: string) =
|
|||||||
|
|
||||||
var flags: UpdateFlags
|
var flags: UpdateFlags
|
||||||
var prefix: string
|
var prefix: string
|
||||||
if not existsFile(testDir/"meta.yaml"):
|
|
||||||
flags.incl skipBlsValidation
|
|
||||||
if existsFile(testDir/"post.ssz"):
|
if existsFile(testDir/"post.ssz"):
|
||||||
prefix = "[Valid] "
|
prefix = "[Valid] "
|
||||||
else:
|
else:
|
||||||
|
@ -32,8 +32,6 @@ proc runTest(identifier: string) =
|
|||||||
|
|
||||||
var flags: UpdateFlags
|
var flags: UpdateFlags
|
||||||
var prefix: string
|
var prefix: string
|
||||||
if not existsFile(testDir/"meta.yaml"):
|
|
||||||
flags.incl skipBlsValidation
|
|
||||||
if existsFile(testDir/"post.ssz"):
|
if existsFile(testDir/"post.ssz"):
|
||||||
prefix = "[Valid] "
|
prefix = "[Valid] "
|
||||||
else:
|
else:
|
||||||
|
@ -25,7 +25,7 @@ import
|
|||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
const
|
const
|
||||||
SSZDir = FixturesDir/"tests-v0.11.0"/const_preset/"phase0"/"ssz_static"
|
SSZDir = FixturesDir/"tests-v0.11.1"/const_preset/"phase0"/"ssz_static"
|
||||||
|
|
||||||
type
|
type
|
||||||
SSZHashTreeRoot = object
|
SSZHashTreeRoot = object
|
||||||
@ -106,7 +106,7 @@ proc runSSZtests() =
|
|||||||
else:
|
else:
|
||||||
raise newException(ValueError, "Unsupported test: " & sszType)
|
raise newException(ValueError, "Unsupported test: " & sszType)
|
||||||
|
|
||||||
suiteReport "Official - 0.11.0 - SSZ consensus objects " & preset():
|
suiteReport "Official - 0.11.1 - SSZ consensus objects " & preset():
|
||||||
runSSZtests()
|
runSSZtests()
|
||||||
|
|
||||||
summarizeLongTests("FixtureSSZConsensus")
|
summarizeLongTests("FixtureSSZConsensus")
|
||||||
|
@ -23,7 +23,7 @@ import
|
|||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
const
|
const
|
||||||
SSZDir = FixturesDir/"tests-v0.11.0"/"general"/"phase0"/"ssz_generic"
|
SSZDir = FixturesDir/"tests-v0.11.1"/"general"/"phase0"/"ssz_generic"
|
||||||
|
|
||||||
type
|
type
|
||||||
SSZHashTreeRoot = object
|
SSZHashTreeRoot = object
|
||||||
|
@ -84,7 +84,8 @@ proc addTestBlock*(
|
|||||||
privKey = hackPrivKey(proposer)
|
privKey = hackPrivKey(proposer)
|
||||||
randao_reveal =
|
randao_reveal =
|
||||||
if skipBlsValidation notin flags:
|
if skipBlsValidation notin flags:
|
||||||
privKey.genRandaoReveal(state.fork, state.slot)
|
privKey.genRandaoReveal(
|
||||||
|
state.fork, state.genesis_validators_root, state.slot)
|
||||||
else:
|
else:
|
||||||
ValidatorSig()
|
ValidatorSig()
|
||||||
|
|
||||||
@ -149,7 +150,8 @@ proc makeAttestation*(
|
|||||||
let
|
let
|
||||||
sig =
|
sig =
|
||||||
if skipBLSValidation notin flags:
|
if skipBLSValidation notin flags:
|
||||||
get_attestation_signature(state.fork, data, hackPrivKey(validator))
|
get_attestation_signature(state.fork, state.genesis_validators_root,
|
||||||
|
data, hackPrivKey(validator))
|
||||||
else:
|
else:
|
||||||
ValidatorSig()
|
ValidatorSig()
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ proc makeFullAttestations*(
|
|||||||
aggregation_bits: CommitteeValidatorsBits.init(committee.len),
|
aggregation_bits: CommitteeValidatorsBits.init(committee.len),
|
||||||
data: data,
|
data: data,
|
||||||
signature: get_attestation_signature(
|
signature: get_attestation_signature(
|
||||||
state.fork, data,
|
state.fork, state.genesis_validators_root, data,
|
||||||
hackPrivKey(state.validators[committee[0]]))
|
hackPrivKey(state.validators[committee[0]]))
|
||||||
)
|
)
|
||||||
# Aggregate the remainder
|
# Aggregate the remainder
|
||||||
@ -212,7 +214,7 @@ proc makeFullAttestations*(
|
|||||||
attestation.aggregation_bits.setBit j
|
attestation.aggregation_bits.setBit j
|
||||||
if skipBLSValidation notin flags:
|
if skipBLSValidation notin flags:
|
||||||
attestation.signature.aggregate(get_attestation_signature(
|
attestation.signature.aggregate(get_attestation_signature(
|
||||||
state.fork, data,
|
state.fork, state.genesis_validators_root, data,
|
||||||
hackPrivKey(state.validators[committee[j]])
|
hackPrivKey(state.validators[committee[j]])
|
||||||
))
|
))
|
||||||
|
|
||||||
|
2
vendor/nim-eth2-scenarios
vendored
2
vendor/nim-eth2-scenarios
vendored
@ -1 +1 @@
|
|||||||
Subproject commit b06d78d1d8c306a3cce80c391856f44bf7db6119
|
Subproject commit 5326d824b1d91ea273095172512eb309f32e0c82
|
Loading…
x
Reference in New Issue
Block a user