Giter Site home page Giter Site logo

snowfork / snowbridge Goto Github PK

View Code? Open in Web Editor NEW
274.0 27.0 97.0 38.86 MB

A trustless bridge between Polkadot and Ethereum

Home Page: https://docs.snowbridge.network

License: Apache License 2.0

Rust 7.68% Shell 5.19% JavaScript 1.20% Go 47.43% Solidity 24.15% Dockerfile 0.02% TypeScript 13.33% Python 0.20% Nix 0.35% HTML 0.18% CSS 0.18% Handlebars 0.09%
polkadot ethereum

snowbridge's People

Contributors

alistair-singh avatar blablacio avatar claravanstaden avatar denalimarsh avatar dependabot[bot] avatar doubledup avatar geimaj avatar guqicun avatar lederstrumpf avatar musnit avatar noc2 avatar parthdesai avatar philipstanislaus avatar rizziepit avatar sumitsnk avatar vgeddes avatar wildmolasses avatar yrong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snowbridge's Issues

Relayer should be refactored

The code has become messy and unorganized, especially after I landed the M4 proof-of-concept work.

Current issues:

  • Need to make the ethereum and substrate parts match each other in terms of general design
  • Application layer concerns have leaked into the bridge level, especially in the substrate portion.
  • The Router concept/type used by our chain implementations doesn't really fit IMO, and makes message sending seem more complex than it needs to be.
  • Style issues (golint, gofmt, etc)

Handle Infura connection drops

Infura is known to drop idle websocket connections, and our relayer does not handle these robustly. This means that after a period of idleness, the header & event subscriptions will be terminated silently.

Cumulus Integration

Need to convert our standalone chain into a Rococo-compatible parachain using the Cumulus toolkit.

Our rococo contains the latest code for this endeavour. Due to ongoing development in upstream dependencies, this work will stay in a branch until things have stabilized.

  • Update chain for compatibility with Substrate v2.0.0-rc5 / rc6: #124
  • Switch Substrate version to rococo-branch
  • Integrate cumulus toolkit
  • Test integration following the setup in the Cumulus workshop

Handling multiple events in a single transaction

Currently, events will be protected from replay protection by checking against the transaction id + block that they originate. This means that two events coming from the same transaction id + block may be considered as the same event, even when there may be two different events in the same transaction.

We need to make sure we can handle this scenario. This should be handled when we migrate to block/transaction processing through light clients, deprecating current dummy verification

Cannot run relayer

Trying to run relayer but it fails:

$ build/artemis-relay run --config /tmp/relay-config.toml
Using config file: /tmp/relay-config.toml
ERRO[0000] Failed to initialize relayer                  error="invalid length, need 256 bits"
Error: invalid length, need 256 bits

Go version

$ go version
go version go1.15.2 linux/amd64

Config file:

 cat /tmp/relay-config.toml
[ethereum]
endpoint = "ws://localhost:9545/"
  [ethereum.bridge]
  address = "0x3629571d48274D3f97fAa41b6E0fa563a1C7618F"
  abi = "/tmp/Bridge-a1a9a522"
[ethereum.apps.eth]
address = "0x6ec61C7B86D1fa37616C5A7a5e0452Fb2Ab0c3E8"
abi = "/tmp/ETHApp-b2823f36"
[ethereum.apps.erc20]
address = "0x103098d4Df85bf4FEF3130fb361c571d57c2271c"
abi = "/tmp/ERC20App-8a2fe332"
[substrate]
endpoint = "ws://127.0.0.1:9944/"

ETHApp contract won't unlock entire amount

@Noc2 got the following error the first time he ran the test suite. the second time it ran fine though. sounds like something fishy worth digging into - @denalimarsh @vgeddes any thoughts? maybe its a timing related thing.

sudo yarn test

yarn run v1.22.5
$ mocha --timeout 35000 --exit


  Bridge
    ETH App
      ✓ should transfer ETH from Ethereum to Substrate (10085ms)
      1) should transfer ETH from Substrate to Ethereum
    ERC20 App
      ✓ should transfer ERC20 tokens from Ethereum to Substrate (10174ms)
      ✓ should transfer ERC20 from Substrate to Ethereum (30078ms)


  3 passing (1m)
  1 failing

  1) Bridge
       ETH App
         should transfer ETH from Substrate to Ethereum:

      AssertionError: expected '0' to equal '10000000000000000'
      + expected - actual

      -0
      +10000000000000000
      
      at Context.<anonymous> (test/test.js:70:71)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)



error Command failed with exit code 1.

cannot start relayer

After I deployed ethereum smart contract using truffle and ran the parachain bridge, I got error when running relayer:

Using config file: /tmp/relay-config.toml

ERRO[0000] Failed to initialize relayer                  
error="json: cannot unmarshal object into Go value of type []struct { Type string; Name string; Inputs []abi.Argument; Outputs []abi.Argument; StateMutability string; Constant bool; Payable bool; Anonymous bool }"

Error: json: cannot unmarshal object into Go value of type []struct { Type string; Name string; Inputs []abi.Argument; Outputs []abi.Argument; StateMutability string; Constant bool; Payable bool; Anonymous bool }

Here is my relay-config.toml:

endpoint = "ws://localhost:9545/"
[ethereum.bridge]
address = "0x722bd05E96b1841cFdfb79E174867541c2AaDEa5"

abi = "/tmp/Bridge.json"
[ethereum.apps.eth]
address = "0xd4b4131bcF86B14B28c4bf2D40A17D88e5fbC2f3"

abi = "/tmp/ETHApp.json"
[ethereum.apps.erc20]
address = "0xb8fDBE6AC4264654B3290108237F7A3C94A70221"

