Skip to content

harden: add layout invariant validation to detectSlabLayout#200

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:harden/layout-invariant-validation
Open

harden: add layout invariant validation to detectSlabLayout#200
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:harden/layout-invariant-validation

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

Summary

  • detectSlabLayout returns layouts from 10+ buildLayout*() functions with no post-construction validation
  • Past layout constant errors (V1M bitmap 726→720, V_ADL bitmap 1006→1008, V12.1 HOST bitmapOff double-subtraction) were only caught by failing tests downstream — not at detection time
  • Fix: validateLayout helper checks 3 structural invariants before returning:
    1. accountsOff > engineOff — accounts array lives after engine header
    2. engineBitmapOff > engineParamsOff — bitmap follows params in engine struct
    3. maxAccounts ∈ [1, 65536] — sane tier bounds
  • Wraps all 11 return paths in detectSlabLayout
  • Catches layout constant transcription errors immediately instead of producing garbled data downstream

Test plan

  • No new test failures (729 passed, same 16 pre-existing)
  • All 10+ layout variants pass all 3 invariants (verified by agent analysis)

🤖 Generated with Claude Code

Added validateLayout helper that checks 3 structural invariants
before any layout is returned from detectSlabLayout:
1. accountsOff > engineOff (accounts come after engine)
2. engineBitmapOff > engineParamsOff (bitmap follows params)
3. maxAccounts in [1, 65536] (sane tier bounds)

Catches transcription errors in layout constants at detection
time instead of producing garbled account data downstream. This
codebase has had multiple such errors (V1M bitmap corrected from
726→720, V_ADL bitmap from 1006→1008, V12.1 HOST bitmapOff
double-subtraction). The invariant check catches this class of
bug immediately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

Warning

Rate limit exceeded

@0x-SquidSol has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 18 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 18 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f4457292-a4c9-4062-8752-aae00fe057e1

📥 Commits

Reviewing files that changed from the base of the PR and between 2f80d79 and 5e1a90e.

📒 Files selected for processing (1)
  • src/solana/slab.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 and usage tips.

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