Skip to Content
EVMCustom Tracer Authoring Guide

Custom Tracer Authoring Guide

Sei exposes the standard debug_trace* RPC suite and accepts the same JavaScript tracer scripts as upstream go-ethereum, with a few Sei-specific safety guards and panic surfacing improvements.

Runtime Expectations

Authoring Patterns

const tracer = { result: { steps: [], gasUsed: 0, errors: [] }, step(log, db) { try { this.result.steps.push({ pc: log.getPC(), op: log.op.toString(), gasCost: log.getCost() }); this.result.gasUsed += log.getCost(); } catch (err) { this.result.errors.push(String(err)); throw err; // bubble up so Sei surfaces it in error.data.trace } }, fault(log, db) { this.result.errors.push(`fault: ${log.getError()}`); }, result() { return this.result; } }; module.exports = tracer;

Recommendations

  • Wrap logic in try/catch to append diagnostic context before re-throwing.
  • Keep returned objects shallow; avoid large arrays or deeply nested state.
  • Include a version identifier in the result to track script revisions.
  • Use db.getBalance, db.getCode, etc., sparingly; each call hits execution state.

Validation Checklist

Panic recoveryIntentionally throw within step and confirm the response includes error.data.trace.
Frame sizeSerialize tracer output and ensure it stays comfortably below 1 MB.
ConcurrencySend max_concurrent_trace_calls + 1 requests; the extra call should queue (not crash).
TimeoutRun a long trace to verify it errors with a timeout rather than hanging indefinitely.

Troubleshooting

ErrorCauseFix
panic: runtime error: index out of rangeTracer script accesses an array out of bounds.Add guards, catch the error, or ensure the data structure matches opcodes observed.
frame length exceeds limitTracer returns payload larger than go-ethereum guard.Stream results to storage or return a summarized payload.
Missing error.data.traceNode running a build without panic surfacing, or panic occurs outside tracer scope.Upgrade to a tracer-enabled release; ensure errors originate inside the tracer so the wrapper can capture them.
Last updated on