Disallow initialisation of a constant variable with a contract code (runtime or create) inside the contract itself.
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Prerequisites
It is possible to define a constant variable which stores a creation or runtime code of a contract.
## Description
This behavior is correct, but the implementation does not verify that the variable stores a contract code in which the variable is being defined. It creates a circular dependencies. This results with no error during syntactic analysis, but results with an ICE during code geneneration stage.
## Environment
- Compiler version: 0.8.31
- Compilation pipeline (legacy, IR, EOF): legacy, IR
- Target EVM version (as per compiler settings): default
- Framework/IDE (e.g. Foundry, Hardhat, Remix): all
- EVM execution environment / backend / blockchain client: ?
- Operating system: Tested on Macos but probably everywhere.
## Steps to Reproduce
```solidity
contract A {
bytes constant public code = type(A).creationCode;
}
```
```
Unhandled exception during test: /solidity/libsolidity/codegen/CompilerContext.cpp(255): Throw in function std::shared_ptr solidity::frontend::CompilerContext::compiledContract(const ContractDefinition &) const
Dynamic exception type: boost::wrapexcept
std::exception::what: Compiled contract not found.
[solidity::util::tag_comment*] = Compiled contract not found.
```
Contributor guide
Research direction
Reproduce the issue with the Solidity contract shown, then inspect solidity/libsolidity/codegen/CompilerContext.cpp around line 255 and the related semantic-analysis and code-generation paths. Done means the self-referential constant contract-code initialization is rejected with a diagnostic rather than reaching an internal compiler error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100