Skip to content

Commit 3db10fb

Browse files
committed
feat(consensus): isthmus network upgrade txs
1 parent 7c07895 commit 3db10fb

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7ef8f9a0ebd6fc97ea8145b1e7b2e763e76bee378575ef495aa16eafbcf7325525bc1b4794e9f0662359bb2c8111840effd73b9afa77cbde108080808303d09080b8b9363035333830363030393566333935666633333337336666666666666666666666666666666666666666666666666666666666666666666666666666666531343630343635373630323033363033363034323537356633353630303134333033383131313630343235373631316666663831343330333131363034323537363131666666393030363534356635323630323035666633356235663566666435623566333536313166666636303031343330333036353530300a

crates/consensus/src/hardforks/forks.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Contains all hardforks represented in the [crate::Hardfork] type.
22
3-
use crate::{Ecotone, Fjord};
3+
use crate::{Ecotone, Fjord, Isthmus};
44

55
/// Optimism Hardforks
66
///
@@ -23,16 +23,26 @@ use crate::{Ecotone, Fjord};
2323
/// let fjord_upgrade_txs = Hardforks::FJORD.txs();
2424
/// assert_eq!(fjord_upgrade_txs.collect::<Vec<_>>().len(), 3);
2525
/// ```
26+
///
27+
/// Build isthmus hardfork upgrade transaction:
28+
/// ```rust
29+
/// use op_alloy_consensus::{Hardfork, Hardforks};
30+
/// let isthmus_upgrade_tx = Hardforks::ISTHMUS.txs();
31+
/// assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 1);
32+
/// ```
2633
#[derive(Debug, Default, Clone, Copy)]
2734
#[non_exhaustive]
2835
pub struct Hardforks;
2936

3037
impl Hardforks {
31-
/// The ecotone hardfork upgrade transactions.
38+
/// The Ecotone hardfork upgrade transactions.
3239
pub const ECOTONE: Ecotone = Ecotone;
3340

34-
/// The fjord hardfork upgrade transactions.
41+
/// The Fjord hardfork upgrade transactions.
3542
pub const FJORD: Fjord = Fjord;
43+
44+
/// The Isthmus hardfork upgrade transactions.
45+
pub const ISTHMUS: Isthmus = Isthmus;
3646
}
3747

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

4959
let fjord_upgrade_txs = Hardforks::FJORD.txs();
5060
assert_eq!(fjord_upgrade_txs.collect::<Vec<_>>().len(), 3);
61+
62+
let isthmus_upgrade_tx = Hardforks::ISTHMUS.txs();
63+
assert_eq!(isthmus_upgrade_tx.collect::<Vec<_>>().len(), 1);
5164
}
5265
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
}

crates/consensus/src/hardforks/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ pub use fjord::Fjord;
1212
mod ecotone;
1313
pub use ecotone::Ecotone;
1414

15+
mod isthmus;
16+
pub use isthmus::Isthmus;
17+
1518
mod utils;
1619
pub(crate) use utils::upgrade_to_calldata;

crates/consensus/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use eip1559::{
2525
};
2626

2727
mod hardforks;
28-
pub use hardforks::{Ecotone, Fjord, Hardfork, Hardforks};
28+
pub use hardforks::{Ecotone, Fjord, Hardfork, Hardforks, Isthmus};
2929

3030
mod source;
3131
pub use source::*;

0 commit comments

Comments
 (0)