Skip to content

chore: remove dependency on forked alloy evm - #145

Merged
rezzmah merged 10 commits into
mainfrom
rezbera/refactor-basic-block-builder
Sep 9, 2025
Merged

rezzmah merged 10 commits into
mainfrom
rezbera/refactor-basic-block-builder

Conversation

@rezzmah

@rezzmah rezzmah commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

closes #109

Summary by CodeRabbit

  • New Features

    • Added a Berachain-specific EVM integration with configurable inspector/tracing and precompile support, plus a new EVM factory.
  • Improvements

    • Simplified RPC transaction paths by removing PoL-specific branching and related inspect flows.
    • Standardized PoL transaction handling and gas reporting for calls.
  • Refactor

    • Replaced the node-wide EVM factory with the new Berachain EVM factory.
  • Chores

    • Switched dependency patches to a revm-based EVM stack and added related dev-dependencies.

@coderabbitai

coderabbitai Bot commented Sep 5, 2025 •

Copy link
Copy Markdown

Walkthrough

Replaces a forked alloy-evm patch with revm-based patches, adds a public evm module implementing BerachainEvm and BerachainEvmFactory, switches config/executor/main to use the new factory, and removes PoL-specific system-call routing and related helpers from the RPC transaction handling.

Changes

Cohort / File(s) Summary
Patch management (revm over alloy-evm)
Cargo.toml
Removed [patch.crates-io] entry for alloy-evm; added patch entries for revm and related crates (revm, revm-primitives, revm-bytecode, revm-database, revm-state, revm-interpreter, revm-inspector, revm-context, revm-context-interface, revm-database-interface) pointing to https://github.com/bluealloy/revm@9008e93. Dev-deps added (alloy-rpc-types-trace, revm-inspectors).
Public module surface
src/lib.rs
Added pub mod evm;.
New Berachain EVM integration
src/evm/mod.rs
Added BerachainEvm wrapper around RevmEvm with inspector toggle, POL TX handling, context accessors, Deref impls, and BerachainEvmFactory implementing EvmFactory (create_evm/create_evm_with_inspector, precompiles wiring, inspector toggling).
Main wiring to new factory
src/main.rs
Replaced EthEvmFactory usage with BerachainEvmFactory import and pass BerachainEvmFactory::default() into BerachainEvmConfig::new_with_evm_factory(...).
Node EVM config updates
src/node/evm/config.rs
BerachainEvmConfig now stores evm_factory: BerachainEvmFactory; new_with_evm_factory signature updated accordingly and imports adjusted.
Node EVM executor updates
src/node/evm/executor.rs
BlockExecutorFactory associated type EvmFactory changed from EthEvmFactory to BerachainEvmFactory; removed unused imports (DatabaseCommit, StateChangeSource).
Node EVM module glue
src/node/evm/mod.rs
Updated calls to pass BerachainEvmFactory::default() and switched imports from EthEvmFactory to BerachainEvmFactory.
RPC execution flow simplification
src/rpc/api.rs
Removed PoL-specific system-call routing and replay_transactions_until; removed inspect helpers for EstimateCall/Trace; simplified imports and unified transaction/inspect paths.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant RPC as RPC (Estimate/Trace)
  participant BerEVM as BerachainEvm
  participant Revm as RevmEvm
  note right of BerEVM #DDEEF8: inspector flag controls path

  User->>RPC: estimate/trace request (tx)
  RPC->>BerEVM: transact(tx_env)
  alt Inspector enabled
    BerEVM->>Revm: inspect_tx(tx_env)
  else Inspector disabled
    BerEVM->>Revm: transact(tx_env)
  end
  Revm-->>BerEVM: result
  BerEVM-->>RPC: result
  RPC-->>User: response
Loading
sequenceDiagram
  autonumber
  participant Node as Node Init
  participant Cfg as BerachainEvmConfig
  participant Fact as BerachainEvmFactory
  participant Exec as BlockExecutor

  Node->>Cfg: new_with_evm_factory(spec, BerachainEvmFactory::default())
  Cfg-->>Node: config
  Node->>Exec: build with config.evm_factory
  Exec->>Fact: create_evm(db, env)
  Fact-->>Exec: BerachainEvm instance
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Assessment against linked issues

