Skip to content

fix: validate RPC batch responses#159

Open
jxom wants to merge 1 commit intomainfrom
fix/rpc-batch-validation
Open

fix: validate RPC batch responses#159
jxom wants to merge 1 commit intomainfrom
fix/rpc-batch-validation

Conversation

@jxom
Copy link
Copy Markdown
Member

@jxom jxom commented Mar 31, 2026

Summary

Fixes 4 High severity audit findings in src/sync/fetcher.rs related to RPC batch response validation.

Findings Fixed

  1. JSON-RPC Batch Reorderingget_blocks_batch and get_receipts_batch assumed responses arrive in request order. Now matches responses by JSON-RPC id field.

  2. RPC Block-Number Spoofing — No validation that the returned block's header.number matched the requested height. Now verifies after id-based matching.

  3. Truncated Batch Response — If the RPC returned fewer items than requested, sync would report success with gaps. Now verifies response count matches request count.

  4. Per-Item Receipt Batch Errors Silently Dropped — Individual error entries in batch receipt responses were ignored. Now checks each item for error field and propagates failures.

Tests Added (7 total)

  • Out-of-order batch responses matched by ID (blocks + receipts)
  • Block number mismatch detection
  • Truncated response error detection
  • Per-item receipt error propagation
  • Happy path with correct in-order responses
  • Existing adaptive split test preserved

Fix 4 High severity audit findings in src/sync/fetcher.rs:

1. JSON-RPC Batch Reordering: Match responses by JSON-RPC id field
   instead of assuming positional order.

2. RPC Block-Number Spoofing: Verify block.header.number matches
   requested height after id-based matching.

3. Truncated Batch Response: Verify response count matches request
   count; error if blocks are missing.

4. Per-Item Receipt Batch Errors: Check each batch response item for
   error field and propagate failures instead of silently dropping.

Amp-Thread-ID: https://ampcode.com/threads/T-019d458d-01b9-76ca-9fb1-b08263a4d59c
Co-authored-by: Amp <amp@ampcode.com>
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