|
| 1 | +//! Module containing a [Transaction] builder for the Isthmus network upgrade transactions. |
| 2 | +//! |
| 3 | +//! Isthmus network upgrade transactions are defined in the [OP Stack Specs][specs]. |
| 4 | +//! |
| 5 | +//! [specs]: https://specs.optimism.io/protocol/isthmus/derivation.html#network-upgrade-automation-transactions |
| 6 | +//! [Transaction]: alloy_consensus::Transaction |
| 7 | +
|
| 8 | +use crate::UpgradeDepositSource; |
| 9 | +use alloc::{string::String, vec::Vec}; |
| 10 | +use alloy_eips::eip2718::Encodable2718; |
| 11 | +use alloy_primitives::{address, Address, Bytes, TxKind, B256, U256}; |
| 12 | + |
| 13 | +use crate::{Hardfork, TxDeposit}; |
| 14 | + |
| 15 | +/// The Isthmus network upgrade transactions. |
| 16 | +#[derive(Debug, Default, Clone, Copy)] |
| 17 | +pub struct Isthmus; |
| 18 | + |
| 19 | +impl Isthmus { |
| 20 | + /// EIP-2935 From Address |
| 21 | + pub const EIP2935_FROM: Address = address!("E9f0662359Bb2c8111840eFFD73B9AFA77CbDE10"); |
| 22 | + |
| 23 | + /// Returns the source hash for the Isthmus Deposit Contract deployment. |
| 24 | + pub fn deposit_contract_source() -> B256 { |
| 25 | + UpgradeDepositSource { intent: String::from("Isthmus: deposit contract deployment") } |
| 26 | + .source_hash() |
| 27 | + } |
| 28 | + |
| 29 | + /// Returns the EIP-2935 creation data. |
| 30 | + pub fn eip2935_creation_data() -> Bytes { |
| 31 | + include_bytes!("./bytecode/eip2935_isthmus.hex").into() |
| 32 | + } |
| 33 | + |
| 34 | + /// Returns the list of [TxDeposit]s for the network upgrade. |
| 35 | + pub fn deposits() -> impl Iterator<Item = TxDeposit> { |
| 36 | + ([TxDeposit { |
| 37 | + source_hash: Self::deposit_contract_source(), |
| 38 | + from: Self::EIP2935_FROM, |
| 39 | + to: TxKind::Create, |
| 40 | + mint: 0.into(), |
| 41 | + value: U256::ZERO, |
| 42 | + gas_limit: 250_000, |
| 43 | + is_system_transaction: false, |
| 44 | + input: Self::eip2935_creation_data(), |
| 45 | + }]) |
| 46 | + .into_iter() |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +impl Hardfork for Isthmus { |
| 51 | + /// Constructs the network upgrade transactions. |
| 52 | + fn txs(&self) -> impl Iterator<Item = Bytes> + '_ { |
| 53 | + Self::deposits().map(|tx| { |
| 54 | + let mut encoded = Vec::new(); |
| 55 | + tx.encode_2718(&mut encoded); |
| 56 | + Bytes::from(encoded) |
| 57 | + }) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +#[cfg(test)] |
| 62 | +mod tests { |
| 63 | + use super::*; |
| 64 | + use alloc::vec; |
| 65 | + use alloy_primitives::hex; |
| 66 | + |
| 67 | + #[test] |
| 68 | + fn test_isthmus_txs_encoded() { |
| 69 | + let isthmus_upgrade_tx = Isthmus.txs().collect::<Vec<_>>(); |
| 70 | + assert_eq!(isthmus_upgrade_tx.len(), 1); |
| 71 | + |
| 72 | + let expected_txs: Vec<Bytes> = |
| 73 | + vec![hex::decode(include_bytes!("./bytecode/isthmus_tx_1.hex")).unwrap().into()]; |
| 74 | + for (i, expected) in expected_txs.iter().enumerate() { |
| 75 | + assert_eq!(isthmus_upgrade_tx[i], *expected); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments