Skip to content

Commit

Permalink
Fix Calculations Relying on MAX_EB
Browse files Browse the repository at this point in the history
  • Loading branch information
ethDreamer committed Jun 21, 2024
1 parent 48f1f40 commit 6c1ae00
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,12 @@ impl<E: EthSpec> BeaconState<E> {
return Err(Error::InsufficientValidators);
}

let max_effective_balance = if self.fork_name_unchecked() >= ForkName::Electra {
spec.max_effective_balance_electra
} else {
spec.max_effective_balance
};

let mut i = 0;
loop {
let shuffled_index = compute_shuffled_index(
Expand All @@ -907,9 +913,7 @@ impl<E: EthSpec> BeaconState<E> {
let random_byte = Self::shuffling_random_byte(i, seed)?;
let effective_balance = self.get_effective_balance(candidate_index)?;
if effective_balance.safe_mul(MAX_RANDOM_BYTE)?
>= spec
.max_effective_balance
.safe_mul(u64::from(random_byte))?
>= max_effective_balance.safe_mul(u64::from(random_byte))?
{
return Ok(candidate_index);
}
Expand Down Expand Up @@ -1091,6 +1095,12 @@ impl<E: EthSpec> BeaconState<E> {

let seed = self.get_seed(epoch, Domain::SyncCommittee, spec)?;

let max_effective_balance = if self.fork_name_unchecked() >= ForkName::Electra {
spec.max_effective_balance_electra
} else {
spec.max_effective_balance
};

let mut i = 0;
let mut sync_committee_indices = Vec::with_capacity(E::SyncCommitteeSize::to_usize());
while sync_committee_indices.len() < E::SyncCommitteeSize::to_usize() {
Expand All @@ -1107,9 +1117,7 @@ impl<E: EthSpec> BeaconState<E> {
let random_byte = Self::shuffling_random_byte(i, seed.as_bytes())?;
let effective_balance = self.get_validator(candidate_index)?.effective_balance;
if effective_balance.safe_mul(MAX_RANDOM_BYTE)?
>= spec
.max_effective_balance
.safe_mul(u64::from(random_byte))?
>= max_effective_balance.safe_mul(u64::from(random_byte))?
{
sync_committee_indices.push(candidate_index);
}
Expand Down

0 comments on commit 6c1ae00

Please sign in to comment.