logoAcademy

Why Precompiles?

Learn about why you should utilize Precompiles in your smart contracts.

Adding precompiles to the Ethereum Virtual Machine (EVM) has several value propositions. We have described a few of them briefly in this chapter.

Performance Optimization

Precompiles are primarily used to optimize the performance of specific types of computations. Adding a new precompile can significantly reduce the computational resources required to perform certain tasks, which can improve the performance of smart contracts and decentralized applications (DApps) depending on these tasks.

The SHA256 hash function (0x02) and the RIPEMD160 hash function (0x03) are examples of precompiles that significantly improve performance. If these functions had to be implemented in a smart contract, they would be computationally expensive and slow. However, as precompiles, they are executed quickly and efficiently.

Security

By incorporating a function as a precompile, it is possible to leverage libraries that have been thoroughly reviewed and audited. This can reduce the risk of bugs and vulnerabilities, improving overall security.

For example, the ModExp (0x05) precompile safely performs modular exponentiation, a complex mathematical operation used in various cryptographic functions.

Access to Go Libraries

Since precompiles are implemented in Go, we can utilize existing Go Libraries. Go has a rich ecosystem of Libraries. Accessing them avoids the need for reimplementation, which takes effort and risks introducing bugs in the process of translating from Go to Solidity.

Check out the implementation of the sha256 hash algorithm to see how much effort a reimplementation to solidity would mean.

Gas Efficiency

Adding a new precompile to the EVM can make certain computations more gas-efficient, reducing costs of execution. This makes it feasible to incorporate more complex operations into smart contracts, enhancing their functionality without unduly increasing the cost of transactions.

The identity precompile (0x04) copies and returns input data. Though simple, it offers gas efficiency because it's faster and cheaper than implementing the same functionality in a standard contract.

Advanced Features and Functionality

By adding new precompiles to the EVM, it is possible to introduce new features and functionalities, such as advanced cryptographic operations, complex mathematical calculations, data structures, and more. This can open up new possibilities for dApps and smart contracts, allowing them to perform tasks that would otherwise be too computationally expensive or technically challenging.

The precompiles for elliptic curve operations, such as ecadd (0x06), ecmul (0x07), and ecpairing (0x08), enable the use of advanced cryptographic functionality in EVM smart contracts. These precompiles are essential for implementing zk-SNARKs, a form of zero-knowledge proof, in Ethereum.

Interoperability

Some precompiles can enhance the interoperability of the EVM with other blockchains or systems. For instance, precompiles could be used to verify proofs from other chains or to perform operations compatible with other cryptographic standards.

The BLS12-381 elliptic curve operations precompiles (0x0a through 0x13, added in the Istanbul upgrade) enhance EVM's interoperability. They allow for operations compatible with the BLS signature scheme and could potentially facilitate inter-blockchain communication.

On this page