Git Product home page Git Product logo

clover73 / custom-precompiled-geth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kommercetradeflow/custom-precompiled-geth

0.0 0.0 0.0 105.12 MB

Official Go implementation of the Ethereum protocol

Home Page: https://geth.ethereum.org

License: GNU Lesser General Public License v3.0

Dockerfile 0.03% Makefile 0.11% Go 87.10% Shell 0.17% NSIS 0.22% Ruby 0.01% Python 0.06% HTML 0.12% JavaScript 4.47% Solidity 0.13% Assembly 0.44% C 6.32% M4 0.24% Java 0.28% Sage 0.28%

custom-precompiled-geth's Introduction

Introduction

This is a workshop example to explain how to implement a new precompiled contract. A precompiled contract is an implemented class within an ethereum node, that is pinned to a fixed contract address.

Objective

Implementing a custom feature as a precompiled contract allows new functionality to be added to mining nodes without making changes to the EVM opcode, making it a much cleaner way to implement complex new feature. Some possible use of this is for adding new cryptographic functions, complex zero knowledge proof verifier, external call to oracles or another chain, etc.

Typically on the base chain, such changes will need to be implemented across all ethereum node implementations and also rquires a hardfork by the miners for adoption. Thus, they need to undergo the lengthy EIP process before mass adoption.

However, when used in building private networks of ethereum nodes, or as a layer-2 plasma chain, it can be very useful to easily add custom functionality to the private chain.

Basic principles

  • Define a new class for the feature, that implements the interface PrecompiledContract. Make the necessary changes in core/vm/contracts.go
  • Add the address of the class to the precompiled contract mapping, also in core/vm/contracts.go
  • Create a corresponding function in the smart contract which calls the precompiled contract using the an assembly call() method, with the predefined address.
call(g, a, v, in, insize, out, outsize)

call contract at address a with input mem[in..(in+insize)) providing g gas and ether value v wei and output area mem[out..(out+outsize)) returning 0 on error (eg. out of gas) and 1 on success

Usage

This repo defines a simple helloPrecompiled precompiled contract which prints out a hello world message on the console of the ethereum node.

Refer to go-ethereum's original README on instructions to build the geth client.

Start a private instance of the geth. You can follow this very useful tutorial reference.

The demo folder contains a simple truffle project with a contract to call the helloPrecompiled precompiled contact. migrate this project to deploy the contract and call the callPrecompiled function.

custom-precompiled-geth's People

Contributors

obscuren avatar karalabe avatar fjl avatar tgerring avatar zelig avatar cjentzsch avatar debris avatar zsfelfoldi avatar holiman avatar gavofyork avatar gluk256 avatar arachnid avatar rjl493456442 avatar nonsense avatar vbuterin avatar cubedro avatar gballet avatar janos avatar kielbarry avatar egonelbre avatar lmars avatar jsvisa avatar ethers avatar jimenezrick avatar ebuchman avatar ligi avatar winsvega avatar ferhatelmas avatar markya0616 avatar acud avatar

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.