Skip to content

keccak256() in comptime context #16421

@cameel

Description

@cameel

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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    low effortThere is not much implementation work to be done. The task is very easy or tiny.medium impactDefault level of impactmust have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions