Skip to content

Commit 071f0a3

Browse files
authored
Merge pull request #3769 from ethDreamer/fix_compute_proposer_index
Electra: Properly Calculate Proposer Probabilities
2 parents 836bc43 + 32b441d commit 071f0a3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

specs/electra/beacon-chain.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- [`BeaconState`](#beaconstate)
4343
- [Helper functions](#helper-functions)
4444
- [Predicates](#predicates)
45+
- [Updated `compute_proposer_index`](#updated-compute_proposer_index)
4546
- [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue)
4647
- [New `is_compounding_withdrawal_credential`](#new-is_compounding_withdrawal_credential)
4748
- [New `has_compounding_withdrawal_credential`](#new-has_compounding_withdrawal_credential)
@@ -438,6 +439,27 @@ class BeaconState(Container):
438439

439440
### Predicates
440441

442+
#### Updated `compute_proposer_index`
443+
444+
```python
445+
def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex], seed: Bytes32) -> ValidatorIndex:
446+
"""
447+
Return from ``indices`` a random index sampled by effective balance.
448+
"""
449+
assert len(indices) > 0
450+
MAX_RANDOM_BYTE = 2**8 - 1
451+
i = uint64(0)
452+
total = uint64(len(indices))
453+
while True:
454+
candidate_index = indices[compute_shuffled_index(i % total, total, seed)]
455+
random_byte = hash(seed + uint_to_bytes(uint64(i // 32)))[i % 32]
456+
effective_balance = state.validators[candidate_index].effective_balance
457+
# [Modified in Electra:EIP7251]
458+
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE_ELECTRA * random_byte:
459+
return candidate_index
460+
i += 1
461+
```
462+
441463
#### Updated `is_eligible_for_activation_queue`
442464

443465
```python

0 commit comments

Comments
 (0)