EIPs Explained

ERC-1900 · Stagnant · ERC · 2019-03-28

ERC-1900: dType - Decentralized Type System for EVM

dType proposes an on-chain registry of Solidity types (structs and their libraries) so projects can share data definitions and tools can decode data consistently.

What problem does it solve?

Every project on Ethereum defines its own structs, even when they describe the same thing. Two protocols that both have a "balance" or "token amount" type cannot pass data to each other without custom glue, and block explorers have to be told each contract's ABI separately to decode it.

dType ("decentralized type system") proposes a shared, on-chain Type Registry. A type is registered once with enough metadata to rebuild its ABI, and anyone can reuse it, compose it into bigger types, or decode data that uses it.

How it works

Type library. Each type is defined by a Solidity library containing the struct plus helpers such as isInstanceOf (validation), structureBytes / destructureBytes (encode and decode), and higher-order functions like map, filter and reduce. Types can contain other types, always forming a directed acyclic graph.

Registry record. For each type, the registry stores:

  • name: the Solidity type name, optionally with a version
  • typeChoice: BaseType, PayableFunction, StateFunction, ViewFunction, PureFunction or Event
  • contractAddress: the type library's address
  • source: a Swarm hash of the source code
  • types: the direct sub-fields, each with name, label and array dimensions ([""] means T[], ["2","3"] means T[2][3])

A record's identifier is keccak256(abi.encodePacked(name)). The interface offers insert, remove, count, get, getByIdentifier, getTypeIdentifier and isRegistered, with LogNew / LogUpdate / LogRemove events.

Composition example from the spec. myBalance = (string accountName, uint256 amount) and myToken = (address token, myBalance balance) give myToken the ABI tuple (address,(string,uint256)).

Sample code

The registry metadata for the composed type (JSON):

{
  "typeChoice": 0,
  "contractAddress": "0x...",
  "source": "0x...",
  "name": "myToken",
  "types": [
    { "name": "address",   "label": "token",   "dimensions": [] },
    { "name": "myBalance", "label": "balance", "dimensions": [] }
  ]
}

A trimmed version of the registry interface:

interface IDType {
    enum TypeChoices { BaseType, PayableFunction, StateFunction, ViewFunction, PureFunction, Event }
    struct dTypes { string name; string label; string[] dimensions; }
    struct dType  { TypeChoices typeChoice; address contractAddress; bytes32 source;
                    string name; dTypes[] types; }

    event LogNew(bytes32 indexed identifier, uint256 indexed index);

    function insert(dType calldata data) external returns (bytes32 identifier);
    function get(string memory name) external view returns (dType memory);
    function isRegistered(bytes32 identifier) external view returns (bool);
}

Things to know

  • Status: Stagnant. It was written against Solidity 0.5 with the then-experimental ABIEncoderV2, and test cases were never added.
  • Governance (who may add or remove types) and permissions are explicitly out of scope; the authors suggest not supporting updates, and note that remove is risky.
  • Using a plain name as the key invites name squatting; the spec only suggests disallowing single English words at first.
  • It was designed as the first step of a larger vision (typed storage, function registries) described in follow-up proposals outside the current EIP index.

#types #registry #abi #solidity #interoperability

Details

Authors
Loredana Cirstea (@loredanacirstea), Christian Tzurcanu (@ctzurcanu)
Status
Stagnant
Type
Standards Track / ERC
Created
2019-03-28
Required by

Machine-readable: Markdown · JSON