Skip to content

Fix trace module wasm build - #343

Merged
0xgleb merged 3 commits into
mainfrom
fix/trace-module-wasm-build
Jul 4, 2025
Merged

Fix trace module wasm build#343
0xgleb merged 3 commits into
mainfrom
fix/trace-module-wasm-build

Conversation

@0xgleb

@0xgleb 0xgleb commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Motivation

trace module of the eval crate is used in wasm in the orderbook

Solution

make trace module (partially) available in wasm

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • Improved WebAssembly (WASM) support by updating dependencies and adjusting module availability for WASM targets.
  • Refactor

    • Modified how certain features and dependencies are conditionally included based on the target platform, ensuring consistent module availability and optimized builds for both WASM and non-WASM environments.

@coderabbitai

coderabbitai Bot commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce new WebAssembly (wasm)-specific dependencies and conditional compilation logic to the rain-interpreter-eval crate. The trace module is now always included, but its internal code selectively compiles different implementations and imports depending on whether the target is wasm or not. No public APIs or logic were otherwise altered.

Changes

File(s) Change Summary
Cargo.toml Added wasm-bindgen-utils v0.0.10 to workspace dependencies.
crates/eval/Cargo.toml Added wasm-specific dependencies: wasm-bindgen-utils (workspace) and revm v25.0.0 with selected features for wasm targets.
crates/eval/src/lib.rs Removed conditional compilation from pub mod trace;, making the trace module always available.
crates/eval/src/trace.rs Added conditional compilation: imports and trait impls for non-wasm targets; wasm-specific imports for wasm targets.

Sequence Diagram(s)

sequenceDiagram
    participant Consumer
    participant rain-interpreter-eval (lib.rs)
    participant trace module (trace.rs)

    Consumer->>rain-interpreter-eval (lib.rs): use trace
    rain-interpreter-eval (lib.rs)->>trace module (trace.rs): call functions/types

    alt Target is WASM
        trace module (trace.rs)->>wasm_bindgen_utils: Use wasm-specific traits/imports
    else Target is not WASM
        trace module (trace.rs)->>std/revm: Use native traits/imports and trait implementations
    end
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc0c5f and d809d5b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml (1 hunks)
  • crates/eval/Cargo.toml (1 hunks)
  • crates/eval/src/lib.rs (0 hunks)
  • crates/eval/src/trace.rs (4 hunks)
