# EIP-2678: Revised Ethereum Smart Contract Packaging Standard (EthPM v3) Source

Author g. nicholas d’andrea, Piper Merriam, Nick Gheorghita, Christian Reitwiessner, Ben Hauser, Bryant Eisenbach https://ethereum-magicians.org/t/ethpm-v3-specification-working-group/4086 Draft Standards Track ERC 2020-05-26 1123

## Simple Summary

A data format describing a smart contract software package.

## Abstract

This EIP defines a data format for package manifest documents, representing a package of one or more smart contracts, optionally including source code and any/all deployed instances across multiple networks. Package manifests are minified JSON objects, to be distributed via content addressable storage networks, such as IPFS.

This document presents a natural language description of a formal specification for version 3 of this format.

## Motivation

This standard aims to encourage the Ethereum development ecosystem towards software best practices around code reuse. By defining an open, community-driven package data format standard, this effort seeks to provide support for package management tools development by offering a general-purpose solution that has been designed with observed common practices in mind.

As version 3 of this specification, this standard seeks to address a number of areas of improvement found for the previous version (defined in EIP-1123). This version:

• Updates the schema for a package manifest to be compatible with the metadata output for compilers.
• Updates the "sources" object definition to support a wider range of source file types and serve as JSON input for a compiler.
• Moves compiler definitions to a top-level "compilers" array in order to:
• Simplify the links between a compiler version, sources, and the compiled assets.
• Simplify packages that use multiple compiler versions.
• Updates key formatting from snake_case to camelCase to be more consistent with JSON convention.

## Specification

This document defines the specification for an EthPM package manifest. A package manifest provides metadata about a package, and in most cases should provide sufficient information about the packaged contracts and its dependencies to do bytecode verification of its contracts.

A hosted version of this specification is available via GitHub Pages. This EIP and the hosted HTML document were both autogenerated from the same documentation source.

### Guiding Principles

This specification makes the following assumptions about the document lifecycle.

1. Package manifests are intended to be generated programmatically by package management software as part of the release process.

2. Package manifests will be consumed by package managers during tasks like installing package dependencies or building and deploying new releases.

3. Package manifests will typically not be stored alongside the source, but rather by package registries or referenced by package registries and stored in something akin to IPFS.

4. Package manifests can be used to verify public deployments of source contracts.

### Conventions

#### RFC2119

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

#### Prefixed vs Unprefixed

A prefixed hexadecimal value begins with 0x. Unprefixed values have no prefix. Unless otherwise specified, all hexadecimal values should be represented with the 0x prefix.

 Prefixed 0xdeadbeef Unprefixed deadbeef

### Document Format

The canonical format is a single JSON object. Packages must conform to the following serialization rules.

• The document must be tightly packed, meaning no linebreaks or extra whitespace.

• The keys in all objects must be sorted alphabetically.

• Duplicate keys in the same object are invalid.

• The document must use UTF-8 encoding.

• The document must not have a trailing newline.

• To ensure backwards compatibility, manifest_version is a forbidden top-level key.

### Document Specification

The following fields are defined for the package. Custom fields may be included. Custom fields should be prefixed with x- to prevent name collisions with future versions of the specification.

### EthPM Manifest Version: manifest

The manifest field defines the specification version that this document conforms to.

• Packages must include this field.
 Required Yes Key manifest Type String Allowed Values ethpm/3

### Package Name: name

The name field defines a human readable name for this package.

• Packages should include this field to be released on an EthPM registry.

• Package names must begin with a lowercase letter and be comprised of only lowercase letters, numeric characters, and the dash character -.

• Package names must not exceed 255 characters in length.

#### Transaction: transaction

The transaction field defines the transaction hash in which this Contract Instance was created.

 Required No Type String Format 0x prefixed hex encoded transaction hash.

#### Block: block

The block field defines the block hash in which this the transaction which created this contract instance was mined.

 Required No Type String Format 0x prefixed hex encoded block hash.

