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 versiontypeChoice:BaseType,PayableFunction,StateFunction,ViewFunction,PureFunctionorEventcontractAddress: the type library's addresssource: a Swarm hash of the source codetypes: the direct sub-fields, each withname,labeland arraydimensions([""]meansT[],["2","3"]meansT[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
removeis 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.