💤 Files with no reviewable changes (1)
  • crates/eval/src/lib.rs
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/trace.rs:92-118
Timestamp: 2025-06-17T18:01:06.316Z
Learning: User 0xgleb considers refactoring to remove a single duplicate as premature optimization in crates/eval/src/trace.rs when dealing with trace-filtering logic.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/trace.rs:120-125
Timestamp: 2025-06-17T17:41:22.817Z
Learning: In crates/eval/src/trace.rs, the TryFrom<RawCallResult> implementation for RainEvalResult intentionally returns empty vectors for stack and writes fields. This restores old functionality that was removed in an update but is needed by downstream code (rain.orderbook).
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: Cargo.toml:11-11
Timestamp: 2025-06-09T07:46:10.639Z
Learning: When analyzing dependency upgrades, always search for the specific programming language and context (e.g., "Rust alloy crate" vs "Alloy framework") to avoid confusion between different libraries with the same name. The alloy crate in Rust is for Ethereum development, not mobile app development.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: Cargo.toml:11-11
Timestamp: 2025-06-09T07:46:10.639Z
Learning: When analyzing dependency upgrades in Rust projects, always search for the specific programming language and context (e.g., "Rust alloy crate" vs "Alloy framework") to avoid confusion between different libraries with the same name. The alloy crate in Rust is for Ethereum development, not mobile app development.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:498-506
Timestamp: 2025-06-17T17:54:43.315Z
Learning: In the rain.interpreter codebase, for the replay_transaction method in crates/eval/src/fork.rs, ignoring the transaction value (using 0 instead of the actual tx value) during replay is acceptable for their use case, even though it may cause divergence from the original transaction execution.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:489-494
Timestamp: 2025-06-17T10:56:40.904Z
Learning: When analyzing error handling in Rust codebases that use external crates like foundry-evm, verify actual compilation behavior rather than assuming missing trait implementations. The `?` operator often works due to comprehensive error conversion implementations provided by the crate ecosystem.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: crates/test_fixtures/src/lib.rs:99-102
Timestamp: 2025-06-09T07:47:06.227Z
Learning: User 0xgleb prefers to keep the current signer registration pattern in LocalEvm test fixture where all other signers are registered with the default wallet, rather than simplifying it to have each wallet sign independently.
Cargo.toml (3)
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: Cargo.toml:11-11
Timestamp: 2025-06-09T07:46:10.639Z
Learning: When analyzing dependency upgrades in Rust projects, always search for the specific programming language and context (e.g., "Rust alloy crate" vs "Alloy framework") to avoid confusion between different libraries with the same name. The alloy crate in Rust is for Ethereum development, not mobile app development.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: Cargo.toml:11-11
Timestamp: 2025-06-09T07:46:10.639Z
Learning: When analyzing dependency upgrades, always search for the specific programming language and context (e.g., "Rust alloy crate" vs "Alloy framework") to avoid confusion between different libraries with the same name. The alloy crate in Rust is for Ethereum development, not mobile app development.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:489-494
Timestamp: 2025-06-17T10:56:40.904Z
Learning: ForkCallError in the rain.interpreter codebase has an `Eyre(#[from] eyre::Report)` variant that provides automatic conversion from eyre::Report. This allows foundry-evm backend methods like `replay_until` to work with the `?` operator since foundry-evm uses eyre for error handling.
crates/eval/Cargo.toml (3)
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/trace.rs:120-125
Timestamp: 2025-06-17T17:41:22.817Z
Learning: In crates/eval/src/trace.rs, the TryFrom<RawCallResult> implementation for RainEvalResult intentionally returns empty vectors for stack and writes fields. This restores old functionality that was removed in an update but is needed by downstream code (rain.orderbook).
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: Cargo.toml:11-11
Timestamp: 2025-06-09T07:46:10.639Z
Learning: When analyzing dependency upgrades in Rust projects, always search for the specific programming language and context (e.g., "Rust alloy crate" vs "Alloy framework") to avoid confusion between different libraries with the same name. The alloy crate in Rust is for Ethereum development, not mobile app development.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: Cargo.toml:11-11
Timestamp: 2025-06-09T07:46:10.639Z
Learning: When analyzing dependency upgrades, always search for the specific programming language and context (e.g., "Rust alloy crate" vs "Alloy framework") to avoid confusion between different libraries with the same name. The alloy crate in Rust is for Ethereum development, not mobile app development.
crates/eval/src/trace.rs (9)
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/trace.rs:120-125
Timestamp: 2025-06-17T17:41:22.817Z
Learning: In crates/eval/src/trace.rs, the TryFrom<RawCallResult> implementation for RainEvalResult intentionally returns empty vectors for stack and writes fields. This restores old functionality that was removed in an update but is needed by downstream code (rain.orderbook).
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/trace.rs:92-118
Timestamp: 2025-06-17T18:01:06.316Z
Learning: User 0xgleb considers refactoring to remove a single duplicate as premature optimization in crates/eval/src/trace.rs when dealing with trace-filtering logic.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:489-494
Timestamp: 2025-06-17T10:56:40.904Z
Learning: When analyzing error handling in Rust codebases that use external crates like foundry-evm, verify actual compilation behavior rather than assuming missing trait implementations. The `?` operator often works due to comprehensive error conversion implementations provided by the crate ecosystem.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:489-494
Timestamp: 2025-06-17T10:56:40.904Z
Learning: ForkCallError in the rain.interpreter codebase has an `Eyre(#[from] eyre::Report)` variant that provides automatic conversion from eyre::Report. This allows foundry-evm backend methods like `replay_until` to work with the `?` operator since foundry-evm uses eyre for error handling.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:489-494
Timestamp: 2025-06-17T10:56:40.904Z
Learning: In the foundry-evm crate, the `replay_until` method on the backend returns an error type that is convertible to `ForkCallError`, so using the `?` operator works without requiring explicit error mapping.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:489-494
Timestamp: 2025-06-17T10:56:40.904Z
Learning: The foundry-evm backend methods like `replay_until` return error types that are properly convertible to `ForkCallError`, so using the `?` operator works without requiring explicit error mapping. The codebase has comprehensive error handling conversions in place.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:498-506
Timestamp: 2025-06-17T17:54:43.315Z
Learning: In the rain.interpreter codebase, for the replay_transaction method in crates/eval/src/fork.rs, ignoring the transaction value (using 0 instead of the actual tx value) during replay is acceptable for their use case, even though it may cause divergence from the original transaction execution.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:496-507
Timestamp: 2025-06-17T10:55:30.500Z
Learning: In foundry-evm's replay_until method return type, the transaction's inner.signer() method returns Address directly, not Option<Address>, so no null checking is needed when calling .as_slice() on it.
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#334
File: crates/eval/src/fork.rs:471-473
Timestamp: 2025-06-17T17:46:09.568Z
Learning: In the rain.interpreter codebase, forking functionality is used specifically for working with their contracts, so genesis block (block_number == 0) scenarios are not expected to occur in practice when replaying transactions.
🔇 Additional comments (7)
Cargo.toml (1)

