Skip to content

fix(contracts): snapshot-contracts refuses a version the network does not run - #763

Merged
PastaPastaPasta merged 2 commits into
masterfrom
fix/snapshot-version-check
Nov 27, 2026
Merged

PastaPastaPasta merged 2 commits into
masterfrom
fix/snapshot-version-check

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #748.

Problem

827ae9c unpinned the SDK, but the guard only checked sdk.version() >= 14. The SDK ratchets its version upward and never down, so an SDK seeded or pinned above the network (a future SDK default, or a pin added back) would still write a snapshot at its own version. The web app raises every visitor's stored SDK version to the snapshot's, and nothing lowers it again. Nothing tested the guard.

Fix

  • The snapshot version now comes from the proved answer's metadata (getManyWithProof(...).metadata.protocolVersion). It must equal sdk.version() and be at least PROTOCOL_VERSION; otherwise nothing is written.
  • The read moves into an exported takeSnapshot, and the check into snapshotVersion. Tests run them against a fake SDK. The case where the SDK is at 15 and mainnet is at 14 is refused; the old guard let it through.

Verified

  • node --test forge-contracts/scripts/snapshot-contracts.test.mjs: 6/6 pass.
  • A live run with evo-sdk 5.1.0 and --out set to a scratch file matches the committed snapshots byte for byte: mainnet at 14 and testnet at 15.

Compat: no committed snapshot changes. The web app and dg are untouched.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Contract snapshots now use the protocol version confirmed by the network and reject mismatches or missing version information.
    • Snapshot reports now reflect the actual number of contracts included.

…oof does not name

The guard compared sdk.version() with a floor. The SDK only ratchets
upward, so an SDK seeded or pinned above the network would still write
a snapshot at its own version, raising every reader's stored version.
The version now comes from the proved answer's metadata and must equal
the SDK's. The read moves into takeSnapshot so a fake SDK can test the
refusal.

Closes #748

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a7aaa98a-0ab8-4f41-acbc-59c558932a70
Commits

Reviewing files that changed from the base of the PR and between d3e7c2a and 7c7c724.

Files selected for processing: 1

  • forge-contracts/scripts/snapshot-contracts.test.mjs

No actionable comments were generated in the recent review.

Walkthrough

The snapshot script now fetches contracts with one proved request and validates the proved protocol version against the SDK version and minimum version. The CLI writes the returned snapshot and reports its actual contract count.

Changes: Contract snapshot version validation

Layer / File(s) Summary
Proved contract retrieval and version checks
forge-contracts/scripts/snapshot-contracts.mjs, forge-contracts/scripts/snapshot-contracts.test.mjs
The script checks the proved protocol version and serializes contracts at that version. Tests cover valid and rejected versions, including an unpinned SDK.
CLI snapshot output
forge-contracts/scripts/snapshot-contracts.mjs
The CLI delegates snapshot creation after its existing deployment checks, writes the returned snapshot, and reports the actual contract count.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • PastaPastaPasta/dash-forge#756: Updates Platform pins and describes SDK behavior for learning protocol versions from proved responses, which this change relies on.
Merge Risk: Minimal · previous review d3e7c

The snapshot script now checks the network's proved protocol version against the SDK version and the minimum version, and refuses to write a snapshot on a mismatch. No merge-blocking risk was found. Valid snapshots should still be produced, and the reported live run matched the committed snapshots.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: snapshot-contracts now refuses to write a snapshot for a version the network does not run. The change matches the summary and objectives: the snapshot version is read …
Description check Passed The description covers the problem, the fix, and verification steps, which matches the 'What and why' and 'How it was tested' intent of the template. It links issue #748 and explains the root cause: t…
Linked Issues check Passed Issue #748 requires that snapshot-contracts.mjs check the network's actual protocol version, not the pinned SDK version, and refuse to write a snapshot at a version the network does not run. A unit or…
Out of Scope Changes check Passed The changes stay in forge-contracts/scripts/snapshot-contracts.mjs and its test file, as the PR description and summary state. The changes consist of:
- snapshotVersion and takeSnapshot exports.…
Full details: Title check

