argotorg / argotorg/solidity

Constant expression evaluation at compile time

Open
#3,157 11 comments 5 reactions 0 assignees View on GitHub
epic effort high impact needs design selected for development
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

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:
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.

Contributor guide

Open the contributing guide

Research direction

No source files, tests, or entry points are named. Read the discussion and related issue #715, then determine which proposed constant-expression approach has been accepted; done requires a settled design and clear validation targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
blockchain, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.