This standard specifies a minimal bytecode implementation to create children of a parent contract with a set of immutable metadata for each child.
Also known as a Proxy Contract but with the additional twist to store metadata or immutable arguments for the cloned contract at the end of the proxy bytecode.
## 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.
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.
// RETURNDATACOPY; (0, 0, returndatasize) - Copy everything into memory that the call returned
// stack = retcode, 0, returndatasize # this is for either revert(0, returndatasize()) or return (0, returndatasize())
// PUSH1 _SUCCESS_; push jumpdest of _SUCCESS_
// JUMPI; jump if delegatecall returned `1`
// REVERT; (0, returndatasize()) if delegatecall returned `0`
// JUMPDEST _SUCCESS_;
// RETURN; (0, returndatasize()) if delegatecall returned non-zero (1)
```
## Security Considerations
This standard only covers the bytecode implementation and does not include any serious side effects of itself.
The reference implementation includes some examples how to make use of it, but it is highly recommended to research side effects depending on how the functionaliy is used and implemented in any project.
## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).