Skip to content

feat: Js Tracer#2305

Merged
carneiro-cw merged 4 commits intomainfrom
js_tracer
Sep 9, 2025
Merged

feat: Js Tracer#2305
carneiro-cw merged 4 commits intomainfrom
js_tracer

Conversation

@carneiro-cw
Copy link
Contributor

@carneiro-cw carneiro-cw commented Sep 9, 2025

PR Type

Enhancement


Description

  • Implemented JS Tracer for EVM execution

  • Added support for custom JavaScript tracing

  • Integrated JsInspector in EVM execution flow

  • Added E2E tests for JS tracing functionality


Diagram Walkthrough

flowchart LR
  A["EVM Execution"] --> B["JsInspector"]
  B --> C["Custom JS Tracer"]
  C --> D["Trace Results"]
  E["E2E Tests"] --> F["Verify JS Tracing"]
Loading

File Walkthrough

Relevant files
Enhancement
evm.rs
Integrate JsInspector into EVM execution flow                       

src/eth/executor/evm.rs

  • Imported JsInspector from revm_inspectors
  • Implemented JsTracer case in GethDebugTracerType
  • Added logic to execute JsInspector and return results
+10/-1   
Tests
e2e-json-rpc.test.ts
Add E2E tests for JavaScript tracing functionality             

e2e/test/external/e2e-json-rpc.test.ts

  • Added test for simple JS tracer counting opcodes
  • Implemented test for JS tracer capturing LOG opcodes
  • Verified correct execution and result format of JS tracers
+100/-0 
Dependencies
Cargo.toml
Enable JS tracer feature in revm-inspectors                           

Cargo.toml

  • Added "js-tracer" feature to revm-inspectors dependency
+1/-1     

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Handling

The error handling in the JsTracer implementation might need improvement. Consider using a custom error type instead of converting errors to strings.

let mut inspector = JsInspector::new(code, opts.tracer_config.into_json()).map_err(|e| anyhow!(e.to_string()))?;
let mut evm_with_inspector = evm.with_inspector(&mut inspector);
evm_with_inspector.fill_env(inspect_input);
let tx = std::mem::take(&mut evm_with_inspector.tx);
let block = std::mem::take(&mut evm_with_inspector.block);
let res = evm_with_inspector.inspect_tx(tx.clone())?;
GethTrace::JS(inspector.json_result(res, &tx, &block, &cache_db).map_err(|e| anyhow!(e.to_string()))?)
Test Timeout

The test "JS tracer for LOG opcodes" has an increased timeout. Consider optimizing the test or investigating why it needs such a long timeout.

