• Stars
    star
    319
  • Rank 131,491 (Top 3 %)
  • Language
    Rust
  • License
    GNU General Publi...
  • Created about 5 years ago
  • Updated 7 months ago

Reviews

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

Repository Details

🌈🌈🌈 NEAR <> Ethereum Decentralized Bridge

Rainbow Bridge CLI

OPS tool to Rainbow Bridge, an Ethereum to Near trustless, fully decentralized, bidirectional bridge

Build status Bridge Version Telegram Chat

Table of Contents

Pre-requisites

The current version of CLI is all-in-one package -- it is used both for production and testing. As a result, even if you need CLI only for the token transfer you need to install all testing dependencies. This will be changed in the future.

  • Install golang, see.
  • Make sure you are using Node with version >=12 and <=13. We recommend using nvm for installing node and npm, if you already don't have one. This constraint will be removed soon;
  • yarn
  • docker, for deterministic compile rust contracts
  • bash, for preparation steps (needs to be re-implemented in JS)

If you want to test with a local near node:

  • You would also need to install resources needed to compile nearcore (in the future this will only be required for the testing CLI):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup default stable
rustup target add wasm32-unknown-unknown
  • Then install dependencies needed for the compilation of nearcore, see.
  • python3 pip , for nearup

Install nearup

pip3 install nearup

Usage

Clone this repo, yarn install, then to learn the commands that you can use with the rainbow bridge run:

    cli/index.js --help

Parameters of each command can be specified through environment variables, command line arguments, entries in the ~/.rainbow/config.json config file, or the default value will be used -- in that priority. If argument is not provided and there is no default value the program will not execute.

If script successfully executes a command then each parameter provided through the command line argument will be written into the config file. Additionally, if scripts generates new parameters (e.g. it deploys a contract to Ethereum and obtains its address) will also be written into the config file. Arguments should not be specified multiple times.

Note, you can use environment variables to pass sensitive data which will not lead to it being written into the config file.

Security

  • Guide on how to quickly configure the watchdog for Mainnet

Bridge is secure as long as majority (1/2) of Etherem mining power is honest and supermajority (2/3) of NEAR stake is honest. There are no additional security requirements, except that Ethereum should be able to accept 1 transaction within 4 hour period even in the worst congestion scenario.

Gas costs

NEAR fees are negligible, both for bridge maintenance and for token transfer. Ethereum fees are the following:

  • To transfer ERC20 token from ETH to NEAR: Approx 43,989 gas to set allowance and approx 37,407 gas to lock it;
  • To transfer ERC20 token back from NEAR to ETH: Approx 240,531 gas to unlock the token;
  • To submit a NEAR block header: approx 697,140 gas;
  • To challenge a NEAR block header: approx 700k gas.

As of 2020-07-14 (gas price is 40 gwei) the cost of running bridge on NEAR mainnnet and Ethereum mainnet is approx 42 USD/day. The cost of ETH->NEAR transfer of ERC20 token is 1 USD. The cost of NEAR->ETH transfer of ERC20 token is 2 USD.

Using Bridge on Testnet

PoA vs PoW Ethereum networks

Rainbow bridge can be deployed either on PoW or PoA networks. However, the main use case of the bridge is Ethereum Mainnet, which makes its design very PoW-centric and it is only trustless and decentralized for PoW networks. Unfortunately, the only popular PoW testnet is Ropsten, which frequently undergoes huge reorgs of more than 16k blocks, because people test 51% attacks on it. 16k reorgs can wipe out entire contracts and revert days of computations. Overall, Ropsten has the following unfortunate specifics that does not exist with Ethereum Mainnet:

  • Extremely long re-orgs;
  • Gas price volatility -- Ropsten blocks might have orders of magnitude different median gas price;
  • Slow block production -- sometimes Ropsten blocks are produced once per several minutes;
  • Infura is unreliable on Ropsten

Therefore we advise users to not use Ropsten for bridge testing. Instead, we recommend using one of Ethereum's PoA testnet. Unfortunately, PoA networks have a differen header format and are also centralized by nature. Therefore when deploying bridge on PoA network please use --near-client-trusted-signer parameter. This will force EthOnNearClient to not validate Ethereum headers (since PoA headers are not valid PoW headers) and accept them only from the provided authority.

The documenation below assumes Rinkeby testnet.

Using existing bridge on Rinkeby

This section explains how to use existing bridge with mock ERC20 token that was already deployed. You would need to have some amount of this token on Rinkeby, so reach out to [email protected] if you want to give it a try.

