EIPs Explained

ERC-6865 · Draft · ERC · 2023-04-10

ERC-6865: On-Chain EIP-712 Visualization

Lets the contract that will consume an EIP-712 signature explain it: a view function returns which assets the user gives up, receives, and for how long, so wallets can show a clear summary before signing.

What problem does it solve?

EIP-712 typed signatures power gasless approvals, NFT marketplace listings and many DeFi orders. Wallets show the raw typed fields, which most users cannot interpret: an innocent-looking "Order" may hand over valuable NFTs for nothing. Phishing sites exploit this.

Wallets could try to decode each protocol off-chain, but that does not scale (too many protocols), is error-prone (misreading the logic is worse than showing nothing) and goes stale when protocols upgrade.

ERC-6865 shifts the job to the protocol: the contract that verifies the signature also exposes a function describing what the signature would do to the user's assets.

How it works

The verifyingContract named in the EIP-712 domain implements:

function visualizeEIP712Message(bytes memory encodedMessage, bytes32 domainHash)
    external view returns (Result memory);
  • encodedMessage is the typed message ABI-encoded with abi.encode.
  • domainHash is the EIP-712 domain separator hash, so the contract can reject versions or protocols it does not support.

It returns:

struct Liveness { uint256 from; uint256 to; }               // validity window (timestamps)
struct UserAssetMovement {
    address assetTokenAddress;  // ERC-20/721/1155 address; address(0) = native ETH
    uint256 id;                 // NFT id (ignored for fungibles)
    uint256[] amounts;          // amount at `from` ... amount at `to`
}
struct Result {
    UserAssetMovement[] assetsIn;   // minimum the user receives
    UserAssetMovement[] assetsOut;  // maximum the user gives
    Liveness liveness;
}

amounts is an array so time-varying prices, such as Dutch auctions, can be expressed: the first entry is the amount at liveness.from, the last at liveness.to. Usually it has one entry.

When asked to sign (eth_signTypedData), a wallet calls this function on the chainId and verifyingContract from the domain and renders "You give X, you receive at least Y, valid until Z". If the domain lacks those fields, wallets should ignore this proposal.

Sample code

Wallet-side call (ethers v6):

import { AbiCoder, Contract, JsonRpcProvider, TypedDataEncoder } from "ethers";

const abi = [
  "function visualizeEIP712Message(bytes encodedMessage, bytes32 domainHash) view returns " +
  "((address assetTokenAddress,uint256 id,uint256[] amounts)[] assetsIn," +
  " (address assetTokenAddress,uint256 id,uint256[] amounts)[] assetsOut," +
  " (uint256 from,uint256 to) liveness)",
];

async function preview(rpcUrl: string, domain: any, encodedMessage: string) {
  const provider = new JsonRpcProvider(rpcUrl);
  const verifier = new Contract(domain.verifyingContract, abi, provider);
  const domainHash = TypedDataEncoder.hashDomain(domain);

  const r = await verifier.visualizeEIP712Message(encodedMessage, domainHash);
  for (const a of r.assetsOut) console.log("You give:", a.assetTokenAddress, a.id, a.amounts);
  for (const a of r.assetsIn)  console.log("You get :", a.assetTokenAddress, a.id, a.amounts);
  console.log("Valid:", new Date(Number(r.liveness.from) * 1000), "→", new Date(Number(r.liveness.to) * 1000));
}
// encodedMessage is built per protocol with AbiCoder.defaultAbiCoder().encode([...types], [...values])

Things to know

  • Status: Draft. The interface may still change, and wallet support should not be assumed.
  • The result is only as trustworthy as the verifyingContract. A malicious contract can return a reassuring but false summary, so wallets should weigh it by the contract's reputation and not treat it as proof of safety.
  • Already-deployed, non-upgradeable protocols cannot add the function; the spec mentions a possible future registry for those.
  • EIP-5267 (retrieving a contract's EIP-712 domain) is a complementary building block for wallets.

#eip712 #signatures #wallets #security #ux

Details

Authors
Abderrahmen Hanafi (@a6-dou)
Status
Draft
Type
Standards Track / ERC
Created
2023-04-10
Requires

Machine-readable: Markdown · JSON