EIP-7732 Boiler Plate

This commit is contained in:
Mark Mackey
2024-08-27 12:38:00 -05:00
parent c042dc14d7
commit 13130dfa4f
52 changed files with 891 additions and 153 deletions

View File

@@ -2,7 +2,6 @@ use serde::Deserialize;
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use std::fmt::Debug;
use types::ForkName;
/// Macro to wrap U128 and U256 so they deserialize correctly.
macro_rules! uint_wrapper {
@@ -57,18 +56,6 @@ impl<T> SszStaticType for T where
{
}
/// Return the fork immediately prior to a fork.
pub fn previous_fork(fork_name: ForkName) -> ForkName {
match fork_name {
ForkName::Base => ForkName::Base,
ForkName::Altair => ForkName::Base,
ForkName::Bellatrix => ForkName::Altair,
ForkName::Capella => ForkName::Bellatrix,
ForkName::Deneb => ForkName::Capella,
ForkName::Electra => ForkName::Deneb,
}
}
#[macro_export]
macro_rules! impl_bls_load_case {
($case_name:ident) => {

View File

@@ -117,7 +117,8 @@ impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => {
initialize_progressive_balances_cache(state, spec)?;
let justification_and_finalization_state =
altair::process_justification_and_finalization(state)?;
@@ -140,7 +141,8 @@ impl<E: EthSpec> EpochTransition<E> for RewardsAndPenalties {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_rewards_and_penalties_slow(state, spec),
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => altair::process_rewards_and_penalties_slow(state, spec),
}
}
}
@@ -173,7 +175,8 @@ impl<E: EthSpec> EpochTransition<E> for Slashings {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => {
process_slashings_slow(state, spec)?;
}
};
@@ -278,7 +281,8 @@ impl<E: EthSpec> EpochTransition<E> for SyncCommitteeUpdates {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_sync_committee_updates(state, spec),
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => altair::process_sync_committee_updates(state, spec),
}
}
}
@@ -291,7 +295,8 @@ impl<E: EthSpec> EpochTransition<E> for InactivityUpdates {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_inactivity_updates_slow(state, spec),
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => altair::process_inactivity_updates_slow(state, spec),
}
}
}
@@ -304,7 +309,8 @@ impl<E: EthSpec> EpochTransition<E> for ParticipationFlagUpdates {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_participation_flag_updates(state),
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => altair::process_participation_flag_updates(state),
}
}
}

View File

@@ -1,6 +1,5 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use crate::cases::common::previous_fork;
use crate::decode::{ssz_decode_state, yaml_decode_file};
use serde::Deserialize;
use state_processing::upgrade::{
@@ -33,8 +32,11 @@ impl<E: EthSpec> LoadCase for ForkTest<E> {
assert_eq!(metadata.fork_name(), fork_name);
// Decode pre-state with previous fork.
let pre_spec = &previous_fork(fork_name).make_genesis_spec(E::default_spec());
let pre = ssz_decode_state(&path.join("pre.ssz_snappy"), pre_spec)?;
let pre_spec = fork_name
.previous_fork()
.unwrap_or(ForkName::Base)
.make_genesis_spec(E::default_spec());
let pre = ssz_decode_state(&path.join("pre.ssz_snappy"), &pre_spec)?;
// Decode post-state with target fork.
let post_spec = &fork_name.make_genesis_spec(E::default_spec());
@@ -69,6 +71,7 @@ impl<E: EthSpec> Case for ForkTest<E> {
ForkName::Capella => upgrade_to_capella(&mut result_state, spec).map(|_| result_state),
ForkName::Deneb => upgrade_to_deneb(&mut result_state, spec).map(|_| result_state),
ForkName::Electra => upgrade_to_electra(&mut result_state, spec).map(|_| result_state),
ForkName::EIP7732 => todo!("upgrade_to_eip7732 not yet implemented"),
};
compare_beacon_state_results_without_caches(&mut result, &mut expected)

View File

@@ -4,7 +4,8 @@ use serde::Deserialize;
use tree_hash::Hash256;
use types::{
light_client_update, BeaconBlockBody, BeaconBlockBodyCapella, BeaconBlockBodyDeneb,
BeaconBlockBodyElectra, BeaconState, FixedVector, FullPayload, Unsigned,
BeaconBlockBodyEIP7732, BeaconBlockBodyElectra, BeaconState, FixedVector, FullPayload,
Unsigned,
};
#[derive(Debug, Clone, Deserialize)]
@@ -131,6 +132,11 @@ impl<E: EthSpec> LoadCase for KzgInclusionMerkleProofValidity<E> {
ssz_decode_file::<BeaconBlockBodyElectra<E>>(&path.join("object.ssz_snappy"))?
.into()
}
// TODO(EIP7732): check this
ForkName::EIP7732 => {
ssz_decode_file::<BeaconBlockBodyEIP7732<E>>(&path.join("object.ssz_snappy"))?
.into()
}
};
let merkle_proof = yaml_decode_file(&path.join("proof.yaml"))?;
// Metadata does not exist in these tests but it is left like this just in case.
@@ -246,6 +252,10 @@ impl<E: EthSpec> LoadCase for BeaconBlockBodyMerkleProofValidity<E> {
ssz_decode_file::<BeaconBlockBodyElectra<E>>(&path.join("object.ssz_snappy"))?
.into()
}
ForkName::EIP7732 => {
ssz_decode_file::<BeaconBlockBodyEIP7732<E>>(&path.join("object.ssz_snappy"))?
.into()
}
};
let merkle_proof = yaml_decode_file(&path.join("proof.yaml"))?;
// Metadata does not exist in these tests but it is left like this just in case.