Explanation

The title names the main change: snapshot-contracts now refuses to write a snapshot for a version the network does not run. The change matches the summary and objectives: the snapshot version is read from the proved response metadata, checked against sdk.version() and PROTOCOL_VERSION, and the write is refused otherwise. The title uses the conventional fix(contracts) prefix. Its length (77 characters) is at the upper end of a concise title but still readable.

Full details: Description check

Explanation

The description covers the problem, the fix, and verification steps, which matches the 'What and why' and 'How it was tested' intent of the template. It links issue #748 and explains the root cause: the guard checked only sdk.version() >= 14, and the SDK version ratchets upward. It also lists the test command and the live run result. The template's checklist items (make check-rust/check-web, vectors, docs/guides) and the Screenshots section are not addressed. These items are either not applicable to a script-only change or are left unstated, so the author should state briefly that they do not apply.

Resolution

Optionally state that the checklist items (make check-rust and make check-web, rule vectors, docs/guides) and the Screenshots section do not apply to this script-only change. This keeps the template complete for reviewers.

Full details: Linked Issues check

Explanation

Issue #748 requires that snapshot-contracts.mjs check the network's actual protocol version, not the pinned SDK version, and refuse to write a snapshot at a version the network does not run. A unit or script test must cover the refusal.

At the reviewed head:

  • takeSnapshot builds EvoSDK without version, so the SDK is not pinned. The comment states this.
  • takeSnapshot reads metadata?.protocolVersion from the proved getManyWithProof answer. This is the network's answer.
  • snapshotVersion(sdkVersion, provedVersion, key) throws, and writes nothing, when the proved version is missing or not a positive integer, when it is below PROTOCOL_VERSION, or when it differs from sdk.version(). It returns the proved version otherwise.
  • The snapshot bytes are serialized at that version (contract.toBytes(platformVersion)).

The test file covers the refusal against a fake SDK. It checks the SDK at 15 with mainnet at 14, the proved version below PROTOCOL_VERSION, a missing proved version, and the unpinned SDK. It also checks snapshotVersion directly. The issue's suggested method (deploy-v2-style unpinned read) differs in detail. The PR uses the proved metadata instead, which meets the stated expected behavior.

I did not run the tests. The assessment relies on the source at head and the PR's reported results. I did not diff against the merge base, so the before-state is taken from the PR description and summary.

Full details: Out of Scope Changes check

Explanation

The changes stay in forge-contracts/scripts/snapshot-contracts.mjs and its test file, as the PR description and summary state. The changes consist of:

  • snapshotVersion and takeSnapshot exports. These implement the #748 check and make it testable offline.
  • A reworked main() that calls takeSnapshot. The CLI keeps its incompleteReason completeness check and its resolveTarget scratch-target rules.
  • Comments that describe the protocol-version requirement.
  • New tests for the refusal and the protocol-version selection.

The devnet-only DAPI address handling and the --record/--out safety rules remain in the code at head. No unrelated file is changed according to the PR description. I did not run a base diff to confirm the file list, so that claim rests on the PR description and summary.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a966dcd8-5b25-4fe6-a25d-f037bac14b0f
Commits

Reviewing files that changed from the base of the PR and between 6e3e1a4 and d3e7c2a.

Files selected for processing: 2

  • forge-contracts/scripts/snapshot-contracts.mjs
  • forge-contracts/scripts/snapshot-contracts.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

The fake SDK now ratchets during getManyWithProof as the real one does,
so reading the version before the read fails the testnet case. A pinned
SDK and a contract missing from the answer are covered too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PastaPastaPasta
PastaPastaPasta merged commit 58c071a into master Nov 27, 2026
18 checks 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.

snapshot-contracts: its protocol-version check can never fail (the SDK is pinned)

1 participant