it("JS tracer for LOG opcodes", async function () {
    this.timeout(120000); // Increase timeout to 2 minutes

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Improve error handling for JS tracer

Consider handling potential errors more gracefully in the JS tracer implementation.
Instead of using map_err to convert errors to strings, create custom error types for
better error handling and reporting.

src/eth/executor/evm.rs [326-332]

-let mut inspector = JsInspector::new(code, opts.tracer_config.into_json()).map_err(|e| anyhow!(e.to_string()))?;
+let mut inspector = JsInspector::new(code, opts.tracer_config.into_json()).map_err(|e| EvmError::JsTracerInitError(e))?;
 let mut evm_with_inspector = evm.with_inspector(&mut inspector);
 evm_with_inspector.fill_env(inspect_input);
 let tx = std::mem::take(&mut evm_with_inspector.tx);
 let block = std::mem::take(&mut evm_with_inspector.block);
 let res = evm_with_inspector.inspect_tx(tx.clone())?;
-GethTrace::JS(inspector.json_result(res, &tx, &block, &cache_db).map_err(|e| anyhow!(e.to_string()))?)
+GethTrace::JS(inspector.json_result(res, &tx, &block, &cache_db).map_err(|e| EvmError::JsTracerResultError(e))?)
Suggestion importance[1-10]: 6

__

Why: The suggestion improves error handling by introducing custom error types (EvmError::JsTracerInitError and EvmError::JsTracerResultError) instead of converting errors to strings. This enhances error reporting and makes debugging easier, but it's not a critical change.

Low
Optimize JS tracer for performance

The JS tracer for LOG opcodes could be optimized for performance. Consider using
bitwise operations instead of arithmetic for opcode checks and use a more efficient
method for address conversion.

e2e/test/external/e2e-json-rpc.test.ts [629-662]

 const logTracer = `{
     logs: [],
     step: function(log, db) {
         const opcode = log.op.toNumber();
-        // LOG0 = 0xa0, LOG1 = 0xa1, LOG2 = 0xa2, LOG3 = 0xa3, LOG4 = 0xa4
-        if (opcode >= 0xa0 && opcode <= 0xa4) {
-            const topicCount = opcode - 0xa0;
+        if ((opcode & 0xf0) === 0xa0) {
+            const topicCount = opcode & 0x0f;
             const offset = log.stack.peek(0);
             const size = log.stack.peek(1);
 
             const topics = [];
             for (let i = 0; i < topicCount; i++) {
                 topics.push(log.stack.peek(2 + i).toString(16));
             }
 
-            // Convert address object to hex string
-            const addrObj = log.contract.getAddress();
-            let address = '0x';
-            for (let i = 0; i < 20; i++) {
-                const byte = addrObj[i.toString()];
-                address += byte.toString(16).padStart(2, '0');
-            }
+            const address = '0x' + log.contract.getAddress().toString('hex');
 
             this.logs.push({
                 address: address,
                 topics: topics,
                 topicCount: topicCount,
                 dataSize: size.toString()
             });
         }
     },
     fault: function(log, db) {},
     result: function(ctx, db) { return this.logs }
 }`;
Suggestion importance[1-10]: 5

__

Why: The suggestion optimizes the JS tracer by using bitwise operations and a more efficient address conversion method. While this improves performance, the impact is moderate as it's in a test file and not in the core functionality.

Low

@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.67%. Comparing base (8d4605c) to head (ce65927).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2305      +/-   ##
==========================================
+ Coverage   77.36%   84.67%   +7.30%     
==========================================
  Files         130      130              
  Lines        9465    10800    +1335     
==========================================
+ Hits         7323     9145    +1822     
+ Misses       2142     1655     -487     
Flag Coverage Δ
contracts-rocks- 44.22% <0.00%> (-0.06%) ⬇️
e2e-admin-password 22.02% <0.00%> (-0.02%) ⬇️
e2e-clock-stratus 24.79% <0.00%> (-0.02%) ⬇️
e2e-genesis 26.28% <0.00%> (-0.02%) ⬇️
e2e-importer-offline 58.40% <0.00%> (-0.08%) ⬇️
e2e-rpc-downloader 53.58% <0.00%> (-0.04%) ⬇️
e2e-stratus 55.81% <100.00%> (+0.02%) ⬆️
leader-follower- 61.39% <0.00%> (-0.05%) ⬇️
rust-tests 31.69% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@carneiro-cw carneiro-cw enabled auto-merge (squash) September 9, 2025 13:25
@carneiro-cw carneiro-cw merged commit d71b5f4 into main Sep 9, 2025
40 checks passed
@carneiro-cw carneiro-cw deleted the js_tracer branch September 9, 2025 13:59
@stratus-benchmark
Copy link

Final benchmark:
Run ID: bench-790ada61

Git Info:

Leader Stats:
RPS Stats: Max: 3555.00, Min: 1829.00, Avg: 2974.56, StdDev: 192.26
TPS Stats: Max: 3305.00, Min: 1456.00, Avg: 2971.41, StdDev: 198.38

Follower Stats:
Imported Blocks/s: Max: 17.00, Min: 4.00, Avg: 10.45, StdDev: 2.55
Imported Transactions/s: Max: 30526.00, Min: 6593.00, Avg: 24512.29, StdDev: 4061.27

Plots:

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.

2 participants

Comments