Allow reverting with signature `error Panic(uint)`
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
Currently, solidity doesn't allow defining errors with the following names `Panic` and `Error` (note: name, not signature).
There are use cases where reverting with this error would be useful.
One example is in library fixed point implementation. When adding two fixed point numbers overflows, then it's useful to revert with `Panic(0x11)` to be consistent with how the compiler would revert in such cases. ([List of error codes](https://github.com/ethereum/solidity/blob/develop/libsolutil/ErrorCodes.h), or [Docs](https://docs.soliditylang.org/en/v0.8.7/control-structures.html#panic-via-assert-and-error-via-require))
---
Possible solutions
1. @chriseth suggested allowing something like `import Panic from std.errors`.
2. Allow defining errors with signature `Panic(uint)` and `Error(string)`.
3. Use inline assembly to mimic the error: no need for the compiler to do anything
4. Use a collision hack. Find `(uint)` with the same hash as `Panic(uint)` and similarly for `Error(string)`.
Contributor guide
Research direction
The issue names no source files, tests, or entry points. Start by comparing the four proposed approaches and the compiler's handling of the reserved Panic and Error names; the work is done when one approach is agreed, implemented, and covered by appropriate compiler tests.
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
- 30/100