Open
Description
Variables can be declared constant
which allows:
- literals
- (arithmetic) expressions
- and function calls to "pure" functions, which is a hardcoded list of:
keccak256
,ecrecover
,sha256
,ripemd160
,addmod
,mulmod
,new
(for creating objects only, such as arrays)
Currently whenever a constant expression is used, the entire expression is placed into the output. This is of course reduced/optimised, but that is mostly restricted to operations on literals and some edge cases.
We should consider one or more of the following:
- split
constant
into two,constant
which only allows literals andconstexpr
which allows more complex expressions - do not allow "pure functions" above which result in a call (
ecrecover
,sha256
,ripemd160
) - allow every pure function, not only the above subset
- evaluate
constant
orconstexpr
in a VM during compilation time and use the result only (this VM could be a subset of the EVM, since many features are not required)
Obviously 2 and 3 contradict eachother. I would opt for 2. unless 4. is implemented and then 3. could be allowed.
Somewhat relevant is #715.