abi = "/tmp/ERC20App.json"
[substrate]
endpoint = "ws://127.0.0.1:9944/"

Is any hint for where is wrong? What is the supported golang version for relayer? Thanks!

Store secrets in AWS secrets

Our Ansible tooling needs to access various secrets in order to generate configuration for our services. We're currently using Ansible Vault to store these secrets in encrypted form in our repo.

This isn't ideal as our repo is public and everyone has access to the ciphertext. So we should try and use AWS Secrets instead.

Ansible Vault is probably still fine for secrets with minor impact such as login usernames, etc.

Integration tests for XCMP transfers

Need to do a live of transfer bridged ETH & ERC20 assets from one parachain to another.

Tasks:

  • Deploy our updated parachain to a testnet
  • Register it twice with different ParaIds.
  • Test XCMP transfers for both ETH and ERC20 transfers.

Decode generic length SCALE-encoded bytes

We've implemented compact uint decoding, allowing us to parse the length of arbitrary SCALE-encoded bytes and use it to properly decode the data. However, we're not currently using the compact uint decoding functionality. As we know the exact length of each variable in the encoded data package submitted to the EthereumApp and ERC20App we're able to decode it according to preset length expectations. While this works for a finite number of registered applications (M4 has just two applications) we'll want to put everything together and decode the SCALE-encoded data in a generic way.

Relayer should be more robust

  • Audit our error handling to ensure that errors don't cause unrecoverable failures, segfaults, exits, etc.
  • Need some way to keep track of which blocks for which we've relayed or haven't relayed events.
  • Improve logging

Provision a test network

Need to setup a test network in the cloud with our Rococo-compatible parachain.

  • Setup Ansible boilerplate
  • Provision AWS resources
  • Deploy relay chain
  • Deploy parachain
  • Deploy relayer daemon for cross-chain transfers
  • DNS endpoints and SSL certificates

Parachain: Verifier should try and keep storage size bounded

Just as a note for the future to keep the storage size bounded:

We could simply have a double map here, where the first key is the block height of the received message. We can the define a maxTailLength, e. g. 200 blocks, and just remove all storage keys where height < currentHeight - 200. At the same time, we decline verification for older blocks.

Originally posted by @philipstanislaus in #79 (comment)

Fix decoding of pallet_scheduler events

Our type definitions in the file below don't match reality, which causes decoding of pallet_scheduler events to fail. This would prevent events from being read for the entire block if the block contains a single pallet_scheduler event:
https://github.com/Snowfork/polkadot-ethereum/blob/v0.2.1-alpha/bridgerelayer/chains/substrate/events.go#L7
https://github.com/Snowfork/polkadot-ethereum/blob/v0.2.1-alpha/bridgerelayer/chains/substrate/streamer.go#L122

The actual fix should go into GSRPC since pallet_scheduler is one of the standard FRAME pallets. So we should move the scheduler event definitions from bridgerelayer/chains/substrate/events.go into GSRPC.

Restrict message size on our parachain

To reduce attack vectors, our parachain should restrict the maximum message size. Not sure what a reasonable limit might be, but I propose that few chains would need more than 2,048 bits (8 * 256 bit words).

Update dependencies for Rococo + XCMP

Figure which upstream branches we're supposed to be using:

Polkadot branch: master (Acala still on gav-xcmp)
Substrate dependency: Not sure (either v2.0.0-rc5 or rococo-branch)
Cumulus branch: Not sure but probably gav-xcmp according to AcalaNetwork/Acala#426

Make use of App IDs to identify applications

Our early design envisioned identifying applications on both chains using opaque 256-bit identifiers. During development however we never diverted from that approach, and used more ad-hoc means of identification in order to get a basic proof of work complete.

We'll need to figure out a final solution for M5.

Update ethashproof merkle roots for Ethereum Lightclient

Our ethash verification relies on having the merkle root of the DAG for the given epoch. We store these roots for the first 512 epochs here: https://github.com/Snowfork/polkadot-ethereum/blob/main/parachain/primitives/ethereum/src/ethashdata.rs. 512 epochs will run out after ~600 days from the date of this issue (very rough estimate based on current block production rate). We should update merkle roots well before that.

The merkle roots can be calculated using https://github.com/talbaneth/ethashproof

Encode recipient's Polkadot address in Bank contract

The recipient's Polkadot address needs to have a fixed length. As different valid addresses can be hex-encoded to different lengths, this is a problem. One potential solution is encoding the Polkadot address to base58 on contract or not packing the data before event emission e.g. using abi.encode instead of abi.encodePacked.

Relayer should submit a mortal extrinsic

From Philip:

Immortal extrinsics are an issue indeed: Since nonces are tracked per account, and accounts can be reaped (nonce will be reset), any immortal transaction can be replayed.

Hence, anyone can mess up our bridge by replaying immortal extrinsics after a reap happens (even if accidentally).

Add token dealer pallet for XCMP

We need to add a pallet that makes it easy to transfer assets using XCMP. The pallet should have dispatchables that allow users to initiate the following asset transfers:

  • Transfer DOT to upwards to the relay chain
  • Transfer bridged Ethereum assets to sibling parachains.

Lock in version of Rust ethash

artemis-ethereum and pallet-verifier-lightclient rely on the Rust ethash implementation at https://github.com/rust-ethereum/ethash. The latest published version is 0.4.0 which uses ethereum-types ^0.8 and primitive-types ^0.6. However, we use 0.9 and 0.7 respectively. To avoid messy type conversions, we either need to get a new version of ethash published, or maintain our own fork like Near did (https://github.com/nearprotocol/rust-ethash?branch=upgrade-eth-types). We're currently using the Near fork

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.