-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(consensus): Isthmus Network Upgrade Txs (#405)
### Description Drafts up the network upgrade transactions for the Isthmus hardfork. - [EIP-2935](https://eips.ethereum.org/EIPS/eip-2935#deployment) -> block hash contract - ~~[EIP-7002](https://eips.ethereum.org/EIPS/eip-7002#deployment) -> withdrawals request contract~~ - ~~[EIP-7251](https://eips.ethereum.org/EIPS/eip-7251#deployment) -> consolidation requests contract~~
- Loading branch information
Showing
7 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7ef89ca0ebd6fc97ea8145b1e7b2e763e76bee378575ef495aa16eafbcf7325525bc1b47943462413af4609098e1e27a490f554f260213d6858080808303d09080b85c60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//! 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, hex, 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!("3462413Af4609098e1E27A490f554f260213D685"); | ||
|
||
/// 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 EIP-2935 creation data. | ||
pub fn eip2935_creation_data() -> Bytes { | ||
let contents = core::str::from_utf8(include_bytes!("./bytecode/eip2935_isthmus.hex")) | ||
.expect("eip-2935 creation data is not valid UTF-8"); | ||
let contents = contents.replace("\n", ""); | ||
let decoded = hex::decode(contents).expect("eip-2935 creation data is not valid hex"); | ||
decoded.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(), | ||
}]) | ||
.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; | ||
|
||
#[test] | ||
fn test_isthmus_txs_encoded() { | ||
let isthmus_upgrade_tx = Isthmus.txs().collect::<Vec<_>>(); | ||
assert_eq!(isthmus_upgrade_tx.len(), 1); | ||
|
||
let expected_first_tx = include_bytes!("./bytecode/isthmus_tx_1.hex"); | ||
let expected_first_tx = | ||
core::str::from_utf8(expected_first_tx).expect("expected_first_tx is not valid UTF-8"); | ||
let expected_first_tx = expected_first_tx.replace("\n", ""); | ||
let expected_first_tx = | ||
hex::decode(expected_first_tx).expect("expected_first_tx is not valid hex"); | ||
let expected_txs: Vec<Bytes> = vec![expected_first_tx.into()]; | ||
for (i, expected) in expected_txs.iter().enumerate() { | ||
assert_eq!(isthmus_upgrade_tx[i], *expected); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters