Skip to content

Commit e58ec88

Browse files
EIP-7688: Forward Compatible Consensus Data Structures (#9450)
## Relevant Links - https://eips.ethereum.org/EIPS/eip-7688 - ethereum/consensus-specs#4630 ## Proposed Changes Adds the necessary types and components to support EIP-7688, along with the cargo patches to pull in the `progressive` versions of the crates in our SSZ stack. ## Testing ```yaml participants_matrix: el: - el_type: nethermind el_image: ethpandaops/nethermind:master cl: - cl_type: nimbus cl_image: ethpandaops/nimbus-eth2:glamsterdam-devnet-7-minimal - cl_type: lodestar cl_image: ethpandaops/lodestar:glamsterdam-devnet-7 - cl_type: lighthouse cl_image: ethpandaops/lighthouse:glamsterdam-devnet-7 - cl_type: teku cl_image: ethpandaops/teku:glamsterdam-devnet-7 ethereum_genesis_generator_params: image: "ethpandaops/ethereum-genesis-generator:glamsterdam-devnet-7" dora_params: image: ethpandaops/dora:glamsterdam-devnet-7 global_log_level: debug network_params: preset: minimal gloas_fork_epoch: 1 additional_services: - dora ``` ## Additional Info Based on the original work by @michaelsproul in #8505 Co-authored-by: Michael Sproul <michael@sigmaprime.io>
1 parent dbd2824 commit e58ec88

102 files changed

Lines changed: 3635 additions & 927 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ inherits = "release"
279279
debug = true
280280

281281
[patch.crates-io]
282+
# FIXME(eip-7688): EIP-7688 development patches
283+
ssz_types = { git = "https://github.com/sigp/ssz_types", rev = "9203d56ad2d7bc5f12133d043e085843f81edcd6" }
284+
milhouse = { git = "https://github.com/sigp/milhouse", rev = "c70f128976ac0d60ea65a978dabd117a921c36ee" }
285+
ethereum_ssz = { git = "https://github.com/sigp/ethereum_ssz", rev = "2059c21ba52cd3a7e39a8ad537012b761812a393" }
286+
ethereum_ssz_derive = { git = "https://github.com/sigp/ethereum_ssz", rev = "2059c21ba52cd3a7e39a8ad537012b761812a393" }
287+
tree_hash = { git = "https://github.com/sigp/tree_hash", rev = "03d9fa474586c125f306dd7a00cf46284575a01f" }
288+
tree_hash_derive = { git = "https://github.com/sigp/tree_hash", rev = "03d9fa474586c125f306dd7a00cf46284575a01f" }
282289
# Temporary patch until the axum migration is complete
283290
warp = { git = "https://github.com/macladson/warp", rev = "6f5f21beab6a240e59470caaab56afd46d46b709" }
284291

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use state_processing::{
4848
common::{
4949
attesting_indices_base,
5050
attesting_indices_electra::{self, get_committee_indices},
51+
attesting_indices_gloas,
5152
},
5253
per_block_processing::errors::{AttestationValidationError, BlockOperationError},
5354
signature_sets::{
@@ -688,6 +689,16 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
688689
signed_aggregate.message.selection_proof.clone(),
689690
signed_aggregate.message.aggregate.data.clone(),
690691
),
692+
SignedAggregateAndProof::Gloas(signed_aggregate) => (
693+
signed_aggregate
694+
.message
695+
.aggregate
696+
.committee_index()
697+
.ok_or(Error::NotExactlyOneCommitteeBitSet(0))?,
698+
signed_aggregate.message.aggregator_index,
699+
signed_aggregate.message.selection_proof.clone(),
700+
signed_aggregate.message.aggregate.data.clone(),
701+
),
691702
};
692703
let slot = data.slot;
693704

@@ -724,6 +735,13 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
724735
)
725736
.map_err(|e| BeaconChainError::from(e).into())
726737
}
738+
SignedAggregateAndProof::Gloas(signed_aggregate) => {
739+
attesting_indices_gloas::get_indexed_attestation(
740+
&committees,
741+
&signed_aggregate.message.aggregate,
742+
)
743+
.map_err(|e| BeaconChainError::from(e).into())
744+
}
727745
}
728746
};
729747

@@ -1562,6 +1580,20 @@ pub fn obtain_indexed_attestation_and_committees_per_slot<T: BeaconChainTypes>(
15621580
}
15631581
})
15641582
}
1583+
AttestationRef::Gloas(att) => {
1584+
attesting_indices_gloas::get_indexed_attestation(&committees, att)
1585+
.map(|attestation| (attestation, committees_per_slot))
1586+
.map_err(|e| {
1587+
if let BlockOperationError::BeaconStateError(NoCommitteeFound(index)) = e {
1588+
Error::NoCommitteeForSlotAndIndex {
1589+
slot: att.data.slot,
1590+
index,
1591+
}
1592+
} else {
1593+
Error::Invalid(e)
1594+
}
1595+
})
1596+
}
15651597
}
15661598
})
15671599
}

beacon_node/beacon_chain/src/beacon_block_reward.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
263263
.safe_mul(WEIGHT_DENOMINATOR)?
264264
.safe_div(PROPOSER_WEIGHT)?;
265265

266-
let mut current_epoch_participation = state.current_epoch_participation()?.clone();
267-
let mut previous_epoch_participation = state.previous_epoch_participation()?.clone();
266+
let mut current_epoch_participation = state.current_epoch_participation()?.to_owned_list();
267+
let mut previous_epoch_participation =
268+
state.previous_epoch_participation()?.to_owned_list();
268269

