-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Disallow oversized types in storage #16491
Copy link
Copy link
Open
Labels
breaking change ⚠️low effortThere is not much implementation work to be done. The task is very easy or tiny.There is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.Changes are not very noticeable or potential benefits are limited.must have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.
Metadata
Metadata
Assignees
Labels
breaking change ⚠️low effortThere is not much implementation work to be done. The task is very easy or tiny.There is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.Changes are not very noticeable or potential benefits are limited.must have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.
Type
Projects
Status
Optional
Abstract
The compiler warns when a type is so large that collisions with another variable in storage become likely (>=
2**64slots):However, the user can still ignore the warning and use the type. Turn the warning into a hard error.
Motivation
The only hard limit is that all the storage variables taken together must not exceed the size of storage, but that only applies to the static part of the layout. Dynamic arrays or mappings allow bypassing it, because storage is assumed to be zeroed and pushing a new empty item has a very low, constant cost. This is a source of odd corner cases and bugs while having very little real-life application.
For example, if you declare a dynamic array where each item occupies half of storage, all odd elements or all even elements of the array overlap in storage. Modifying one, modifies the others. This is perfectly fine taking into account circular nature of storage, but may be surprising to users even if they find a use case for something like this.
When implementing
deletefor such an array, you have to be careful to avoid length overflowing to zero (which is an actual bug: #16481). It also played a factor in #15587, where the bug was reproducible without inline assembly only due to the fact that one can declare enormous arrays.Specification
Backwards Compatibility
This is a breaking change.