35

Where can I find an authoritative/"official" listing of the pre-compiled contracts currently on the Ethereum network, along with their exact specifications? I couldn't find anything in the official documentation, but maybe I'm looking in the wrong place. Ideally, I'm looking for a list that will be kept up-to-date (as new EIPs will get approved).

Eugene Osovetsky
  • 493
  • 1
  • 4
  • 6

2 Answers2

35

Here are the precompiled contracts, the numbering is the address of the contract:

  1. Recovery of ECDSA signature
  2. Hash function SHA256
  3. Hash function RIPEMD160
  4. Identity
  5. Modular exponentiation (EIP 198)
  6. Addition on elliptic curve alt_bn128 (EIP 196)
  7. Scalar multiplication on elliptic curve alt_bn128 (EIP 196)
  8. Checking a pairing equation on curve alt_bn128 (EIP 197)
  9. BLAKE2b hash function (EIP 152)

A definitive list and specification is the Ethereum Yellow Paper.

The first 4:

... so-called ‘precompiled’ contracts, meant as a preliminary piece of architecture that may later become native extensions. The four contracts in addresses 1, 2, 3 and 4 execute the elliptic curve public key recovery function, the SHA2 256-bit hash scheme, the RIPEMD 160-bit hash scheme and the identity function respectively.

As the protocol is updated, the Yellow Paper will also get updated.

Here is a blog post with examples of using the next 4 precompiled contracts.

iamdefinitelyahuman
  • 2,876
  • 1
  • 12
  • 32
eth
  • 85,679
  • 53
  • 285
  • 406
  • 2
    Thanks! Turns out Appendix E of the Yellow Paper is exactly what I was looking for. – Eugene Osovetsky Apr 25 '17 at 01:19
  • Why does the contract at address 1 not have any source code? https://etherscan.io/address/0x0000000000000000000000000000000000000001 is the source published somewhere? – pinhead Jun 15 '17 at 19:21
  • 3
    @pinhead They don't have EVM bytecode: their source code is in the clients themselves, for example Geth – eth Jun 23 '17 at 06:15
23

And in the (Geth) code, they can be found in contracts.go:

// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
// contracts used in the Byzantium release.
var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
    common.BytesToAddress([]byte{1}): &ecrecover{},
    common.BytesToAddress([]byte{2}): &sha256hash{},
    common.BytesToAddress([]byte{3}): &ripemd160hash{},
    common.BytesToAddress([]byte{4}): &dataCopy{},
    common.BytesToAddress([]byte{5}): &bigModExp{},
    common.BytesToAddress([]byte{6}): &bn256Add{},
    common.BytesToAddress([]byte{7}): &bn256ScalarMul{},
    common.BytesToAddress([]byte{8}): &bn256Pairing{},
}
Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144