snowfork / snowbridge Goto Github PK
View Code? Open in Web Editor NEWA trustless bridge between Polkadot and Ethereum
Home Page: https://docs.snowbridge.network
License: Apache License 2.0
A trustless bridge between Polkadot and Ethereum
Home Page: https://docs.snowbridge.network
License: Apache License 2.0
The code has become messy and unorganized, especially after I landed the M4 proof-of-concept work.
Current issues:
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.Currently setting up an end-to-end test is tedious and very error-prone.
This should be too long for most substrate chains (~6 seconds block time). Can we maybe add this to the config?
Originally posted by @philipstanislaus in #79 (comment)
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.
For example, rename Broker
to BridgeIn
. Especially since the trait only covers a subset of the Broker module's behavior.
See review comments:
See #79 (comment)
Need to deploy all our infrastructure to some kind of infrastructure. AWS for example.
See #69 (comment)
Need to address this review comment: #100 (comment)
Could you add a comment why we allow longer payloads? Thanks!
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
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/"
@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.
Something like:
Can use this approach, which relies on Netlify's proxy feature: https://community.netlify.com/t/support-guide-can-i-deploy-multiple-repositories-in-a-single-site/179
"properties": {
"ss58Format": 42,
"tokenDecimals": 12,
"tokenSymbol": "ROC"
},
We should calculate the weights for dispatchables in the parachain's lightclient verifier pallet.
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!
There doesn't seem to be a good reason for it. The contents of bridgerelayer/cmd/
could just be moved to bridgerelayer
Can we be more specific with argument names and channels here?
func NewChain(msgsObserved chan<- chain.Message, msgsToSend <-chan chain.Message) (*Chain, error) {
Originally posted by @philipstanislaus in #69 (comment)
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.
Need to do a live of transfer bridged ETH & ERC20 assets from one parachain to another.
Tasks:
We currently run our hashing via code in our parachain wasm binary. Ideally polkadot would add this as a host function we can use directly. If they do this, then we should port over to using it.
Comment on our PR: #147 (comment)
Comment on Substrate keccak: paritytech/substrate@510e68b
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.
The bridge relayer has indirect dependencies on three different versions/forks of GSRPC.
See #40 (comment)
The sovereign account of H on D will be credited with 21 PolkaETH.
=> The sovereign account of H on D will be reduced with 21 PolkaETH
Need to setup a test network in the cloud with our Rococo-compatible parachain.
The runtime-wide hash function is configurable in the frame_system
pallet. So to create a standalone substrate chain, or a parachain it is possible to use Keccak256
. This will simplify the verification process in Solidity as verifying a blake2b header against a hash is expensive.
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)
This is pretty important to ensure that target applications can trust the messages being passed onto them by the verifier.
See https://github.com/Snowfork/polkadot-ethereum/pull/5/files#r453729105
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.
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).
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
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.
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
https://github.com/paritytech/polkadot/tree/gav-xcmp/xcm/xcm-handler
The pallet uses XcmExecutor and TransactAsset to execute messages.
We'll need to perform benchmarking in order to calculate the appropriate weights.
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
.
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).
See https://www.di.ens.fr/~stern/data/St101.pdf.
To resolve, the Verifier contract should be updated with:
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
revert("ECDSA: invalid signature 's' value");
}
The Ethereum relayer's router must be tested to ensure compatibility with the updated Verifier.
The current approach is nicely decoupled but will result in high and varying runtime overhead.
See https://github.com/Snowfork/polkadot-ethereum/pull/5/files#r453730843
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:
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
Implement TransactAsset trait to enable withdraws and deposits from our assets pallet via XCMP
https://github.com/paritytech/polkadot/blob/master/xcm/xcm-executor/src/traits.rs#L58
To save gas, we could just iterate backwards over the array instead of reversing it, right?
Originally posted by @philipstanislaus in #51 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.