-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft EIP for ENS support for contract ABIs #205
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78d65c3
Draft EIP for ENS support for contract ABIs
Arachnid b784a5d
Fix signature for resolver function
Arachnid b3e5913
Rename abi to ABI to avoid name clashes
Arachnid 2a10500
Update and rename eip-ens-abi-lookup.md to eip-634.md
Arachnid 6c821a1
Update eip-634.md
Arachnid c17cb78
Update eip-634.md
Arachnid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
## Preamble | ||
|
||
EIP: <to be assigned> | ||
Title: ENS support for contract ABIs | ||
Author: Nick Johnson <[email protected]> | ||
Type: Standard Track | ||
Category: ERCs | ||
Status: Draft | ||
Created: 2017-02-06 | ||
Requires: 137, 181 | ||
|
||
|
||
## Simple Summary | ||
This EIP proposes a mechanism for storing ABI definitions in ENS, for easy lookup of contract interfaces by callers. | ||
|
||
## Abstract | ||
ABIs are important metadata required for interacting with most contracts. At present, they are typically supplied out-of-band, which adds an additional burden to interacting with contracts, particularly on a one-off basis or where the ABI may be updated over time. The small size of ABIs permits an alternative solution, storing them in ENS, permitting name lookup and ABI discovery via the same process. | ||
|
||
ABIs are typically quite compact; the largest in-use ABI we could find, that for the DAO, is 9450 bytes uncompressed JSON, 6920 bytes uncompressed CBOR, and 1128 bytes when the JSON form is compressed with zlib. Further gains on CBOR encoding are possible using a CBOR extension that permits eliminating repeated strings, which feature extensively in ABIs. Most ABIs, however, are far shorter than this, consisting of only a few hundred bytes of uncompressed JSON. | ||
|
||
This EIP defines a resolver profile for retrieving contract ABIs, as well as encoding standards for storing ABIs for different applications, allowing the user to select between different representations based on their need for compactness and other considerations such as onchain access. | ||
|
||
## Specification | ||
### ABI encodings | ||
In order to allow for different tradeoffs between onchain size and accessibility, several ABI encodings are defined. Each ABI encoding is defined by a unique constant with only a single bit set, allowing for the specification of 256 unique encodings in a single uint. | ||
|
||
The currently recognised encodings are: | ||
|
||
| ID | Description | | ||
|----|----------------------| | ||
| 1 | JSON | | ||
| 2 | zlib-compressed JSON | | ||
| 4 | CBOR | | ||
| 8 | URI | | ||
|
||
This table may be extended in future through the EIP process. | ||
|
||
Encoding type 1 specifies plaintext JSON, uncompressed; this is the standard format in which ABIs are typically encoded, but also the bulkiest, and is not easily parseable onchain. | ||
|
||
Encoding type 2 specifies zlib-compressed JSON. This is significantly smaller than uncompressed JSON, and is straightforward to decode offchain. However, it is impracticalfor onchain consumers to use. | ||
|
||
Encoding type 4 is [CBOR](http://cbor.io/). CBOR is a binary encoding format that is a superset of JSON, and is both more compact and easier to parse in limited environments such as the EVM. Consumers that support CBOR are strongly encouraged to also support the [stringref extension](http://cbor.schmorp.de/stringref) to CBOR, which provides significant additional reduction in encoded size. | ||
|
||
Encoding type 8 indicates that the ABI can be found elsewhere, at the specified URI. This is typically the most compact of the supported forms, but also adds external dependencies for implementers. The specified URI may use any schema, but HTTP, IPFS, and Swarm are expected to be the most common. | ||
|
||
### Resolver profile | ||
A new resolver interface is defined, consisting of the following method: | ||
|
||
function abi(uint256 contentType) constant returns (uint256, bytes); | ||
|
||
The interface ID of this interface is 0xe0a8166a. | ||
|
||
contentType is a bitfield, and is the bitwise OR of all the encoding types the caller will accept. Resolvers that implement this interface must return an ABI encoded using one of the requested formats, or `(0, "")` if they do not have an ABI for this function, or do not support any of the requested formats. | ||
|
||
The `abi` resolver profile is valid on both forward and reverse records. | ||
|
||
### ABI lookup process | ||
|
||
When attempting to fetch an ABI based on an ENS name, implementers should first attempt an ABI lookup on the name itself. If that lookup returns no results, they should attempt a reverse lookup on the Ethereum address the name resolves to. | ||
|
||
Implementers should support as many of the ABI encoding formats as practical. | ||
|
||
## Rationale | ||
|
||
Storing ABIs onchain avoids the need to introduce additional dependencies for applications wishing to fetch them, such as swarm or HTTP access. Given the typical compactness of ABIs, we believe this is a worthwhile tradeoff in many cases. | ||
|
||
The two-step resolution process permits different names to provide different ABIs for the same contract, such as in the case where it's useful to provide a minimal ABI to some callers, as well as specifying ABIs for contracts that did not specify one of their own. The fallback to looking up an ABI on the reverse record permits contracts to specify their own canonical ABI, and prevents the need for duplication when multiple names reference the same contract without the need for different ABIs. | ||
|
||
## Copyright | ||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add two new identifiers:
Or perhaps only
URI of Solidity metadata hash
, which can be eitherbzzr://..
oripfs://..
at the moment.Reason being that the metadata is (currently) a JSON object containing some details about the compilation process and the resulting ABI and Natspec objects.
For the metadata see http://solidity.readthedocs.io/en/develop/miscellaneous.html#contract-metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't all of those just be URIs, though?
Edit: Which is to say, could we just add a 'metadata URI' option, assuming we don't ever want to store the actual metadata on chain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URI in this spec points to an ABI object, while the metadata URI is not an ABI object, but contains the ABI too.
Potentially it could be stored if needed, but isn't Swarm a better way to store data? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so I'm suggesting adding one additional type, for a 'metadata URI', so callers can distinguish between getting back a URI to just the ABI, or to the whole metadata. There's no need to encode what kind of URI it is (swarm, ipfs, etc) in the resolver.
Alternately, we could define a completely separate 'metadata URI' resolver profile.