ERC-2157 dType storage registry extension standard (dType Storage Extension - Decentralized Type System for EVM)

Stagnant · Other · created 2019-06-28

An extension proposal to ERC-1900. It standardizes the ABI of storage contracts so that anyone can store and look up data for the decentralized type system dType in the same way.

Why it is needed

Ethereum currently has no standard for determining where public data is stored. While ERC-1900 standardized the type definitions themselves, where the actual data instances of that type are stored, which contract and which path, varies by project. As a result, finding data externally is limited to relying on a centralized cache such as a blockchain explorer, or directly analyzing the blockchain to find contracts that use a particular type. This approach also blocks on-chain interoperability that would standardly reference data paths. For example, even if a marketplace contract wants to fetch data for a particular product type, there is no fixed rule for where that data is stored, so custom lookup logic must be written from scratch each time.

What to implement

In depth

What the TypeRootContract does

ERC-1900 has a contractAddress field in its type metadata, which originally held the type definition library address. This proposal redefines that field to hold the address of a TypeRootContract instead. The TypeRootContract is a simple contract holding only two values: libraryAddress (the ERC-1900 type definition library address) and storageAddress (the address of the storage contract holding the type data). This lets anyone look at a type's registry entry and immediately find where its definition code and its actual data each live.

The CRUD pattern of the TypeStorageContract

The TypeStorageContract follows the Solidity CRUD pattern and is defined with a common ABI comprising the functions insert, insertBytes, remove, update, isStored, getByHash, getByIndex, and count. insert takes the struct value from the type library as is, while insertBytes takes data encoded as bytes. Because every storage contract implements this ABI identically, any type's data can be handled with the same function names and signatures.

How is the primary identifier determined

Each record's primary identifier is not an arbitrarily assigned value; it is computed by the type library's getIdentifier function based on the actual values of the type instance. Instances with the same values always get the same identifier, so the data path is deterministic and anyone can locate the same record the same way.

typeIndex and index-based lookup

Storage keeps the identifiers of records in order in a bytes32 array called typeIndex, and each record also carries a monotonically increasing index number. getByHash looks up a record by identifier and getByIndex by this index number, so the full set of records can be iterated and retrieved even without knowing the identifier. The count function reports the total number of records stored.

Why a separate contract was pulled out instead of extending the registry

Rather than adding a storage contract address field to the dType registry itself, a separate TypeRootContract was introduced because it makes it easier to change the interface in the future and is more extensible. It also lets dType itself and all TypeStorage contracts share the same storage pattern, lowering the cost of writing, testing, and auditing code.

Backwards compatibility, implementation status, and current status

This proposal does not affect existing Ethereum standards or implementations, but it uses ABIEncoderV2, which was experimental at the time. Test cases have not yet been written, and it states that a work-in-progress implementation exists in the pipeos-one/dType repository and will be updated once consensus on the specification is reached. This proposal is currently Stagnant, a draft that stalled without further progress or finalization.

Original ERC · ← ERCs