Objective Addressed Explanation
Replace alloy-evm fork with alternative approach; refactor tracing integration to avoid fork (#109) ✅

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Removed PoL-specific system-call handling and replay_transactions_until (src/rpc/api.rs) This RPC behavioral simplification and removal of PoL routing is not specified in #109, which targets avoiding the alloy-evm fork/refactoring tracing; it changes RPC execution logic beyond the stated objective.

"I twitch my whiskers at code anew,
From alloy forks to revm we flew.
Inspectors tucked and precompiles set,
Transactions hop—no system-call fret.
A rabbit cheers for tidy root! 🐇✨"

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rezbera/refactor-basic-block-builder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rezzmah
rezzmah marked this pull request as ready for review September 5, 2025 09:13
@rezzmah

rezzmah commented Sep 5, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 5, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/rpc/api.rs (2)

212-234: Don’t require to for Ethereum create tx; do require it for POL.

Contract-creation (Ethereum) uses to = None. Current checks reject valid create requests. Gate to.is_some() only for POL, not Ethereum. Mirror this in can_submit/can_build.

-        if self.to.is_none() {
-            missing.push("to");
-        }
+        // `to` is optional for Ethereum create tx, but required for POL (create is disallowed anyway).
+        if matches!(ty, BerachainTxType::Berachain) && self.to.is_none() {
+            missing.push("to");
+        }
@@
-    fn can_submit(&self) -> bool {
-        self.from.is_some() &&
-            self.to.is_some() &&
-            self.gas.is_some() &&
-            (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
-    }
+    fn can_submit(&self) -> bool {
+        self.from.is_some()
+            && self.gas.is_some()
+            && (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
+            && (self.transaction_type != Some(POL_TX_TYPE) || self.to.is_some())
+    }
@@
-    fn can_build(&self) -> bool {
-        self.to.is_some() &&
-            self.gas.is_some() &&
-            (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
-    }
+    fn can_build(&self) -> bool {
+        self.gas.is_some()
+            && (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
+            && (self.transaction_type != Some(POL_TX_TYPE) || self.to.is_some())
+    }

Also applies to: 238-250


601-614: Zero out POL transaction gas on all exit paths and remove duplicated evm.transact call
Unconditionally invoke evm.transact(...) into a single mut res, then if tx_type == POL_TX_TYPE, match on res.result to reset gas_used to 0 for Success, Revert, and Halt.

🧹 Nitpick comments (6)
src/rpc/api.rs (1)

277-287: Defaulting nonce to 0 during prep_for_submission is risky.

Auto-filling a nonce can cause accidental replay/race with account state. Prefer leaving it unset and letting upstream fill it.

-        if self.nonce.is_none() {
-            self.nonce = Some(0);
-        }
+        // Leave nonce unset; provider/signers should determine the correct nonce.
src/alloy_evm/mod.rs (2)

132-133: Error message polish (clarity).

Change to a clear, user-facing message.

-                TxKind::Create => Err(EVMError::Custom("pol tx cannot be create".into())),
+                TxKind::Create => Err(EVMError::Custom("POL transactions cannot be contract creation (Create)".into())),

189-202: Minor: build without inspector when inspect = false (if available).

You always construct with an inspector and then gate with a bool. If the builder supports a non-inspector path, prefer it to reduce overhead.

If Context::build_mainnet() (no inspector) exists, prefer it here and keep create_evm_with_inspector as-is. Otherwise, current approach is acceptable for now.

src/lib.rs (1)

5-5: Module name may be confusing.

The new EVM wrapper targets revm, not alloy-evm. Consider pub mod evm; or pub mod berachain_evm; to avoid confusion in public API.

src/node/evm/executor.rs (2)

112-153: Minor cleanup: remove redundant local use statements.

use reth::revm::DatabaseCommit; and use reth_evm::block::StateChangeSource; are already imported at top; drop the inner shadowing to reduce noise.

-        use reth::revm::DatabaseCommit;
-        use reth_evm::block::StateChangeSource;
+        // (imports already present at module scope)

188-194: Narrow the POL skip condition; current match may skip future non-POL Berachain txs.

Today, any BerachainTxEnvelope::Berachain(_) is skipped. If other Berachain-native txs appear later, they’ll never execute. Prefer an explicit “POL already executed” guard.

Apply within this function:

-        if let BerachainTxEnvelope::Berachain(_) = tx.tx() {
-            return Ok(Some(0));
-        }
+        if let BerachainTxEnvelope::Berachain(_) = tx.tx() {
+            // Skip only if POL was executed in `apply_pre_execution_changes`.
+            if self.ctx.prev_proposer_pubkey.is_some() {
+                return Ok(Some(0));
+            }
+        }

And (outside this hunk) consider adding a boolean flag on the executor to make the invariant explicit:

// struct BerachainBlockExecutor<'a, Evm> { ... 
pub pol_executed: bool,
// set to true in `execute_pol_transaction_with_receipt()` after success,
// and check that flag here to decide skipping.

Would you like me to wire this flag end-to-end?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7e893b0 and c94cac7.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • Cargo.toml (0 hunks)
  • src/alloy_evm/mod.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/node/evm/config.rs (4 hunks)
  • src/node/evm/executor.rs (3 hunks)
  • src/node/evm/mod.rs (2 hunks)
  • src/rpc/api.rs (2 hunks)
💤 Files with no reviewable changes (1)
  • Cargo.toml
🧰 Additional context used
🧬 Code graph analysis (5)
src/node/evm/config.rs (1)
src/node/evm/executor.rs (1)
  • evm_factory (332-334)
src/main.rs (1)
src/node/evm/config.rs (1)
  • new_with_evm_factory (45-55)
src/rpc/api.rs (1)
src/node/evm/executor.rs (1)
  • evm (321-323)
src/alloy_evm/mod.rs (1)
src/rpc/api.rs (1)
  • inspect (586-615)
src/node/evm/mod.rs (1)
src/node/evm/config.rs (1)
  • new_with_evm_factory (45-55)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Check documentation
  • GitHub Check: Run tests
  • GitHub Check: Security audit
  • GitHub Check: Clippy lint
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (8)
src/node/evm/mod.rs (2)

10-13: Swapping to BerachainEvmFactory import looks correct.

Consistent with config/executor changes; no API surface change here.


40-44: Factory injection switch LGTM.

BerachainEvmFactory::default() passed into new_with_evm_factory matches the new type.

src/node/evm/executor.rs (2)

2-2: Import switch to BerachainEvmFactory is consistent.

Matches associated type change below.


327-327: Associated EvmFactory updated correctly.

Type aligns with config and main; trait bounds appear unchanged.

src/node/evm/config.rs (2)

2-2: Import swap to BerachainEvmFactory matches the refactor.


37-38: Config field and constructor now typed to BerachainEvmFactory — looks good.

Public surface remains stable; call sites updated accordingly.

Also applies to: 47-48

src/main.rs (2)

7-7: Main import updated to BerachainEvmFactory.

Consistent with the rest of the PR.


33-33: All checks passed — factory wiring clean and transact_system_call implemented.
Verification confirms no EthEvmFactory remnants, no forked alloy-evm in Cargo.toml, BerachainEvmFactory implements EvmFactory, and transact_system_call is defined in the EVM wrapper.

Comment thread src/alloy_evm/mod.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/evm/mod.rs (1)

176-189: DRY up duplicated EVM construction code

Both constructors duplicate the Context::mainnet + with_* + with_precompiles chain. Factor into a small helper to reduce divergence risk.

Example (outside this impl):

fn build_inner<DB, I>(db: DB, input: EvmEnv, inspector: I) -> RevmEvm<EthEvmContext<DB>, I, EthInstructions<EthInterpreter, EthEvmContext<DB>>, PrecompilesMap, EthFrame>
where
    DB: Database,
    I: Inspector<EthEvmContext<DB>>,
{
    let spec_id = input.cfg_env.spec;
    Context::mainnet()
        .with_block(input.block_env)
        .with_cfg(input.cfg_env)
        .with_db(db)
        .build_mainnet_with_inspector(inspector)
        .with_precompiles(PrecompilesMap::from_static(Precompiles::new(
            PrecompileSpecId::from_spec_id(spec_id),
        )))
}

Also applies to: 199-209

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c94cac7 and bc06386.

📒 Files selected for processing (6)
  • src/evm/mod.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/node/evm/config.rs (4 hunks)
  • src/node/evm/executor.rs (3 hunks)
  • src/node/evm/mod.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/lib.rs
  • src/main.rs
  • src/node/evm/executor.rs
  • src/node/evm/config.rs
🧰 Additional context used
🧬 Code graph analysis (2)
src/node/evm/mod.rs (1)
src/node/evm/config.rs (1)
  • new_with_evm_factory (45-55)
src/evm/mod.rs (2)
src/node/evm/executor.rs (2)
  • evm (318-320)
  • finish (236-308)
src/rpc/api.rs (1)
  • inspect (586-615)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Check documentation
  • GitHub Check: Security audit
  • GitHub Check: Run tests
  • GitHub Check: Clippy lint
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
src/evm/mod.rs (2)

121-126: Confirm PoL system-call semantics (value/gas handling)

This path ignores tx.value and any gas settings. Confirm that PoL system calls must always be value-less and gas-free in all execution contexts (not only RPC inspection). If not, plumb value/gas accordingly.


25-35: MSRV check for #[expect(missing_debug_implementations)]

Ensure your MSRV supports #[expect(...)] on lints. If not, swap to #[allow(missing_debug_implementations)] or gate by cfg_attr.

src/node/evm/mod.rs (2)

40-44: Switch to BerachainEvmFactory LGTM

Factory injection reads clean and matches config.rs signature.


10-13: Verify public export of crate::evm

Ensure src/lib.rs publicly exposes the evm module so this use path resolves in downstream crates/binaries.

Comment thread src/evm/mod.rs Resolved
Comment thread src/evm/mod.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/rpc/api.rs (2)

79-91: PoL requests lose their type — set transaction_type in the From<BerachainTxEnvelope> conversion.

Without setting transaction_type, output_tx_type() will treat PoL requests as Ethereum variants, breaking validation and routing through the new builder. Fix by tagging PoL with POL_TX_TYPE.

             BerachainTxEnvelope::Berachain(pol_tx) => Self {
                 to: Some(pol_tx.to.into()),
                 gas: Some(pol_tx.gas_limit),
                 gas_price: Some(pol_tx.gas_price),
                 value: Some(pol_tx.value()),
                 input: Some(pol_tx.input().clone()).into(),
                 nonce: Some(pol_tx.nonce()),
                 chain_id: pol_tx.chain_id(),
                 from: Some(pol_tx.from),
+                transaction_type: Some(POL_TX_TYPE),
                 ..Default::default()
             },

208-217: Don’t forbid contract-creation txs — drop hard requirement for to.

JSON-RPC creation uses to = null. Requiring to.is_some() in complete_type, can_submit, and can_build blocks legitimate create txs.

         if self.from.is_none() {
             missing.push("from");
         }
-        if self.to.is_none() {
-            missing.push("to");
-        }
         if self.gas.is_none() {
             missing.push("gas");
         }
-    fn can_submit(&self) -> bool {
-        self.from.is_some() &&
-            self.to.is_some() &&
-            self.gas.is_some() &&
-            (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
-    }
+    fn can_submit(&self) -> bool {
+        self.from.is_some()
+            && self.gas.is_some()
+            && (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
+    }
-    fn can_build(&self) -> bool {
-        self.to.is_some() &&
-            self.gas.is_some() &&
-            (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
-    }
+    fn can_build(&self) -> bool {
+        self.gas.is_some()
+            && (self.gas_price.is_some() || self.max_fee_per_gas.is_some())
+    }

Also applies to: 234-245

🧹 Nitpick comments (4)
src/rpc/api.rs (4)

273-284: Avoid defaulting nonce to 0 in prep_for_submission().

Defaulting to 0 can underflow/replace pending nonces. Leave nonce unset so upstream fill logic resolves it.

     fn prep_for_submission(&mut self) {
-        if self.nonce.is_none() {
-            self.nonce = Some(0);
-        }
         if self.value.is_none() {
             self.value = Some(U256::ZERO);
         }
         if self.input.input.is_none() {
             self.input.input = Some(Bytes::new());
         }
     }

If eth_sendTransaction relies on this path in your stack, confirm upstream nonce-filling is active; otherwise we should wire provider nonce here.


407-410: Debug type name mismatch.

Use the actual type name for clarity in logs.

-        f.debug_struct("EthApi").finish_non_exhaustive()
+        f.debug_struct("BerachainApi").finish_non_exhaustive()

44-50: De-drift the display label for PoL.

Hardcoding "BRIP-0004" risks drift vs. POL_TX_TYPE. Consider a shared const or helper mapping.

Would you like a small helper (e.g., const POL_DISPLAY: &str = "BRIP-0004";) wired next to POL_TX_TYPE?


6-6: Potential unused import.

use alloy_consensus::Transaction; appears unused in this file; remove to avoid warnings.

- use alloy_consensus::Transaction;

Run a quick check to confirm no downstream usage via re-exports.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bc06386 and b9f394c.

📒 Files selected for processing (2)
  • src/evm/mod.rs (1 hunks)
  • src/rpc/api.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/evm/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Run tests
  • GitHub Check: Security audit
  • GitHub Check: Check documentation
  • GitHub Check: Clippy lint
  • GitHub Check: semgrep-cloud-platform/scan

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/evm/mod.rs (2)

6-8: Use helper to read tx type and fix error string (repeat from prior review)

Avoid direct field access to tx.tx_type for cross-version stability and improve the error message.

 use reth::revm::{
     Context, ExecuteEvm, InspectEvm, Inspector, MainBuilder, MainContext, SystemCallEvm,
     context::{
-        BlockEnv, CfgEnv, Evm as RevmEvm, TxEnv,
+        BlockEnv, CfgEnv, Evm as RevmEvm, TxEnv, Transaction as TxEnvTransaction,
         result::{EVMError, HaltReason, ResultAndState},
     },
-        if tx.tx_type == POL_TX_TYPE {
+        if TxEnvTransaction::tx_type(&tx) == POL_TX_TYPE {
             return match tx.kind {
-                TxKind::Create => Err(EVMError::Custom("pol tx cannot be create".into())),
+                TxKind::Create => Err(EVMError::Custom("POL Create transactions are unsupported".into())),
                 TxKind::Call(to) => {

Also applies to: 122-126


184-191: Factory Context must match the EVM’s context type (repeat from prior review)

Inspector bounds require the factory’s Context to be EthEvmContext<DB>.

-    type Context<DB: Database> = Context<BlockEnv, TxEnv, CfgEnv, DB>;
+    type Context<DB: Database> = EthEvmContext<DB>;
🧹 Nitpick comments (2)
src/evm/mod.rs (2)

127-139: Clarify whether POL gas should be zeroed on all outcomes, not just Success

Your comment says “Set gas_used to 0 for POL transactions” but only Success is handled. If intended, consider covering Revert/Halt too.

-                    result.result = match result.result {
-                        ExecutionResult::Success { reason, gas_refunded, logs, output, .. } => {
-                            ExecutionResult::Success {
-                                reason,
-                                gas_used: 0,
-                                gas_refunded,
-                                logs,
-                                output,
-                            }
-                        }
-                        other => other,
-                    };
+                    result.result = match result.result {
+                        ExecutionResult::Success { reason, gas_refunded, logs, output, .. } => {
+                            ExecutionResult::Success {
+                                reason,
+                                gas_used: 0,
+                                gas_refunded,
+                                logs,
+                                output,
+                            }
+                        }
+                        ExecutionResult::Revert { output, .. } => {
+                            ExecutionResult::Revert { output, gas_used: 0 }
+                        }
+                        ExecutionResult::Halt { reason, .. } => {
+                            ExecutionResult::Halt { reason, gas_used: 0 }
+                        }
+                        other => other,
+                    };

193-207: DRY up the EVM construction

Both constructors duplicate the builder chain; factor into a small helper to reduce drift.

@@
-    fn create_evm<DB: Database>(&self, db: DB, input: EvmEnv) -> Self::Evm<DB, NoOpInspector> {
-        let spec_id = input.cfg_env.spec;
-        BerachainEvm {
-            inner: Context::mainnet()
-                .with_block(input.block_env)
-                .with_cfg(input.cfg_env)
-                .with_db(db)
-                .build_mainnet_with_inspector(NoOpInspector {})
-                .with_precompiles(PrecompilesMap::from_static(Precompiles::new(
-                    PrecompileSpecId::from_spec_id(spec_id),
-                ))),
-            inspect: false,
-        }
-    }
+    fn create_evm<DB: Database>(&self, db: DB, input: EvmEnv) -> Self::Evm<DB, NoOpInspector> {
+        BerachainEvm { inner: self.build_inner(db, input, NoOpInspector {}), inspect: false }
+    }
@@
-    ) -> Self::Evm<DB, I> {
-        let spec_id = input.cfg_env.spec;
-        BerachainEvm {
-            inner: Context::mainnet()
-                .with_block(input.block_env)
-                .with_cfg(input.cfg_env)
-                .with_db(db)
-                .build_mainnet_with_inspector(inspector)
-                .with_precompiles(PrecompilesMap::from_static(Precompiles::new(
-                    PrecompileSpecId::from_spec_id(spec_id),
-                ))),
-            inspect: true,
-        }
-    }
+    ) -> Self::Evm<DB, I> {
+        BerachainEvm { inner: self.build_inner(db, input, inspector), inspect: true }
+    }
+
+impl BerachainEvmFactory {
+    fn build_inner<DB: Database, I: Inspector<EthEvmContext<DB>>>(
+        &self,
+        db: DB,
+        input: EvmEnv,
+        inspector: I,
+    ) -> reth::revm::Evm<
+        EthEvmContext<DB>,
+        I,
+        EthInstructions<EthInterpreter, EthEvmContext<DB>>,
+        PrecompilesMap,
+        EthFrame,
+    > {
+        let spec_id = input.cfg_env.spec;
+        Context::mainnet()
+            .with_block(input.block_env)
+            .with_cfg(input.cfg_env)
+            .with_db(db)
+            .build_mainnet_with_inspector(inspector)
+            .with_precompiles(PrecompilesMap::from_static(Precompiles::new(
+                PrecompileSpecId::from_spec_id(spec_id),
+            )))
+    }
+}

Also applies to: 208-226

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b9f394c and 0dff02e.

📒 Files selected for processing (1)
  • src/evm/mod.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Check documentation
  • GitHub Check: Run tests
  • GitHub Check: Security audit
  • GitHub Check: Clippy lint
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
src/evm/mod.rs (1)

235-283: Precompile availability tests look solid

Good coverage of spec-dependent precompiles (MODEXP, BLAKE2F) and assertions across early vs later forks.

Comment thread src/evm/mod.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Cargo.toml (1)

4-4: Pin Rust toolchain for Edition 2024

No rust-toolchain.toml (or rust-toolchain) was found in the repo—add one at the project root to pin a Rust release that supports the 2024 edition (e.g. Rust 1.71+), ensuring CI and local environments use a compatible toolchain.

♻️ Duplicate comments (2)
src/evm/mod.rs (2)

190-199: Align factory Context type to EthEvmContext to satisfy Inspector bounds

Using reth::revm::Context<...> here breaks Inspector/InspectorFor bounds vs. the EVM’s context (EthEvmContext<DB>).

Apply:

-    type Context<DB: Database> = Context<BlockEnv, TxEnv, CfgEnv, DB>;
+    type Context<DB: Database> = EthEvmContext<DB>;

This matches I: Inspector<EthEvmContext<DB>> used by BerachainEvm and fixes generic coherence in create_evm_with_inspector.


111-117: Fix field access: read from inner.ctx, not from nonexistent struct fields

Current code won’t compile; self.block/self.cfg are not fields on BerachainEvm.

Apply:

-    fn block(&self) -> &BlockEnv {
-        &self.block
-    }
+    fn block(&self) -> &BlockEnv {
+        &self.inner.ctx.block
+    }

-    fn chain_id(&self) -> u64 {
-        self.cfg.chain_id
-    }
+    fn chain_id(&self) -> u64 {
+        self.inner.ctx.cfg.chain_id
+    }
🧹 Nitpick comments (1)
src/evm/mod.rs (1)

200-213: Minor: avoid ambiguous Context::mainnet() symbol

Given the associated type Context on the trait, explicitly qualify the builder to the reth type to reduce confusion.

-            inner: Context::mainnet()
+            inner: reth::revm::Context::mainnet()
                 .with_block(input.block_env)
                 .with_cfg(input.cfg_env)
                 .with_db(db)

(Repeat similarly below.)

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1551e51 and 1aa292a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • src/evm/mod.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/evm/mod.rs (2)
src/node/evm/executor.rs (3)
  • new (57-72)
  • evm (318-320)
  • finish (236-308)
src/node/evm/config.rs (1)
  • evm_env (103-135)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Check documentation
  • GitHub Check: Run tests
  • GitHub Check: Clippy lint
  • GitHub Check: Security audit
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
Cargo.toml (2)

106-119: Verify all RevM workspace crates use rev 9008e93
Run locally:

cargo tree -e no-dev | rg -nP 'revm(-[a-z]+)? v|bluealloy/revm'

Ensure every revm* crate (including newly split interfaces) resolves to commit 9008e93 to avoid mixed sources.


72-76: No version skew detected — Cargo.lock lists both alloy-rpc-types and alloy-rpc-types-trace at 1.0.27, so the trace crate aligns with the core RPC types.

src/evm/mod.rs (2)

119-147: POL gas_used normalization: consider non-success outcomes

You zero gas_used only on Success. If the intent is “POL never consumes gas,” consider normalizing other outcomes too, or document why only success is zeroed.

Would you like a follow-up patch to set gas_used = 0 for Revert as well?


173-183: Components exposure looks good

Returning DB/Inspector/Precompiles via components(_mut) cleanly supports inspector retrieval in tests.

@rezzmah

rezzmah commented Sep 5, 2025

Copy link
Copy Markdown
Contributor Author

todo: replay_transactions_until further investigation since it previously didn't seen to trace the system call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: alternative solution to forking alloy-evm

1 participant