Skip to content

Sanitize on-chain OI/insurance before Number() in live-market-state - #2495

Open
0x-SquidSol wants to merge 1 commit into
dcccrypto:playgroundfrom
0x-SquidSol:fix/live-market-state-oi-sentinel
Open

Sanitize on-chain OI/insurance before Number() in live-market-state#2495
0x-SquidSol wants to merge 1 commit into
dcccrypto:playgroundfrom
0x-SquidSol:fix/live-market-state-oi-sentinel

Conversation

@0x-SquidSol

Copy link
Copy Markdown
Contributor

What

Wrap live-market-state's OI/insurance bigint→Number conversions with
sanitizeOnChainValue.

Why

markPriceUsd is guarded (< MAX_SANE_PRICE_E6), but oiLongQ/oiShortQ/
insurance were Number(rawBigint) with no guard. A sentinel/uninitialized slab
(u64::MAX) therefore produces an astronomically large OI/insurance that flows into
total_open_interest_usd. sanitizeOnChainValue zeros sentinels and negatives —
the same treatment markPrice and other on-chain reads already receive.

Changes

  • live-market-state: sanitizeOnChainValue on OI long/short + insurance before Number().
  • regression test: u64::MAX → 0, negatives → 0, legit values preserved.

Testing

  • npx tsc --noEmit — clean.
  • New test — 3/3 pass.

Notes

  • Frontend + devnet scope; no program/keeper/mainnet changes.

…rket-state

markPrice is guarded (< MAX_SANE_PRICE_E6) but oiLongQ/oiShortQ/insurance were
Number(rawBigint) with no guard, so a sentinel/uninitialized slab (u64::MAX) yields
an astronomically large value that propagates into total_open_interest_usd. Wrap
the three conversions with sanitizeOnChainValue (zeros sentinels and negatives) —
the same treatment markPrice and other on-chain reads already get.

- live-market-state: sanitizeOnChainValue on OI long/short + insurance
- add a regression test (u64::MAX -> 0; negatives -> 0; legit values preserved)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@0x-SquidSol
0x-SquidSol requested a review from dcccrypto as a code owner August 5, 2026 19:55
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@0x-SquidSol is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@0x-SquidSol, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3eb26f59-b630-41e7-950e-e34add6e775a

📥 Commits

Reviewing files that changed from the base of the PR and between f2a3bbe and 0893c6e.

📒 Files selected for processing (2)
  • app/__tests__/lib/live-market-state-oi-sentinel.test.ts
  • app/lib/live-market-state.ts

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

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

@dcccrypto dcccrypto left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Correct. Suite: 2922 passed / 0 failed. sanitizeOnChainValue takes and
returns bigint, so wrapping before Number() is the right order — a sentinel is
zeroed while still exact, rather than after a lossy double conversion.

One wording correction: the comment says this is "Same treatment markPrice
gets"
, but markPriceUsd doesn't use sanitizeOnChainValue — it uses an inline
range guard at :104:

if (e6 > 0n && e6 < MAX_SANE_PRICE_E6) markPriceUsd = Number(e6) / 1_000_000;

Different helper, different shape (range check vs sentinel/negative zeroing), and
a different failure mode: out-of-range price → null, out-of-range OI → 0. Both
are defensible, but "same treatment" will mislead the next reader into thinking
one helper covers the file. Worth saying "the same class of guard" — or, better,
worth asking whether markPrice should move onto the shared helper so there's one
convention here rather than two.

Test doesn't bind the fix. I reverted all three wrappers back to bare
Number(...) — the bug fully restored — and
live-market-state-oi-sentinel.test.ts stayed 3/3 green. parseLiveState is
module-private, but parseMarketGroupV17OI can be mocked to return u64::MAX and
the exported reader asserted to yield 0.

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