#### Runtime Bytecode: runtimeBytecode

The runtimeBytecode field defines the runtime portion of bytecode for this Contract Instance. When present, the value from this field supersedes the runtimeBytecode from the Contract Type for this Contract Instance.

 Required No Type Object Format Must conform to the Bytecode Object format.

Every entry in the linkReferences for this bytecode must have a corresponding entry in the linkDependencies section.

### The Compiler Information Object

The compilers field defines the various compilers and settings used during compilation of any Contract Types or Contract Instance included in this package.

A Compiler Information object is defined to have the following key/value pairs.

#### Name: name

The name field defines which compiler was used in compilation.

 Required Yes Key name Type String

#### Version: version

The version field defines the version of the compiler. The field should be OS agnostic (OS not included in the string) and take the form of either the stable version in semver format or if built on a nightly should be denoted in the form of <semver>-<commit-hash> ex: 0.4.8-commit.60cc1668.

 Required Yes Key version Type String

#### Settings: settings

The settings field defines any settings or configuration that was used in compilation. For the "solc" compiler, this should conform to the Compiler Input and Output Description.

 Required No Key settings Type Object

#### Contract Types: contractTypes

A list of the Contract Alias or Contract Types in this package that used this compiler to generate its outputs.

• All contractTypes that locally declare runtimeBytecode should be attributed for by a compiler object.

• A single contractTypes must not be attributed to more than one compiler.

 Required No Key contractTypes Type Array(Contract Alias)

### BIP122 URIs

BIP122 URIs are used to define a blockchain via a subset of the BIP-122 spec.

blockchain://<genesis_hash>/block/<latest confirmed block hash>


The <genesis hash> represents the blockhash of the first block on the chain, and <latest confirmed block hash> represents the hash of the latest block that’s been reliably confirmed (package managers should be free to choose their desired level of confirmations).

### Glossary

The terms in this glossary have been updated to reflect the changes made in V3.

ABI
The JSON representation of the application binary interface. See the official specification for more information.

A public identifier for an account on a particular chain

Bytecode
The set of EVM instructions as produced by a compiler. Unless otherwise specified this should be assumed to be hexadecimal encoded, representing a whole number of bytes, and prefixed with 0x.

 Unlinked Bytecode The hexadecimal representation of a contract’s EVM instructions that contains sections of code that requires linking for the contract to be functional. The sections of code which are unlinked must be filled in with zero bytes. Example: 0x606060405260e06000730000000000000000000000000000000000000000634d536f Linked Bytecode The hexadecimal representation of a contract’s EVM instructions which has had all Link References replaced with the desired Link Values. Example: 0x606060405260e06000736fe36000604051602001526040518160e060020a634d536f

Chain Definition
This definition originates from BIP122 URI.

A URI in the format blockchain://<chain_id>/block/<block_hash>

• chain_id is the unprefixed hexadecimal representation of the genesis hash for the chain.

• block_hash is the unprefixed hexadecimal representation of the hash of a block on the chain.

A chain is considered to match a chain definition if the the genesis block hash matches the chain_id and the block defined by block_hash can be found on that chain. It is possible for multiple chains to match a single URI, in which case all chains are considered valid matches

Any URI which contains a cryptographic hash which can be used to verify the integrity of the content found at the URI.

The URI format is defined in RFC3986

It is recommended that tools support IPFS and Swarm.

Contract Alias
This is a name used to reference a specific Contract Type. Contract aliases must be unique within a single Package.

The contract alias must use one of the following naming schemes:

• <contract-name>

• <contract-name><identifier>

The <contract-name> portion must be the same as the Contract Name for this contract type.

The <identifier> portion must match the regular expression ^[-a-zA-Z0-9]{1,256}$. Contract Instance A contract instance a specific deployed version of a Contract Type. All contract instances have an Address on some specific chain. Contract Instance Name A name which refers to a specific Contract Instance on a specific chain from the deployments of a single Package. This name must be unique across all other contract instances for the given chain. The name must conform to the regular expression ^[a-zA-Z_$][a-zA-Z0-9_$]{0,255}$

