Skip to content

fix(core): BigInt for gasUsed + topicToAddress length guard - #161

Merged
Th0rgal merged 2 commits into
mainfrom
fix/audit-low-severity
Feb 25, 2026
Merged

fix(core): BigInt for gasUsed + topicToAddress length guard#161
Th0rgal merged 2 commits into
mainfrom
fix/audit-low-severity

Conversation

@Th0rgal

@Th0rgal Th0rgal commented Feb 25, 2026

Copy link
Copy Markdown
Owner

Summary

Two low-severity fixes from codebase audit:

1. parseIntBigInt for gasUsed (fetcher.ts:736-741)

parseInt(frame.gasUsed, 16) returns an IEEE 754 double, losing precision above Number.MAX_SAFE_INTEGER (2^53). The rest of the codebase consistently uses BigInt for hex-to-number conversions. Replaced with BigInt() in a try/catch, which also simplifies the NaN fallback logic.

2. topicToAddress length guard (event-decoder.ts:81-83)

If a log topic from an unvalidated debug_traceCall response is shorter than 42 characters, topic.slice(26) produces a truncated or empty string, resulting in "0x" — an invalid address. Added a guard that returns the zero address for malformed short topics.

Test plan

  • 37 relevant tests pass (event-decoder + fetcher)
  • Type-check clean (desktop + generator)
  • No behavioral change for valid inputs

🤖 Generated with Claude Code


Note

Low Risk
Low risk, localized robustness fixes in simulation decoding; behavior only changes for malformed debug_traceCall responses or very large gasUsed values where parseInt could lose precision.

Overview
Improves simulation trace decoding robustness.

gasUsed parsed from debug_traceCall now uses BigInt (with try/catch) instead of parseInt, preventing precision loss for large values and simplifying failure handling. topicToAddress now guards against too-short topics and returns the zero address rather than producing an invalid/truncated address.

Written by Cursor Bugbot for commit f4862bb. This will update automatically on new commits. Configure here.

Two low-severity fixes from codebase audit:

1. `fetcher.ts`: Replace `parseInt(frame.gasUsed, 16)` with
   `BigInt(frame.gasUsed)` for gasUsed extraction. `parseInt` returns
   an IEEE 754 double which loses precision above 2^53. While gas
   values fit today, this is inconsistent with the rest of the codebase
   which uses BigInt for hex-to-number conversions. Also simplifies the
   NaN fallback to a try/catch.

2. `event-decoder.ts`: Add length guard to `topicToAddress()`. If a
   topic is shorter than 42 chars (a valid 32-byte topic is 66 chars),
   `slice(26)` would produce a truncated or empty address. This guards
   against malformed trace data from unvalidated RPC responses during
   generation. Returns the zero address for short topics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Feb 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
safe-lens-generator Ready Ready Preview, Comment Feb 25, 2026 11:12am

Request Review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread packages/core/src/lib/simulation/event-decoder.ts Outdated
A 32-byte topic is 66 chars ("0x" + 64 hex). The guard used 42
(address length) instead of 66 (topic length), allowing topics
between 42-65 chars to produce truncated addresses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Th0rgal
Th0rgal merged commit f92d6a5 into main Feb 25, 2026
4 checks passed
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.

1 participant