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 function and revert reason. It provides 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 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.

Action Detection

interface IERC5568 {
    function walletSignal24(bytes32 selector, bytes function_data) view returns (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.

To indicate that an action needs to be taken, return the instruction_id and instruction_data. To indicate no actions need to be taken, set instruction_id to be 0 and instruction_data to any value.

Custom Revert Reason

To signal an action was not taken, a compliant smart contract MUST revert with the following error:

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, the walletSignal24 function MUST be simulated locally. It MUST be treated as if it were a non-view function capable of making state changes (e.g. CALLS to non-view functions are allowed). If the resulting instruction_id is nonzero, an action needs to be taken.

The instruction_id, and instruction_data MUST be taken from the walletSignal24 simulation. 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 this more developer-friendly.

ERC-165 is not used, since the interface is simple enough that it can be detected simply by calling the function.

Backwards Compatibility

Human-Readable Revert Messages

See Revert Reason Collisions.

ERC-3668

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 and related rights waived via CC0.