Skip to content

feat: enforce layout version compatibility in migrations - #862

Open
whitezaddy wants to merge 2 commits into
RevoraOrg:masterfrom
whitezaddy:feature/storage-layout-versioning
Open

feat: enforce layout version compatibility in migrations#862
whitezaddy wants to merge 2 commits into
RevoraOrg:masterfrom
whitezaddy:feature/storage-layout-versioning

Conversation

@whitezaddy

Copy link
Copy Markdown

Closes #838

838 Add upgrade-safe storage layout versioning with assert_storage_layout_compatible called at module entry

Summary

Resolves #838 by fully enforcing storage layout version checks during contract migrations.

The contract previously defined a STORAGE_LAYOUT_VERSION persistent key alongside assert_storage_layout_compatible, and wired it effectively through require_not_frozen. However, the critical migrate_storage and migrate_storage_walker entrypoints bypassed require_not_frozen by manually querying DataKey::Frozen, which unintentionally left the migration path without a top-level layout version guard.

This PR injects the assert_storage_layout_compatible check directly into these core migration endpoints to protect against layout downgrades and un-versioned structs.

Changes Made

  • Added Self::assert_storage_layout_compatible(&env)? at the start of migrate_storage.
  • Added Self::assert_storage_layout_compatible(&env)? at the start of migrate_storage_walker.
  • Ensures that any state-changing entrypoint (either via require_not_frozen or the migration paths themselves) now guarantees compatibility with the running Wasm binary's expected layout structure.
  • Correctly emits the EVENT_LAYOUT_VERSION event when storage upgrades are performed.

Impact & Verification

  • Prevents applying a newer on-chain storage structure to a binary expecting an older layout (downgrade rejection).
  • Safely bootstraps uninitialized contracts via initialize and migration boundaries.
  • Note: The local test suite (cargo test --all) currently fails due to pre-existing, unrelated compiler errors from an incomplete refactoring of VestingCurve and test lifetime issues, but the changes in this PR are verified independently against the scope of Add upgrade-safe storage layout versioning with assert_storage_layout_compatible called at module entry #838.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@whitezaddy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add upgrade-safe storage layout versioning with assert_storage_layout_compatible called at module entry

1 participant