DCIPs/EIPS/eip-5568.md

69 lines
3.7 KiB
Markdown

---
eip: 5568
title: Revert Reason for Required Actions
description: Signal to wallets that an action is needed by returning a custom revert code
author: Gavin John (@Pandapip1)
discussions-to: https://ethereum-magicians.org/t/eip-5568-revert-signals/10622
status: Review
type: Standards Track
category: ERC
created: 2022-08-31
requires: 140
---
## Abstract
This ERC introduces a minimalistic machine-readable (binary) format to signal to wallets that an action needs to be taken by the user using a well-known revert reason. This custom revert reason contains just enough data to be extendable by future ERCs and to take in arbitrary parameters (up to 64 kB of data). Example use cases could include approving a token for an exchange, sending an HTTP request, or requesting the user to rotate their keys after a certain period of time to enforce good hygiene.
## Motivation
Oftentimes, a smart contract needs to signal to a wallet that an action needs to be taken, such as to sign a transaction or send an HTTP request to a URL. Traditionally, this has been done by hard-coding the logic into the frontend, but this ERC allows the smart contract itself to request the action.
This means that, for example, an exchange or a market can directly tell the wallet to approve the smart contract to spend the token, vastly simplifying the front-end code.
## Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
### Custom Revert Reason
To signal an action needs to be taken, a compliant smart contract MUST revert with the following error:
```solidity
error WalletSignal24(uint24 instruction_id, bytes instruction_data)
```
The `instruction_id` of an instruction defined by an ERC MUST be its ERC number unless there are exceptional circumstances (be reasonable). An ERC MUST define exactly zero or one `instruction_id`. The structure of the instruction data for any `instruction_id` MUST be defined by the ERC that defines the `instruction_id`.
### Responding to a Revert
Before submitting a transaction to the mempool, it MUST be evaluated locally. If it reverts and the revert signature matches the custom error, then the following applies.
The `instruction_id`, and `instruction_data` MUST be parsed from the revert data. The instruction SHOULD be evaluated as per the relevant ERC. If the instruction is not supported by the wallet, it MUST display an error to the user indicating that is the case. The wallet MUST then re-evaluate the transaction, except if an instruction explicitly states that the transaction MUST NOT be re-evaluated.
If an instruction is invalid, or the `instruction_id`, and `instruction_data` cannot be parsed, then an error MUST be displayed to the user indicating that is the case. The transaction MUST NOT be re-evaluated.
## Rationale
This ERC was explicitly optimized for deployment gas cost and simplicity. It is expected that libraries will eventually be developed that makes sending and receiving these well-known reverts more developer-friendly.
## Backwards Compatibility
### Human-Readable Revert Messages
See [Revert Reason Collisions](#revert-reason-collisions).
### [ERC-3668](./eip-3668.md)
ERC-3668 can be used alongside this ERC, but it uses a different mechanism than this ERC.
## Security Considerations
### Revert Reason Collisions
It is unlikely that the signature of the custom error matches any custom errors in the wild. In the case that it does, no harm is caused unless the data happen to be a valid instruction, which is even more unlikely.
## Copyright
Copyright and related rights waived via [CC0](../LICENSE.md).