Skip to content

Commit

Permalink
feat: eip-7702 (paradigmxyz#9214)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Smith <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: joshieDo <[email protected]>
Co-authored-by: Dan Cline <[email protected]>
  • Loading branch information
5 people authored Jul 11, 2024
1 parent fc3d0eb commit fc4c037
Show file tree
Hide file tree
Showing 25 changed files with 877 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ revm-primitives = { version = "6.0.0", features = [
revm-inspectors = "0.4"

# eth
alloy-chains = "0.1.15"
alloy-chains = "0.1.18"
alloy-primitives = "0.7.2"
alloy-dyn-abi = "0.7.2"
alloy-sol-types = "0.7.2"
Expand Down
7 changes: 7 additions & 0 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,13 @@ impl ChainSpecBuilder {
self
}

/// Enable Prague at genesis.
pub fn prague_activated(mut self) -> Self {
self = self.cancun_activated();
self.hardforks.insert(EthereumHardfork::Prague, ForkCondition::Timestamp(0));
self
}

/// Enable Bedrock at genesis
#[cfg(feature = "optimism")]
pub fn bedrock_activated(mut self) -> Self {
Expand Down
8 changes: 8 additions & 0 deletions crates/net/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ pub struct AnnouncedTxTypesMetrics {

/// Histogram for tracking frequency of EIP-4844 transaction type
pub(crate) eip4844: Histogram,

/// Histogram for tracking frequency of EIP-7702 transaction type
pub(crate) eip7702: Histogram,
}

#[derive(Debug, Default)]
Expand All @@ -350,6 +353,7 @@ pub struct TxTypesCounter {
pub(crate) eip2930: usize,
pub(crate) eip1559: usize,
pub(crate) eip4844: usize,
pub(crate) eip7702: usize,
}

impl TxTypesCounter {
Expand All @@ -368,6 +372,9 @@ impl TxTypesCounter {
TxType::Eip4844 => {
self.eip4844 += 1;
}
TxType::Eip7702 => {
self.eip7702 += 1;
}
_ => {}
}
}
Expand All @@ -381,5 +388,6 @@ impl AnnouncedTxTypesMetrics {
self.eip2930.record(tx_types_counter.eip2930 as f64);
self.eip1559.record(tx_types_counter.eip1559 as f64);
self.eip4844.record(tx_types_counter.eip4844 as f64);
self.eip7702.record(tx_types_counter.eip7702 as f64);
}
}
1 change: 1 addition & 0 deletions crates/net/network/src/transactions/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ impl FilterAnnouncement for EthMessageFilter {
}
}

// TODO(eip7702): update tests as needed
#[cfg(test)]
mod test {
use super::*;
Expand Down
28 changes: 28 additions & 0 deletions crates/primitives/src/alloy_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ impl TryFrom<alloy_rpc_types::Transaction> for Transaction {
.ok_or(ConversionError::MissingMaxFeePerBlobGas)?,
}))
}
Some(TxType::Eip7702) => {
// this is currently unsupported as it is not present in alloy due to missing rpc
// specs
Err(ConversionError::Custom("Unimplemented".to_string()))
/*
// EIP-7702
Ok(Transaction::Eip7702(TxEip7702 {
chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?,
nonce: tx.nonce,
max_priority_fee_per_gas: tx
.max_priority_fee_per_gas
.ok_or(ConversionError::MissingMaxPriorityFeePerGas)?,
max_fee_per_gas: tx
.max_fee_per_gas
.ok_or(ConversionError::MissingMaxFeePerGas)?,
gas_limit: tx
.gas
.try_into()
.map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?,
to: tx.to.map_or(TxKind::Create, TxKind::Call),
value: tx.value,
access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?,
authorization_list: tx
.authorization_list
.ok_or(ConversionError::MissingAuthorizationList)?,
input: tx.input,
}))*/
}
#[cfg(feature = "optimism")]
Some(TxType::Deposit) => {
let fields = tx
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub use transaction::{
AccessList, AccessListItem, IntoRecoveredTransaction, InvalidTransactionError, Signature,
Transaction, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered,
TransactionSignedNoHash, TryFromRecoveredTransaction, TxEip1559, TxEip2930, TxEip4844,
TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
TxEip7702, TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID,
EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
};

// Re-exports
Expand Down
7 changes: 7 additions & 0 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ impl Decodable for ReceiptWithBloom {
buf.advance(1);
Self::decode_receipt(buf, TxType::Eip4844)
}
0x04 => {
buf.advance(1);
Self::decode_receipt(buf, TxType::Eip7702)
}
#[cfg(feature = "optimism")]
0x7E => {
buf.advance(1);
Expand Down Expand Up @@ -471,6 +475,9 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
TxType::Eip4844 => {
out.put_u8(0x03);
}
TxType::Eip7702 => {
out.put_u8(0x04);
}
#[cfg(feature = "optimism")]
TxType::Deposit => {
out.put_u8(0x7E);
Expand Down
17 changes: 16 additions & 1 deletion crates/primitives/src/transaction/compat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Address, Transaction, TransactionSigned, TxKind, U256};
use revm_primitives::TxEnv;
use revm_primitives::{AuthorizationList, TxEnv};

/// Implements behaviour to fill a [`TxEnv`] from another transaction.
pub trait FillTxEnv {
Expand Down Expand Up @@ -70,6 +70,21 @@ impl FillTxEnv for TransactionSigned {
tx_env.blob_hashes.clone_from(&tx.blob_versioned_hashes);
tx_env.max_fee_per_blob_gas = Some(U256::from(tx.max_fee_per_blob_gas));
}
Transaction::Eip7702(tx) => {
tx_env.gas_limit = tx.gas_limit;
tx_env.gas_price = U256::from(tx.max_fee_per_gas);
tx_env.gas_priority_fee = Some(U256::from(tx.max_priority_fee_per_gas));
tx_env.transact_to = tx.to;
tx_env.value = tx.value;
tx_env.data = tx.input.clone();
tx_env.chain_id = Some(tx.chain_id);
tx_env.nonce = Some(tx.nonce);
tx_env.access_list = tx.access_list.0.clone();
tx_env.blob_hashes.clear();
tx_env.max_fee_per_blob_gas.take();
tx_env.authorization_list =
Some(AuthorizationList::Signed(tx.authorization_list.clone()));
}
#[cfg(feature = "optimism")]
Transaction::Deposit(tx) => {
tx_env.access_list.clear();
Expand Down
Loading

0 comments on commit fc4c037

Please sign in to comment.