logoAcademy

Creating a Hash Function Precompile

Learn how to create a Hash Function Precompile.

What We're Building

In this section, we'll create a precompile for the hash function md5. Since there's a Go library for this hash function, we can avoid reimplementing the algorithm in Solidity and make use of the better efficiency of Go over Solidity.

Reference Implementation

To help you understand how precompiles are built, we'll compare each step with a reference example: A precompile for the sha256 hash function. Both precompiles are very similar and just have a single function, which returns the hashed value.

Overview of Steps

Here's an overview of the steps:

  1. Create a Solidity interface for the precompile
  2. Generate the ABI
  3. Write the precompile code in Go
  4. Configure and register the precompile
  5. Build and run your customized EVM
  6. Connect Remix to your customized EVM and interact with the precompile

Let's begin!

On this page