home / skills / multiversx / mx-ai-skills / diff_review
This skill helps you analyze diffs between versions of smart contracts, emphasizing upgradeability, regression testing, and data flow integrity.
npx playbooks add skill multiversx/mx-ai-skills --skill diff_reviewReview the files below or copy the command above to add this skill to your agents.
---
name: diff_review
description: Reviewing changes between versions of SCs (Upgradeability checks).
---
# Differential Review
This skill helps you analyze the difference between two versions of a codebase, focusing on security implications of changes.
## 1. Upgradeability Checks (MultiversX)
When reviewing a diff between `v1` and `v2` of a Smart Contract:
- **Storage Layout**:
- *Critical*: Did the order of fields in a `struct` stored in a `VecMapper` or `SingleValueMapper` change?
- *Result*: Usage of existing data will interpret bytes incorrectly (Memory Corruption).
- *Fix*: Append new fields to the end of structs, never reorder.
- **Initialization**:
- *Critical*: Does `v2` introduce new Storage Mappers?
- *Check*: Are they initialized in `#[upgrade]`? (Remember `#[init]` is NOT called on upgrade).
## 2. Regression Testing
- **New Features**: Do they break old invariants?
- **Deleted Code**: Was a check removed? Why?
## 3. Workflow
1. **Generate Diff**: `git diff v1..v2`.
2. **Filter Noise**: Ignore formatting/style changes.
3. **Trace Data**: Follow the flow of changed data structures.
This skill analyzes differences between two codebase versions with a focus on smart contract upgradeability and security impacts. It highlights storage layout changes, initialization gaps, and regression risks so maintainers can spot breaking upgrades quickly. The guidance is practical and oriented to actionable checks and fixes.
The skill inspects diffs to identify changes to storage structs, mappers, and initialization logic. It flags reordered or newly added fields in persisted structs, missing upgrade-time initialization for new storage mappers, and deletions that remove important checks. It also helps filter noise and trace data flows to assess behavioral regressions.
What exactly breaks if struct field order changes?
Reordering fields causes existing stored bytes to map to the wrong fields, creating memory corruption and incorrect state interpretation.
How do I ensure new storage mappers are safe on upgrade?
Add explicit initialization in the upgrade handler (#[upgrade]) and include regression tests that exercise the new mappers against existing state.