Place re-entrancy lock immediately after used storage slots #2308
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
In storage, place re-entrancy locks immediately after the last used storage slot.
How I did it
Within
parser/global_context.py
, storage variables are stored inGlobalContext._globals
. The storage slot for each storage variable is determined fromlen(self._globals)
prior to adding the variable into the dict. Arrays, mappings, and other multiple-slot types are always assigned exactly one slot, but their actual location is calculated from aSHA3
operation (see #769 for more details).Re-entrancy locks start at slot
0xFFFFFF
and if more than this many storage variables are defined, a compile-time exception is raised.This PR sets the initial re-entrancy lock to location
len(self._globals)
- immediately after the last used storage slot. This works because globals are defined while parsing the module scope, but re-entrancy locks are defined when parsing the local scope of each function. Thus, there is no overlap and by the time we get to the locks we know with certainy the exact size of storage.How to verify it
Run tests.
Cute Animal Picture