---
eip: 8074
label: ERC-8074
title: Self-Describing Bytes via EIP-712 Selectors
status: Draft
type: Standards Track
category: ERC
created: 2025-10-30
requires: 712
official: https://eips.ethereum.org/EIPS/eip-8074
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8074.md
canonical: https://eips.huatuo.xyz/ja/eip-8074/
lang: ja
tldr: 汎用の bytes パラメーター内のデータに、EIP-712 の型文字列から得た 4 バイトのセレクターと DataList ラッパーでタグを付け、コントラクトが複数種類のペイロードを認識してデコードできるようにする。
tags: [abi, encoding, eip-712, extensibility, bytes]
---

# ERC-8074: Self-Describing Bytes via EIP-712 Selectors

> Defines a convention for self-describing structured data in `bytes` parameters using 4-byte selectors derived from EIP-712 type strings.

**TL;DR:** 汎用の bytes パラメーター内のデータに、EIP-712 の型文字列から得た 4 バイトのセレクターと DataList ラッパーでタグを付け、コントラクトが複数種類のペイロードを認識してデコードできるようにする。

## 何を解決するのか

多くのインターフェースは、拡張性のために末尾に `bytes data` パラメーターを持ちます。[ERC-721](/eip-721/) と [ERC-1155](/eip-1155/) の `safeTransferFrom` や、[ERC-5750](/eip-5750/) の一般的なパターンがそうです。その中身はアドホックです。受け取るコントラクトはデコード方法を推測しなければならず、複数種類のペイロードを簡単に受け付けることもできず、コントラクト間で転送されたペイロードは、それぞれに異なる解釈をされるかもしれません。

ERC-8074 は、バイト列が自分が何であるかを示すための、ごく小さな取り決めを追加します。

## 仕組み

**単一のペイロード**

- 構造体の正規の [EIP-712](/eip-712/) 型文字列を用意します。例: `TransferNote(bytes32 reference,string comment,uint256 deadline)`
- そのセレクターは `bytes4(keccak256(typeString))` で、この例では `0xf91f3a24` です。
- エンコードは `selector ++ abi.encode(fields...)` です。

**複数のペイロード**

- `DataList(bytes[] items)`（セレクター `0xae74f986`）で包みます: `0xae74f986 ++ abi.encode(items)`
- 各 item は、それ自体が有効な単一のペイロードでなければなりません。

**デコードのルール**

- 先頭の 4 バイトを読みます。それが `0xae74f986` なら `bytes[]` をデコードし、各 item を処理します。
- 既知のセレクターなら、残りをその構造体としてデコードします。
- 未知のセレクターは**無視しなければなりません（must）**。順序は問いません。生成側は重複を避けるべきです。

この ERC を知らないコントラクトは、ペイロードを不透明なバイト列として扱い続けられます。

## サンプルコード

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract NoteReceiver {
    bytes4 constant TRANSFER_NOTE =
        bytes4(keccak256("TransferNote(bytes32 reference,string comment,uint256 deadline)")); // 0xf91f3a24
    bytes4 constant DATA_LIST = bytes4(keccak256("DataList(bytes[] items)"));                 // 0xae74f986

    event Note(bytes32 reference, string comment, uint256 deadline);

    function encodeNote(bytes32 ref, string calldata c, uint256 d) external pure returns (bytes memory) {
        return abi.encodePacked(TRANSFER_NOTE, abi.encode(ref, c, d));
    }

    function handle(bytes calldata data) public {
        if (data.length < 4) return;
        bytes4 sel = bytes4(data[:4]);
        if (sel == DATA_LIST) {
            bytes[] memory items = abi.decode(data[4:], (bytes[]));
            require(items.length <= 8, "too many items");
            for (uint256 i = 0; i < items.length; i++) this.handle(items[i]);
        } else if (sel == TRANSFER_NOTE) {
            (bytes32 r, string memory c, uint256 d) = abi.decode(data[4:], (bytes32, string, uint256));
            emit Note(r, c, d);
        }
        // unknown selectors: ignore
    }
}
```

## 知っておくべきこと

- ステータスは **Draft** です。
- `DataList` を解析する際は処理量に上限を設けてください。仕様は、最大 8 item・合計 8 KB などの制限や、期待するセレクターがすべて見つかった時点で打ち切ることを提案しています。
- 4 バイトのセレクターが識別するのは*型*であって、信頼できる送信者ではありません。重要な場合は、データを別途（たとえば EIP-712 署名で）認証してください。
- 型文字列は正規の EIP-712 形式（カンマの後にスペースなし、パラメーター名は正確に）でなければ、セレクターが一致しません。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-8074
