Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ava-labs/precompile-evm
A new repository for Subnet-EVM Stateful Precompiles
https://github.com/ava-labs/precompile-evm
avalanche evm precompile subnet subnet-evm
Last synced: about 2 months ago
JSON representation
A new repository for Subnet-EVM Stateful Precompiles
- Host: GitHub
- URL: https://github.com/ava-labs/precompile-evm
- Owner: ava-labs
- License: lgpl-3.0
- Created: 2023-02-23T12:21:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T20:58:13.000Z (4 months ago)
- Last Synced: 2024-09-18T01:05:20.194Z (4 months ago)
- Topics: avalanche, evm, precompile, subnet, subnet-evm
- Language: Shell
- Homepage:
- Size: 1.71 MB
- Stars: 20
- Watchers: 14
- Forks: 10
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Precompile-EVM
Precompile-EVM is a repository for registering precompiles to Subnet-EVM without forking the Subnet-EVM codebase. Subnet-EVM supports registering external precompiles through `precompile/modules` package. By importing Subnet-EVM as a library, you can register your own precompiles to Subnet-EVM and build it together with Subnet-EVM.
## Environment Setup
To effectively build, run, and test Precompile-EVM, the following is a (non-exhaustive) list of dependencies that you will need:
- Golang
- Node.js
- [AvalancheGo](https://github.com/ava-labs/avalanchego)To get started easily, we provide a Dev Container specification, that can be used using GitHub Codespace or locally using Docker and VS Code. DevContainers are a concept that utilizes containerization (via Docker containers) to create consistent and isolated development environment. We can access this environment through VS code, which allows for the development experience to feel as if you were developing locally..
### Dev Container in Codespace
Codespaces is a development environment service offered by GitHub that allows developers to write, run, test, and debug their code directly on a cloud machine provided by GitHub. The developer can edit the code through a VS Code running in the browser or locally.
To run a Codespace click on the **Code** and switch to the **Codespaces** tab. There, click **Create Codespace on branch [...]**.
### Local Dev Container
In order to run the Dev Container locally:
- Install VS Code, Docker and the [Dev Container Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
- Clone the Repository
- Open the Container by issuing the Command "Dev Containers: Reopen in Container" in the VS Code command palette (on Mac-OS, run [Cmd + Shift + P]).## Learn about Precompile-EVM
To get a comprehensive introduction to Precompile-EVM, take the Avalanche Academy course on [Customizing the EVM](https://academy.avax.com/course/customize-evm).
## How to use
There is an example branch [hello-world-example](https://github.com/ava-labs/precompile-evm/tree/hello-world-example) in this repository. You can check the example branch to see how to register precompiles and test them.
### Generate Precompile Files
First, you need to create your precompile contract interface in the `contracts` directory and build the ABI. Then you can generate your precompile files with `./scripts/generate_precompile.sh --abi {abiPath} --out {outPath}`. This script installs the `precompilegen` tool from Subnet-EVM and runs it to generate your precompile.
### Register Precompile
In `plugin/main.go` Subnet-EVM is already imported and ready to be Run from the main package. All you need to do is explicitly register your precompiles to Subnet-EVM in `plugin/main.go` and build it together with Subnet-EVM. Precompiles generated by `precompilegen` tool have a self-registering mechanism in their `module.go/init()` function. All you need to do is to force-import your precompile packprecompile package in `plugin/main.go`.
### Build
You can build your precompile and Subnet-EVM with `./scripts/build.sh`. This script builds Subnet-EVM, and your precompile together and generates a binary file. The binary file is compatible with AvalancheGo plugins.
### Run
You can run you Precompile-EVM by using the Avalanche CLI.
First, create the configuration for your subnet.
```bash
avalanche subnet create mysubnet --custom --vm $AVALANCHEGO_PLUGIN_PATH/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy --genesis ./.devcontainer/genesis-example.json
```Next, launch the Subnet with your custom VM:
```bash
avalanche subnet deploy mysubnet
```### Test
You can create contract tests in `contracts/test` with the Hardhat test framework. These can be run by adding ginkgko test cases in `tests/precompile/solidity/suites.go` and a suitable genesis file in `tests/precompile/genesis`. You can install AvalancheGo binaries with `./scripts/install_avalanchego_release.sh` then run the tests with `./scripts/run_ginkgo.sh`
## Changing Versions
In order to upgrade the Subnet-EVM version, you need to change the version in `go.mod` and `scripts/versions.sh`. You can also change the AvalancheGo version through `scripts/versions.sh` as well. Then you can run `./scripts/build.sh` to build the plugin with the new version.
## AvalancheGo Compatibility
```text
[v0.2.0] [email protected] (Protocol Version: 33)
[v0.2.1] [email protected] (Protocol Version: 35)
[v0.2.2] [email protected] (Protocol Version: 35)
[v0.2.3] [email protected] (Protocol Version: 35)
[v0.2.4] [email protected] (Protocol Version: 37)
```