Skip to content

harden: add instruction data length assertions to critical encoders#197

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:harden/encoder-length-assertions
Open

harden: add instruction data length assertions to critical encoders#197
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:harden/encoder-length-assertions

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

Summary

  • Only encodeInitMarket had a post-encode length assertion (352 bytes). All other encoders returned concatBytes(...) with no size verification.
  • A developer adding/removing a field from concatBytes without updating the layout could silently produce wrong-length instruction data, causing the on-chain decoder to misparse or panic.
  • Added assertions to 5 safety-critical encoders:
Encoder Expected Fields Why Critical
encodeTradeCpi 21 bytes 4 User funds — trade execution
encodeTradeCpiV2 22 bytes 5 User funds — trade execution
encodeTradeNoCpi 21 bytes 4 User funds — trade execution
encodeExecuteAdl 3 bytes 2 Auto-deleveraging positions
encodeUpdateConfig 145 bytes 14 Market config — highest layout-error risk
  • All enc* helpers return fixed-size arrays — assertions can never false-positive on valid inputs
  • Follows the encodeInitMarket pattern already established at line 260

Test plan

  • All 44 instruction tests pass
  • No new test failures (729 passed, same 16 pre-existing)

🤖 Generated with Claude Code

Added post-encode length assertions to 5 safety-critical encoder
functions following the encodeInitMarket pattern (line 260):

- encodeTradeCpi: 21 bytes (user funds)
- encodeTradeCpiV2: 22 bytes (user funds)
- encodeTradeNoCpi: 21 bytes (user funds)
- encodeExecuteAdl: 3 bytes (auto-deleveraging)
- encodeUpdateConfig: 145 bytes (14 fields, highest layout-error risk)

Each assertion catches field addition/removal bugs that would
silently produce wrong-length instruction data, causing the
on-chain decoder to misparse fields or panic. The enc* helpers
always produce fixed-size output, so the assertions can never
false-positive on valid inputs.

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 38 minutes and 10 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 38 minutes and 10 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: 479a9066-4d4b-4721-821a-2aae91731e47

📥 Commits

Reviewing files that changed from the base of the PR and between 2f80d79 and 25ddc57.

📒 Files selected for processing (1)
  • src/abi/instructions.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