Validator Contracts in Genesis file with POA Blockchain

Girish
3 min readNov 5, 2018

There are different ways to define the set of authorities in the chain specification file. The easiest way is to use a fixed list of authorities. Any change in this list requires a hard fork, and thus an off-chain synchronization between the parties running authority nodes.

A fixed list of addresses works well for small networks with few participants. However, it lacks flexibility as there is no easy way to add or remove validators, there is also no monitoring mechanism to report if authority nodes are offline. Using a contract, however, allows to manage authorities without hard fork as well as reporting misbehaving authorities.

Two ways to use contracts

  1. After the chain is set up and running
  • You can deploy the contract after the chain is setup
  • Use truffle/remix or any other tools to deploy the contracts in the blockchain.
  • Configure the contract
  • Mention the block number from when the contract should be used for the validator list

2. In the genesis file, while setting up the network.

The below tutorial will focus on method 2.

The usual genesis file validators will look like below. There are 2 validators in the network.

"validators" : {
"list": [
"0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
"0x00Aa39d30F0D20FF03a22cCfc30B7EfbFca597C2"
]
}

We will use the Kovan Validator set Contracts in this example. Code

Check out the code for Kovan Validator set and use remixd to share contracts with Remix IDE using below commands

$ git clone https://github.com/parity-contracts/kovan-validator-set.git$ cd kovan-validator-set
$ remixd --remix-ide https://remix.ethereum.org -s contracts/

Go to https://remix.ethereum.org

Click on the link icon and connect to the local file share

The required contracts will appear in Localhost section in Remix IDE

Compile the contracts and Click on Run tab at the top right corner of IDE.

Select RelayedOwnedSet contract from the drop down and expand the deploy function to pass constructor arguments.

for argument _relaySet, in the example “0x0000000000000000000000000000000000000005” is used and for

_initial, [“0x97b4ee02ffb24a3ffdd5b8d07fee94a6808d30d6”] is used.

Click on the briefcase button to encode values and copy it to the clipboard.

Note: I have the account for 0x97b4ee02ffb24a3ffdd5b8d07fee94a6808d30d6 and its corresponding privatekey json file. This account will be used as validator and to start the node.

Now update the genesis file accounts section. Add account 0x0000000000000000000000000000000000000005 and paste the ABI copied from Remix IDE.

Paste your abi replacing [PASTE_HERE]

and the accounts sections with account 0x0000000000000000000000000000000000000005"accounts": {"0x0000000000000000000000000000000000000001": {"builtin": {"name": "ecrecover","pricing": { "linear": { "base": 3000, "word": 0 } }},"balance": "1"},...
...
...
...
"0x0000000000000000000000000000000000000005": { "balance": "10000000000000000000000", "constructor" : "[PASTE_HERE]" }
}

Also, replace the validators list in genesis file with below code.

"validators": {"safeContract": "0x0000000000000000000000000000000000000005"}

Start the blockchain. You will see something like this

2018–11–05 19:05:01 UTC Signal for switch to contract-based validator set.
2018–11–05 19:05:01 UTC Initial contract validators: [0x97b4ee02ffb24a3ffdd5b8d07fee94a6808d30d6]
2018–11–05 19:05:05 UTC Imported #1 0xf4e6…1c33 (0 txs, 0.00 Mgas, 0 ms, 0.56 KiB)

Now to get the list of current validators, and to interact with the validators contract, use the contact address 0x0000000000000000000000000000000000000005

Open Remix IDE again. Go to the Run Tab, select the RelayedOwnedSet Contract.

in At Address Paste the contract address 0x0000000000000000000000000000000000000005

Click on function getValidators. the result is the initial addressed used in contract constructor arguments.

0x97b4ee02ffb24a3ffdd5b8d07fee94a6808d30d6

--

--