Skip to content

Commit

Permalink
feat(consensus): isthmus network upgrade txs
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jan 31, 2025
1 parent 7c07895 commit b566df9
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5f556101f880602d5f395ff33373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5f5561019e80602d5f395ff33373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd
1 change: 1 addition & 0 deletions crates/consensus/src/hardforks/bytecode/isthmus_tx_1.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7ef8f9a0ebd6fc97ea8145b1e7b2e763e76bee378575ef495aa16eafbcf7325525bc1b4794e9f0662359bb2c8111840effd73b9afa77cbde108080808303d09080b8b9363035333830363030393566333935666633333337336666666666666666666666666666666666666666666666666666666666666666666666666666666531343630343635373630323033363033363034323537356633353630303134333033383131313630343235373631316666663831343330333131363034323537363131666666393030363534356635323630323035666633356235663566666435623566333536313166666636303031343330333036353530300a
1 change: 1 addition & 0 deletions crates/consensus/src/hardforks/bytecode/isthmus_tx_2.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7ef9048ca0d7103194e3e72ff7b95822746ebbd97b2488b35c59b024c667140d5c8043584994a05d9eed37862dab22b002b8f6668b8fb0c4d7988080808303d09080b9044b3766666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666663566353536313031663838303630326435663339356666333333373366666666666666666666666666666666666666666666666666666666666666666666666666666665313436306362353736303131356635343830376666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666313436313031663435373630303138323032363030313930356635623566383231313135363036383537383130313930383330323834383330323930303439313630303130313931393036303464353635623930393339303034393235303530353033363630333831343630383835373336363130316634353733343631303166343537356635323630323035666633356233343130363130316634353736303031353436303031303136303031353536303033353438303630303330323630303430313333383135353630303130313566333538313535363030313031363032303335393035353333363036303162356635323630333835663630313433373630346335666130363030313031363030333535303035623630303335343630303235343830383230333830363031303131363064663537353036303130356235663562383138313134363130313833353738323831303136303033303236303034303138313630346330323831353436303630316238313532363031343031383136303031303135343831353236303230303139303630303230313534383037666666666666666666666666666666666666666666666666666666666666666666303030303030303030303030303030303030303030303030303030303030303031363832353239303630313030313930363034303163393038313630333831633831363030373031353338313630333031633831363030363031353338313630323831633831363030353031353338313630323031633831363030343031353338313630313831633831363030333031353338313630313031633831363030323031353338313630303831633831363030313031353335333630303130313630653135363562393130313830393231343631303139353537393036303032353536313031613035363562393035303566363030323535356636303033353535623566353438303766666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666663134313536313031636435373530356635623630303135343630303238323832303131313631303165323537353035303566363130316538353635623031363030323930303335623566353535663630303135353630346330323566663335623566356666640a
1 change: 1 addition & 0 deletions crates/consensus/src/hardforks/bytecode/isthmus_tx_3.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7ef903d8a0bce1c9a1ed49c420ff0567861314f0acc7cca0944b76307fedf038bffd26a50e94e24b968ab4319a580d9ffc7ac29466894feeb3618080808303d09080b903973766666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666663566353536313031396538303630326435663339356666333333373366666666666666666666666666666666666666666666666666666666666666666666666666666665313436306433353736303131356635343830376666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666313436313031396135373630303138323032363030313930356635623566383231313135363036383537383130313930383330323834383330323930303439313630303130313931393036303464353635623930393339303034393235303530353033363630363031343630383835373336363130313961353733343631303139613537356635323630323035666633356233343130363130313961353736303031353436303031303136303031353536303033353438303630303430323630303430313333383135353630303130313566333538313535363030313031363032303335383135353630303130313630343033353930353533333630363031623566353236303630356636303134333736303734356661303630303130313630303335353030356236303033353436303032353438303832303338303630303231313630653735373530363030323562356635623831383131343631303132393537383238313031363030343032363030343031383136303734303238313534363036303162383135323630313430313831363030313031353438313532363032303031383136303032303135343831353236303230303139303630303330313534393035323630303130313630653935363562393130313830393231343631303133623537393036303032353536313031343635363562393035303566363030323535356636303033353535623566353438303766666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666663134313536313031373335373530356635623630303135343630303138323832303131313631303138383537353035303566363130313865353635623031363030313930303335623566353535663630303135353630373430323566663335623566356666640a
19 changes: 16 additions & 3 deletions crates/consensus/src/hardforks/forks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains all hardforks represented in the [crate::Hardfork] type.
use crate::{Ecotone, Fjord};
use crate::{Ecotone, Fjord, Isthmus};

/// Optimism Hardforks
///
Expand All @@ -23,16 +23,26 @@ use crate::{Ecotone, Fjord};
/// let fjord_upgrade_txs = Hardforks::FJORD.txs();
/// assert_eq!(fjord_upgrade_txs.collect::<Vec<_>>().len(), 3);
/// ```
///
/// Build isthmus hardfork upgrade transaction:
/// ```rust
/// use op_alloy_consensus::{Hardfork, Hardforks};
/// let isthmus_upgrade_tx = Hardforks::ISTHMUS.txs();
/// assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 3);
/// ```
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
pub struct Hardforks;

impl Hardforks {
/// The ecotone hardfork upgrade transactions.
/// The Ecotone hardfork upgrade transactions.
pub const ECOTONE: Ecotone = Ecotone;

/// The fjord hardfork upgrade transactions.
/// The Fjord hardfork upgrade transactions.
pub const FJORD: Fjord = Fjord;

/// The Isthmus hardfork upgrade transactions.
pub const ISTHMUS: Isthmus = Isthmus;
}

