argotorg / argotorg/solidity

Disallow adding `indexed` on complex/dynamic types in events

Open
#16,417 9 comments 1 reaction 1 assignee Claimed by @nikola-matic View on GitHub
breaking change :warning: feature
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Abstract

It is currently possible to add the `indexed` keyword to event variables that have a complex or dynamic type. According to the [documentation on this](https://docs.soliditylang.org/en/latest/abi-spec.html?utm_source=chatgpt.com#events), this will be translated into adding a new topic with the hash of that variable. This makes sense because complex/dynamic types are potentially more than one word, while a topic is only one word.

The problem comes from a common usage of the `indexed` keyword, that is: spend a bit more gas to ensure indexing by nodes directly. That mental model is wrong though with complex/dynamic types, as noted above, because then the variable cannot be retrieved, only the hash can be retrieved from logs. This can create real issues, where an (immutable) smart contract is first developed with an indexed complex/dynamic type and then when fetching data is later needed, users/integrators realize that it's not possible.

## Motivation

Prevent complex/dynamic types from being indexed. Indexing the hash of that variable is still possible in Solidity, and an entire class of errors is completely prevented.

## Specification

Throw an error when a complex/dynamic type is indexed.

## Backwards Compatibility

Old contracts may not compile, but the error message could explain how to adapt them. The error could come with an explanation along the lines of: "Values of more than 32 bytes cannot be natively indexed, the `indexed` keyword should be removed from this field. In case indexing is needed, consider also adding an extra `indexed` event field with the hash of that value."

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.