We assume you have two accounts:

  • One NEAR account on NEAR testnet with at least 1 NEAR token. We denote it as <near_token_holder_account> and its secret key as <near_token_holder_sk>;
  • One Ethereum account on Rinkeby testnet with at least 1 ETH and 100 ERC20 tokens (this example uses ERC20 deployed to 0x8151a8F90267bFf183E06921841C5dE774499388 as an example. If you want some of these ERC20 tokens please contact [email protected]). We denote it as <eth_token_holder_address> and its private key as <eth_token_holder_sk>;

Make sure you have rainbow cli installed:

yarn install

If you have already used the bridge on this machine run a cleanup:

cli/index.js clean

If you're using rainbow-bridge-cli 1.x, create ~/.rainbow/config.json file with the following content:

{
  "nearNetworkId": "testnet",
  "nearNodeUrl": "https://rpc.testnet.near.org/",
  "ethNodeUrl": "https://rinkeby.infura.io/v3/<project_id>",
  "nearMasterAccount": "<near_token_holder_account>",
  "nearMasterSk": "<near_token_holder_sk>",
  "nearClientAccount": "ethonnearclient10",
  "nearProverAccount": "ethonnearprover10",
  "nearClientTrustedSigner": "eth2nearrelay10.testnet",
  "ethMasterSk": "<eth_token_holder_sk>",
  "ethEd25519Address": "0x9003342d15B21b4C42e1702447fE2f39FfAF55C2",
  "ethClientAddress": "0xF721c979db97413AA9D0F91ad531FaBF769bb09C",
  "ethProverAddress": "0xc5D62d66B8650E6242D9936c7e50E959BA0F9E37",
  "ethErc20Address": "0x8151a8F90267bFf183E06921841C5dE774499388",
  "ethLockerAddress": "0x5f7Cc23F90b5264a083dcB3b171c7111Dc32dD00",
  "nearFunTokenAccount": "mintablefuntoken11"
}

If you are using rainbow-bridge-cli 2.x, create ~/.rainbow/config.json file with the following content:

{
  "nearNetworkId": "testnet",
  "nearNodeUrl": "https://rpc.testnet.near.org/",
  "ethNodeUrl": "https://rinkeby.infura.io/v3/<project_id>",
  "nearMasterAccount": "<near_token_holder_account>",
  "nearMasterSk": "<near_token_holder_sk>",
  "nearClientAccount": "ethonnearclient10",
  "nearProverAccount": "ethonnearprover10",
  "nearClientTrustedSigner": "eth2nearrelay10.testnet",
  "ethMasterSk": "<eth_token_holder_sk>",
  "ethEd25519Address": "0x9003342d15B21b4C42e1702447fE2f39FfAF55C2",
  "ethClientAddress": "0xF721c979db97413AA9D0F91ad531FaBF769bb09C",
  "ethProverAddress": "0xc5D62d66B8650E6242D9936c7e50E959BA0F9E37",
  "nearTokenFactoryAccount": "ntf4.bridge2.testnet",
  "ethErc20Address": "0x21e7381368baa3f3e9640fe19780c4271ad96f37",
  "ethLockerAddress": "0x7f66c116a4f51e43e7c1c33d3714a4acfa9c40fb",
  "nearErc20Account": "21e7381368baa3f3e9640fe19780c4271ad96f37.ntf4.bridge2.testnet"
}

You can get infura project id, by registering at infura.io.

To transfer ERC20 from ETH to NEAR run:

cli/index.js TESTING transfer-eth-erc20-to-near --amount 10 --eth-sender-sk <eth_token_holder_address> --near-receiver-account <near_token_holder_account>

(If the command interrupts in the middle re-run it and it will resume the transfer. PoA RPC sometimes has issues) Wait for the transfer to finish. You should see:

Transferred
Balance of <near_token_holder_account> after the transfer is 10

To transfer ERC20 back from NEAR to ETH run:

cli/index.js TESTING transfer-eth-erc20-from-near --amount 1 --near-sender-account <near_token_holder_account> --near-sender-sk <near_token_holder_sk> --eth-receiver-address <eth_token_holder_address>

You should see:

ERC20 balance of <eth_token_holder_address> after the transfer: 91

Congratulations, you have achieved a roundtrip of ERC20 token through the bridge!

Deploying and Using Locally

To locally test the bridge run:

cli/index.js clean
cli/index.js prepare
cli/index.js start near-node
cli/index.js start ganache

Initializing the contracts

First let's initialize the contracts that bridge needs to function:

cli/index.js init-near-contracts
cli/index.js init-eth-ed25519
cli/index.js init-eth-client --eth-client-lock-eth-amount 1000 --eth-client-lock-duration 10
cli/index.js init-eth-prover

Now, let's set up token on Ethereum blockchain that we can transfer to NEAR blockchain (this can be your own token).

cli/index.js init-eth-erc20
cli/index.js init-eth-locker