38-38: Confirm wasm-bindgen-utils version and security

It looks like wasm-bindgen-utils = "0.0.10" is not referenced in the main wasm-bindgen changelogs or Rust security advisories, nor is there a clearly documented newer version. To be certain:

• In Cargo.toml (line 38), verify on crates.io that 0.0.10 is still the latest stable release of wasm-bindgen-utils.
• Run cargo audit (or check RustSec) to ensure there are no known vulnerabilities in this crate version.

crates/eval/Cargo.toml (1)

23-30: No action needed on revm version mismatch

The upgrade from 24.0.1 to 25.0.0 introduces only non-breaking, additive features (multi-transaction execution and flag fixes) and does not affect existing APIs. You can safely use revm = "25.0.0" for the Wasm target without compatibility concerns.

crates/eval/src/trace.rs (5)

1-1: Conditional compilation for imports looks correct.

The imports are properly gated to exclude foundry-evm and related dependencies from wasm builds, which makes sense since these crates likely don't support wasm.

Also applies to: 4-4, 6-6, 10-10


13-14: WASM-specific imports added correctly.

The conditional import of wasm_bindgen_utils for wasm targets is appropriate and follows Rust conditional compilation best practices.


69-97: Major conversion implementation excluded from wasm.

The From<ForkTypedReturn<eval4Call>> implementation is excluded from wasm builds, which makes sense since it depends on foundry-evm types. However, this removes a key way to construct RainEvalResult from fork results.

Ensure that wasm builds have alternative ways to construct RainEvalResult instances, or document that this conversion path is not needed for wasm use cases.


105-135: TryFrom implementation properly gated for non-wasm builds.

The TryFrom<RawCallResult> implementation is correctly excluded from wasm builds since it depends on foundry-evm types. The implementation looks correct for non-wasm targets.


216-216: WASM-specific serialization traits added correctly.

The conditional derives and wasm-bindgen traits are properly implemented for wasm compatibility. The Tsify derive and impl_wasm_traits! macro usage follows wasm-bindgen best practices.

Also applies to: 219-219, 222-223

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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.

@0xgleb
0xgleb requested review from findolor and hardyjosh June 30, 2025 09:48
@0xgleb
0xgleb marked this pull request as ready for review June 30, 2025 09:48
@0xgleb 0xgleb self-assigned this Jun 30, 2025
@0xgleb 0xgleb linked an issue Jun 30, 2025 that may be closed by this pull request
@0xgleb 0xgleb mentioned this pull request Jul 1, 2025
4 tasks
@0xgleb
0xgleb merged commit 7891976 into main Jul 4, 2025
@0xgleb
0xgleb deleted the fix/trace-module-wasm-build branch July 4, 2025 09:20
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.

Expose trace module for use in the orderbook

3 participants