Sanitize on-chain OI/insurance before Number() in live-market-state - #2495
Sanitize on-chain OI/insurance before Number() in live-market-state#24950x-SquidSol wants to merge 1 commit into
Conversation
…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 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. |
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
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. Comment |
dcccrypto
left a comment
There was a problem hiding this comment.
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.
What
Wrap
live-market-state's OI/insurance bigint→Number conversions withsanitizeOnChainValue.Why
markPriceUsdis guarded (< MAX_SANE_PRICE_E6), butoiLongQ/oiShortQ/insurancewereNumber(rawBigint)with no guard. A sentinel/uninitialized slab(u64::MAX) therefore produces an astronomically large OI/insurance that flows into
total_open_interest_usd.sanitizeOnChainValuezeros sentinels and negatives —the same treatment
markPriceand other on-chain reads already receive.Changes
sanitizeOnChainValueon OI long/short + insurance beforeNumber().Testing
npx tsc --noEmit— clean.Notes