Skip to content

Verify fully remote proofs against the freshest head - #946

Closed
hakarrr wants to merge 2 commits into
holepunchto:mainfrom
hakarrr:fix-791-stale-head-length
Closed

hakarrr wants to merge 2 commits into
holepunchto:mainfrom
hakarrr:fix-791-stale-head-length

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 8, 2026

Copy link
Copy Markdown

Fixes #791

The race

verify() in lib/fully-remote-proof.js reads the head once at the start, then upgrades the core and requests the proof batch. If storage advances in between (a concurrent update appending a block), the proof is verified against the new state but newer is still computed by comparing batch.length against the stale head read from before verification, so info can report a stale newer value.

The fix

Re-read the head after verifyFullyRemote succeeds and compute newer against the freshest head:

const freshHead = await store.getHead()
result.newer = batch.length > freshHead.length

Test

Adds fully remote proof - newer uses freshest head, which deterministically simulates the race by wrapping the storage so the first head read (the one taken at the start of verify()) returns a stale length while the post-verification read sees the advanced core. Without the fix the test reports newer: true (stale); with the fix it reports newer: false as expected. Note: the race is simulated via the storage wrapper rather than a real concurrent append, to keep the test deterministic.

Verification

  • New test fails pre-fix (newer reported stale) and passes post-fix
  • All tests in test/fully-remote-proof.js pass (3/3, 12 assertions)
  • prettier --check and lunte clean on both changed files
  • The full test/replicate.js suite exceeds this machine's memory at the pre-existing "one missing block, big core (slow)" test, so verification was scoped to the affected file

hakarrr and others added 2 commits November 9, 2026 02:04
The head was read once at the start of verify() and the batch length was compared against it after verification, so a concurrent update advancing storage in between made the result stale. Re-read the head after verifying and compare against that.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Simulates a storage advance during proof verification by doctoring the first head read, then asserts newer is computed against the fresh head.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr
hakarrr requested a review from a team November 8, 2026 20:35
@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Low impact] The PR appears safe to merge; no actionable issues were found.

Summary

Re-reads the stored head after proof checks so newer reflects updates that arrived during verification.

  • Fully remote proof results use the latest local head to set newer.

Diagram

sequenceDiagram
  participant V as verify
  participant S as Storage
  V->>S: Read authentication and initial head
  V->>S: Read tree roots
  Note over S: Another update may advance the head
  V->>V: Check proof and signature
  V->>S: Read head again
  S-->>V: Latest stored head
  V->>V: Compare proof length with latest head length
Loading

Reviews (2) · Last reviewed commit: "Test that newer reflects the freshest he..." · Reviewed by Greptile

@hakarrr

hakarrr commented Nov 8, 2026

Copy link
Copy Markdown
Author

Closing as duplicate of #791, which already addresses the stale head read. My apologies - I mistook that open PR for an issue when scanning the tracker.

@hakarrr hakarrr closed this Nov 8, 2026
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