In cases where there is a single deployed instance of a given Contract Type, package managers should use the Contract Alias for that contract type for this name.

In cases where there are multiple deployed instances of a given contract type, package managers should use a name which provides some added semantic information as to help differentiate the two deployed instances in a meaningful way.

Contract Name
The name found in the source code that defines a specific Contract Type. These names must conform to the regular expression ^[a-zA-Z_$][a-zA-Z0-9_$]{0,255}$. There can be multiple contracts with the same contract name in a projects source files. Contract Type Refers to a specific contract in the package source. This term can be used to refer to an abstract contract, a normal contract, or a library. Two contracts are of the same contract type if they have the same bytecode. Example: contract Wallet { ... }  A deployed instance of the Wallet contract would be of of type Wallet. Identifier Refers generally to a named entity in the Package. A string matching the regular expression ^[a-zA-Z][-_a-zA-Z0-9]{0,255}$

A location within a contract’s bytecode which needs to be linked. A link reference has the following properties.

 offset Defines the location within the bytecode where the link reference begins. length Defines the length of the reference. name (optional) A string to identify the reference

A link value is the value which can be inserted in place of a Link Reference

The act of replacing Link References with Link Values within some Bytecode.

Package
Distribution of an application’s source or compiled bytecode along with metadata related to authorship, license, versioning, et al.

For brevity, the term Package is often used metonymously to mean Package Manifest.

Package Manifest
A machine-readable description of a package.

Prefixed
Bytecode string with leading 0x.

 Example 0xdeadbeef

Unprefixed
Not Prefixed.

 Example deadbeef

## Rationale

The following use cases were considered during the creation of this specification.

 owned A package which contains contracts which are not meant to be used by themselves but rather as base contracts to provide functionality to other contracts through inheritance. transferable A package which has a single dependency. standard-token A package which contains a reusable contract. safe-math-lib A package which contains deployed instance of one of the package contracts. piper-coin A package which contains a deployed instance of a reusable contract from a dependency. escrow A package which contains a deployed instance of a local contract which is linked against a deployed instance of a local library. wallet A package with a deployed instance of a local contract which is linked against a deployed instance of a library from a dependency. wallet-with-send A package with a deployed instance which links against a deep dependency. simple-auction Compiler "metadata" field output.

Each use case builds incrementally on the previous one.

A full listing of Use Cases can be found on the hosted version of this specification.

## Backwards Compatibility

To improve understanding and readability of the EthPM spec, the manifest_version field was updated to manifest in v3. To ensure backwards compatibility, v3 packages must define a top-level "manifest" with a value of "ethpm/3". Additionally, "manifest_version" is a forbidden top-level key in v3 packages.

## Implementations

This submission aims to coincide with development efforts towards widespread implementation in commonly-used development tools.

The following tools are known to have begun or are nearing completion of a supporting implementation.

Full support in implementation may require Further Work, specified below.

## Further Work

This EIP addresses only the data format for package descriptions. Excluded from the scope of this specification are:

• Package registry interface definition ERC 1319

• Tooling integration, or how packages are stored on disk.

These efforts should be considered separate, warranting future dependent EIP submssions.

## Acknowledgements

The authors of this document would like to thank the original authors of EIP-190, EIP-1123, all community contributors, and the Ethereum community at large.

## Security Considerations

The same security considerations from v2 are still relevant for EthPM v3. Using EthPM packages implicitly requires that users import &/or execute code written by others. The EthPM spec guarantees that when using a properly constructed and released EthPM package, the user will have the exact same code that was included in the package by the package author. However, it is impossible to guarantee that this code is safe to interact with. Therefore, it is critical that end users only interact with EthPM packages authored and released by individuals or organizations that they trust to include non-malicious code.

Copyright and related rights waived via CC0.