mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-03-03 19:50:28 +00:00
Phase 1 to Bitvector/Bitlist
This commit is contained in:
parent
becb7a032a
commit
80c680e614
@ -272,6 +272,16 @@ def get_custody_chunk_count(crosslink: Crosslink) -> int:
|
||||
return crosslink_length * chunks_per_epoch
|
||||
```
|
||||
|
||||
### `get_bitfield_bit`
|
||||
|
||||
```python
|
||||
def get_bitfield_bit(bitfield: bytes, i: int) -> int:
|
||||
"""
|
||||
Extract the bit in ``bitfield`` at position ``i``.
|
||||
"""
|
||||
return (bitfield[i // 8] >> (i % 8)) % 2
|
||||
```
|
||||
|
||||
### `get_custody_chunk_bit`
|
||||
|
||||
```python
|
||||
@ -566,7 +576,7 @@ def process_bit_challenge(state: BeaconState,
|
||||
chunk_count = get_custody_chunk_count(attestation.data.crosslink)
|
||||
assert verify_bitfield(challenge.chunk_bits, chunk_count)
|
||||
# Verify the first bit of the hash of the chunk bits does not equal the custody bit
|
||||
custody_bit = get_bitfield_bit(attestation.custody_bitfield, attesters.index(challenge.responder_index))
|
||||
custody_bit = attestation.custody_bitfield[attesters.index(challenge.responder_index)]
|
||||
assert custody_bit != get_bitfield_bit(get_chunk_bits_root(challenge.chunk_bits), 0)
|
||||
# Add new bit challenge record
|
||||
new_record = CustodyBitChallengeRecord(
|
||||
|
@ -92,7 +92,7 @@ class ShardAttestation(Container):
|
||||
slot: Slot
|
||||
shard: Shard
|
||||
shard_block_root: Bytes32
|
||||
aggregation_bitfield: Bytes[PLACEHOLDER]
|
||||
aggregation_bitfield: Bitlist[PLACEHOLDER]
|
||||
aggregate_signature: BLSSignature
|
||||
```
|
||||
|
||||
@ -230,10 +230,9 @@ def verify_shard_attestation_signature(state: BeaconState,
|
||||
attestation: ShardAttestation) -> None:
|
||||
data = attestation.data
|
||||
persistent_committee = get_persistent_committee(state, data.shard, data.slot)
|
||||
assert verify_bitfield(attestation.aggregation_bitfield, len(persistent_committee))
|
||||
pubkeys = []
|
||||
for i, index in enumerate(persistent_committee):
|
||||
if get_bitfield_bit(attestation.aggregation_bitfield, i) == 0b1:
|
||||
if attestation.aggregation_bitfield[i]:
|
||||
validator = state.validators[index]
|
||||
assert is_active_validator(validator, get_current_epoch(state))
|
||||
pubkeys.append(validator.pubkey)
|
||||
|
@ -168,7 +168,7 @@ If a client wants to update its `finalized_header` it asks the network for a `Bl
|
||||
{
|
||||
'header': BeaconBlockHeader,
|
||||
'shard_aggregate_signature': BLSSignature,
|
||||
'shard_bitfield': 'bytes',
|
||||
'shard_bitfield': Bitlist[PLACEHOLDER],
|
||||
'shard_parent_block': ShardBlock,
|
||||
}
|
||||
```
|
||||
@ -180,13 +180,13 @@ def verify_block_validity_proof(proof: BlockValidityProof, validator_memory: Val
|
||||
assert proof.shard_parent_block.beacon_chain_root == hash_tree_root(proof.header)
|
||||
committee = compute_committee(proof.header, validator_memory)
|
||||
# Verify that we have >=50% support
|
||||
support_balance = sum([v.effective_balance for i, v in enumerate(committee) if get_bitfield_bit(proof.shard_bitfield, i) is True])
|
||||
support_balance = sum([v.effective_balance for i, v in enumerate(committee) if proof.shard_bitfield[i]])
|
||||
total_balance = sum([v.effective_balance for i, v in enumerate(committee)])
|
||||
assert support_balance * 2 > total_balance
|
||||
# Verify shard attestations
|
||||
group_public_key = bls_aggregate_pubkeys([
|
||||
v.pubkey for v, index in enumerate(committee)
|
||||
if get_bitfield_bit(proof.shard_bitfield, index) is True
|
||||
if proof.shard_bitfield[index]
|
||||
])
|
||||
assert bls_verify(
|
||||
pubkey=group_public_key,
|
||||
|
Loading…
x
Reference in New Issue
Block a user