Now, let's initialize token factory on NEAR blockchain.

cli/index.js init-near-token-factory

Starting the services

Now start the services that will relay the information between the chains:

cli/index.js start eth2near-relay
cli/index.js start near2eth-relay --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201
cli/index.js start bridge-watchdog --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202

Note, you can observe the logs of the relays by running:

pm2 logs

Transferring tokens

Let's check the balance of bridged tokens from ETH to NEAR before starting the transfer. To this end let's use node0 account, which is automatically created and funded on startup when localnet is started.

cli/index.js TESTING get-bridge-on-near-balance --near-receiver-account node0

Then transfer some tokens with:

cli/index.js TESTING transfer-eth-erc20-to-near --amount 1000 --eth-sender-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200 --near-receiver-account node0 --near-master-account neartokenfactory

Now you check the balance of node0 again. You should notice the balance was changed.

Note, when we deployed ERC20 to the Ethereum blockchain we have minted a large number of tokens to the default master key of Ganache, so we have transferred ERC20 tokens from it to node0 account. Notice that we are using neartokenfactory.node0 account here to pay for the NEAR gas fees, any account for which we know a secret key would've worked too. You must observe blocks being submitted.

You can also manually check the ERC20 balance of the receiver before and after receiving the transfer back from the NEAR side

cli/index.js TESTING get-erc20-balance 0xEC8bE1A5630364292E56D01129E8ee8A9578d7D8

Now let's try to transfer one token back to Ethereum

cli/index.js TESTING transfer-eth-erc20-from-near --amount 1 --near-sender-account node0 --near-sender-sk ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP --eth-receiver-address 0xEC8bE1A5630364292E56D01129E8ee8A9578d7D8

You should observe the change of the ERC20 balance as reported by the CLI.

Stopping the services

To stop relay services and node clients execute the following command:

cli/index.js stop all

Or you can stop them one by one using these commands:

cli/index.js stop near-node
cli/index.js stop ganache
cli/index.js stop eth2near-relay
cli/index.js stop near2eth-relay
cli/index.js stop bridge-watchdog

Contract Development Workflow

Above steps are ways to run a local bridge and development workflows you need if make any changes to rainbow-bridge-cli. If you want to update any of solidity or rust contracts, they're not in this repo now and workflow is as following.

  • Install dependencies:
cli/index.js clean
cli/index.js prepare
  • Start local NEAR network and Ganache
cli/index.js near-node
cli/index.js ganache
  • If you want to modify solidity contracts, go to node_modules/rainbow-bridge-sol, make changes there and run ./build_all.sh to recompile solidity contracts.
  • If you want to modify rust contracts, go to node_modules/ranbow-bridge-rs, make changes there and run ./build_all.sh to recompile rust contracts.
  • If you want to modify rainbow bridge lib, go to node_modules/rainbow-bridge-lib and make changes there
  • Follow instructions above to init eth contracts and near contracts, start services and start testing with bridge
  • For changes to Solidity contract, Rust contract, and rainbow-bridge-lib, please submit PRs to: https://github.com/near/rainbow-bridge-sol , https://github.com/near/rainbow-bridge-rs , and https://github.com/near/rainbow-bridge-lib respectively.
  • After PR merged in contract repos and rainbow-bridge-lib repo, we will periodically publish them as new version of npm packages. And rainbow-bridge-cli will adopt new version of them.

More Repositories

1

aurora-engine

⚙️ Aurora Engine implements an Ethereum Virtual Machine (EVM) on the NEAR Protocol.
Rust
329
star
2

rainbow-bridge-frontend

🌈 Send ERC20 tokens from Ethereum to NEAR
HTML
69
star
3

hardhat-storage-layout

Generate Ethereum smart contract storage layout with Hardhat.
TypeScript
63
star
4

rainbow-token-connector

ERC-20/NEP-141 Token Connector for Rainbow Bridge
Rust
62
star
5

aurora-cli

Aurora Engine command-line interface (CLI).
JavaScript
45
star
6

aurora.js

[DEPRECATED] Aurora Engine client library for JavaScript.
TypeScript
38
star
7

eth-connector

A temporary repo for ETH connector to be used by EVM
JavaScript
36
star
8

doc.aurora.dev

The source repository for the Aurora documentation website.
JavaScript
34
star
9

aurora-contracts-sdk

Rust and Solidity SDK to interact with Aurora.
Rust
30
star
10

near-web3-provider

[Deprecated] Web3 NEAR Provider
JavaScript
27
star
11

evm-bully

Stress testing and benchmarking tool for the NEAR EVM
Go
27
star
12

aurora-relayer

[DEPRECATED] Web3-compatible relayer server for Aurora.
TypeScript
26
star
13

