Skip to content

Instantly share code, notes, and snippets.

@atif-konasl
Last active September 14, 2020 03:06
Show Gist options
  • Save atif-konasl/fd0d79b7c2536a176602cb63386be12a to your computer and use it in GitHub Desktop.
Save atif-konasl/fd0d79b7c2536a176602cb63386be12a to your computer and use it in GitHub Desktop.
Genesis spec prepare for geth aura.

Genesis json file according to openethereum spec and wiki

parity-aura-genesis.json

{
    "name": "DemoPoA",
    "engine": {
        "authorityRound": {
            "params": {
                "stepDuration": "5",
                "validators" : {
                    "list": [
                        "0x76814b3644f20903b8472434e8c8efb2aa79e546",
                        "0xcdf269895f63617ea00e1494956f419cf14a2828"
                    ]
                }
            }
        }
    },
    "params": {
        "gasLimitBoundDivisor": "0x400",
        "maximumExtraDataSize": "0x20",
        "minGasLimit": "0x1388",
        "networkID" : "0x2323",
        "eip155Transition": 0,
        "validateChainIdTransition": 0,
        "eip140Transition": 0,
        "eip211Transition": 0,
        "eip214Transition": 0,
        "eip658Transition": 0
    },
    "genesis": {
        "seal": {
            "authorityRound": {
                "step": "0x0",
                "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
            }
        },
        "difficulty": "0x20000",
        "author": "0x0000000000000000000000000000000000000000",
        "timestamp": "0x00",
        "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "extraData": "0x",
        "gasLimit": "0x222222",
    },
    "accounts": {
        "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
        "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
        "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
        "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
        "0xea294b897567b3a677c499a051e9032d52bd7347": { "balance": "10000000000000000000000" }
    }
}

Genesis json file is created for geth AuRa

geth-aura-genesis.json

