Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Add runtime check for non-OP Stack chains when the optimism feature…
Browse files Browse the repository at this point in the history
… flag is enabled.
  • Loading branch information
clabby committed Nov 1, 2023
1 parent ef487c0 commit 779ca19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 9 additions & 0 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
pub async fn execute(mut self, ctx: CliContext) -> eyre::Result<()> {
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);

// Runtime safety check for the `optimism` feature flag being enabled on a non-OP Stack
// chain.
#[cfg(feature = "optimism")]
if !self.chain.is_optimism() {
eyre::bail!(
"The `optimism` feature flag is enabled, but the chain is a non OP Stack chain."
)
}

// Raise the fd limit of the process.
// Does not do anything on windows.
raise_fd_limit();
Expand Down
4 changes: 1 addition & 3 deletions crates/revm/src/optimism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ pub fn extract_l1_info(block: &Block) -> Result<L1BlockInfo, BlockExecutionError
}

/// Parses the calldata of the [L1BlockInfo] transaction.
pub fn parse_l1_info_tx(data: impl AsRef<[u8]>) -> Result<L1BlockInfo, BlockExecutionError> {
let data = data.as_ref();

pub fn parse_l1_info_tx(data: &[u8]) -> Result<L1BlockInfo, BlockExecutionError> {
// The setL1BlockValues tx calldata must be exactly 260 bytes long, considering that
// we already removed the first 4 bytes (the function selector). Detailed breakdown:
// 32 bytes for the block number
Expand Down
7 changes: 1 addition & 6 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,7 @@ where
.block_by_number(meta.block_number)?
.ok_or(EthApiError::UnknownBlockNumber)?;

let l1_block_info = {
let body = reth_revm::optimism::parse_l1_info_tx(
&block.body.first().ok_or(EthApiError::InternalEthError)?.input()[4..],
);
body.ok().map(Rc::new)
};
let l1_block_info = reth_revm::optimism::extract_l1_info(&block).ok().map(Rc::new);
let optimism_tx_meta = self.build_op_tx_meta(&tx, l1_block_info, block.timestamp)?;

build_transaction_receipt_with_block_receipts(
Expand Down

0 comments on commit 779ca19

Please sign in to comment.