ERC-3448: MetaProxy Standard

A minimal bytecode implementation for creating proxy contracts with immutable metadata attached to the bytecode


Metadata
Status: FinalStandards Track: ERCCreated: 2021-03-29
Authors
pinkiebell (@pinkiebell)

Abstract


By standardizing on a known minimal bytecode proxy implementation with support for immutable metadata, this standard allows users and third party tools (e.g. Etherscan) to: (a) simply discover that a contract will always redirect in a known manner and (b) depend on the behavior of the code at the destination contract as the behavior of the redirecting contract and (c) verify/view the attached metadata.

Tooling can interrogate the bytecode at a redirecting address to determine the location of the code that will run along with the associated metadata - and can depend on representations about that code (verified source, third-party audits, etc). This implementation forwards all calls via DELEGATECALL and any (calldata) input plus the metadata at the end of the bytecode to the implementation contract and then relays the return value back to the caller. In the case where the implementation reverts, the revert is passed back along with the payload data.

Motivation


This standard supports use-cases wherein it is desirable to clone exact contract functionality with different parameters at another address.

Specification


The exact bytecode of the MetaProxy contract is:


wherein the bytes at indices 21 - 41 (inclusive) are replaced with the 20 byte address of the master functionality contract. Additionally, everything after the MetaProxy bytecode can be arbitrary metadata and the last 32 bytes (one word) of the bytecode must indicate the length of the metadata in bytes.


Rationale


The goals of this effort have been the following:

  • a cheap way of storing immutable metadata for each child instead of using storage slots
  • inexpensive deployment of clones
  • handles error return bubbling for revert messages

Backwards Compatibility


There are no backwards compatibility issues.

Test Cases


Tested with:

  • invocation with no arguments
  • invocation with arguments
  • invocation with return values
  • invocation with revert (confirming reverted payload is transferred)

A solidity contract with the above test cases can be found in the EIP asset directory.

Reference Implementation


A reference implementation can be found in the EIP asset directory.

Deployment bytecode

A annotated version of the deploy bytecode:


MetaProxy

A annotated version of the MetaProxy bytecode:


Examples

The following code snippets serve only as suggestions and are not a discrete part of this standard.

Proxy construction with bytes from abi.encode


Proxy construction with bytes from calldata


Retrieving the metadata from calldata and abi.decode


Retrieving the metadata via a call to self


Apart from the examples above, it is also possible to use Solidity Structures or any custom data encoding.

Security Considerations


This standard only covers the bytecode implementation and does not include any serious side effects of itself. The reference implementation only serves as a example. It is highly recommended to research side effects depending on how the functionality is used and implemented in any project.

Copyright


Copyright and related rights waived via CC0.