Skip to content

fix(slab): wire validateLayout into all detectSlabLayout tier branches - #346

Open
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/slab-validatelayout-coverage-upstream
Open

fix(slab): wire validateLayout into all detectSlabLayout tier branches#346
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/slab-validatelayout-coverage-upstream

Conversation

@Morenikeoa

Copy link
Copy Markdown

Summary

validateLayout (checks accountsOff <= dataLen and that the bitmap region fits within the buffer) was wired into only 3 of 15 buildLayout* call sites in detectSlabLayout: V12_19, V12_17, V12_15. The other 12 (V12_1EP, V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D ×2 branches, V1D-legacy, V1, V1-legacy) returned their built layout directly with no consistency check.

This codebase has shipped exactly this class of bug before (wrong slab tier sizes, wrong bitmap/account byte offsets) on tiers that, at the time, had no automated guard against it. If a future offset/size constant for any of the 12 previously-unguarded tiers were wrong, this defensive layer would not catch it and could silently propagate a bad layout into parseHeader/parseConfig/parseEngine/parseAccount.

No currently-registered tier size actually violates the invariant — that's why this gap never surfaced as a test failure; it's a coverage gap in a defense-in-depth mechanism, not an active misparse.

Fix

Wrap every buildLayout*(...) return value in validateLayout(...) inside detectSlabLayout, including both branches of the V1D/V2 disambiguation path.

Test plan

  • Added a regression test in test/slab.test.ts that reads detectSlabLayout's source and asserts every buildLayout* call site is wrapped in validateLayout(...) — the most direct way to verify the wiring exists, since no real registered tier size can currently trigger an actual validateLayout throw (by construction, every SLAB_TIERS_* entry was computed to satisfy the invariant).
  • Confirmed it fails against the prior code (15 call sites, only 3 wrapped) and passes against this fix (15/15 wrapped).
  • Full suite green (pnpm test exit 0, including "detectSlabLayout validateLayout coverage check passed!"); vitest portion unchanged at 851 passed / 31 skipped since the new test lives in slab.test.ts, run via tsx outside the vitest-counted suite.

validateLayout (checks accountsOff <= dataLen and that the bitmap
region fits within the buffer) was wired into only 3 of 15
buildLayout* call sites in detectSlabLayout: V12_19, V12_17, V12_15.
The other 12 (V12_1EP, V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D
x2 branches, V1D-legacy, V1, V1-legacy) returned their built layout
directly with no consistency check.

This codebase has shipped exactly this class of bug before (wrong
slab tier sizes, wrong bitmap/account byte offsets) on tiers that, at
the time, had no automated guard against it. If a future offset/size
constant for any of the 12 previously-unguarded tiers were wrong,
this defensive layer would not catch it and could silently propagate
a bad layout into parseHeader/parseConfig/parseEngine/parseAccount.

No currently-registered tier size actually violates the invariant —
that's why this gap never surfaced as a test failure; it's a coverage
gap in a defense-in-depth mechanism, not an active misparse.

Fix: wrap every buildLayout*(...) return value in validateLayout(...)
inside detectSlabLayout, including both branches of the V1D/V2
disambiguation path.

Added a regression test in test/slab.test.ts that reads
detectSlabLayout's source and asserts every buildLayout* call site is
wrapped in validateLayout(...) — the most direct way to verify the
wiring exists, since no real registered tier size can currently
trigger an actual validateLayout throw (by construction, every
SLAB_TIERS_* entry was computed to satisfy the invariant). Confirmed
it fails against the prior code (15 call sites, only 3 wrapped) and
passes against this fix (15/15 wrapped).

Full suite (pnpm test): exit 0, all green, including "detectSlabLayout
validateLayout coverage check passed!". Vitest portion unchanged at
851 passed | 31 skipped (882 total) — the new test lives in
slab.test.ts, run via tsx outside the vitest-counted suite.
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Morenikeoa, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes and 39 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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 credits.

🚦 How do rate 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 see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: de6f6fc6-b7c8-4c62-aedb-7588fadb92ff

📥 Commits

Reviewing files that changed from the base of the PR and between 673bc47 and 8cd662c.

📒 Files selected for processing (2)
  • src/solana/slab.ts
  • test/slab.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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