Code Monkey home page Code Monkey logo

precompile-evm's Introduction

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:

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
  • 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.

How to use

There is an example branch 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.

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

[v0.1.0-v0.1.1] [email protected] (Protocol Version: 26)
[v0.1.2] [email protected] (Protocol Version: 27)
[v0.1.3] [email protected] (Protocol Version: 28)
[v0.1.4] [email protected] (Protocol Version: 28)
[v0.1.5] [email protected] (Protocol Version: 29)
[v0.1.6] [email protected] (Protocol Version: 30)
[v0.1.7] [email protected] (Protocol Version: 30)
[v0.1.8] [email protected] (Protocol Version: 31)

precompile-evm's People

Contributors

ceyonur avatar martineckardt avatar rodrigovillar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

precompile-evm's Issues

v0.1.6

Release

The release version and a description of the planned changes to be included in the release:

Subnet-EVM + AvalancheGo Version Bumps

Issues

Link the major issues planned to be included in the release:

Version bumps only

Documentation

Link the relevant documentation PRs for this release.

#51

Checklist

  • Update Precompile-EVM version in plugin/main.go
  • Bump AvalancheGo dependency for RPCChainVM Compatibility in go.mod and versions.sh
  • Bump Subnet-EVM version in go.mod and versions.sh
  • Add new entry in compatibility.json for RPCChainVM Compatibility
  • Update AvalancheGo compatibility in README

Bump Subnet-EVM 0.5.6

Release
Bump Subnet-EVM & AvalancheGo and also minimum GoLang version.

Issues
Only bumping versions.

Checklist

  • Update version in scripts/versions.sh and plugin/main.go
  • Bump AvalancheGo dependency for RPCChainVM Compatibility
  • Add new entry in compatibility.json for RPCChainVM Compatibility
  • Update AvalancheGo compatibility in README

Validator Querier Precompile

We currently expose validator sets through AccessibleState.GetSnowContext().ValidatorState in stateful precompile function. Meaning that we can actually perform a query for subnet validators (and even other subnet validators) and provide this functionality to smart contracts. This could be very handy for governance, delegations, rewards and staking operations.

Seeing `invalid function selector` error when writing to StateDB.

I've been seeing an invalid function selector error when porting over the VRF precompile to precompile-evm and I wanted to confirm it wasn't a bug which I was introducing so I confirmed that it also appears in the HelloWorld precompile. It happens whenever we write to storage. So for example calling the setGreeting function in HelloWorld

[node1] INFO [07-10|13:41:03.551] <5sHuoVPHJANLGtFMGCWBcdagZPP8ym2WybMewRPnMsr36qgsF Chain> github.com/ava-labs/subnet-evm/rpc/handler.go:403: Served eth_call reqid=80 execTime="683.625µs" procTime="684.232µs" totalTime="684.534µs" err="invalid function selector 0x01ffc9a7"

It doesn't appear to affect the precompile working but I wanted to bring it to your attention.

Precompile-EVM v0.1.5

Release
The release version and a description of the planned changes to be included in the release.

Bump Subnet-EVM/AvalancheGo versions.

Issues
Version Bump only

Documentation
Version Bump Only

Checklist

  • Update version in scripts/versions.sh and plugin/main.go
  • Bump AvalancheGo dependency for RPCChainVM Compatibility
  • Add new entry in compatibility.json for RPCChainVM Compatibility
  • Update AvalancheGo compatibility in README

v0.1.7

Release

Versions bump

Checklist

  • Update Precompile-EVM version in plugin/main.go
  • Bump AvalancheGo dependency for RPCChainVM Compatibility in go.mod and versions.sh
  • Bump Subnet-EVM version in go.mod and versions.sh
  • Add new entry in compatibility.json for RPCChainVM Compatibility
  • Update AvalancheGo compatibility in README

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.