Skip to content

fix(merkle): use latest available version when exact contractTreeElem…#13

Merged
niconiconi merged 1 commit into
mainfrom
fix/merkle-local-proof-version-fallback
Apr 14, 2026
Merged

fix(merkle): use latest available version when exact contractTreeElem…#13
niconiconi merged 1 commit into
mainfrom
fix/merkle-local-proof-version-fallback

Conversation

@es-kt

@es-kt es-kt commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

…ents version is missing

When totalElements crosses a 32-element batch boundary, contractTreeElements jumps by 32. If the local chairman tree hasn't merged that batch yet (e.g. due to indexer lag or sync gaps), getChairmanMerkleVersion returns undefined for the exact version — causing hybrid mode to silently skip local proof and fall back to the remote freezer service.

Fix: when the exact version is unavailable, fall back to the latest stored version that still covers all requested CIDs. The returned latest_cid is adjusted to match the version actually used, so pickMerkleRootIndex finds the correct on-chain root (its search window already tolerates this offset).

Verified: 12h / 550+ cycles / 356 transfers with zero proof errors on Sepolia testnet, with the remote freezer service completely unreachable.

Summary

Brief description of changes.

Changes

Testing

  • pnpm run test passes
  • pnpm run build succeeds
  • pnpm run type-check passes

Related Issues

Closes #

…ents version is missing

When totalElements crosses a 32-element batch boundary, contractTreeElements
jumps by 32. If the local chairman tree hasn't merged that batch yet (e.g. due
to indexer lag or sync gaps), getChairmanMerkleVersion returns undefined for
the exact version — causing hybrid mode to silently skip local proof and fall
back to the remote freezer service.

Fix: when the exact version is unavailable, fall back to the latest stored
version that still covers all requested CIDs. The returned latest_cid is
adjusted to match the version actually used, so pickMerkleRootIndex finds
the correct on-chain root (its search window already tolerates this offset).

Verified: 12h / 550+ cycles / 356 transfers with zero proof errors on Sepolia
testnet, with the remote freezer service completely unreachable.

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the local Merkle proof generation logic in MerkleEngine to include a fallback mechanism. When the exact contract version is unavailable locally, the engine now attempts to use the latest local version that covers all requested CIDs. It also updates the returned latest_cid to match the version used and refines error reporting to distinguish between missing storage adapters and missing version data. I have no feedback to provide.

@niconiconi niconiconi merged commit f4a43e0 into main Apr 14, 2026
1 check passed
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.

2 participants