Skip to content

Commit

Permalink
feat(consensus): eip-7251 network upgrade tx
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jan 31, 2025
1 parent 6a2c19f commit 4761893
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
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_3.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7ef903d8a0bce1c9a1ed49c420ff0567861314f0acc7cca0944b76307fedf038bffd26a50e94e24b968ab4319a580d9ffc7ac29466894feeb3618080808303d09080b903973766666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666663566353536313031396538303630326435663339356666333333373366666666666666666666666666666666666666666666666666666666666666666666666666666665313436306433353736303131356635343830376666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666313436313031396135373630303138323032363030313930356635623566383231313135363036383537383130313930383330323834383330323930303439313630303130313931393036303464353635623930393339303034393235303530353033363630363031343630383835373336363130313961353733343631303139613537356635323630323035666633356233343130363130313961353736303031353436303031303136303031353536303033353438303630303430323630303430313333383135353630303130313566333538313535363030313031363032303335383135353630303130313630343033353930353533333630363031623566353236303630356636303134333736303734356661303630303130313630303335353030356236303033353436303032353438303832303338303630303231313630653735373530363030323562356635623831383131343631303132393537383238313031363030343032363030343031383136303734303238313534363036303162383135323630313430313831363030313031353438313532363032303031383136303032303135343831353236303230303139303630303330313534393035323630303130313630653935363562393130313830393231343631303133623537393036303032353536313031343635363562393035303566363030323535356636303033353535623566353438303766666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666663134313536313031373335373530356635623630303135343630303138323832303131313631303138383537353035303566363130313865353635623031363030313930303335623566353535663630303135353630373430323566663335623566356666640a
4 changes: 2 additions & 2 deletions crates/consensus/src/hardforks/forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{Ecotone, Fjord, Isthmus};
/// ```rust
/// use op_alloy_consensus::{Hardfork, Hardforks};
/// let isthmus_upgrade_tx = Hardforks::ISTHMUS.txs();
/// assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 2);
/// assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 3);
/// ```
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
Expand Down Expand Up @@ -60,6 +60,6 @@ mod tests {
assert_eq!(fjord_upgrade_txs.collect::<Vec<_>>().len(), 3);

let isthmus_upgrade_tx = Hardforks::ISTHMUS.txs();
assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 2);
assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 3);
}
}
42 changes: 31 additions & 11 deletions crates/consensus/src/hardforks/isthmus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! 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;
Expand All @@ -20,6 +23,9 @@ impl Isthmus {
/// 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") }
Expand All @@ -34,6 +40,14 @@ impl Isthmus {
.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()
Expand All @@ -44,6 +58,11 @@ impl Isthmus {
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> {
([
Expand All @@ -67,6 +86,16 @@ impl Isthmus {
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()
}
Expand All @@ -84,7 +113,6 @@ impl Hardfork for Isthmus {
}

#[cfg(test)]
#[cfg(feature = "std")]
mod tests {
use super::*;
use alloc::vec;
Expand All @@ -93,20 +121,12 @@ mod tests {
#[test]
fn test_isthmus_txs_encoded() {
let isthmus_upgrade_tx = Isthmus.txs().collect::<Vec<_>>();
assert_eq!(isthmus_upgrade_tx.len(), 2);

// let expected_tx = include_bytes!("./bytecode/isthmus_tx_2.hex");
// // Parse as a string.
// let expected_tx = String::from_utf8_lossy(expected_tx);
// // Remove newlines
// let expected_tx = expected_tx.replace("\n", "");
//
// // Write the expected tx as a string to the file
// std::fs::write("isthmus_tx_2.hex", expected_tx).unwrap();
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);
Expand Down

0 comments on commit 4761893

Please sign in to comment.