A Verifyable Chain Relay for Proof of Stake Blockchains

A Verifyable Chain Relay for Proof of Stake Blockchains

This repository contains a proof of concept implementation of a fully verifyable Ethereum 2.0 chain relay for usage on EVM-compatible blockchains. The prototype is work in progress and not intended for production usage.

Project Structure & Licenses

The repository contains customized code forks of three open source projects:

All changes are lincensed under the projects' original license.

The structure of the folder chainrelay is initialized by Truffle, while its contents are created as part of this project and licensed under GNU GPLv3. This README is also licensed under GNU GPLv3.

Please note that this repository contains intermediate files for reference only.

Getting Started

This section describes how to get started with running the chain relay prototype.

Running a custom Ethereum testnet with Go-Ethereum

Deploying and testing the chain relay prototype requires running a custom version of the Go Ethereum client. In order to compile the custom version of Go Ethereum and create and run a custom ephemeral version of the Ethereum blockchain, make sure Go as well as a C compiler is installed and execute the following commands:

cd go-ethereum
make geth 
./build/bin/geth --rpc.gascap 30000000 --datadir test-chain-dir --http --dev --vmdebug --verbosity 3 --rpcapi debug,eth,personal,net,web3

The customized files in go-ethereum are

File path Description of changes
go-ethereum/core/genesis.go (1) Replacing the block Gas limit of 11,500,000 with 1,150,000,000. (2) Replacing the ModExp precompile function and contract at the address 0x0000000000000000000000000000000000000005 with a FastAggregateVerify precompile.
go-ethereum/core/vm/contracts.go (1) Replacing the ModExp precompile with a FastAggregateVerify precompile based on Herumi BLS. It verifies a given signature, message and public key array triple. True is returned if valid, false if invalid. (2) Replacing the ModExp precompile Gas cost calculation with an estimation of the Gas cost caused by EIP-2537 operations on the BLS12-381 curve.

Deploying chain relay smart contracts and running test scenarios with Truffle

Deploying different versions of the chain relay smart contract and reproducibly testing it is faciliated by Truffle. All files in the folder chainrelay are initialized by Truffle or part of the chain relay smart contract, deployment, or testing setup. chainrelay/contracts contains the chain relay prototype smart contracts as Solidity source code in different configurations (Eth2 sync committee with 32 members, Eth2 sync committee with 512 members, Eth2 sync committee with 512 members and No-Store optimization). chainrelay/migrations contains instructions for Truffle on how to deploy the contracts for testing. chainrelay/tests contains test scenarios defined in Solidity (*.sol) as well as JavaScript (*.js). The file chainrelay/tests/evaluation.js contains the test scenarios used for evaluating the chain relay prototype, specifically its Gas consumption.

In order to deploy the smart contracts and run the tests, make sure Truffle and NodeJS and NPM are installed, start the customized Ethereum testnet (see above) and run the following commands:

cd chainrelay
npm install truffle-assertions
truffle test

This deploys the smart contracts and executes all test scenarios. To execute a single test scenario, for example the scenarios relevant for the evaluation of the prototype, run truffle test test/evaluation.js.

The file chainrelay/recording_test_results.txt contains a recording of the output of running all tests.

Creating custom tests

Generating BLS aggregate signatures for testing

In order to generate BLS multi-signatures for testing purposes, compiled binaries of Herumi's BLS library are used with a Eth2 compatible configuration. Messages are signed with a set of pseudo-random private keys, which are derived from a seed and therefore deterministic. The number of signers (default 512) as well as the message to be signed (default 32BytesMessageForSigningGoodness) can be adjusted in bls-eth-go-binary/generate_signature_test_data.go.

To generate test data and print it to a shell, make sure Go is installed and run

go run bls-eth-go-binary/generate_signature_test_data.go

Generating SSZ structures and merkle proofs

The folder eth2.0-specs contains the official Eth2 specification, which includes definitions of the SSZ data structures used by nodes and for signing by validators. Initializing and working with SSZ data structures as defined by the specification is possible with the executable Python specification. All the test data used by the Truffle test scenarios is generated from or similar to the code in the file eth2.0-specs/tests/generators/ssz_static/generate_ssz_test_data.py. The file can be run to re-generate lots of test data or can be used as a boilerplate for generating further test data.

Please note that this file is a log of many commands used for generating test data structures for the evaluation of the prototype and some data might be outdated. For a structured introduction to generating SSZ data structures, please refer to the Ethereum specification.

The file can be run by installing Python 3 (do consider creating a virtual environment beforehand) and running the commands

export PYTHONPATH="${PYTHONPATH}:/path/to/eth2.0-specs/tests/core/pyspec"
cd eth2.0-specs/tests/generators/ssz_static
pip3 install -r requirements.txt
python3 generate_ssz_test_data.py

For navigating SSZ data structures and generating additional test data, it is also helpful to load the file in an interactive Python shell by running python3 -i generate_ssz_test_data.py.

Note that the file also contains the class ChainRelayAlpha, which is an early version of the prototype chain relay written in Python. It was used testing first versions of the application logic and defining helper functions derived from the specification. While it is not up to date with the Solidity version of the chain relay prototype, it may still be used to check generated SSZ test data.

Similar Resources

A collection about awesome blockchains

A collection about awesome blockchains

A collection about awesome blockchains - open distributed public databases w/ crypto hashes incl. git ;-). Blockchains are the new tulips :tulip::tulip::tulip:. Distributed is the new centralized.

