• Stars
    star
    493
  • Rank 89,239 (Top 2 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CosmosSDK application for moving assets on and off of EVM based, POW chains

Gravity Bridge

Gravity bridge is Cosmos <-> Ethereum bridge designed to run on the Cosmos Hub focused on maximum design simplicity and efficiency.

Gravity can transfer ERC20 assets originating on Ethereum to a Cosmos based chain and back to Ethereum.

The ability to transfer assets originating on Cosmos to an ERC20 representation on Ethereum is coming within a few months.

Status

Gravity bridge is under development and will be undergoing audits soon. Instructions for deployment and use are provided in the hope that they will be useful.

It is your responsibility to understand the financial, legal, and other risks of using this software. There is no guarantee of functionality or safety. You use Gravity entirely at your own risk.

You can keep up with the latest development by watching our public standups feel free to join yourself and ask questions.

  • Solidity Contract
    • Multiple ERC20 support
    • Tested with 100+ validators
    • Unit tests for every throw condition
    • Audit for assets originating on Ethereum
    • Support for issuing Cosmos assets on Ethereum
  • Cosmos Module
    • Basic validator set syncing
    • Basic transaction batch generation
    • Ethereum -> Cosmos Token issuing
    • Cosmos -> Ethereum Token issuing
    • Bootstrapping
    • Genesis file save/load
    • Validator set syncing edge cases
    • Slashing
    • Relaying edge cases
    • Transaction batch edge cases
    • Support for issuing Cosmos assets on Ethereum
    • Audit
  • Orchestrator / Relayer
    • Validator set update relaying
    • Ethereum -> Cosmos Oracle
    • Transaction batch relaying
    • Tendermint KMS support
    • Audit

The design of Gravity Bridge

  • Trust in the integrity of the Gravity bridge is anchored on the Cosmos side. The signing of fraudulent validator set updates and transaction batches meant for the Ethereum contract is punished by slashing on the Cosmos chain. If you trust the Cosmos chain, you can trust the Gravity bridge operated by it, as long as it is operated within certain parameters.
  • It is mandatory for peg zone validators to maintain a trusted Ethereum node. This removes all trust and game theory implications that usually arise from independent relayers, once again dramatically simplifying the design.

Key design Components

  • A highly efficient way of mirroring Cosmos validator voting onto Ethereum. The Gravity solidity contract has validator set updates costing ~500,000 gas ($2 @ 20gwei), tested on a snapshot of the Cosmos Hub validator set with 125 validators. Verifying the votes of the validator set is the most expensive on chain operation Gravity has to perform. Our highly optimized Solidity code provides enormous cost savings. Existing bridges incur more than double the gas costs for signature sets as small as 8 signers.
  • Transactions from Cosmos to ethereum are batched, batches have a base cost of ~500,000 gas ($2 @ 20gwei). Batches may contain arbitrary numbers of transactions within the limits of ERC20 sends per block, allowing for costs to be heavily amortized on high volume bridges.

Operational parameters ensuring security

  • There must be a validator set update made on the Ethereum contract by calling the updateValset method at least once every Cosmos unbonding period (usually 2 weeks). This is because if there has not been an update for longer than the unbonding period, the validator set stored by the Ethereum contract could contain validators who cannot be slashed for misbehavior.
  • Cosmos full nodes do not verify events coming from Ethereum. These events are accepted into the Cosmos state based purely on the signatures of the current validator set. It is possible for the validators with >2/3 of the stake to put events into the Cosmos state which never happened on Ethereum. In this case observers of both chains will need to "raise the alarm". We have built this functionality into the relayer.

Run Gravity bridge right now using docker

We provide a one button integration test that deploys a full arbitrary validator Cosmos chain and testnet Geth chain for both development + validation. We believe having a in depth test environment reflecting the full deployment and production-like use of the code is essential to productive development.

Currently on every commit we send hundreds of transactions, dozens of validator set updates, and several transaction batches in our test environment. This provides a high level of quality assurance for the Gravity bridge.

Because the tests build absolutely everything in this repository they do take a significant amount of time to run. You may wish to simply push to a branch and have Github CI take care of the actual running of the tests.

To run the test simply have docker installed and run.

bash tests/all-up-test.sh

There are optional tests for specific features

Valset stress changes the validating power randomly 25 times, in an attempt to break validator set syncing

bash tests/all-up-test.sh VALSET_STRESS

Batch stress sends 300 transactions over the bridge and then 3 batches back to Ethereum. This code can do up to 10k transactions but Github Actions does not have the horsepower.

bash tests/all-up-test.sh BATCH_STRESS

Validator out tests a validator that is not running the mandatory Ethereum node. This validator will be slashed and the bridge will remain functioning.

bash tests/all-up-test.sh VALIDATOR_OUT

Developer guide

Solidity Contract

in the solidity folder

Run HUSKY_SKIP_INSTALL=1 npm install, then npm run typechain.

Run npm run evm in a separate terminal and then

Run npm run test to run tests.

After modifying solidity files, run npm run typechain to recompile contract typedefs.

The Solidity contract is also covered in the Cosmos module tests, where it will be automatically deployed to the Geth test chain inside the development container for a micro testnet every integration test run.

Cosmos Module

We provide a standard container-based development environment that automatically bootstraps a Cosmos chain and Ethereum chain for testing. We believe standardization of the development environment and ease of development are essential so please file issues if you run into issues with the development flow.

Go unit tests

These do not run the entire chain but instead test parts of the Go module code in isolation. To run them, go into /module and run make test

To hand test your changes quickly

This method is dictinct from the all up test described above. Although it runs the same components it's much faster when editing individual components.

  1. run ./tests/build-container.sh
  2. run ./tests/start-chains.sh
  3. switch to a new terminal and run ./tests/run-tests.sh
  4. Or, docker exec -it gravity_test_instance /bin/bash should allow you to access a shell inside the test container

Change the code, and when you want to test it again, restart ./tests/start-chains.sh and run ./tests/run-tests.sh.

Explanation:

./tests/build-container.sh builds the base container and builds the Gravity test zone for the first time. This results in a Docker container which contains cached Go dependencies (the base container).

./tests/start-chains.sh starts a test container based on the base container and copies the current source code (including any changes you have made) into it. It then builds the Gravity test zone, benefiting from the cached Go dependencies. It then starts the Cosmos chain running on your new code. It also starts an Ethereum node. These nodes stay running in the terminal you started it in, and it can be useful to look at the logs. Be aware that this also mounts the Gravity repo folder into the container, meaning changes you make will be reflected there.

./tests/run-tests.sh connects to the running test container and runs the integration test found in ./tests/integration-tests.sh

Tips for IDEs:

  • Launch VS Code in /solidity with the solidity extension enabled to get inline typechecking of the solidity contract
  • Launch VS Code in /module/app with the go extension enabled to get inline typechecking of the dummy cosmos chain

Working inside the container

It can be useful to modify, recompile, and restart the testnet without restarting the container, for example if you are running a text editor in the container and would not like it to exit, or if you are editing dependencies stored in the container's /go/ folder.

In this workflow, you can use ./tests/reload-code.sh to recompile and restart the testnet without restarting the container.

For example, you can use VS Code's "Remote-Container" extension to attach to the running container started with ./tests/start-chains.sh, then edit the code inside the container, restart the testnet with ./tests/reload-code.sh, and run the tests with ./tests/integration-tests.sh.

Debugger

To use a stepping debugger in VS Code, follow the "Working inside the container" instructions above, but set up a one node testnet using ./tests/reload-code.sh 1. Now kill the node with pkill gravityd. Start the debugger from within VS Code, and you will have a 1 node debuggable testnet.

More Repositories

1

cosmos-sdk

⛓️ A Framework for Building High Value Public Blockchains ✨
Go
6,216
star
2

cosmos

Internet of Blockchains ⚛
TeX
1,266
star
3

ibc

Interchain Standards (ICS) for the Cosmos network & interchain ecosystem.
TeX
914
star
4

ethermint-archive

Ethereum on Tendermint using Cosmos-SDK!
Go
662
star
5

cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
TypeScript
641
star
6

ibc-go

Inter-Blockchain Communication Protocol (IBC) implementation in Golang.
Go
541
star
7

awesome-cosmos

Collection of Cosmos related resources
516
star
8

chain-registry

Python
510
star
9

sdk-tutorials

Tutorials for building modules for the Cosmos SDK
Go
495
star
10

gaia

Cosmos Hub
Go
470
star
11

iavl

Merkleized IAVL+ Tree implementation in Go
Go
417
star
12

ethermint

Ethermint is a scalable and interoperable Ethereum, built on Proof-of-Stake with fast-finality using the Cosmos SDK.
Go
410
star
13

relayer

An IBC relayer for ibc-go
Go
389
star
14

cosmos-rust

The home of all shared Rust resources for the Cosmos ecosystem.
Rust
302
star
15

ibc-rs

Rust implementation of the Inter-Blockchain Communication (IBC) protocol.
Rust
200
star
16

testnets

Cosmos Testnets
Shell
157
star
17

interchain-security

Replicated security (aka interchain security V1) is an open sourced IBC application which allows cosmos blockchains to lease their proof-of-stake security to one another.
Go
153
star
18

mainnet

It's happening!
Go
127
star
19

ics23

Building generic merkle proof format for IBC
Rust
116
star
20

gex

In-terminal explorer for Cosmos SDK blockchains.
Go
97
star
21

ibc-apps

IBC applications and middleware for Cosmos SDK chains.
Go
82
star
22

cosmos-multisig-ui

Create multisigs and multisig transactions on Cosmos chains
TypeScript
81
star
23

cosmos-academy

Content for Cosmos Academy
Go
68
star
24

stargate-launch

58
star
25

gogoproto

Protocol Buffers for Go with Gadgets for Cosmos
Go
57
star
26

relayer-archive

An example of a server side IBC relayer to be used for Game of Zones and beyond
Go
56
star
27

scaffold

Scaffolding for Cosmos-SDK based application
Go
55
star
28

game-of-stakes

Python
52
star
29

ledger-cosmos

C
52
star
30

ibc-proto-rs

Rust Protobuf definitions and gRPC clients for interacting with Cosmos SDK, IBC and Interchain Security
Rust
47
star
31

modules

Go
44
star
32

ledger-cosmos-obsolete

Ledger Nano S support for Tendermint/Cosmos
C++
42
star
33

governance

Resources for Cosmos governance
Shell
40
star
34

snap

Packages That Add Cosmos Support Into Metamask. The Cosmos is Expanding!
TypeScript
38
star
35

cosmos-proto

Go
36
star
36

b9-checkers-academy-draft

TypeScript
32
star
37

amino-js

go-amino + GopherJS + TypeScript
Go
31
star
38

faucet

Token faucet web app for the Cosmos Hub and Gaia testnets.
Vue
25
star
39

atlas

An open source Cosmos SDK module registry.
Vue
25
star
40

cips

The Cosmos Improvements Proposals
JavaScript
25
star
41

cosmos-db

Go
22
star
42

research

21
star
43

developer-portal

JavaScript
21
star
44

cosmos-sdk-js

(NOTICE: Very out of date) JavaScript client for the Cosmos SDK API
JavaScript
20
star
45

gosec

Go
18
star
46

sp1-ics07-tendermint

This is a zero knowledge IBC tendermint light client written using SP1 and ibc-rs (WIP)
Rust
18
star
47

stargate

Stargate Roadmap Website
Vue
17
star
48

burner-chains

Low-security temporary experimental application-specific blockchains
17
star
49

vuepress-theme-cosmos

This repository is deprecated and is not maintained. Please, use another system for documentation.
Vue
16
star
50

v1.cosmos.network

DEPRECATED - The website for Cosmos - Internet of Blockchains
HTML
15
star
51

qa-integration

Python
15
star
52

ethermint_abci

DEPRECATED - moved to https://github.com/cosmos/ethermint
Go
15
star
53

interchain-attestation

Go
13
star
54

vega-test

Shell
12
star
55

fundraiser-cli

CLI tool for participating in Cosmos Fundraiser
Go
12
star
56

registry

11
star
57

community

11
star
58

cosmos-registrar

A tool for pulling data from cosmos networks and pushing it to git repos
Go
10
star
59

solidity-ibc-eureka

This is a work-in-progress solidity implementation of IBC Eureka.
Solidity
9
star
60

fundraiser-lib

JS module for participating in Cosmos Fundraiser
JavaScript
9
star
61

composer

TypeScript
9
star
62

cosmos-sdk-docs

HTML
9
star
63

ledger-cosmos-go

Go
8
star
64

groups-ui

TypeScript
7
star
65

security

Cosmos Security contains guidelines (and tools in the future) for a responsible security incident disclosure
7
star
66

rollkit-ibc

Rollkit Wasm light client (WIP)
Go
6
star
67

iavl-bench

Go
6
star
68

interchain-security-gravity

Python
6
star
69

faucet-backend

Faucet Backend
Go
6
star
70

ibc-docs

5
star
71

chainparse

Go
5
star
72

advocates

Cosmos Advocates
5
star
73

images

Cosmos Docker Images
Shell
4
star
74

keystone

Go
4
star
75

rosetta

Rosetta implementation for cosmos zones
Go
4
star
76

academy-checkers-ui

TypeScript
4
star
77

.github

GitHub Actions, Workflows, and templates used across the Cosmos org.
4
star
78

vanity

HTML
4
star
79

fundraiser

Code for the fundraiser subdomain
Vue
3
star
80

did-cosmos

3
star
81

tools

Tools used in our various repos
Go
3
star
82

gravity-dex-site

Gravity DEX: The Cosmos Interchain Exchange
Vue
3
star
83

hackatom2021

HackAtom VI
Vue
3
star
84

jobs

PHP
3
star
85

cosmos-sdk-ics-fork

2
star
86

nightly-stack

2
star
87

gravity-bridge-site

Vue
1
star
88

temp-archive

1
star
89

crypto

Go
1
star
90

conversations-site

CSS
1
star
91

hackatom2020

HackAtom V
Vue
1
star
92

wallet-registry

1
star
93

gogogateway

Go
1
star