{
	"config": {
		"chainId": 1994,
		"daoForkSupport": true,
		"eip150Block": 0,
		"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
		"eip155Block": 0,
		"eip158Block": 0,
		"homesteadBlock": 0,
		"byzantiumBlock": 0,
		"constantinopleBlock": 0,
		"petersburgBlock": 0,
		"istanbulBlock": 1561651,
		"authorityRound": {
			"stepDuration": "5",
			"validators" : [
				"0x76814b3644f20903b8472434e8c8efb2aa79e546",
				"0xcdf269895f63617ea00e1494956f419cf14a2828"
			]
		}
     },
	"seal": {
           "step": "0x0",
           "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
     },
	"difficulty": "0x20000",
	"gasLimit": "0x5B8D80",
	"alloc": {
		"0000000000000000000000000000000000000000": { "balance": "0x1" },
		"0000000000000000000000000000000000000001": { "balance": "0x1" },
		"0000000000000000000000000000000000000002": { "balance": "0x1" },
		"0000000000000000000000000000000000000003": { "balance": "0x1" },
		"0000000000000000000000000000000000000004": { "balance": "0x1" },
		"0xea294b897567b3a677c499a051e9032d52bd7347": { "balance": "10000000000000000000000" }
}

Steps considarded for matching hash of genesis block (0th block)

  • When execute geth init command, genesis block is created and stored in db. so, i tried to change the init command pipeline so that i can generate the block hash as same as parity aura.

  • Changed in 3 files in geth's existing code in geth init execution flow -

	* core/genesis.go
	* core/types/block.go
	* params/config.go

Generate header hash of parity and geth aura

  • parity - 0x90ad…50bc
  • geth - 0xe194adec7e1bfa3e2d90febd0de621ab105be9824c8b3d5e56b915edde5d7985

Generated genesis block data from parity aura and geth aura

  • parity aura
	{
	  author: "0x0000000000000000000000000000000000000000",
	  difficulty: 131072,
	  extraData: "0x",
	  gasLimit: 2236962,
	  gasUsed: 0,
	  hash: "0x90ad0ff267414c3e617636de716a08c3515476821f4e936cd2fe032eb55650bc",
	  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
	  miner: "0x0000000000000000000000000000000000000000",
	  number: 0,
	  parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
	  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
	  sealFields: ["0x80", "0xb8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"],
	  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
	  signature: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
	  size: 533,
	  stateRoot: "0xbdf86c865faeac71f77b4bd28df3a4e5154d6a47513db0fe9cf6d8b6f9aac4ab",
	  step: "0",
	  timestamp: 0,
	  totalDifficulty: 131072,
	  transactions: [],
	  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
	  uncles: []
	}
  • For geth aura, i just executed geth init command and the rest of the flow was as it is. For that reason, i got the header and block data from log debug in console.
INFO [09-14|02:22:21.577] Maximum peer count                       ETH=50 LES=0 total=50
INFO [09-14|02:22:21.577] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
DEBUG[09-14|02:22:21.577] FS scan times                            list="60.445µs" set="7.511µs" diff="3.645µs"
INFO [09-14|02:22:21.579] Set global gas cap                       cap=25000000
INFO [09-14|02:22:21.579] Allocated cache and file handles         database=/home/atif/Lukso/experiment/geth-aura/datadir/geth/chaindata cache=16.00MiB handles=16
INFO [09-14|02:22:21.709] Writing custom genesis block 
INFO [09-14|02:22:21.710] Persisted trie from memory database      nodes=8 size=1.14KiB time="200.518µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
Genesis header hash %v
 0xe194adec7e1bfa3e2d90febd0de621ab105be9824c8b3d5e56b915edde5d7985
Genesis header rlp f9028fa000000000000000000000000000000000000000000000000000000000000000008080940000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934780a06c4b5c48978156c08ab45fac49bad170389aaae1a8354d313b924f014b0f1343a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808322222283020000f88580b88230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030a00000000000000000000000000000000000000000000000000000000000000000880000000000000000940000000000000000000000000000000000000000
DEBUG[09-14|02:22:21.710] Prepared genesis block.                  block="&{header:0xc00028a000 uncles:[] transactions:[] hash:{v:<nil>} size:{v:<nil>} td:0xc0001e4c60 ReceivedAt:0001-01-01 00:00:00 +0000 UTC ReceivedFrom:<nil>}"
INFO [09-14|02:22:21.710] Successfully wrote genesis state         database=chaindata hash="e194ad…5d7985"
INFO [09-14|02:22:21.710] Allocated cache and file handles         database=/home/atif/Lukso/experiment/geth-aura/datadir/geth/lightchaindata cache=16.00MiB handles=16
INFO [09-14|02:22:21.854] Writing custom genesis block 
INFO [09-14|02:22:21.860] Persisted trie from memory database      nodes=8 size=1.14KiB time=5.848604ms  gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
Genesis header hash %v
 0xe194adec7e1bfa3e2d90febd0de621ab105be9824c8b3d5e56b915edde5d7985
Genesis header rlp f9028fa000000000000000000000000000000000000000000000000000000000000000008080940000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934780a06c4b5c48978156c08ab45fac49bad170389aaae1a8354d313b924f014b0f1343a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808322222283020000f88580b88230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030a00000000000000000000000000000000000000000000000000000000000000000880000000000000000940000000000000000000000000000000000000000
DEBUG[09-14|02:22:21.860] Prepared genesis block.                  block="&{header:0xc0002f6780 uncles:[] transactions:[] hash:{v:<nil>} size:{v:<nil>} td:0xc00000ef20 ReceivedAt:0001-01-01 00:00:00 +0000 UTC ReceivedFrom:<nil>}"
INFO [09-14|02:22:21.860] Successfully wrote genesis state         database=lightchaindata hash="e194ad…5d7985"

Findings

* Header hash mismatch.
* Genesis block hash of geth aura not matched with parity aura. 
* My observation is that, there could be a problem in rlp encoding or in hashing function.
* I used rlpdump to debug parity aura genesis block and found that all value has been matched with geth aura header block data.

Important parity files that are needed to investigate

```
eth/spec/src/seal.rs
eth/spec/src/genesis.rs
eth/spec/src/spec.rs  [line no - 512, tracing header hash]
```

ToDo

* Next try investigate parity aura spec and build from source code.
* Try to generate rlp endcoded bytes for genesis header in parity aura then compare with geth genesis header.
* Trace parity aura and added some extra log if needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment