fix: uninitialized immutable values#3409
Merged
charles-cooper merged 19 commits intoMay 18, 2023
Merged
Conversation
immutable variables can be read before assignment in constructor code, and their memory location is accessed, but that memory might not yet be initialized. prior to this commit, its value is not necessarily `empty(type)` since memory could have been written to ephemerally. in particular, `create_copy_of` (and its sister, `create_from_blueprint`) use `msize` to determine a starting location for where to copy the target bytecode into memory, while the immutables section start is determined using the static memory allocator. in case that `msize` is still less than the immutables section end, `create_copy_of` can write to the immutables section, thereby resulting in reads from the immutables section to return garbage. this commit fixes the issue by issuing an `mload <immutables_section_end>` before executing any initcode, which forces `msize` to be initialized past the end of the immutables section (and therefore, accessing an immutable before it is initialized in the constructor will produce the "expected" `empty()` value for the immutable). note that a corresponding `mload` is not required for runtime code, because vyper requires all memory variables to be instantiated at the declaration site, so there is no way that msize can produce a pointer to an uninitialized memory variable.
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## master #3409 +/- ##
==========================================
+ Coverage 89.09% 89.17% +0.08%
==========================================
Files 84 84
Lines 10763 10765 +2
Branches 2452 2453 +1
==========================================
+ Hits 9589 9600 +11
+ Misses 781 771 -10
- Partials 393 394 +1
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
fubuloubu
approved these changes
May 15, 2023
fubuloubu
approved these changes
May 18, 2023
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.
What I did
fix #3101
How I did it
ensure msize is initialized past end of immutables section before entering the constructor.
How to verify it
the provided test cases fail on master (97ff017) but not on this branch.
Commit message
Description for the changelog
Cute Animal Picture