fix(escrow): implement explicit legacy version and migration checks - #1249
Open
onyekachi66 wants to merge 1 commit into
Open
fix(escrow): implement explicit legacy version and migration checks#1249onyekachi66 wants to merge 1 commit into
onyekachi66 wants to merge 1 commit into
Conversation
|
@onyekachi66 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1216
Approach
This PR addresses the correctness and security gap where older storage lacking a version marker could corrupt live escrow state if its layout was incorrectly guessed. We introduce an explicit
LEGACY_VERSION(5) and a typed errorEscrowError::AmbiguousLegacyStorage(93). Themigratefunction now explicitly detects the absence of a version marker and verifies if the storage matches the known legacy layout (by checking for the existence ofDataKey::FundingTokenandDataKey::Treasury). If it doesn't match the known legacy layout, the ambiguous storage is rejected withAmbiguousLegacyStorage.Test Evidence
We have added focused unit and integration coverage for the new behavior in
escrow/src/tests/migration_errors.rs, covering every requested edge case:test_known_legacy_layout_migrationtest_ambiguous_legacy_storage_missing_markertest_unknown_markertest_migration_repeatedtest_partial_migrationAll existing tests pass with no regressions, and the new checks maintain atomic, bounded state changes with no dead code.
Security Notes
has(&DataKey::FundingToken)andhas(&DataKey::Treasury)as the heuristic to identify a fully initialized V5 known legacy layout. If those keys are absent on a markerless instance, we reject it as ambiguous rather than guessing its layout, preventing corruption.AmbiguousLegacyStorageerror is structured, stable, and does not leak internal details.migrateremain intact and precede the new version marker logic, ensuring safe concurrent invocation and replay resistance.