Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This, along with the wonderful Ethash verification work done by SmartPool, allow

## How It Works
* Important Notes:
* In order to do cross-chain verification, we need valid block header informations stored in PeaceRelay contracts so that other proofs (Eg. transaction proof, account state proof) can be verified based on merkle roots in the block header. In this rudimentary version of Peace Relay, we assume the block header submitted is the correct header from the counter chain. In the future, these headers will be verified based on PoW within and chain re-organization will be taken care of.
* In order to do cross-chain verification, we need valid block header information stored in PeaceRelay contracts so that other proofs (Eg. transaction proof, account state proof) can be verified based on merkle roots in the block header. In this rudimentary version of Peace Relay, we assume the block header submitted is the correct header from the counter chain. In the future, these headers will be verified based on PoW within and chain re-organization will be taken care of.
* In the demo, when user in one chain (say ETH) wants to transfer his funds to another chain (say ETC). He will lock his ethers in ETH and gets some tokens on ETC in return. He then can use these tokens for his business on ETC chain. If someone wish to trade ethers between chains, they can use Peace Relay the way others use BTC Relay - by verifying a transaction and its value.

* Step by step:
Expand All @@ -22,14 +22,14 @@ This, along with the wonderful Ethash verification work done by SmartPool, allow
* `ETHLocking` contract deployed on Kovan
* `ETHToken` contract deployed on Rinkeby

### ETH to ETH tokens on ETC / Kovan to Rinkeby
### ETH to ETH tokens on ETC || Kovan to Rinkeby
1. Send the desired ETH to be converted to the `ETHLocking` contract on Kovan using the `ETHLocking.lock()` function.
- Note that there is no way this function will abort(throw) unless it runs out of gas during execution.
2. Wait for Kovan block which contains the transaction to be relayed to Rinkeby. In the meantime, generate the proof of the transaction off-chain.
3. Send transaction to execute `ETHToken.mint()` function using the generated proof in the previous step. This will mint ETH tokens.
- The user can then spend those tokens at will until one day where they wish to convert them back to ethers in ETH / Kovan

### ETH tokens on ETC back to ETH / Rinkeby back to Kovan
### ETH tokens on ETC back to ETH || Rinkeby back to Kovan
1. Send tokens to be burnt using the `ETHToken.burn()` function.
2. Wait for Rinkeby block containing the transaction to be relayed to Kovan. In the meantime, generate the proof of the transaction off-chain.
- The proof here contains the transaction and corresponding transaction receipt
Expand All @@ -41,13 +41,15 @@ There are 2 wallets needed: 1 that does the submitting of block headers, and ano

## Contract deployment
The contracts' codes can be found in the ./contracts folder.
1. Deploy a `PeaceRelay` contract on Rinkeby. This contract relays block headers from Kovan.
2. Deploy another `PeaceRelay` contract on Kovan. This contract relays block headers from Rinkeby.
3. Deploy a `ETHToken` contract on Rinkeby, which takes in the Rinkeby `PeaceRelay` contract address (Step 1) as a constructor argument.
4. Deploy a `ETHLocking` contract on Kovan, which has the Kovan `PeaceRelay` (Step 2) and Rinkeby `ETHToken` contract (Step 3) addresses as its constructor arguments.
1. Deploy a `PeaceRelay` contract on Rinkeby. This contract relays block headers from Kovan. The constructor argument is the desired **Kovan** block number to start relaying from, such as `7422101`.
2. Deploy a `ETHToken` contract on Rinkeby, which takes in the Rinkeby `PeaceRelay` contract address (previous step) as a constructor argument. Eg. `"0xa469a40f1bfa089761b226c084c6eaec6a19bc4f"`
3. Deploy another `PeaceRelay` contract on Kovan. This contract relays block headers from Rinkeby. The constructor argument is the desired **Rinkeby** block number to start relaying from.
4. Deploy a `ETHLocking` contract on Kovan, which has the Rinkeby `ETHToken` (Step 2) and Kovan `PeaceRelay` (Step 3) contract addresses as its constructor arguments. Eg. `"0xd8f16118cd79042491cde899d4963aae7d35fb7b","0xa469a40f1bfa089761b226c084c6eaec6a19bc4f"`
5. Go back to the deployed `ETHToken` contract on Rinkeby and call the `changeETHLockingAddr()` function using the `ETHLocking` contract address (Step 4) as the input argument.
6. **IMPORTANT:** The relayers' addresses must be authorised in the `PeaceRelay` contracts by calling the `authorise()` function. This need not be done if the creators of the `PeaceRelay` contracts are the relayers themselves.

## Setting up the relayers
We used AWS to do the relaying of block headers. All necessary files can be found in the ./cli folder. Create a linux server (you may run locally as well) and upload those files onto the server.
We use AWS to do the relaying of block headers. All necessary files can be found in the ./cli folder. Create a linux server (you may run locally as well) and upload those files onto the server.
1. Edit the `settings.json` file. Input the different contract addresses and private keys of the 2 wallets that does the block header submissions and transaction submissions.
2. Run the command `node peacerelay.js --from={srcChain} --to={destChain} --start={blockNum}` where
* `srcChain` is the chain **from** which the block headers are to be relayed (smallcaps)
Expand All @@ -57,10 +59,15 @@ We used AWS to do the relaying of block headers. All necessary files can be foun
* Eg. `node peacerelay.js --from=rinkeby --to=kovan --start=2136659` (Relays Rinkeby block headers to the Kovan PeaceRelay contract, starting from block 2136659)

## Setting up the website
0. It is assumed that the contracts have been deployed and relayers have been set up.
1. Run `truffle deploy` to compile contracts. You should now have a `build` folder. The json files will be needed for the front-end website. (Namely, the ABI of the contracts)
0. It is assumed that the contracts have been deployed and relayers have been set up, and either `npm` or `yarn` has been installed.
1. Run `truffle deploy` to compile contracts. You should now have a `build` folder. The json files will be needed for the front-end website. To be specific, only the ABI of the contracts is needed, so an alternative is to copy the contract codes to [Remix](http://remix.ethereum.org) to obtain the ABI.
2. Ensure that the `settings.json` file has the correct information as mentioned in step 2 of the 'setting up the relayers' section.
3. Run `npm install` to install dependencies.
3. Run `npm install` or `yarn install` to install dependencies.
4. Run `npm run dev` or `yarn && yarn start`.
5. Website should be available via `localhost:3000`

## Example
1. [PeaceRelay contract](https://rinkeby.etherscan.io/address/0xa469a40f1bfa089761b226c084c6eaec6a19bc4f#code) relaying Kovan blocks to Rinkeby. Note that "imports" will need to have the code concatenated into one file as etherscan does not support "imports" in separate files for verification.
2. [ETHToken contract](https://rinkeby.etherscan.io/address/0xd8f16118cd79042491cde899d4963aae7d35fb7b#code)
3. [PeaceRelay contract](https://kovan.etherscan.io/address/0xa469a40f1bfa089761b226c084c6eaec6a19bc4f#code) relaying Rinkeby blocks to Kovan.
4. [ETHLocking contract](https://kovan.etherscan.io/address/0xd8f16118cd79042491cde899d4963aae7d35fb7b)
Loading