269270
for attestation in block.body().attestations() {
270271
let data = attestation.data();
@@ -289,7 +290,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
289290
};
290291

291292
let validator_participation = epoch_participation
292-
.get_mut(index)
293+
.as_mut()
294+
.into_get_mut(index)
293295
.ok_or(BeaconStateError::ParticipationOutOfBounds(index))?;
294296

295297
if participation_flag_indices.contains(&flag_index)

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
12581258
if header_from_payload != execution_payload_header {
12591259
for txn in execution_payload.transactions() {
12601260
debug!(
1261-
bytes = format!("0x{}", hex::encode(&**txn)),
1261+
bytes = format!("0x{}", hex::encode(txn)),
12621262
"Reconstructed txn"
12631263
);
12641264
}
@@ -1746,12 +1746,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
17461746
) -> Result<Option<Attestation<T::EthSpec>>, Error> {
17471747
match attestation {
17481748
AttestationRef::Base(att) => self.get_aggregated_attestation_base(&att.data),
1749-
AttestationRef::Electra(att) => self.get_aggregated_attestation_electra(
1750-
att.data.slot,
1751-
&att.data.tree_hash_root(),
1752-
att.committee_index()
1753-
.ok_or(Error::AttestationCommitteeIndexNotSet)?,
1754-
),
1749+
AttestationRef::Electra(_) | AttestationRef::Gloas(_) => self
1750+
.get_aggregated_attestation_electra(
1751+
attestation.data().slot,
1752+
&attestation.data().tree_hash_root(),
1753+
attestation
1754+
.committee_index()
1755+
.ok_or(Error::AttestationCommitteeIndexNotSet)?,
1756+
),
17551757
}
17561758
}
17571759

@@ -5892,27 +5894,36 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
58925894
bls_to_execution_changes,
58935895
} = partial_beacon_block;
58945896

5895-
let (attester_slashings_base, attester_slashings_electra) =
5896-
attester_slashings.into_iter().fold(
5897-
(Vec::new(), Vec::new()),
5898-
|(mut base, mut electra), slashing| {
5899-
match slashing {
5900-
AttesterSlashing::Base(slashing) => base.push(slashing),
5901-
AttesterSlashing::Electra(slashing) => electra.push(slashing),
5902-
}
5903-
(base, electra)
5904-
},
5905-
);
5906-
let (attestations_base, attestations_electra) = attestations.into_iter().fold(
5907-
(Vec::new(), Vec::new()),
5908-
|(mut base, mut electra), attestation| {
5909-
match attestation {
5910-
Attestation::Base(attestation) => base.push(attestation),
5911-
Attestation::Electra(attestation) => electra.push(attestation),
5897+
let mut attester_slashings_base = Vec::new();
5898+
let mut attester_slashings_electra = Vec::new();
5899+
for slashing in attester_slashings {
5900+
match slashing {
5901+
AttesterSlashing::Base(slashing) => attester_slashings_base.push(slashing),
5902+
AttesterSlashing::Electra(slashing) => attester_slashings_electra.push(slashing),
5903+
// Gloas-typed slashings cannot be included in pre-Gloas blocks, and Gloas
5904+
// blocks are produced via `complete_partial_beacon_block_gloas`.
5905+
AttesterSlashing::Gloas(_) => {
5906+
return Err(BlockProductionError::InvalidBlockVariant(
5907+
"Gloas attester slashing in pre-Gloas block production".to_owned(),
5908+
));
59125909
}
5913-
(base, electra)
5914-
},
5915-
);
5910+
}
5911+
}
5912+
let mut attestations_base = Vec::new();
5913+
let mut attestations_electra = Vec::new();
5914+
for attestation in attestations {
5915+
match attestation {
5916+
Attestation::Base(attestation) => attestations_base.push(attestation),
5917+
Attestation::Electra(attestation) => attestations_electra.push(attestation),
5918+
// Gloas-typed attestations cannot be included in pre-Gloas blocks, and Gloas
5919+
// blocks are produced via `complete_partial_beacon_block_gloas`.
5920+
Attestation::Gloas(_) => {
5921+
return Err(BlockProductionError::InvalidBlockVariant(
5922+
"Gloas attestation in pre-Gloas block production".to_owned(),
5923+
));
5924+
}
5925+
}
5926+
}
59165927

59175928
let (inner_block, maybe_blobs_and_proofs, execution_payload_value) = match &state {
59185929
BeaconState::Base(_) => (
@@ -6167,11 +6178,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
61676178
blob_kzg_commitments: kzg_commitments
61686179
.ok_or(BlockProductionError::InvalidPayloadFork)?,
61696180
execution_requests: maybe_requests
6170-
.map(|r| ExecutionRequestsElectra {
6171-
deposits: r.deposits().clone(),
6172-
withdrawals: r.withdrawals().clone(),
6173-
consolidations: r.consolidations().clone(),
6174-
})
61756181
.ok_or(BlockProductionError::MissingExecutionRequests)?,
61766182
},
61776183
}),
@@ -6226,11 +6232,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
62266232
blob_kzg_commitments: kzg_commitments
62276233
.ok_or(BlockProductionError::InvalidPayloadFork)?,
62286234
execution_requests: maybe_requests
6229-
.map(|r| ExecutionRequestsElectra {
6230-
deposits: r.deposits().clone(),
6231-
withdrawals: r.withdrawals().clone(),
6232-
consolidations: r.consolidations().clone(),
6233-
})
62346235
.ok_or(BlockProductionError::MissingExecutionRequests)?,
62356236
},
62366237
}),

0 commit comments

Comments
 (0)