Giter Club home page Giter Club logo

gear-bridges's Introduction

Gear Bridges

Gear Bridge is an implementation of a trustless ZK-based cross-chain bridge facilitating the transfer of assets between Ethereum and Gear-based blockchains, such as the Vara network.

High-Level One-Directional Gear -> Eth Design

The Gear -> Eth transfer protocol allows relaying messages from Gear-based blockchains to Ethereum. These messages consist of generic data defined by protocols built on top of the bridge. The protocol doesn't guarantee the order in which messages are relayed.

This repository contains the implementation of a token bridging protocol built on top of a more generic messaging protocol.

Components Present in Gear -> Eth Bridge

Components of Gear -> Eth Bridge

  • GRC-20: A program capable of transferring, burning, and minting GRC-20 tokens. It repeats the implementation of the ERC20 standard on the Gear network, the standard implementation GRC-20 can be found here.
  • GRC-20 Gateway: Receives GRC-20 tokens from users, burns them, and emits a message to the pallet-gear-bridge built-in actor. This message contains information about which token is being bridged, how much of it, and the recipient of funds on the Ethereum network.
  • Pallet-Gear-Bridges: a Built-in Actor - the entry point into the generic bridging protocol. Receives messages from any actor on the Gear network and relays them to pallet-gear-bridge.
  • Pallet-Gear-Bridge: Receives messages from the pallet-gear-bridges built-in actor and stores them in the binary Merkle trie. This Merkle trie gets slashed at the end of each ERA.
  • Backend: Reads Gear state, queues ZK-proof generation, and submits ZK-proofs to Ethereum.
  • Prover: Capable of creating two types of ZK-proofs: proof of authority set changes and proof of inclusion of Merkle trie root into the storage of pallet-gear-bridge. The combination of these proofs allows for trustless relaying of Merkle trie roots from pallet-gear-bridge storage to Ethereum.
  • Relayer Contract: Accepts proofs of Merkle trie root inclusion and, if they're valid, stores Merkle trie roots in memory.
  • Gnark-Verifier: A contract capable of verifying plonk proofs created by gnark. The submitted proofs are plonky2 proofs wrapped by gnark.
  • Message Queue Contract: Used to recover messages from Merkle tries. A user can request a message to be relayed further onto Ethereum by providing proof of inclusion of a message actually included in the Merkle trie, given that this Merkle root was already relayed by backend (or another party). This is also the exit point of the generic Gear -> Eth bridging protocol.
  • ERC20 Treasury: A treasury that accepts user funds and releases them. Release can only be triggered by a message relayed over the bridge from the GRC-20 gateway.

Workflow of Gear -> Eth Token* Transfer

Note

*Gear itself is not a blockchain network and has no native token. This refers to the token of any network built on Gear technology, such as Vara.

Workflow of Gear -> Eth Transferr

  • The user submits a message to the GRC-20 gateway to initiate bridging.
  • The GRC-20 gateway burns GRC-20 tokens and emits a message to the pallet-gear-bridge built-in actor.
  • The pallet-gear-bridge built-in actor relays the message to pallet-gear-bridge.
  • The pallet-gear-bridge stores the message in a Merkle trie.
  • Eventually, the backend (or another party) relays the message to the relayer contract, and it gets stored there.
  • The user sees that their message was relayed and submits a Merkle proof of inclusion to the message queue contract.
  • The message queue contract reads the Merkle root from the relayer contract, checks the Merkle proof, and relays the message to the ERC20 treasury.
  • The ERC20 treasury releases funds to the user's account on Ethereum.

Prover Circuits

Block Finality

The Block Finality circuit proves that a specific block was finalized by an authority set on the Gear chain. This involves verifying that a majority (>2/3) of validators have signed the GRANDPA vote for the block.

block finality circuit

Validator Set Change

The Validator Set Change circuit proves that the validator set has changed. This change means that the current validator set finalized a block containing the next validator set in its storage. The circuit verifies that a majority of validators from the current set have set hash inclusion into the storage of pallet-gear-bridge and signed the vote for the change.

validator set change circuit

Substrate Storage Trie Circuits

Substrate storage trie circuits are used to prove the inclusion of data into the Substrate storage trie. Currently, there are two types of nodes supported:

Branch Node Without Value

This circuit parses branch nodes in the trie, which do not contain a value but help navigate the structure.

branch node parser circuit

Hashed Value Leaf

This circuit parses leaf nodes in the trie, which contain the hashed values of the stored data.

leaf node parser circuit

These individual proofs are composed into a storage proof, which proves that specific data exists at a particular address within a block's storage.

storage proof circuit

Recent Validator Set

The Recent Validator Set circuit is used to prove a chain of validator set changes, demonstrating the transition from the genesis validator set to the most recent validator set. The genesis validator set is encoded as a constant within the circuit.

recent validator set circuit

Message Inclusion

The Message Inclusion circuit is used to prove that a specific message Merkle root was submitted on the Gear chain for bridging, indicating its inclusion in the pallet-gear-bridge storage.

message sent circuit

Final Proof

The Final Proof circuit is the proof submitted to Ethereum. It proves that a message Merkle root was present in the storage of pallet-gear-bridge at a specific finalized block. This final proof ensures the validity of the cross-chain message.

final proof circuit

gear-bridges's People

Contributors

mertwole avatar koinov avatar gshep avatar holykol avatar

Stargazers

 avatar Nicolas Marshall avatar  avatar Javed Khan avatar Vadim Smirnov avatar Shun Kakinoki avatar  avatar saham avatar

Watchers

 avatar  avatar

gear-bridges's Issues

Move to `BEEFY`

Add BEEFY to gear and verify BEEFY signatures(probably ECDSA) in prover

Relayers stability

Problem to Solve

For now relayers consider tx succeeded when it's submitted to ethereum

Possible Solution

Wait for block finalization on ethereum

Notes

No response

Implement trusted proof storage on gear

After #14

Store proofs in some program on VARA to provide guarantee of possibility to relay message after indefinite time passed as it was sent on VARA. To achieve this, this program may verify proofs to provide single-point access to all the historical proofs for validator set changes.

Introduce mocks for circuits

Proving may take a long time, so for the testability it's preferrable to use circuit mocks that can be proven in reasonable times

Relayer for Checkpointeths

Problem to Solve

construct finality/period updates and send them to Checkpointeths
determine the state of the program on startup and replay back checkpoints if necessary

Possible Solution

Notes

No response

Bridging payment service

Problem to Solve

Possible Solution

Introduce program that will charge users for bridging

Notes

No response

Emergency stop

If 2 proofs are submitted and both are valid but have conflicting data then bridge must be halted.

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.