The contract at address 0x04 is the identity function. What is it and what are use cases for it?
-
3excuse my ignorance, what is "address 4"? – Afr Jan 23 '16 at 12:53
-
Addresses are just numbers. Your address is in hex and try converting it to decimal. Addresses don't have to be such large numbers though, so this precompiled contract was put at address 4 (instead of say 4 trillion). – eth♦ Jan 23 '16 at 20:45
The Identity function simply returns whatever its input is.
At a talk given by Vitalik Buterin, it's for efficient data copying.
It costs 15 gas + 3 gas for each 32 bytes of input data (rounded up).
It is a precompiled contract located at address 4.
-
1Could anyone paste a link to the talk where Vitalik describes this efficient data copying via the identity function? – Paul Razvan Berg Jan 6 '19 at 14:57
As defined on page 18 of Ethereum's formal specification written by Gavin Wood (a.k.a the "Yellow Paper"), there are 4 pre-compiled contracts that are mapped to addresses 1-4 in the Ethereum blockchain, as demonstrated in this Pyeth snippet:
specials = {
decode_hex(k): v for k, v in
{
'0000000000000000000000000000000000000001': proc_ecrecover,
'0000000000000000000000000000000000000002': proc_sha256,
'0000000000000000000000000000000000000003': proc_ripemd160,
'0000000000000000000000000000000000000004': proc_identity,
}.items()
}
The first 3 functions are ECDSARECOVER, RIPEMD-160, and SHA2-256. The fourth function is the "Identity function"](https://en.wikipedia.org/wiki/Identity_function). The identity function "simply defines the output as the input".
Precompiled contracts' addresses need a little bit of ether deposited so that it's cheaper to call them. Message calls to non-existent accounts are more expensive, so we don't want to let developers pay the gas for initialising the accounts when the network could do it in the first place.
Update: Since Byzantium, there are 4 more precompiled contracts: Modular Exponentiation, alt_bn128 Addition, alt_bn128 Scalar Multiplication and alt_bn128 Pairing Checks at addresses 0x05, 0x06, 0x07 and 0x08 respectively.
-
-
1For "why account addresses 1-4 need 1 wei to start" please post answer to: ethereum.stackexchange.com/q/1607/42 – eth♦ Apr 28 '16 at 16:16
If you're looking for a formal description, check out Appendix E of the yellow paper:
Where:
Ξpre
= a function which checks the call has enough gas, reverts otherwisegr
= resulted gas cost, 15 + 3 for every 32 bytes of input dataId
= the identity's function input data
Identity on Ethereum
We can now attempt to create the Identity implementation on Ethereum. We are grateful to Ethereum, ConsenSys, Factom, IDCubed and other developers who helped us hone the ideas found below. Ethereum concepts
- Ethereum has a notion of an account, unlike the bitcoin. Account has the associated private/public keys.
- Ethereum has a notion of a contract, which is a code executed by Ethereum nodes.
- Unlike a bitcoin transaction that goes from many inputs to many outputs, Ethereum transaction goes from one account to another, or from one account to a contract.
- Contract is code that can also store key-value pairs. This makes it possible to manage identities. This contract store is expensive, and with high probability we will move the part that do not require strong consensus, to a separate store (DHT).
- In DHT-based design we relied on object versioning where versions formed a linked list. In Ethereum we forego this approach and rely on a combination of transactions and the current identity state in Identity contract's store.
Source: https://github.com/tradle/about/wiki/Identity-on-Ethereum
-
No, that is not what @eth is asking about. Instead this is about the identity function as defined here: github.com/ethereum/pyethereum/blob/… – Joris Bontje Jan 23 '16 at 20:30