refactor(contracts): separate v4/v5 init slot clearing in L2ContractsManagerUtils#19797
Open
refactor(contracts): separate v4/v5 init slot clearing in L2ContractsManagerUtils#19797
Conversation
maurelian
commented
Mar 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #19797 +/- ##
==========================================
+ Coverage 75.4% 80.4% +5.0%
==========================================
Files 194 139 -55
Lines 11286 7258 -4028
==========================================
- Hits 8519 5842 -2677
+ Misses 2623 1416 -1207
+ Partials 144 0 -144
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…ManagerUtils The v4 and v5 initialization clearing paths were interleaved, making the code hard to follow and causing a redundant SSTORE when _slot == v5Slot. Separate them into distinct blocks and add a validation that v5 offset must be 0.
7395c34 to
f5ffd51
Compare
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.
Summary
if (_slot != v5Slot)block, v5 path runs unconditionally belowL2ContractsManager_InvalidV5Offsetrevert when v5 slot is passed with a non-zero offset_offset(previously untested) and the new v5 offset validationMotivation
The previous code always ran both v4 and v5 clearing logic, relying on implicit no-ops for the version that doesn't apply. When
_slot == v5Slot, this caused a redundant SSTORE and a confusing re-read of a slot that was just written to. The refactored version is semantically identical but easier to reason about.Test plan
L2ContractsManagerUtils_UpgradeToAndCall_Testtests passtest_upgrade_v4NonZeroOffset_succeeds— exercises offset=2 bit-shiftingtest_upgrade_v4InitializingNonZeroOffset_reverts— revert with offset=2test_upgrade_v5InvalidOffset_reverts— validates new offset guard