Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add init electra spec #376

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions ethereum-consensus/src/electra/beacon_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
use crate::{
altair::SyncAggregate,
capella::SignedBlsToExecutionChange,
deneb::polynomial_commitments::KzgCommitment,
electra::{Attestation, ExecutionPayload},
phase0::{AttesterSlashing, Deposit, Eth1Data, ProposerSlashing, SignedVoluntaryExit},
primitives::{BlsSignature, Bytes32, Root, Slot, ValidatorIndex},
ssz::prelude::*,
};

#[derive(
Default, Debug, Clone, SimpleSerialize, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct BeaconBlockBody<
const MAX_PROPOSER_SLASHINGS: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const MAX_ATTESTER_SLASHINGS: usize,
const MAX_ATTESTATIONS: usize,
const MAX_DEPOSITS: usize,
const MAX_VOLUNTARY_EXITS: usize,
const SYNC_COMMITTEE_SIZE: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize,
const MAX_COMMITTEES_PER_SLOT: usize,
const MAX_VALIDATORS_PER_SLOT: usize,
const MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: usize,
const MAX_EXECUTION_LAYER_EXITS: usize,
> {
pub randao_reveal: BlsSignature,
pub eth1_data: Eth1Data,
pub graffiti: Bytes32,
pub proposer_slashings: List<ProposerSlashing, MAX_PROPOSER_SLASHINGS>,
pub attester_slashings:
List<AttesterSlashing<MAX_VALIDATORS_PER_COMMITTEE>, MAX_ATTESTER_SLASHINGS>,
pub attestations:
List<Attestation<MAX_COMMITTEES_PER_SLOT, MAX_VALIDATORS_PER_SLOT>, MAX_ATTESTATIONS>,
pub deposits: List<Deposit, MAX_DEPOSITS>,
pub voluntary_exits: List<SignedVoluntaryExit, MAX_VOLUNTARY_EXITS>,
pub sync_aggregate: SyncAggregate<SYNC_COMMITTEE_SIZE>,
pub execution_payload: ExecutionPayload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD,
MAX_EXECUTION_LAYER_EXITS,
>,
pub bls_to_execution_changes: List<SignedBlsToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES>,
pub blob_kzg_commitments: List<KzgCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
}

#[derive(
Default, Debug, Clone, SimpleSerialize, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct BeaconBlock<
const MAX_PROPOSER_SLASHINGS: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const MAX_ATTESTER_SLASHINGS: usize,
const MAX_ATTESTATIONS: usize,
const MAX_DEPOSITS: usize,
const MAX_VOLUNTARY_EXITS: usize,
const SYNC_COMMITTEE_SIZE: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize,
const MAX_COMMITTEES_PER_SLOT: usize,
const MAX_VALIDATORS_PER_SLOT: usize,
const MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: usize,
const MAX_EXECUTION_LAYER_EXITS: usize,
> {
#[serde(with = "crate::serde::as_str")]
pub slot: Slot,
#[serde(with = "crate::serde::as_str")]
pub proposer_index: ValidatorIndex,
pub parent_root: Root,
pub state_root: Root,
pub body: BeaconBlockBody<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
MAX_BLOB_COMMITMENTS_PER_BLOCK,
MAX_COMMITTEES_PER_SLOT,
MAX_VALIDATORS_PER_SLOT,
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD,
MAX_EXECUTION_LAYER_EXITS,
>,
}

#[derive(
Default, Debug, Clone, SimpleSerialize, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct SignedBeaconBlock<
const MAX_PROPOSER_SLASHINGS: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const MAX_ATTESTER_SLASHINGS: usize,
const MAX_ATTESTATIONS: usize,
const MAX_DEPOSITS: usize,
const MAX_VOLUNTARY_EXITS: usize,
const SYNC_COMMITTEE_SIZE: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize,
const MAX_COMMITTEES_PER_SLOT: usize,
const MAX_VALIDATORS_PER_SLOT: usize,
const MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: usize,
const MAX_EXECUTION_LAYER_EXITS: usize,
> {
pub message: BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
MAX_BLOB_COMMITMENTS_PER_BLOCK,
MAX_COMMITTEES_PER_SLOT,
MAX_VALIDATORS_PER_SLOT,
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD,
MAX_EXECUTION_LAYER_EXITS,
>,
pub signature: BlsSignature,
}
66 changes: 66 additions & 0 deletions ethereum-consensus/src/electra/beacon_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::{
altair::SyncCommittee,
capella::HistoricalSummary,
electra::ExecutionPayloadHeader,
phase0::{BeaconBlockHeader, Checkpoint, Eth1Data, Fork, Validator, JUSTIFICATION_BITS_LENGTH},
primitives::{Bytes32, Gwei, ParticipationFlags, Root, Slot, ValidatorIndex, WithdrawalIndex},
ssz::prelude::*,
};

