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).
2 Answers
Here are the precompiled contracts, the numbering is the address of the contract:
- Recovery of ECDSA signature
- Hash function SHA256
- Hash function RIPEMD160
- Identity
- Modular exponentiation (EIP 198)
- Addition on elliptic curve alt_bn128 (EIP 196)
- Scalar multiplication on elliptic curve alt_bn128 (EIP 196)
- Checking a pairing equation on curve alt_bn128 (EIP 197)
- 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.
-
2Thanks! Turns out Appendix E of the Yellow Paper is exactly what I was looking for. Apr 25, 2017 at 1:19
-
Why does the contract at address 1 not have any source code? etherscan.io/address/0x0000000000000000000000000000000000000001 is the source published somewhere?– pinheadJun 15, 2017 at 19:21
-
3
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{},
}
-
1Here's the link to this code in the master branch: github.com/ethereum/go-ethereum/blob/master/core/vm/… Nov 18, 2020 at 5:13
-
@RichardHorrocks none of those precompiles can call back another contract right ? Oct 9, 2021 at 10:20