Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
spec v0.9.2 minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Dec 5, 2019
1 parent c430ab6 commit 8143ff7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
31 changes: 17 additions & 14 deletions eth2/beacon/tools/builder/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

from eth2._utils.bls import bls
from eth2._utils.hash import hash_eth2
from eth2.beacon.attestation_helpers import validate_indexed_attestation_aggregate_signature
from eth2.beacon.attestation_helpers import (
validate_indexed_attestation_aggregate_signature,
)
from eth2.beacon.committee_helpers import get_beacon_committee
from eth2.beacon.epoch_processing_helpers import get_attesting_indices, get_indexed_attestation
from eth2.beacon.epoch_processing_helpers import (
get_attesting_indices,
get_indexed_attestation,
)
from eth2.beacon.helpers import compute_epoch_at_slot, get_domain
from eth2.beacon.signature_domain import SignatureDomain
from eth2.beacon.types.aggregate_and_proof import AggregateAndProof
Expand All @@ -21,7 +26,7 @@
TARGET_AGGREGATORS_PER_COMMITTEE = 16


def slot_signature(
def get_slot_signature(
state: BeaconState, slot: Slot, privkey: int, config: CommitteeConfig
) -> BLSSignature:
"""
Expand Down Expand Up @@ -105,7 +110,8 @@ def validate_aggregate_and_proof(
Reference: https://github.com/ethereum/eth2.0-specs/blob/v09x/specs/networking/p2p-interface.md#global-topics # noqa: E501
"""
if (
aggregate_and_proof.aggregate.data.slot + attestation_propagation_slot_range < state.slot
aggregate_and_proof.aggregate.data.slot + attestation_propagation_slot_range
< state.slot
or aggregate_and_proof.aggregate.data.slot > state.slot
):
raise ValidationError(
Expand All @@ -121,9 +127,9 @@ def validate_aggregate_and_proof(
aggregate_and_proof.aggregate.aggregation_bits,
config,
)
if aggregate_and_proof.index not in attesting_indices:
if aggregate_and_proof.aggregator_index not in attesting_indices:
raise ValidationError(
f"The aggregator index ({aggregate_and_proof.index}) is not within"
f"The aggregator index ({aggregate_and_proof.aggregator_index}) is not within"
f" the aggregate's committee {attesting_indices}"
)

Expand All @@ -135,7 +141,8 @@ def validate_aggregate_and_proof(
config,
):
raise ValidationError(
f"The given validator {aggregate_and_proof.index} is not selected aggregator"
f"The given validator {aggregate_and_proof.aggregator_index}"
" is not a selected aggregator"
)

validate_aggregator_proof(state, aggregate_and_proof, config)
Expand All @@ -147,7 +154,7 @@ def validate_aggregator_proof(
state: BeaconState, aggregate_and_proof: AggregateAndProof, config: CommitteeConfig
) -> None:
slot = aggregate_and_proof.aggregate.data.slot
pubkey = state.validators[aggregate_and_proof.index].pubkey
pubkey = state.validators[aggregate_and_proof.aggregator_index].pubkey
domain = get_domain(
state,
SignatureDomain.DOMAIN_BEACON_ATTESTER,
Expand All @@ -165,13 +172,9 @@ def validate_aggregator_proof(


def validate_aggregate_signature(
state: BeaconState,
attestation: Attestation,
config: CommitteeConfig
state: BeaconState, attestation: Attestation, config: CommitteeConfig
) -> None:
indexed_attestation = get_indexed_attestation(state, attestation, config)
validate_indexed_attestation_aggregate_signature(
state,
indexed_attestation,
config.SLOTS_PER_EPOCH,
state, indexed_attestation, config.SLOTS_PER_EPOCH
)
16 changes: 9 additions & 7 deletions eth2/beacon/types/aggregate_and_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@
class AggregateAndProof(ssz.Serializable):

fields = [
("index", uint64),
("selection_proof", bytes96),
("aggregator_index", uint64),
("aggregate", Attestation),
("selection_proof", bytes96),
]

def __init__(
self,
index: ValidatorIndex = default_validator_index,
selection_proof: BLSSignature = EMPTY_SIGNATURE,
aggregator_index: ValidatorIndex = default_validator_index,
aggregate: Attestation = default_attestation,
selection_proof: BLSSignature = EMPTY_SIGNATURE,
) -> None:
super().__init__(
index=index, selection_proof=selection_proof, aggregate=aggregate
aggregator_index=aggregator_index,
aggregate=aggregate,
selection_proof=selection_proof,
)

def __str__(self) -> str:
return (
f"index={self.index},"
f" selection_proof={humanize_hash(self.selection_proof)},"
f"aggregator_index={self.aggregator_index},"
f" aggregate={self.aggregate},"
f" selection_proof={humanize_hash(self.selection_proof)},"
)


Expand Down
4 changes: 2 additions & 2 deletions tests/eth2/core/beacon/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ def sample_state(sample_beacon_state_params):
@pytest.fixture
def sample_aggregate_and_proof_params(sample_attestation_params):
return {
"index": 5,
"selection_proof": 1,
"aggregator_index": 5,
"aggregate": Attestation(**sample_attestation_params),
"selection_proof": 1,
}


Expand Down
6 changes: 4 additions & 2 deletions tests/eth2/core/beacon/tools/builder/test_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from eth2.beacon.tools.builder.aggregator import (
TARGET_AGGREGATORS_PER_COMMITTEE,
get_aggregate_from_valid_committee_attestations,
get_slot_signature,
is_aggregator,
slot_signature,
)
from eth2.beacon.tools.builder.validator import sign_transaction
from eth2.beacon.types.attestations import Attestation
Expand All @@ -34,7 +34,9 @@ def test_aggregator_selection(validator_count, privkeys, genesis_state, config):
aggregator_count = 0
for index in range(validator_count):
if index in committee:
signature = slot_signature(genesis_state, slot, privkeys[index], config)
signature = get_slot_signature(
genesis_state, slot, privkeys[index], config
)
attester_is_aggregator = is_aggregator(
state, slot, committee_index, signature, config
)
Expand Down
10 changes: 6 additions & 4 deletions tests/eth2/core/beacon/types/test_aggregate_and_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
def test_defaults(sample_aggregate_and_proof_params):
aggregate_and_proof = AggregateAndProof(**sample_aggregate_and_proof_params)

assert aggregate_and_proof.index == sample_aggregate_and_proof_params["index"]
assert (
aggregate_and_proof.selection_proof
== sample_aggregate_and_proof_params["selection_proof"]
assert aggregate_and_proof.aggregator_index == (
sample_aggregate_and_proof_params["aggregator_index"]
)
assert (
aggregate_and_proof.aggregate == sample_aggregate_and_proof_params["aggregate"]
)
assert (
aggregate_and_proof.selection_proof
== sample_aggregate_and_proof_params["selection_proof"]
)
10 changes: 5 additions & 5 deletions trinity/components/eth2/beacon/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
)
from eth2.beacon.tools.builder.aggregator import (
get_aggregate_from_valid_committee_attestations,
get_slot_signature,
is_aggregator,
slot_signature,
)
from eth2.beacon.tools.builder.committee_assignment import (
CommitteeAssignment,
Expand Down Expand Up @@ -377,8 +377,8 @@ def _get_local_attesters_at_assignment(
"""
for validator_index, (_, assignment) in self.local_validator_epoch_assignment.items():
if (
assignment.slot == target_assignment.slot
and assignment.committee_index == target_assignment.committee_index
assignment.slot == target_assignment.slot and
assignment.committee_index == target_assignment.committee_index
):
yield validator_index

Expand Down Expand Up @@ -490,7 +490,7 @@ async def aggregate(
# 2. For each attester
for validator_index, privkey in attesting_validator_privkeys.items():
# Check if the vallidator is one of the aggregators
signature = slot_signature(
signature = get_slot_signature(
state, slot, privkey, CommitteeConfig(config),
)
is_aggregator_result = is_aggregator(
Expand All @@ -514,7 +514,7 @@ async def aggregate(
# (it's possible with same CommitteeIndex and different AttesatationData)
for aggregate in aggregates:
aggregate_and_proof = AggregateAndProof(
index=validator_index,
aggregator_index=validator_index,
aggregate=aggregate,
selection_proof=selected_proofs[validator_index],
)
Expand Down

0 comments on commit 8143ff7

Please sign in to comment.