Skip to content

[Storehouse] Verify entries on same-height Registers.Store - #8624

Open
zhangchiqing wants to merge 2 commits into
masterfrom
leo/security-audit-k3-same-height-store-verify
Open

[Storehouse] Verify entries on same-height Registers.Store#8624
zhangchiqing wants to merge 2 commits into
masterfrom
leo/security-audit-k3-same-height-store-verify

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented Jul 27, 2026

Copy link
Copy Markdown
Member

Improving error handling in Registers.Store

Summary by CodeRabbit

  • Bug Fixes
    • Added integrity checks when saving register data at an existing height.
    • Conflicting values or unexpected registers now return an error instead of being silently accepted.
    • Preserved previously stored values when a conflicting update is rejected.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 35ffc4e7-3363-478c-bd77-4dad5821082f

📥 Commits

Reviewing files that changed from the base of the PR and between 1fdc565 and b66702f.

📒 Files selected for processing (2)
  • storage/pebble/registers.go
  • storage/pebble/registers_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • storage/pebble/registers_test.go
  • storage/pebble/registers.go

📝 Walkthrough

Walkthrough

Registers.Store now validates repeated stores at the latest height against persisted register values. It returns errors for mismatched or missing entries. Tests cover conflicting values, additional registers, and preservation of the original value.

Changes

Register integrity verification

Layer / File(s) Summary
Same-height store verification
storage/pebble/registers.go, storage/pebble/registers_test.go
Store verifies entries at the latest height with byte comparisons. It rejects conflicting or absent registers and classifies other retrieval failures as irrecoverable. Tests confirm that stored values remain unchanged after validation fails.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change to verify entries in same-height Registers.Store calls.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leo/security-audit-k3-same-height-store-verify

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.

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter

codecov-commenter commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
storage/pebble/registers.go 81.81% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@zhangchiqing
zhangchiqing marked this pull request as ready for review July 27, 2026 13:34
@zhangchiqing
zhangchiqing requested a review from a team as a code owner July 27, 2026 13:34
Comment on lines +164 to +167
stored, err := s.Get(entry.Key, height)
if err != nil {
return fmt.Errorf("cannot verify stored register %v at height %d: %w", entry.Key, height, err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get documents storage.ErrNotFound as an expected error, but here it means a detected divergence, so it must not stay detectable on Store's return. Handle ErrNotFound as a divergence error and wrap other errors with irrecoverable.NewExceptionf:

stored, err := s.Get(entry.Key, height)
if errors.Is(err, storage.ErrNotFound) {
	return fmt.Errorf("register %v was not stored at height %d", entry.Key, height)
}
if err != nil {
	return irrecoverable.NewExceptionf("cannot verify stored register %v at height %d: %w", entry.Key, height, err)
}

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.

3 participants