`keccak256()` in comptime context
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Abstract
Implement evaluation of `keccak256()` in comptime context.
While this is technically implementable without prerequisites, it won't be usable in practice without implementing at least stage 1 of #16420.
```solidity
contract C layout at uint(keccak256("my.contract.id")) {}
```
## Motivation
The goal is to allow the use of `keccak256()` builtin in `layout at` specifiers.
There are two layout base expressions in common use: [`erc7201`](https://eips.ethereum.org/EIPS/eip-7201) and plain hashing of a string using `keccak256()`. We're adding a builtin for the former in #15968, but for completeness we should also support the latter.
The main hurdle here is the return type. `keccak256()` returns `bytes32` while the layout base expressions must be integers. We also do not support type conversions in compile-time context so constant expressions of that type cannot be simply converted.
## Backwards Compatibility
Fully backwards-compatible.
Contributor guide
Assessment
This issue has not been assessed yet.