Skip to content

Feature/cli submit block #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7faf296
Can call the latest block from an instance of ethereum
maxrobot Jun 18, 2018
294747f
Adding in a testing framework
maxrobot Jun 19, 2018
4061564
got the CLI working and RPC stuff off in a different file.
maxrobot Jun 19, 2018
facb261
added the rlp encoding testing which was surprisingly painful and tes…
maxrobot Jun 19, 2018
c10346b
Ok we now can pull RLP encoded blocks :)
maxrobot Jun 19, 2018
957c3ee
Cleaned up the generation of RLP encoded blocks
maxrobot Jun 20, 2018
52fba22
Started creating the contract to actually verify signatures legitimately
maxrobot Jun 20, 2018
529efca
Merge pull request #2 from maxrobot/feature/rpc-calls
Jun 20, 2018
fa71842
Understand how to ecrecover stuff signed in the javascript modules pi…
maxrobot Jun 20, 2018
b474ad0
Initial inauthenticate block is there
maxrobot Jun 21, 2018
2c6be71
Another painful thing to figure out even though it was quite simple, …
maxrobot Jun 21, 2018
665779c
So everything is working as expected would be nice to handle the cont…
maxrobot Jun 21, 2018
62a8d2c
Not sure
maxrobot Jun 22, 2018
5a12e59
have funcitonality to query smart contracts from golang cli
maxrobot Jun 22, 2018
bf1469e
Have added the functionality to query the validators contract
maxrobot Jun 22, 2018
23b2e1e
Improved the CLI help and also the readme
maxrobot Jun 23, 2018
7a86b03
Just didnt want to see the bad link in the README
maxrobot Jun 24, 2018
5fe2666
Improved the readme and added the user accounts to the setup.json
maxrobot Jun 25, 2018
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
105 changes: 90 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,122 @@
# Clique Block Verification
This repo allows you to set up a "Clique" proof of authority Ethereum blockchain with two separate peers who both engage in the sealing of blocks. The instructions are based on the tutorial of [Salanfe](https://hackernoon.com/setup-your-own-private-proof-of-authority-ethereum-network-with-geth-9a0a3750cda8) but has the more complicated parts already initialised.
# Block Validation Scheme
Block validation scheme is a set of smart contract which aim to be able to ensure that block headers submitted to the contract are sealed by an approved partie(s). The motivation behind this is to update the state of a Clique PoA or Istanbul PBFT chain onto any other blockchain. To do this we first need to know which blocks are valid - dependent on the definition of a valid by the underlying consensus algorithm.

Once the network has been launched the tests validate that the blocks have been signed by a known validator.
At this stage a Clique PoA chain is launched and then the block headers updated to the smart contract which is deployed on itself. However in the near future this will be extended to update the Clique header onto any other chain. For a full description and roadmap of the project please refer to the Clearmatics [Ion-Stage-2 Wiki](https://github.com/clearmatics/ion/wiki/Ion-Stage-2---Proposal#validation).

## Launch the Network
In order to run the network first install an instance of [geth](https://geth.ethereum.org/downloads/) the directory structure and accounts have been set up a priori. Hence all that is required to launch the network is to follow these instructions:
## Running the Project
This project contains a number of components:
* Validation smart contract and tests
* Clique _proof of authority_ test network
* Command Line Interface for interacting with the smart contract

### Initialise Nodes
In order to use the smart contracts and run the tests it is necessary to first initialise the test network.

***Note:*** that as the contract searches for specific parts of the block header that only exist in Clique, Ganache or Ethash chains cannot be used.

### Initialise the Test Network
The instructions are based on the tutorial of [Salanfe](https://hackernoon.com/setup-your-own-private-proof-of-authority-ethereum-network-with-geth-9a0a3750cda8) but has the more complicated parts already initialised.

First install an instance of [geth](https://geth.ethereum.org/downloads/) and clone the repo.

Having cloned and entered the repo:
```
$ git clone [email protected]:maxrobot/validation.git
$ cd /path/to/validation
```

Now run the command:
```
$ tree -L 1
```

Which hopefully returns this:
```
├── abi
├── build
├── contracts
├── migrations
├── package.json
├── poa-network
├── README.md
├── src
├── test
└── truffle.js
```

#### Initialise Nodes
Network files are found in the `/path/to/validation/poa-network` directory. Enter the poa-network directory and initialise the two nodes which will be sealing blocks:
```
$ cd /path/to/validation/poa-network
$ geth --datadir node1/ init genesis.json
$ geth --datadir node2/ init genesis.json
```

### Launch the Bootnode
#### Launch the Bootnode
The boot node tells the peers how to connect with each other. In another terminal instance run:
```
$ bootnode -nodekey boot.key -verbosity 9 -addr :30310
$ INFO [06-07|12:16:21] UDP listener up self=enode://dcb1dbf8d710eb7d10e0e2db1e6d3370c4b048efe47c7a85c4b537b60b5c11832ef25f026915b803e928c1d93f01b853131e412c6308c4c6141d1504c78823c8@[::]:30310
```
As the peers communicate this terminal should fill with logs.

### Start and Attach to the Nodes
Each node must be launch, either as a background operation or on separate terminal instances. For node 1:
***Note:*** bootnode may not be found if go-ethereum/geth is not installed fully.

#### Start and Attach to the Nodes
Each node must be launched either as a background operation or on separate terminal instances. Thus from the poa-network directory for node 1 run:
```
$ geth --datadir node1/ --syncmode 'full' --port 30311 --rpc --rpcaddr 'localhost' --rpcport 8501 --bootnodes 'enode://dcb1dbf8d710eb7d10e0e2db1e6d3370c4b048efe47c7a85c4b537b60b5c11832ef25f026915b803e928c1d93f01b853131e412c6308c4c6141d1504c78823c8@127.0.0.1:30310' --networkid 1515 --gasprice '1' -unlock '0x2be5ab0e43b6dc2908d5321cf318f35b80d0c10d' --password node1/password.txt --mine
```
then attach,
then attach:
```
$ geth attach node1/geth.ipc
```
node 2:
and again for node 2:
```
$ geth --datadir node2/ --syncmode 'full' --port 30312 --rpc --rpcaddr 'localhost' --rpcport 8502 --bootnodes 'enode://dcb1dbf8d710eb7d10e0e2db1e6d3370c4b048efe47c7a85c4b537b60b5c11832ef25f026915b803e928c1d93f01b853131e412c6308c4c6141d1504c78823c8@127.0.0.1:30310' --networkid 1515 --gasprice '0' -unlock '0x8671e5e08d74f338ee1c462340842346d797afd3' --password node2/password.txt --mine
```
again attach,
attaching:
```
$ geth attach node2/geth.ipc
```
Notice that IPC has been used to attach to the nodes, this allows the clique module to be used.
***Note:*** that IPC has been used to attach to the nodes, this allows the clique module to be used.

## Test
After launching the network:
### Testing Contracts
After launching the network, from the root of the repository:
```
$ npm install
$ truffle test
```

### Ion Command Line Interface
The Ion CLI is a tool for handling the passing of block headers between to blockchains written in Golang to leverage the extensive ethereum libraries. It is not a critical part of the Ion infrastructure rather is just an open utility that people can extend and use as they see fit.

In its current form the Ion CLI allows the user to connect to two separate blockchains, via RPC, and submit block headers to a validation contract.

#### Running the CLI
As mentioned in the project description this simple implementation of the validation contract is active only on a single blockchain, however the CLI is simulating the passing of the headers to and from as if it were between separate chains.

Having followed the instructions on how to setup a Clique blockchain, which is hosted on `127.0.0.1:8502`, and running another chain on `127.0.0.1:8501` we can attach the CLI.

```
$ cd /path/to/validation/src
$ make build
```
Assuming a successful build the tool can be run,
```
$ ./ion-cli [/path/to/setup.json]
===============================================================
Ion Command Line Interface

RPC Client [to]:
Listening on: 127.0.0.1:8501
User Account: 0x2be5ab0e43b6dc2908d5321cf318f35b80d0c10d
Ion Contract: 0xb9fd43a71c076f02d1dbbf473c389f0eacec559f

RPC Client [from]:
Listening on: 127.0.0.1:8502
User Account: 0x8671e5e08d74f338ee1c462340842346d797afd3
===============================================================
>>>
```


1 change: 1 addition & 0 deletions abi/ECVerify.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions abi/ECVerify.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146080604052600080fd00a165627a7a72305820acb6e646edaf05c92bfe7c53e47edcf3f96a2d5cf3d55019662508f330c1d89f0029
1 change: 1 addition & 0 deletions abi/Migrations.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"new_address","type":"address"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"last_completed_migration","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"completed","type":"uint256"}],"name":"setCompleted","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]
1 change: 1 addition & 0 deletions abi/Migrations.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102f8806100606000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100aa5780638da5cb5b146100d5578063fdacd5761461012c575b600080fd5b34801561007357600080fd5b506100a8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610159565b005b3480156100b657600080fd5b506100bf610241565b6040518082815260200191505060405180910390f35b3480156100e157600080fd5b506100ea610247565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561013857600080fd5b506101576004803603810190808035906020019092919050505061026c565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561023d578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b15801561022457600080fd5b505af1158015610238573d6000803e3d6000fd5b505050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102c957806001819055505b505600a165627a7a7230582090db59736857b6a69a78d054d092a30ff8e90f10f6f3bca8afc3d994c885eedd0029
1 change: 1 addition & 0 deletions abi/Recover.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"header","type":"bytes"},{"name":"prefixHeader","type":"bytes"},{"name":"prefixExtraData","type":"bytes"}],"name":"ExtractHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"header","type":"bytes"},{"name":"sig","type":"bytes"}],"name":"VerifyBlock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"data","type":"bytes32"},{"name":"sig","type":"bytes"}],"name":"VerifyHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"}],"name":"broadcastSig","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"header","type":"bytes"},{"indexed":false,"name":"parentHash","type":"bytes"},{"indexed":false,"name":"rootHash","type":"bytes"}],"name":"broadcastHashData","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"blockHash","type":"bytes32"}],"name":"broadcastHash","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"header","type":"bytes"}],"name":"test","type":"event"}]
1 change: 1 addition & 0 deletions abi/Recover.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610b11806100606000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063b0e7308f1461005c578063d09ca90414610151578063fdace1be14610200575b600080fd5b34801561006857600080fd5b5061014f600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610277565b005b34801561015d57600080fd5b506101fe600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061055e565b005b34801561020c57600080fd5b506102756004803603810190808035600019169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610840565b005b60008060608060608060606000808b5198508b6040518082805190602001908083835b6020831015156102bf578051825260208201915060208101905060208303925061029a565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902097507fcd7ee33e1a630d6301d87631aab1d4ddce7e1942593cd2689aa989f76d67cf018860405180826000191660001916815260200191505060405180910390a1608d89036040519080825280601f01601f1916602001820160405280156103635781602001602082028038833980820191505090505b509650601f6040519080825280601f01601f19166020018201604052801561039a5781602001602082028038833980820191505090505b50955060416040519080825280601f01601f1916602001820160405280156103d15781602001602082028038833980820191505090505b509450602a6040519080825280601f01601f1916602001820160405280156104085781602001602082028038833980820191505090505b509350610419878d60008a516108b6565b600260218801600260208e016004610bb8fa5061043c868d608c8c0389516108b6565b600160208701600160208d016004610bb8fa5061045f848d602a8c0387516108b6565b61046a878786610971565b9250826040518082805190602001908083835b6020831015156104a2578051825260208201915060208101905060208303925061047d565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902091506104e1858d606b8c0388516108b6565b6104eb8286610a1d565b90507fba2fe28067a0918af64c5359b1579f887bf1479dd3163c7e5d456314168854a581604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1505050505050505050505050565b600080606080856040518082805190602001908083835b60208310151561059a5780518252602082019150602081019050602083039250610575565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902093506105d38486610a1d565b925060206040519080825280601f01601f1916602001820160405280156106095781602001602082028038833980820191505090505b50915060206040519080825280601f01601f1916602001820160405280156106405781602001602082028038833980820191505090505b5090506106518287600460206108b6565b61065f8187605b60206108b6565b7f8511795469a13c04a2bc22c3f1309fc0bd918a0a25a3e7e222a0417b719274c786838360405180806020018060200180602001848103845287818151815260200191508051906020019080838360005b838110156106cb5780820151818401526020810190506106b0565b50505050905090810190601f1680156106f85780820380516001836020036101000a031916815260200191505b50848103835286818151815260200191508051906020019080838360005b83811015610731578082015181840152602081019050610716565b50505050905090810190601f16801561075e5780820380516001836020036101000a031916815260200191505b50848103825285818151815260200191508051906020019080838360005b8381101561079757808201518184015260208101905061077c565b50505050905090810190601f1680156107c45780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390a17fba2fe28067a0918af64c5359b1579f887bf1479dd3163c7e5d456314168854a583604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1505050505050565b600061084c8383610a1d565b90507fba2fe28067a0918af64c5359b1579f887bf1479dd3163c7e5d456314168854a581604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1505050565b60008090505b8181101561096a57838184018151811015156108d457fe5b9060200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002858281518110151561092d57fe5b9060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806001019150506108bc565b5050505050565b606060008060008060008060608a5196508951955060208701945088519350600260208888010101925060028487890101019150816040519080825280601f01601f1916602001820160405280156109d85781602001602082028038833980820191505090505b50905086602082018860208e016004610bb8fa50858582018760208d016004610bb8fa50838382018560208c016004610bb8fa50809750505050505050509392505050565b60008060008060418551141515610a3357600080fd5b6020850151925060408501519150606085015160001a9050601b8160ff161015610a5e57601b810190505b601b8160ff161480610a735750601c8160ff16145b1515610a7e57600080fd5b610a8a86828585610a95565b935050505092915050565b60008060006040518781528660208201528560408201528460608201526020816080836001610bb8fa9250805191505060011515821515141515610ad857600080fd5b80925050509493505050505600a165627a7a7230582084747b0b9ea8d1285e7c7714b82fb8ff314f3245d9b3e8132f7679cf08b7ca2b0029
1 change: 1 addition & 0 deletions abi/Validation.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"header","type":"bytes"},{"name":"prefixHeader","type":"bytes"},{"name":"prefixExtraData","type":"bytes"}],"name":"ValidateBlock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"GetValidators","outputs":[{"name":"_validators","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_validators","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"}],"name":"broadcastSig","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"header","type":"bytes"},{"indexed":false,"name":"parentHash","type":"bytes"},{"indexed":false,"name":"rootHash","type":"bytes"}],"name":"broadcastHashData","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"blockHash","type":"bytes32"}],"name":"broadcastHash","type":"event"}]
Loading