Skip to content

Commit

Permalink
Merge pull request #170 from jimmygchen/deneb-types-and-presets
Browse files Browse the repository at this point in the history
Add Deneb (EIP-4844) types and presets
  • Loading branch information
ralexstokes committed Jul 16, 2023
2 parents e380108 + 4d40289 commit 1728010
Show file tree
Hide file tree
Showing 20 changed files with 1,132 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/configs/goerli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub const BELLATRIX_FORK_VERSION: Version = [2, 0, 16, 32];
pub const BELLATRIX_FORK_EPOCH: Epoch = 112260;
pub const CAPELLA_FORK_VERSION: Version = [3, 0, 16, 32];
pub const CAPELLA_FORK_EPOCH: Epoch = 162304;
pub const EIP4844_FORK_VERSION: Version = [4, 0, 16, 32];
pub const EIP4844_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const DENEB_FORK_VERSION: Version = [4, 0, 16, 32];
pub const DENEB_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const INACTIVITY_SCORE_BIAS: u64 = 4;
pub const INACTIVITY_SCORE_RECOVERY_RATE: u64 = 16;
pub const PROPOSER_SCORE_BOOST: u64 = 40;
Expand Down Expand Up @@ -61,8 +61,8 @@ pub fn config() -> Config {
bellatrix_fork_epoch: BELLATRIX_FORK_EPOCH,
capella_fork_version: CAPELLA_FORK_VERSION,
capella_fork_epoch: CAPELLA_FORK_EPOCH,
eip4844_fork_version: EIP4844_FORK_VERSION,
eip4844_fork_epoch: EIP4844_FORK_EPOCH,
deneb_fork_version: DENEB_FORK_VERSION,
deneb_fork_epoch: DENEB_FORK_EPOCH,
seconds_per_slot: SECONDS_PER_SLOT,
seconds_per_eth1_block: SECONDS_PER_ETH1_BLOCK,
min_validator_withdrawability_delay: MIN_VALIDATOR_WITHDRAWABILITY_DELAY,
Expand Down
8 changes: 4 additions & 4 deletions src/configs/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub const BELLATRIX_FORK_VERSION: Version = [2, 0, 0, 0];
pub const BELLATRIX_FORK_EPOCH: Epoch = 144896;
pub const CAPELLA_FORK_VERSION: Version = [3, 0, 0, 0];
pub const CAPELLA_FORK_EPOCH: Epoch = 194048;
pub const EIP4844_FORK_VERSION: Version = [4, 0, 0, 0];
pub const EIP4844_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const DENEB_FORK_VERSION: Version = [4, 0, 0, 0];
pub const DENEB_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const INACTIVITY_SCORE_BIAS: u64 = 4;
pub const INACTIVITY_SCORE_RECOVERY_RATE: u64 = 16;
pub const PROPOSER_SCORE_BOOST: u64 = 40;
Expand Down Expand Up @@ -59,8 +59,8 @@ pub fn config() -> Config {
bellatrix_fork_epoch: BELLATRIX_FORK_EPOCH,
capella_fork_version: CAPELLA_FORK_VERSION,
capella_fork_epoch: CAPELLA_FORK_EPOCH,
eip4844_fork_version: EIP4844_FORK_VERSION,
eip4844_fork_epoch: EIP4844_FORK_EPOCH,
deneb_fork_version: DENEB_FORK_VERSION,
deneb_fork_epoch: DENEB_FORK_EPOCH,
seconds_per_slot: SECONDS_PER_SLOT,
seconds_per_eth1_block: SECONDS_PER_ETH1_BLOCK,
min_validator_withdrawability_delay: MIN_VALIDATOR_WITHDRAWABILITY_DELAY,
Expand Down
8 changes: 4 additions & 4 deletions src/configs/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub const BELLATRIX_FORK_VERSION: Version = [2, 0, 0, 1];
pub const BELLATRIX_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const CAPELLA_FORK_VERSION: Version = [3, 0, 0, 1];
pub const CAPELLA_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const EIP4844_FORK_VERSION: Version = [4, 0, 0, 1];
pub const EIP4844_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const DENEB_FORK_VERSION: Version = [4, 0, 0, 1];
pub const DENEB_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const SECONDS_PER_SLOT: u64 = 6;
pub const SECONDS_PER_ETH1_BLOCK: u64 = 14;
pub const MIN_VALIDATOR_WITHDRAWABILITY_DELAY: Epoch = 256;
Expand Down Expand Up @@ -60,8 +60,8 @@ pub fn config() -> Config {
bellatrix_fork_epoch: BELLATRIX_FORK_EPOCH,
capella_fork_version: CAPELLA_FORK_VERSION,
capella_fork_epoch: CAPELLA_FORK_EPOCH,
eip4844_fork_version: EIP4844_FORK_VERSION,
eip4844_fork_epoch: EIP4844_FORK_EPOCH,
deneb_fork_version: DENEB_FORK_VERSION,
deneb_fork_epoch: DENEB_FORK_EPOCH,
seconds_per_slot: SECONDS_PER_SLOT,
seconds_per_eth1_block: SECONDS_PER_ETH1_BLOCK,
min_validator_withdrawability_delay: MIN_VALIDATOR_WITHDRAWABILITY_DELAY,
Expand Down
4 changes: 2 additions & 2 deletions src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub struct Config {
pub capella_fork_version: Version,
pub capella_fork_epoch: Epoch,
#[serde(with = "crate::serde::as_hex")]
pub eip4844_fork_version: Version,
pub eip4844_fork_epoch: Epoch,
pub deneb_fork_version: Version,
pub deneb_fork_epoch: Epoch,

pub seconds_per_slot: u64,
pub seconds_per_eth1_block: u64,
Expand Down
8 changes: 4 additions & 4 deletions src/configs/sepolia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub const BELLATRIX_FORK_VERSION: Version = [144, 0, 0, 113];
pub const BELLATRIX_FORK_EPOCH: Epoch = 100;
pub const CAPELLA_FORK_VERSION: Version = [144, 0, 0, 114];
pub const CAPELLA_FORK_EPOCH: Epoch = 56832;
pub const EIP4844_FORK_VERSION: Version = [4, 0, 16, 32];
pub const EIP4844_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const DENEB_FORK_VERSION: Version = [4, 0, 16, 32];
pub const DENEB_FORK_EPOCH: Epoch = FAR_FUTURE_EPOCH;
pub const INACTIVITY_SCORE_BIAS: u64 = 4;
pub const INACTIVITY_SCORE_RECOVERY_RATE: u64 = 16;
pub const PROPOSER_SCORE_BOOST: u64 = 40;
Expand Down Expand Up @@ -62,8 +62,8 @@ pub fn config() -> Config {
bellatrix_fork_epoch: BELLATRIX_FORK_EPOCH,
capella_fork_version: CAPELLA_FORK_VERSION,
capella_fork_epoch: CAPELLA_FORK_EPOCH,
eip4844_fork_version: EIP4844_FORK_VERSION,
eip4844_fork_epoch: EIP4844_FORK_EPOCH,
deneb_fork_version: DENEB_FORK_VERSION,
deneb_fork_epoch: DENEB_FORK_EPOCH,
seconds_per_slot: SECONDS_PER_SLOT,
seconds_per_eth1_block: SECONDS_PER_ETH1_BLOCK,
min_validator_withdrawability_delay: MIN_VALIDATOR_WITHDRAWABILITY_DELAY,
Expand Down
127 changes: 127 additions & 0 deletions src/deneb/beacon_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use crate::altair::SyncAggregate;
use crate::capella::SignedBlsToExecutionChange;
use crate::deneb::ExecutionPayload;
use crate::kzg::KzgCommitment;
use crate::phase0::{
Attestation, AttesterSlashing, Deposit, Eth1Data, ProposerSlashing, SignedVoluntaryExit,
};
use crate::primitives::{BlsSignature, Bytes32, Root, Slot, ValidatorIndex};
use ssz_rs::prelude::*;

#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(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,
> {
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_VALIDATORS_PER_COMMITTEE>, 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,
>,
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)]
#[cfg_attr(feature = "serde", derive(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_BLOBS_PER_BLOCK: usize,
> {
#[serde(with = "crate::serde::as_string")]
pub slot: Slot,
#[serde(with = "crate::serde::as_string")]
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_BLOBS_PER_BLOCK,
>,
}

#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(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_BLOBS_PER_BLOCK: 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_BLOBS_PER_BLOCK,
>,
pub signature: BlsSignature,
}
67 changes: 67 additions & 0 deletions src/deneb/beacon_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use crate::altair::SyncCommittee;
use crate::capella::HistoricalSummary;
use crate::deneb::ExecutionPayloadHeader;
use crate::phase0::{
BeaconBlockHeader, Checkpoint, Eth1Data, Fork, Validator, JUSTIFICATION_BITS_LENGTH,
};
use crate::primitives::{
Bytes32, Gwei, ParticipationFlags, Root, Slot, ValidatorIndex, WithdrawalIndex,
};
use ssz_rs::prelude::*;

#[derive(Default, Debug, SimpleSerialize, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(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,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
> {
#[serde(with = "crate::serde::as_string")]
pub genesis_time: u64,
pub genesis_validators_root: Root,
#[serde(with = "crate::serde::as_string")]
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_string")]
pub eth1_deposit_index: u64,
pub validators: List<Validator, VALIDATOR_REGISTRY_LIMIT>,
#[serde(with = "crate::serde::collection_over_string")]
pub balances: List<Gwei, VALIDATOR_REGISTRY_LIMIT>,
pub randao_mixes: Vector<Bytes32, EPOCHS_PER_HISTORICAL_VECTOR>,
#[serde(with = "crate::serde::collection_over_string")]
pub slashings: Vector<Gwei, EPOCHS_PER_SLASHINGS_VECTOR>,
#[serde(with = "crate::serde::collection_over_string")]
pub previous_epoch_participation: List<ParticipationFlags, VALIDATOR_REGISTRY_LIMIT>,
#[serde(with = "crate::serde::collection_over_string")]
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::collection_over_string")]
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_string")]
pub next_withdrawal_index: WithdrawalIndex,
#[serde(with = "crate::serde::as_string")]
pub next_withdrawal_validator_index: ValidatorIndex,
pub historical_summaries: List<HistoricalSummary, HISTORICAL_ROOTS_LIMIT>,
}
Loading

0 comments on commit 1728010

Please sign in to comment.