diff --git a/specs/lightclient/beacon-chain.md b/specs/lightclient/beacon-chain.md index 1b434faf4..2fbe190e4 100644 --- a/specs/lightclient/beacon-chain.md +++ b/specs/lightclient/beacon-chain.md @@ -50,7 +50,6 @@ This is a standalone beacon chain patch adding light client support via sync com | Name | Value | | - | - | -| `G1_POINT_AT_INFINITY` | `BLSPubkey(b'\xc0' + b'\x00' * 47)` | | `G2_POINT_AT_INFINITY` | `BLSSignature(b'\xc0' + b'\x00' * 95)` | ### Misc @@ -139,19 +138,12 @@ def get_sync_committee_indices(state: BeaconState, epoch: Epoch) -> Sequence[Val seed = get_seed(state, base_epoch, DOMAIN_SYNC_COMMITTEE) i = 0 sync_committee_indices: List[ValidatorIndex] = [] - if len(active_validator_indices) < SYNC_COMMITTEE_SIZE: - committee_size = len(active_validator_indices) - else: - committee_size = SYNC_COMMITTEE_SIZE - while len(sync_committee_indices) < committee_size: + while len(sync_committee_indices) < SYNC_COMMITTEE_SIZE: shuffled_index = compute_shuffled_index(uint64(i % active_validator_count), active_validator_count, seed) candidate_index = active_validator_indices[shuffled_index] random_byte = hash(seed + uint_to_bytes(uint64(i // 32)))[i % 32] effective_balance = state.validators[candidate_index].effective_balance - if ( - effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte - and candidate_index not in sync_committee_indices - ): + if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte: sync_committee_indices.append(candidate_index) i += 1 return sync_committee_indices @@ -171,11 +163,6 @@ def get_sync_committee(state: BeaconState, epoch: Epoch) -> SyncCommittee: bls.AggregatePKs(pubkeys[i:i + SYNC_COMMITTEE_PUBKEY_AGGREGATES_SIZE]) for i in range(0, len(pubkeys), SYNC_COMMITTEE_PUBKEY_AGGREGATES_SIZE) ] - # Pad G1_POINT_AT_INFINITY to the BLSPubkey Vectors - if len(pubkeys) < SYNC_COMMITTEE_SIZE: - pubkeys += [G1_POINT_AT_INFINITY] * (SYNC_COMMITTEE_SIZE - len(pubkeys)) - aggregates_length = SYNC_COMMITTEE_SIZE // SYNC_COMMITTEE_PUBKEY_AGGREGATES_SIZE - aggregates += [G1_POINT_AT_INFINITY] * (aggregates_length - len(aggregates)) return SyncCommittee(pubkeys=pubkeys, pubkey_aggregates=aggregates) ``` diff --git a/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py b/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py index 21557dedd..b7b2381e3 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py +++ b/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py @@ -31,9 +31,3 @@ def compute_aggregate_sync_committee_signature(spec, state, slot, participants): ) ) return bls.Aggregate(signatures) - - -def get_padded_sync_committee_bits(spec, sync_committee_bits): - if len(sync_committee_bits) < spec.SYNC_COMMITTEE_SIZE: - return sync_committee_bits + [False] * (spec.SYNC_COMMITTEE_SIZE - len(sync_committee_bits)) - return sync_committee_bits diff --git a/tests/core/pyspec/eth2spec/test/lightclient_patch/block_processing/test_process_sync_committee.py b/tests/core/pyspec/eth2spec/test/lightclient_patch/block_processing/test_process_sync_committee.py index 14f3a9f0a..37cd0992b 100644 --- a/tests/core/pyspec/eth2spec/test/lightclient_patch/block_processing/test_process_sync_committee.py +++ b/tests/core/pyspec/eth2spec/test/lightclient_patch/block_processing/test_process_sync_committee.py @@ -9,7 +9,6 @@ from eth2spec.test.helpers.state import ( ) from eth2spec.test.helpers.sync_committee import ( compute_aggregate_sync_committee_signature, - get_padded_sync_committee_bits, ) from eth2spec.test.context import ( PHASE0, PHASE1, @@ -29,9 +28,7 @@ def test_invalid_signature_missing_participant(spec, state): block = build_empty_block_for_next_slot(spec, state) # Exclude one participant whose signature was included. - block.body.sync_committee_bits = get_padded_sync_committee_bits( - spec, [index != random_participant for index in committee] - ) + block.body.sync_committee_bits = [index != random_participant for index in committee] block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, @@ -54,7 +51,7 @@ def test_invalid_signature_extra_participant(spec, state): block = build_empty_block_for_next_slot(spec, state) # Exclude one signature even though the block claims the entire committee participated. - block.body.sync_committee_bits = get_padded_sync_committee_bits(spec, [True] * len(committee)) + block.body.sync_committee_bits = [True] * len(committee) block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, @@ -86,7 +83,7 @@ def test_sync_committee_rewards(spec, state): pre_balances = state.balances.copy() block = build_empty_block_for_next_slot(spec, state) - block.body.sync_committee_bits = get_padded_sync_committee_bits(spec, [True] * committee_size) + block.body.sync_committee_bits = [True] * committee_size block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, @@ -129,7 +126,7 @@ def test_invalid_signature_past_block(spec, state): # NOTE: need to transition twice to move beyond the degenerate case at genesis block = build_empty_block_for_next_slot(spec, state) # Valid sync committee signature here... - block.body.sync_committee_bits = get_padded_sync_committee_bits(spec, [True] * len(committee)) + block.body.sync_committee_bits = [True] * len(committee) block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, @@ -142,7 +139,7 @@ def test_invalid_signature_past_block(spec, state): invalid_block = build_empty_block_for_next_slot(spec, state) # Invalid signature from a slot other than the previous - invalid_block.body.sync_committee_bits = get_padded_sync_committee_bits(spec, [True] * len(committee)) + invalid_block.body.sync_committee_bits = [True] * len(committee) invalid_block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, @@ -178,7 +175,7 @@ def test_invalid_signature_previous_committee(spec, state): yield 'pre', state block = build_empty_block_for_next_slot(spec, state) - block.body.sync_committee_bits = get_padded_sync_committee_bits(spec, [True] * len(committee)) + block.body.sync_committee_bits = [True] * len(committee) block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, @@ -221,7 +218,7 @@ def test_valid_signature_future_committee(spec, state): yield 'pre', state block = build_empty_block_for_next_slot(spec, state) - block.body.sync_committee_bits = get_padded_sync_committee_bits(spec, [True] * len(committee_indices)) + block.body.sync_committee_bits = [True] * len(committee_indices) block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state, diff --git a/tests/core/pyspec/eth2spec/test/lightclient_patch/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/lightclient_patch/sanity/test_blocks.py index 93f8cd3ee..9033a0f15 100644 --- a/tests/core/pyspec/eth2spec/test/lightclient_patch/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/lightclient_patch/sanity/test_blocks.py @@ -8,7 +8,6 @@ from eth2spec.test.helpers.block import ( ) from eth2spec.test.helpers.sync_committee import ( compute_aggregate_sync_committee_signature, - get_padded_sync_committee_bits, ) from eth2spec.test.context import ( PHASE0, PHASE1, @@ -24,9 +23,7 @@ def run_sync_committee_sanity_test(spec, state, fraction_full=1.0): yield 'pre', state block = build_empty_block_for_next_slot(spec, state) - block.body.sync_committee_bits = get_padded_sync_committee_bits( - spec, [index in participants for index in committee] - ) + block.body.sync_committee_bits = [index in participants for index in committee] block.body.sync_committee_signature = compute_aggregate_sync_committee_signature( spec, state,