partner-relayer-deploy

Deploy NEAR and Aurora Relayer with up-to-date data, easily.
Shell
25
star
14

evm2near

evm2near compiles Solidity contracts into NEAR WebAssembly contracts.
Rust
25
star
15

rainbow-bridge-client

Monorepo containing Aurora-maintained libraries for using the Rainbow Bridge
TypeScript
25
star
16

near-plugins

Implementation of common patterns used for NEAR smart contracts.
Rust
24
star
17

bridge-assets

Bridge assets info&metadata repository
Python
23
star
18

aurora-examples

A boilerplate for sample DApps/Ethereum contracts on Aurora.
JavaScript
20
star
19

relayer2-public

Web3-compatible relayer server for Aurora.
Go
15
star
20

aurora-cli-rs

Command-line tool for interacting with the Aurora Engine
Rust
14
star
21

borealis-engine-lib

Rust
11
star
22

near-erc20-connector

A connector to Rainbow Bridge that allows sending $NEAR to Ethereum as an ERC-20 token (eNEAR)
Rust
11
star
23

aurora-forwarder-contracts

Smart contracts for the Forwarder project
Rust
10
star
24

backstage-plugin-blockchainradar

Discover and manage contracts, multisigs and their access control policies on various blockchains.
TypeScript
6
star
25

aurora-staking-contracts

Aurora staking contracts
TypeScript
6
star
26

near-api-go

Go library to interact with NEAR Protocol via RPC API
Go
6
star
27

aurora-eth-connector

Aurora Eth Connector contract implementation based on NEP-141 for Aurora Engine contract
Rust
6
star
28

aurora-workspace

Aurora Workspaces library for the Aurora Engine contract based on NEAR Protocol
Rust
6
star
29

rainbow-non-fungible-token-connector

5
star
30

standalone-rpc

Standalone RPC node for Aurora
Shell
5
star
31

bridge-analytics

[DEPRECATED] Bridge-analytics utilities
JavaScript
4
star
32

hardhat-aurora

Hardhat plugin for Aurora.
4
star
33

remaphore

Admin tool employing NATS to coordinate processes on distributed infrastructure.
Go
4
star
34

aurora.go

Aurora Engine client for Go
4
star
35

bridge-metadata

JavaScript
3
star
36

backstage-entities

Handlebars
2
star
37

borealis-block-finder

Find blocks based on properties values
Rust
2
star
38

aurora-testing

Integration test suite for the Aurora stack.
2
star
39

aurora-engine-migration-tool

Aurora Engine migration tool set
Rust
2
star
40

aurora-staking

The Aurora staking pool which generates rewards for those that lock their AURORA.
2
star
41

aurora-utils

Reusable code for go projects
Go
2
star
42

bounties

Bounty program for Aurora Ecosystem
2
star
43

native-erc20-connector

Connect native Aurora ERC-20 tokens with NEAR
Rust
2
star
44

azul-app

TypeScript
2
star
45

evm-relayer

Processes incoming metatransactions, sending them to the NEAR EVM
JavaScript
2
star
46

AIPs

Aurora Improvement Proposals repository
2
star
47

btc-light-client-contract

Bitcoin light client implementation for Near Protocol
Rust
2
star
48

fast-bridge-protocol

Rust
2
star
49

aurora-relayer-dumps

2
star
50

nats-prober

NATS request/response prober
Go
1
star
51

bridge-cli

CLI application to interact with rainbow bridge.
TypeScript
1
star
52

aurora-engine-build

Dockerized build for aurora-engine
Dockerfile
1
star
53

tarserv

Tarserv serves streaming tar files from filesystem snapshots.
Go
1
star
54

.github

GitHub configuration for all Aurora repositories.
1
star
55

aurora-faucet

Faucet web application for the Aurora TestNet and BetaNet.
1
star
56

aurora-plus-staking-graph

TypeScript
1
star
57

sshaclsrv

SSH ACL server.
Go
1
star
58

aurora-press-kit

Aurora press kit.
1
star
59

aurora-relayer-indexer

Aurora relayer indexer
Go
1
star
60

backstage-blockchain-actions

A suite of Backstage workflows for Github Actions
TypeScript
1
star
61

aurora-dao-ui

Aurora DAO user interface
JavaScript
1
star
62

relayer2-base

Aurora Go library providing common basis for public and private relayer implementations
Go
1
star
63

fast-bridge-common

Rust
1
star
64

near-rpc-speedup

This repository provides a guide on how to set up and deploy the near-rpc-speedup project, which enhances the efficiency of NEAR protocol RPC nodes through caching. It includes step-by-step instructions for deploying two critical services using Docker and docker-compose
Shell
1
star