ERC-1921 dType function registration extension (dType Functions Extension)

Stagnant · Other · created 2019-04-06

Registers a smart contract's pure and view functions in the dType registry together with their input and output types and contract address, enabling automation tools to find, chain, and execute the functions.

Why it is needed

The dType registry proposed by EIP-1900 allows data types to be registered and looked up, but there was no way to register the functions that use those types. This made it difficult to automatically find and execute functions on the blockchain, or to chain and combine them with one another. Services such as block explorers, smart contract IDEs, and security analysis tools also each had to collect and manage a contract's ABI information separately, and it was not easy to pick out a single verified function from an already deployed contract for reuse or focused auditing. Without a commonly referenceable function registry, improving even a small piece of logic required redeploying the entire contract, making it easy for duplicated, unverified code to accumulate in chain state.

What to implement

In depth

Addition of the outputs field

This proposal adds an outputs field to EIP-1900's type registration definition. Previously, only a function's input types (types) could be registered; this extends registration to include output types as well. It is limited to pure or view functions that do not change state. Each function is registered in the dType registry with the fields name (unique function name, required), types (input types and labels, required), outputs (output types and labels, required), contractAddress (the contract address where the function resides, optional for interfaces), and source (a bytes32 reference pointing to the function's source code, optional).

Example of a function registration object

The original text gives an example object registering a function called setStaked. name is "setStaked", types consist of a single input of type TypeA, outputs consist of a single output of type TypeB, and the object also includes contractAddress, source, and typeChoice values. This object is passed directly to a call to <dType registry>.insert({...}) and recorded in the registry. Since the input and output types reference types already registered in the registry, there is no need to fully describe the ABI information anew for every function.

The setOutputs Function

setOutputs(bytes32 identifier, dTypes[] memory outputs) is a public function that sets the list of output types for the identifier of an already registered type. identifier is the type identifier defined in EIP-1900, and outputs is the dTypes array defined in EIP-1900. Output type information can be added or updated even after a function has been registered.

Implementation Suggestion: the outputs Mapping

The dType registry implementation suggests storing outputs as mapping(bytes32 => dTypes[]) public outputs; In other words, this structure stores each function's identifier as the key and that function's output type array as the value.

Why Functions Are Registered Individually

Registering each pure/view function as an independent entry, rather than registering an entire contract as a unit, aims for several advantages over whole-contract registration. It builds a globally reusable collection of functions and allows the design to scale using functional programming patterns instead of locking logic inside contracts. It links a function and the types it uses bidirectionally, making automation easier, and lets users pick only the functions that have passed community consensus from contracts that are already deployed. It also enables narrowly scoped improvements, registering only an improved version of a function without redeploying the entire contract, and makes fine-grained auditing and state-free mainnet testing of individual functions possible.

Backward Compatibility of the Signature Format

Storing minimal ABI information on-chain allows the system to adapt even if the way function signatures are computed changes later (for example, from bytes4 to bytes32). To support this, the proposal suggests registering several signature-computation functions together with dType, such as getSignatureBytes4(bytes32 identifier) and getSignatureBytes32(bytes32 identifier). Each returns, as bytes4 or bytes32 respectively, the signature of the function identified by identifier.

Storage Cost Concerns and Current Status

There is a concern that contractAddress must be stored redundantly for every function belonging to the same contract, but the proposal states that this is expected to be offset by reduced duplication across the chain overall, through reuse of already registered types and functions. It states that a concrete calculation of storage costs will be added once the specification and implementation are more fully developed. This proposal does not affect existing Ethereum standards or implementations, and it also supports registering functions of contracts that are already deployed. However, this ERC is in Stagnant status, test cases have not yet been written, and the proposal has stalled with no further progress.

Original ERC · ← ERCs