Skip to content

Constant expression evaluation at compile time #3157

Open
@axic

Description

@axic

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:

  1. split constant into two, constant which only allows literals and constexpr which allows more complex expressions
  2. do not allow "pure functions" above which result in a call (ecrecover, sha256, ripemd160)
  3. allow every pure function, not only the above subset
  4. evaluate constant or constexpr 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic effortMulti-stage task that may require coordination between team members across multiple PRs.high impactChanges are very prominent and affect users or the project in a major way.needs designThe proposal is too vague to be implemented right awayselected for developmentIt's on our short-term development

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions