diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 972470303..967fb5e62 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -424,6 +424,18 @@ func get_attesting_indices*(state: BeaconState, result = initHashSet[ValidatorIndex]() let committee = get_beacon_committee( state, data.slot, data.index.CommitteeIndex, stateCache) + + # This shouldn't happen if one begins with a valid BeaconState and applies + # valid updates, but one can construct a BeaconState where it does. Do not + # do anything here since the PendingAttestation wouldn't have made it past + # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#attestations + # which checks len(attestation.aggregation_bits) == len(committee) that in + # nim-beacon-chain lives in check_attestation(...). + # Addresses https://github.com/status-im/nim-beacon-chain/issues/922 + if bits.len != committee.len: + trace "get_attesting_indices: inconsistent aggregation and committee length" + return + for i, index in committee: if bits[i]: result.incl index diff --git a/beacon_chain/spec/network.nim b/beacon_chain/spec/network.nim index 2f62d6edb..e6e0b8ee3 100644 --- a/beacon_chain/spec/network.nim +++ b/beacon_chain/spec/network.nim @@ -20,7 +20,7 @@ const topicAttesterSlashingsSuffix* = "attester_slashing/ssz" topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz" - # https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/p2p-interface.md#configuration + # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#configuration ATTESTATION_SUBNET_COUNT* = 64 defaultEth2TcpPort* = 9000 @@ -59,7 +59,7 @@ func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string = raiseAssert e.msg func getAttestationTopic*(forkDigest: ForkDigest, committeeIndex: uint64): string = - # https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/validator.md#broadcast-attestation + # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#broadcast-attestation try: let topicIndex = committeeIndex mod ATTESTATION_SUBNET_COUNT &"/eth2/{toHex forkDigest}/committee_index{topicIndex}{topicAttestationsSuffix}" diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 60838ffd8..6a53aeef8 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -451,7 +451,7 @@ proc process_block*( true -# 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 # TODO There's more to do here - the spec has helpers that deal set up some of # the fields in here! proc makeBeaconBlock*( diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index dc9416198..9022844e1 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -88,7 +88,7 @@ func get_previous_epoch*(state: BeaconState): Epoch = else: current_epoch - 1 -# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#compute_committee +# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#compute_committee func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest, index: uint64, count: uint64, stateCache: var StateCache): seq[ValidatorIndex] = ## Return the committee corresponding to ``indices``, ``seed``, ``index``, @@ -115,7 +115,7 @@ func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest, except KeyError: raiseAssert("Cached entries are added before use") -# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_beacon_committee +# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#get_beacon_committee func get_beacon_committee*( state: BeaconState, slot: Slot, index: CommitteeIndex, cache: var StateCache): seq[ValidatorIndex] = @@ -204,7 +204,7 @@ func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache): compute_proposer_index(state, indices, seed, stateCache) -# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#validator-assignments +# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#validator-assignments func get_committee_assignment( state: BeaconState, epoch: Epoch, validator_index: ValidatorIndex): Option[tuple[a: seq[ValidatorIndex], b: CommitteeIndex, c: Slot]] {.used.} = @@ -229,7 +229,7 @@ func get_committee_assignment( return some((committee, idx, slot)) none(tuple[a: seq[ValidatorIndex], b: CommitteeIndex, c: Slot]) -# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#validator-assignments +# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#validator-assignments func is_proposer( state: BeaconState, validator_index: ValidatorIndex): bool {.used.} = var cache = get_empty_per_epoch_cache()