The assignment of immutable variables
in the constructor
is affected by the subsequent bytecode
#14049
Projects
immutable variables
in the constructor
is affected by the subsequent bytecode
#14049
Description
The assignment of
Immutable Variable
in theconstructor
function may be incorrectly assigned under the influence of subsequent inline assembly code (for examplemsotre
).Environment
Steps to Reproduce
The expected behavior of the following code is that
a
is0x4B20993Bc481177ec7E8f571
, but is eventually assigned the valuemsg.sender
.Reasons
The reason for the above problem is that, unlike other source code compilation results, the assignment of an
immutable -variable
is firstmstore
in thememory
area starting at0x80
, and thenmload
is used to save the variable to thestack
area after theconstructor
’s user code is executed, andmstore
is executed again aftercodecopy
to modify thebytecode
content.This means that the code after the
immutable-variable
assignment may still affect its execution logic. For example,mstore.
Impact
Through the collection of open-source projects, we can easily find a large number of functions that use the
mstore
operation.For example, the following code snippet
This means that mstore operations are common, and we need to be wary of such operations being called in
constructors
that haveimmutable variables
.Fix
We suggest giving some
warning
about the above problem in the compilation result to warning users of the above risk.The text was updated successfully, but these errors were encountered: