Skip to content

Commit

Permalink
Fix ef tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Oct 16, 2024
1 parent c0cac0e commit b28d010
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::common::{
};
use crate::per_block_processing::errors::{BlockProcessingError, IntoWithIndex};
use crate::VerifySignatures;
use errors::DepositInvalid;
use types::consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR};
use types::typenum::U33;

Expand Down Expand Up @@ -455,12 +454,7 @@ pub fn apply_deposit<E: EthSpec>(
pubkey: deposit_data.pubkey,
withdrawal_credentials: deposit_data.withdrawal_credentials,
amount,
signature: deposit_data.signature.decompress().map_err(|_| {
BlockProcessingError::DepositInvalid {
index: deposit_index,
reason: DepositInvalid::BadBlsBytes,
}
})?,
signature: deposit_data.signature,
slot: spec.genesis_slot, // Use `genesis_slot` to distinguish from a pending deposit request
})?;
} else {
Expand All @@ -478,6 +472,7 @@ pub fn apply_deposit<E: EthSpec>(

// [Modified in Electra:EIP7251]
if state.fork_name_unchecked() >= ForkName::Electra {
let amount = 0;
// Create a new validator.
let mut validator = Validator {
pubkey: deposit_data.pubkey,
Expand Down Expand Up @@ -535,12 +530,7 @@ pub fn apply_deposit<E: EthSpec>(
pubkey: deposit_data.pubkey,
withdrawal_credentials: deposit_data.withdrawal_credentials,
amount,
signature: deposit_data.signature.decompress().map_err(|_| {
BlockProcessingError::DepositInvalid {
index: deposit_index,
reason: DepositInvalid::BadBlsBytes,
}
})?,
signature: deposit_data.signature,
slot: spec.genesis_slot, // Use `genesis_slot` to distinguish from a pending deposit request
})?;
}
Expand Down Expand Up @@ -706,7 +696,7 @@ fn is_valid_switch_to_compounding_request<E: EthSpec>(

let source_validator = state.get_validator(source_index)?;
// Verify the source withdrawal credentials
if let Some(withdrawal_address) = source_validator.get_execution_withdrawal_address(spec) {
if let Some(withdrawal_address) = source_validator.get_eth1_withdrawal_credential(spec) {
if withdrawal_address != consolidation_request.source_address {
return Ok(false);
}
Expand All @@ -721,6 +711,7 @@ fn is_valid_switch_to_compounding_request<E: EthSpec>(
return Ok(false);
}
// Verify exits for source has not been initiated
// TODO(pawan): this could be set by process_registry_updates too
if source_validator.exit_epoch != spec.far_future_epoch {
return Ok(false);
}
Expand All @@ -733,6 +724,7 @@ pub fn process_consolidation_request<E: EthSpec>(
consolidation_request: &ConsolidationRequest,
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
dbg!("here");
if is_valid_switch_to_compounding_request(state, consolidation_request, spec)? {
let Some(source_index) = state
.pubkey_cache()
Expand Down
17 changes: 12 additions & 5 deletions consensus/state_processing/src/per_epoch_processing/single_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn process_epoch_single_pass<E: EthSpec>(
let mut next_epoch_cache = PreEpochCache::new_for_next_epoch(state)?;

let pending_deposits_ctxt = if fork_name.electra_enabled() && conf.pending_deposits {
Some(PendingDepositsContext::new(state, spec)?)
Some(PendingDepositsContext::new(state, spec, &conf)?)
} else {
None
};
Expand Down Expand Up @@ -367,7 +367,7 @@ pub fn process_epoch_single_pass<E: EthSpec>(
pubkey: deposit.pubkey,
withdrawal_credentials: deposit.withdrawal_credentials,
amount: deposit.amount,
signature: deposit.signature.into(),
signature: deposit.signature,
},
spec,
)
Expand Down Expand Up @@ -869,7 +869,11 @@ fn process_single_slashing(
}

impl PendingDepositsContext {
fn new<E: EthSpec>(state: &BeaconState<E>, spec: &ChainSpec) -> Result<Self, Error> {
fn new<E: EthSpec>(
state: &BeaconState<E>,
spec: &ChainSpec,
config: &SinglePassConfig,
) -> Result<Self, Error> {
let available_for_processing = state
.deposit_balance_to_consume()?
.safe_add(state.get_activation_exit_churn_limit(spec)?)?;
Expand Down Expand Up @@ -925,8 +929,11 @@ impl PendingDepositsContext {
// balance update does not happen until *after* the registry update, so we don't need to
// account for changes to the effective balance that would push it below the ejection
// balance here.
let will_be_exited = validator.is_active_at(current_epoch)
&& validator.effective_balance <= spec.ejection_balance;
// Note: we only consider this if registry_updates are enabled in the config.
// EF tests require us to run epoch_processing functions in isolation.
let will_be_exited = config.registry_updates
&& (validator.is_active_at(current_epoch)
&& validator.effective_balance <= spec.ejection_balance);
is_validator_exited = already_exited || will_be_exited;
is_validator_withdrawn = validator.withdrawable_epoch < next_epoch;
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/state_processing/src/upgrade/electra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ pub fn upgrade_to_electra<E: EthSpec>(
validator.activation_eligibility_epoch = spec.far_future_epoch;
let pubkey = validator.pubkey;
let withdrawal_credentials = validator.withdrawal_credentials;
dbg!("is this getting hit");

post.pending_deposits_mut()?
.push(PendingDeposit {
pubkey,
withdrawal_credentials,
amount: balance_copy,
signature: Signature::infinity()?,
signature: Signature::infinity()?.into(),
slot: spec.genesis_slot,
})
.map_err(Error::MilhouseError)?;
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ impl<E: EthSpec> BeaconState<E> {
pubkey: validator.pubkey,
withdrawal_credentials: validator.withdrawal_credentials,
amount: excess_balance,
signature: Signature::infinity()?,
signature: Signature::infinity()?.into(),
slot: spec.genesis_slot,
})?;
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/types/src/deposit_request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::test_utils::TestRandom;
use crate::{Hash256, PublicKeyBytes, Signature};
use crate::{Hash256, PublicKeyBytes};
use bls::SignatureBytes;
use serde::{Deserialize, Serialize};
use ssz::Encode;
use ssz_derive::{Decode, Encode};
Expand All @@ -10,7 +11,6 @@ use tree_hash_derive::TreeHash;
arbitrary::Arbitrary,
Debug,
PartialEq,
Eq,
Hash,
Clone,
Serialize,
Expand All @@ -25,7 +25,7 @@ pub struct DepositRequest {
pub withdrawal_credentials: Hash256,
#[serde(with = "serde_utils::quoted_u64")]
pub amount: u64,
pub signature: Signature,
pub signature: SignatureBytes,
#[serde(with = "serde_utils::quoted_u64")]
pub index: u64,
}
Expand All @@ -36,7 +36,7 @@ impl DepositRequest {
pubkey: PublicKeyBytes::empty(),
withdrawal_credentials: Hash256::ZERO,
amount: 0,
signature: Signature::empty(),
signature: SignatureBytes::empty(),
index: 0,
}
.as_ssz_bytes()
Expand Down
3 changes: 1 addition & 2 deletions consensus/types/src/pending_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use tree_hash_derive::TreeHash;
arbitrary::Arbitrary,
Debug,
PartialEq,
Eq,
Hash,
Clone,
Serialize,
Expand All @@ -24,7 +23,7 @@ pub struct PendingDeposit {
pub withdrawal_credentials: Hash256,
#[serde(with = "serde_utils::quoted_u64")]
pub amount: u64,
pub signature: Signature,
pub signature: SignatureBytes,
pub slot: Slot,
}

Expand Down
11 changes: 11 additions & 0 deletions consensus/types/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ impl Validator {
.flatten()
}

pub fn get_eth1_withdrawal_credential(&self, spec: &ChainSpec) -> Option<Address> {
self.has_eth1_withdrawal_credential(spec)
.then(|| {
self.withdrawal_credentials
.as_slice()
.get(12..)
.map(Address::from_slice)
})
.flatten()
}

/// Changes withdrawal credentials to the provided eth1 execution address.
///
/// WARNING: this function does NO VALIDATION - it just does it!
Expand Down
2 changes: 1 addition & 1 deletion testing/ef_tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TESTS_TAG := v1.5.0-alpha.7
TESTS_TAG := v1.5.0-alpha.8
TESTS = general minimal mainnet
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))

Expand Down

0 comments on commit b28d010

Please sign in to comment.