#[cfg(test)]
Expand All @@ -48,5 +58,8 @@ mod tests {

let fjord_upgrade_txs = Hardforks::FJORD.txs();
assert_eq!(fjord_upgrade_txs.collect::<Vec<_>>().len(), 3);

let isthmus_upgrade_tx = Hardforks::ISTHMUS.txs();
assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 3);
}
}
135 changes: 135 additions & 0 deletions crates/consensus/src/hardforks/isthmus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//! Module containing a [Transaction] builder for the Isthmus network upgrade transactions.
//!
//! Isthmus network upgrade transactions are defined in the [OP Stack Specs][specs].
//!
//! [specs]: https://specs.optimism.io/protocol/isthmus/derivation.html#network-upgrade-automation-transactions
//! [Transaction]: alloy_consensus::Transaction
use crate::UpgradeDepositSource;
use alloc::{string::String, vec::Vec};
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{address, Address, Bytes, TxKind, B256, U256};

use crate::{Hardfork, TxDeposit};

/// The Isthmus network upgrade transactions.
#[derive(Debug, Default, Clone, Copy)]
pub struct Isthmus;

impl Isthmus {
/// EIP-2935 From Address
pub const EIP2935_FROM: Address = address!("E9f0662359Bb2c8111840eFFD73B9AFA77CbDE10");

/// EIP-7002 From Address
pub const EIP7002_FROM: Address = address!("a05D9eED37862daB22b002b8F6668B8Fb0c4D798");

/// EIP-7251 From Address
pub const EIP7251_FROM: Address = address!("e24B968aB4319a580d9FFc7Ac29466894FeEb361");

/// Returns the source hash for the Isthmus Deposit Contract deployment.
pub fn deposit_contract_source() -> B256 {
UpgradeDepositSource { intent: String::from("Isthmus: deposit contract deployment") }
.source_hash()
}

/// Returns the source hash for the Isthmus Withdrawals Request Contract deployment.
pub fn withdrawals_request_contract_source() -> B256 {
UpgradeDepositSource {
intent: String::from("Isthmus: withdrawals request contract deployment"),
}
.source_hash()
}

/// Returns the source hash for the Isthmus Consolidation Requests Contract deployment.
pub fn consolidation_requests_contract_source() -> B256 {
UpgradeDepositSource {
intent: String::from("Isthmus: consolidation requests contract deployment"),
}
.source_hash()
}

/// Returns the EIP-2935 creation data.
pub fn eip2935_creation_data() -> Bytes {
include_bytes!("./bytecode/eip2935_isthmus.hex").into()
}

/// Returns the EIP-7002 creation data.
pub fn eip7002_creation_data() -> Bytes {
include_bytes!("./bytecode/eip7002_isthmus.hex").into()
}

/// Returns the EIP-7251 creation data.
pub fn eip7251_creation_data() -> Bytes {
include_bytes!("./bytecode/eip7251_isthmus.hex").into()
}

/// Returns the list of [TxDeposit]s for the network upgrade.
pub fn deposits() -> impl Iterator<Item = TxDeposit> {
([
TxDeposit {
source_hash: Self::deposit_contract_source(),
from: Self::EIP2935_FROM,
to: TxKind::Create,
mint: 0.into(),
value: U256::ZERO,
gas_limit: 250_000,
is_system_transaction: false,
input: Self::eip2935_creation_data(),
},
TxDeposit {
source_hash: Self::withdrawals_request_contract_source(),
from: Self::EIP7002_FROM,
to: TxKind::Create,
mint: 0.into(),
value: U256::ZERO,
gas_limit: 250_000,
is_system_transaction: false,
input: Self::eip7002_creation_data(),
},
TxDeposit {
source_hash: Self::consolidation_requests_contract_source(),
from: Self::EIP7251_FROM,
to: TxKind::Create,
mint: 0.into(),
value: U256::ZERO,
gas_limit: 250_000,
is_system_transaction: false,
input: Self::eip7251_creation_data(),
},
])
.into_iter()
}
}

impl Hardfork for Isthmus {
/// Constructs the network upgrade transactions.
fn txs(&self) -> impl Iterator<Item = Bytes> + '_ {
Self::deposits().map(|tx| {
let mut encoded = Vec::new();
tx.encode_2718(&mut encoded);
Bytes::from(encoded)
})
}
}

#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;
use alloy_primitives::hex;

#[test]
fn test_isthmus_txs_encoded() {
let isthmus_upgrade_tx = Isthmus.txs().collect::<Vec<_>>();
assert_eq!(isthmus_upgrade_tx.len(), 3);

let expected_txs: Vec<Bytes> = vec![
hex::decode(include_bytes!("./bytecode/isthmus_tx_1.hex")).unwrap().into(),
hex::decode(include_bytes!("./bytecode/isthmus_tx_2.hex")).unwrap().into(),
hex::decode(include_bytes!("./bytecode/isthmus_tx_3.hex")).unwrap().into(),
];
for (i, expected) in expected_txs.iter().enumerate() {
assert_eq!(isthmus_upgrade_tx[i], *expected);
}
}
}
3 changes: 3 additions & 0 deletions crates/consensus/src/hardforks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ pub use fjord::Fjord;
mod ecotone;
pub use ecotone::Ecotone;

mod isthmus;
pub use isthmus::Isthmus;

mod utils;
pub(crate) use utils::upgrade_to_calldata;
2 changes: 1 addition & 1 deletion crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use eip1559::{
};

mod hardforks;
pub use hardforks::{Ecotone, Fjord, Hardfork, Hardforks};
pub use hardforks::{Ecotone, Fjord, Hardfork, Hardforks, Isthmus};

mod source;
pub use source::*;
Expand Down

0 comments on commit b566df9

Please sign in to comment.