argotorg / argotorg/solidity

Promote custom errors to proper types.

Open
#15,388 0 comments 1 reaction 0 assignees View on GitHub
high effort medium impact selected for development
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

We already introduced the ability to use custom errors as second argument for ``require``.
Ultimately, we can treat custom errors as regular types that can be stored in local variables and passed to functions like normal arguments. This could be done either by introducing a separate type for each custom error or by introducing a generic type ``error`` - in either case the value would be encoded as a ``bytes memory`` containing the abi-encoding of the error. Conceptually, that's also what already happens for "require with custom error".

Moving further in this direction will take some work, since it involves thinking about all explicit and implicit conversion behaviour of the new custom error type (as well as the question whether it should be one or several types still needs to be settled).

However, we can already continue in this direction by allowing an explicit conversion from calls to error constructors to ``bytes memory``.

So as a next step we can allow:

```
error CustomError(uint);
function f() public {
bytes memory errorEncoding = bytes(CustomError(42));
}
```

this would solve the use case of https://github.com/ethereum/solidity/pull/14974#issuecomment-2324307483, resp. would supersede https://github.com/ethereum/solidity/issues/14287

The specification for this first step would be:
Calls to error constructors can still *only* occur in revert statements, as second argument to require, and (with this change) also as arguments to a type conversion call to ``bytes``. The resulting type would be ``bytes memory``.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing custom-error handling for require and the behavior described in pull request #14974 and issue #14287. Check how error-constructor calls are currently restricted, then validate the first-step specification: conversion to bytes memory is accepted while other contexts remain rejected.

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
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.