Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP-5568: Required Action Signals Using Revert Reasons #5568

Merged
merged 13 commits into from Nov 2, 2022
70 changes: 70 additions & 0 deletions EIPS/eip-5568.md
@@ -0,0 +1,70 @@
---
eip: 5568
title: Required Action Signals Using Revert Reasons
description: Signal to wallets that an action is needed by returning a custom revert code
author: Pandapip1 (@Pandapip1)
discussions-to: https://ethereum-magicians.org/t/eip-5568-revert-signals/10622
status: Draft
type: Standards Track
category: Interface
created: 2022-08-31
requires: 140
---

## Abstract

This EIP 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 EIPs 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 EIP 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 send a signal to a wallet, a compliant smart contract MUST revert with the following error:

```solidity
error WalletSignal24(uint8 number_hint, uint24 instruction_id, bytes instruction_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if error is a proper solidity here. I wonder if there is a typo here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is proper solidity as of 0.8.4: https://blog.soliditylang.org/2021/04/21/custom-errors/

```

The `number_hint` is an estimate of the number of signals that will be sent after the current signal. If a guess is availabe, `number_hint` MUST be that estimate. If a guess is unavailable, `number_hint` MUST be `0`.

The `instruction_id` of an instruction defined by an EIP MUST be its EIP number unless there are exceptional circumstances (be reasonable). An EIP MUST define exactly zero or one `instruction_id`. The structure of the instruction data for any `instruction_id` MUST be defined by the EIP that defines the `instruction_id`.

### Signal Response

Before submitting a transaction to the mempool, it MUST be evaluated locally. If it reverts and the revert signature matches the custom error, then it MUST be treated as a signal. (It is RECOMMENDED for wallets to show a warning if the transaction reverts, even if the revert is not a signal).

The `number_hint`, `instruction_id`, and `instruction_data` MUST be parsed from the revert data. It is RECOMMENDED for wallets to show a progress indicator using the `number_hint`. The instruction SHOULD be evaluated as per the relevant EIP. 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 `number_hint`, `instruction_id`, and `instruction_data` cannot be parsed, then an error MUST be displayed to the user indicating that is the case.

## Rationale

This EIP was explicitly optimized for deployment gas cost and simplicity. It is expected that libraries will eventually be developed that makes sending and receiving signals more developer-friendly.

## Backwards Compatibility

### Human-Readable Revert Messages

See [Revert Reason Collisions](#revert-reason-collisions).

### [EIP-3668](./eip-3668.md)

EIP-3668 can be used alongside this EIP, but it uses a different mechanism than this EIP.

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