Jan 2, 2023

A naive and simple implementation of blockchains.

naivechain A naive and simple implementation of blockchains. Build And Run Download and compile go get -v github.com/kofj/naivechain Start First Node

Dec 5, 2022

Dijetsnetgo: a blockchains platform with high throughput, and blazing fast transactions

Dijetsnetgo: a blockchains platform with high throughput, and blazing fast transactions

Node implementation for the Avalanche network - a blockchains platform with high

Jan 18, 2022

Signing, Keystore and RLP encoding utilities for EVM / Ethereum / secp256k1 based blockchains

Signing, Keystore and RLP encoding utilities for EVM / Ethereum / secp256k1 based blockchains. Written in Go with an enterprise friendly Apache 2.0 license, and a runtime JSON/RPC proxy server. Part of the Hyperledger FireFly project

Aug 9, 2022

Proof on concept with metamask

Local Run go run ./app.go # generate swagger go get github.com/swaggo/swag/cmd/swag Swag init -g app.go Local Docker Compose Run # rebuild docker ima

Aug 6, 2022

Proof of Work (POW) using SHA1 hashes

Important The main repository is hosted at Codeberg. Proof of Work (SHA1) This repository contains a naive implementation of a Proof of Work (POW) usi

Dec 23, 2021

Proof of Work Algorithms For Golang

Proof of Work Algorithms Overview Note: This library is still in active developm

Jan 7, 2022

Proof of History in Golang. Taking key concepts from the Solana whitepaper and providing examples in Go

Proof of History - Concepts in Go ________ ________ ___ ___ |\ __ \|\ __ \|\ \|\ \ \ \ \|\ \ \ \|\ \ \ \\\ \

Oct 13, 2022
Comments
  • Reorganize project

    Reorganize project

    Currently, all changes in respective libraries and clients are part of the repository. As a result, it is difficult to grasp what is part of the relay and what is a dependency. Furthermore, fetching from the upstream repo is problematic.

    This PR targets to clean up the repo by applying the following changes:

    • Pull content of chainrelay folder to root folder
    • Use npm and truffel dependencies to retrieve contracts etc.
    • Conclude changes to geth in a dedicated repo that was forked from the upstream repo. The repo is then added as a gitmodule to this repo
    • Go code for generating test BLS signatures is now part of the test folder and the BLS library is added as go dependency
    • Python code for generating SSZ structures and Merkle proofs use eth2.0-specs as a dependency that is pulled from github rather than hosting it in this repo
  • How to do transaction inclusion verification in PoSChainRelay?

    How to do transaction inclusion verification in PoSChainRelay?

    Hi, I have read the smart contract code of PoSChainRelay. I didn't find the function to verify a specific transaction, it seems the chainrelay only stores the finalized block. Can this chainrelay verify the inclusion of the transaction? Do you have a plan to implement this?

Evmos is a scalable, high-throughput Proof-of-Stake blockchain that is fully compatible and interoperable with Ethereum.

Evmos Evmos is a scalable, high-throughput Proof-of-Stake blockchain that is fully compatible and interoperable with Ethereum. It's built using the Co

Dec 31, 2022
Ethermint is a scalable and interoperable Ethereum library, built on Proof-of-Stake with fast-finality using the Cosmos SDK.
Ethermint is a scalable and interoperable Ethereum library, built on Proof-of-Stake with fast-finality using the Cosmos SDK.

Ethermint Ethermint is a scalable and interoperable Ethereum library, built on Proof-of-Stake with fast-finality using the Cosmos SDK which runs on to

Jan 3, 2023
The goal of Binance Smart Chain is to bring programmability and interoperability to Binance Chain

Binance Smart Chain The goal of Binance Smart Chain is to bring programmability

Aug 17, 2022
XT Smart Chain, a chain based on the go-ethereum fork

XT Smart Chain XT Smart Chain (XSC) is a decentralized, high-efficiency and ener

Dec 28, 2022
Berylbit PoW chain using Ethash, EPI-Burn and geth. The chain will be using bot congestion flashbot bundles through nodes

Berylbit PoW chain using Ethash, EPI-Burn and geth. The chain will be using bot congestion flashbot bundles through nodes. Soon, We will work towards

Jun 30, 2022
Go-chain - EVM-compatible chain secured by the Lachesis consensus algorithm

ICICB galaxy EVM-compatible chain secured by the Lachesis consensus algorithm. B

Jun 8, 2022
Celer cBridge relay node implementation in Golang

cBridge Relay Node Official implementation of cBridge relay node in Golang. Prerequisites Prepare Machine To run a cBridge relay node, it is recommend

Sep 27, 2022
a Golang sdk for working with DeFi protocols, and ethereum compatible blockchains
a Golang sdk for working with DeFi protocols, and ethereum compatible blockchains

A golang sdk for working with DeFi protocols and general utilities for working with ethereum-compatible blockchains. packages bclient bindings cli con

Dec 15, 2022
A blockchains platform with high throughput, and blazing fast transactions
A blockchains platform with high throughput, and blazing fast transactions

Node implementation for the Avalanche network - a blockchains platform with high throughput, and blazing fast transactions. Installation Avalanche is

Oct 31, 2021
Avalanche: a network composed of multiple blockchains

Coreth and the C-Chain Avalanche is a network composed of multiple blockchains.

Dec 14, 2022