View File

@@ -24,9 +24,9 @@ use state_processing::{
use std::fmt::Debug;
use types::{
Attestation, AttesterSlashing, BeaconBlock, BeaconBlockBody, BeaconBlockBodyBellatrix,
BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconBlockBodyElectra, BeaconState,
BlindedPayload, ConsolidationRequest, Deposit, DepositRequest, ExecutionPayload, FullPayload,
ProposerSlashing, SignedBlsToExecutionChange, SignedVoluntaryExit, SyncAggregate,
BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconBlockBodyEIP7732, BeaconBlockBodyElectra,
BeaconState, BlindedPayload, ConsolidationRequest, Deposit, DepositRequest, ExecutionPayload,
FullPayload, ProposerSlashing, SignedBlsToExecutionChange, SignedVoluntaryExit, SyncAggregate,
WithdrawalRequest,
};
@@ -110,7 +110,8 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
| BeaconState::Electra(_)
| BeaconState::EIP7732(_) => {
initialize_progressive_balances_cache(state, spec)?;
altair_deneb::process_attestation(
state,
@@ -137,7 +138,7 @@ impl<E: EthSpec> Operation<E> for AttesterSlashing<E> {
| ForkName::Bellatrix
| ForkName::Capella
| ForkName::Deneb => Self::Base(ssz_decode_file(path)?),
ForkName::Electra => Self::Electra(ssz_decode_file(path)?),
ForkName::Electra | ForkName::EIP7732 => Self::Electra(ssz_decode_file(path)?),
})
}
@@ -308,6 +309,7 @@ impl<E: EthSpec> Operation<E> for BeaconBlockBody<E, FullPayload<E>> {
ForkName::Capella => BeaconBlockBody::Capella(<_>::from_ssz_bytes(bytes)?),
ForkName::Deneb => BeaconBlockBody::Deneb(<_>::from_ssz_bytes(bytes)?),
ForkName::Electra => BeaconBlockBody::Electra(<_>::from_ssz_bytes(bytes)?),
ForkName::EIP7732 => BeaconBlockBody::EIP7732(<_>::from_ssz_bytes(bytes)?),
_ => panic!(),
})
})
@@ -363,6 +365,10 @@ impl<E: EthSpec> Operation<E> for BeaconBlockBody<E, BlindedPayload<E>> {
let inner = <BeaconBlockBodyElectra<E, FullPayload<E>>>::from_ssz_bytes(bytes)?;
BeaconBlockBody::Electra(inner.clone_as_blinded())
}
ForkName::EIP7732 => {
let inner = <BeaconBlockBodyEIP7732<E, FullPayload<E>>>::from_ssz_bytes(bytes)?;
BeaconBlockBody::EIP7732(inner.clone_as_blinded())
}
_ => panic!(),
})
})

View File

@@ -60,6 +60,14 @@ impl<E: EthSpec> LoadCase for TransitionTest<E> {
spec.deneb_fork_epoch = Some(Epoch::new(0));
spec.electra_fork_epoch = Some(metadata.fork_epoch);
}
ForkName::EIP7732 => {
spec.altair_fork_epoch = Some(Epoch::new(0));
spec.bellatrix_fork_epoch = Some(Epoch::new(0));
spec.capella_fork_epoch = Some(Epoch::new(0));
spec.deneb_fork_epoch = Some(Epoch::new(0));
spec.electra_fork_epoch = Some(Epoch::new(0));
spec.eip7732_fork_epoch = Some(metadata.fork_epoch);
}
}
// Load blocks