#[derive(
Default, Debug, SimpleSerialize, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct BeaconState<
const SLOTS_PER_HISTORICAL_ROOT: usize,
const HISTORICAL_ROOTS_LIMIT: usize,
const ETH1_DATA_VOTES_BOUND: usize,
const VALIDATOR_REGISTRY_LIMIT: usize,
const EPOCHS_PER_HISTORICAL_VECTOR: usize,
const EPOCHS_PER_SLASHINGS_VECTOR: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const SYNC_COMMITTEE_SIZE: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
> {
#[serde(with = "crate::serde::as_str")]
pub genesis_time: u64,
pub genesis_validators_root: Root,
#[serde(with = "crate::serde::as_str")]
pub slot: Slot,
pub fork: Fork,
pub latest_block_header: BeaconBlockHeader,
pub block_roots: Vector<Root, SLOTS_PER_HISTORICAL_ROOT>,
pub state_roots: Vector<Root, SLOTS_PER_HISTORICAL_ROOT>,
pub historical_roots: List<Root, HISTORICAL_ROOTS_LIMIT>,
pub eth1_data: Eth1Data,
pub eth1_data_votes: List<Eth1Data, ETH1_DATA_VOTES_BOUND>,
#[serde(with = "crate::serde::as_str")]
pub eth1_deposit_index: u64,
pub validators: List<Validator, VALIDATOR_REGISTRY_LIMIT>,
#[serde(with = "crate::serde::seq_of_str")]
pub balances: List<Gwei, VALIDATOR_REGISTRY_LIMIT>,
pub randao_mixes: Vector<Bytes32, EPOCHS_PER_HISTORICAL_VECTOR>,
#[serde(with = "crate::serde::seq_of_str")]
pub slashings: Vector<Gwei, EPOCHS_PER_SLASHINGS_VECTOR>,
#[serde(with = "crate::serde::seq_of_str")]
pub previous_epoch_participation: List<ParticipationFlags, VALIDATOR_REGISTRY_LIMIT>,
#[serde(with = "crate::serde::seq_of_str")]
pub current_epoch_participation: List<ParticipationFlags, VALIDATOR_REGISTRY_LIMIT>,
pub justification_bits: Bitvector<JUSTIFICATION_BITS_LENGTH>,
pub previous_justified_checkpoint: Checkpoint,
pub current_justified_checkpoint: Checkpoint,
pub finalized_checkpoint: Checkpoint,
#[serde(with = "crate::serde::seq_of_str")]
pub inactivity_scores: List<u64, VALIDATOR_REGISTRY_LIMIT>,
pub current_sync_committee: SyncCommittee<SYNC_COMMITTEE_SIZE>,
pub next_sync_committee: SyncCommittee<SYNC_COMMITTEE_SIZE>,
pub latest_execution_payload_header:
ExecutionPayloadHeader<BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES>,
#[serde(with = "crate::serde::as_str")]
pub next_withdrawal_index: WithdrawalIndex,
#[serde(with = "crate::serde::as_str")]
pub next_withdrawal_validator_index: ValidatorIndex,
pub historical_summaries: List<HistoricalSummary, HISTORICAL_ROOTS_LIMIT>,
#[serde(with = "crate::serde::as_str")]
pub deposit_receipts_start_index: u64,
}
1 change: 1 addition & 0 deletions ethereum-consensus/src/electra/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const UNSET_DEPOSIT_RECEIPTS_START_INDEX: u64 = u64::MAX;
17 changes: 17 additions & 0 deletions ethereum-consensus/src/electra/deposit_receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::{
primitives::{BlsPublicKey, BlsSignature, Bytes32, Gwei},
ssz::prelude::*,
};

#[derive(
Default, Debug, Clone, SimpleSerialize, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct DepositReceipt {
pub pubkey: BlsPublicKey,
pub withdrawal_credentials: Bytes32,
#[serde(with = "crate::serde::as_str")]
pub amount: Gwei,
pub signature: BlsSignature,
#[serde(with = "crate::serde::as_str")]
pub index: u64,
}
12 changes: 12 additions & 0 deletions ethereum-consensus/src/electra/execution_layer_exit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{
primitives::{BlsPublicKey, ExecutionAddress},
ssz::prelude::*,
};

#[derive(
Default, Debug, Clone, SimpleSerialize, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct ExecutionLayerExit {
pub source_address: ExecutionAddress,
pub validator_pubkey: BlsPublicKey,
}
Loading