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 prague engine types #557

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
35 changes: 35 additions & 0 deletions crates/eips/src/eip6110.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Contains Deposit types, first introduced in the Prague hardfork: <https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md>
//!
//! See also [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110): Supply validator deposits on chain
//!
//! Provides validator deposits as a list of deposit operations added to the Execution Layer block.

use alloy_primitives::{address, Address, FixedBytes, B256};
use alloy_rlp::{RlpDecodable, RlpEncodable};

/// Mainnet deposit contract address.
pub const MAINNET_DEPOSIT_CONTRACT_ADDRESS: Address =
address!("00000000219ab540356cbb839cbe05303d7705fa");

/// This structure maps onto the deposit object from [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110).
#[derive(Clone, Copy, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)]
#[cfg_attr(
any(test, feature = "arbitrary"),
derive(proptest_derive::Arbitrary, arbitrary::Arbitrary)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "ssz", derive(ssz_derive::Encode, ssz_derive::Decode))]
pub struct Deposit {
/// Validator public key
pub pubkey: FixedBytes<48>,
/// Withdrawal credentials
pub withdrawal_credentials: B256,
/// Amount in GWEI
mattsse marked this conversation as resolved.
Show resolved Hide resolved
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex"))]
pub amount: u64,
/// Deposit signature
pub signature: FixedBytes<96>,
/// Deposit index
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex"))]
pub index: u64,
}
1 change: 1 addition & 0 deletions crates/eips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod eip4788;
pub mod eip4844;
pub use eip4844::{calc_blob_gasprice, calc_excess_blob_gas};

pub mod eip6110;
pub mod merge;

pub mod eip4895;
4 changes: 2 additions & 2 deletions crates/rpc-types-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ alloy-primitives = { workspace = true, features = ["rlp", "serde"] }
alloy-consensus = { workspace = true, features = ["std"] }
alloy-rpc-types.workspace = true
alloy-serde.workspace = true
alloy-eips = { workspace = true, features = ["serde"] }

# ssz
ethereum_ssz_derive = { workspace = true, optional = true }
Expand All @@ -28,11 +29,10 @@ thiserror.workspace = true

# jsonrpsee
jsonrpsee-types = { version = "0.22", optional = true }
alloy-eips = { workspace= true, optional = true }

[features]
jsonrpsee-types = ["dep:jsonrpsee-types"]
ssz = ["dep:ethereum_ssz", "dep:ethereum_ssz_derive", "alloy-primitives/ssz", "alloy-rpc-types/ssz", "dep:alloy-eips", "alloy-eips/ssz"]
ssz = ["dep:ethereum_ssz", "dep:ethereum_ssz_derive", "alloy-primitives/ssz", "alloy-rpc-types/ssz", "alloy-eips/ssz"]
kzg = ["alloy-consensus/kzg"]

[dev-dependencies]
Expand Down
24 changes: 24 additions & 0 deletions crates/rpc-types-engine/src/exit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Contains Exit types, first introduced in the Prague hardfork: <https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md>
//!
//! See also [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110).

use alloy_primitives::{FixedBytes, B256};
use serde::{Deserialize, Serialize};

/// This structure maps onto the exit object
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExitV1 {
/// Validator public key
pub pubkey: FixedBytes<48>,
/// Withdrawal credentials
pub withdrawal_credentials: B256,
/// Amount in GWEI
mattsse marked this conversation as resolved.
Show resolved Hide resolved
#[serde(with = "alloy_serde::u64_hex")]
pub amount: u64,
/// Deposit signature
pub signature: FixedBytes<96>,
/// Deposit index
#[serde(with = "alloy_serde::u64_hex")]
Comment on lines +19 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume these are exit sig/exit index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly no idea

index field
The index field may appear unnecessary but it is important information for deposit processing flow on the Consensus Layer.

not very helpful -.-

Copy link
Member

@onbjerg onbjerg Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, a lot of the fields are not present in that doc.. is it out of date?

pub index: u64,
}
6 changes: 5 additions & 1 deletion crates/rpc-types-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod cancun;
mod exit;
mod forkchoice;
mod optimism;
pub mod payload;
mod transition;

pub use self::{cancun::*, forkchoice::*, optimism::*, payload::*, transition::*};
pub use self::{cancun::*, exit::*, forkchoice::*, optimism::*, payload::*, transition::*};

#[doc(inline)]
pub use alloy_eips::eip6110::Deposit;

/// The list of all supported Engine capabilities available over the engine endpoint.
pub const CAPABILITIES: [&str; 12] = [
Expand Down
34 changes: 34 additions & 0 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Payload types.
use crate::ExitV1;
use alloy_consensus::{Blob, Bytes48};
use alloy_eips::eip6110::Deposit;
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
use alloy_rpc_types::{transaction::BlobTransactionSidecar, Withdrawal};
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -399,6 +401,38 @@ impl ssz::Encode for ExecutionPayloadV3 {
}
}

/// This structure maps on the ExecutionPayloadV4 structure of the beacon chain spec.
///
/// See also: <https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md#ExecutionPayloadV4>
///
/// This structure has the syntax of ExecutionPayloadV3 and appends the new fields: depositReceipts
/// and exits.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExecutionPayloadV4 {
/// Inner V3 payload
#[serde(flatten)]
pub payload_inner: ExecutionPayloadV3,
/// Array of deposits.
///
/// This maps directly to the Deposits defined in [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110).
pub deposit_receipts: Vec<Deposit>,
/// Array of exits
pub exits: Vec<ExitV1>,
}

impl ExecutionPayloadV4 {
/// Returns the withdrawals for the payload.
pub const fn withdrawals(&self) -> &Vec<Withdrawal> {
self.payload_inner.withdrawals()
}

/// Returns the timestamp for the payload.
pub const fn timestamp(&self) -> u64 {
self.payload_inner.payload_inner.timestamp()
}
}

/// This includes all bundled blob related data of an executed payload.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlobsBundleV1 {
Expand Down
Loading