Skip to content
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

core: initializing a clique network with invalid genesis extradata is not rejected, crashes later #20710

Closed
adamschmideg opened this issue Feb 24, 2020 · 9 comments · Fixed by #24470

Comments

@adamschmideg
Copy link
Contributor

Hi there,

Please note that this is an issue tracker reserved for bug reports and feature requests.

For general questions please use the gitter channel or the Ethereum stack exchange at https://ethereum.stackexchange.com.

System information

Geth version: 1.9.11-unstable
OS & Version: OSX

Expected behaviour

Complain gracefully

Actual behaviour

panic: runtime error: makeslice: len out of range

Steps to reproduce the behaviour

geth --datadir /tmp/reproduce init genesis.json 
geth  --networkid=42  --datadir /tmp/reproduce  --unlock 0xda19f35c667420aa4A468710D6542Fd88714e73E

where genesis.json is

{
  "version": "1",
  "genesis": {
    "author": "0x0000000000000000000000000000000000000000",
    "difficulty": "0x1",
    "extraData": "0xdeadbeef",
    "gasLimit": "0x900000",
    "nonce": "0x00000000deadbeef",
    "timestamp": "0x0"
  },
  "config": {
    "chainId": 42,
    "clique": {
      "period": 5,
      "epoch": 3000
    }
  },
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1",
  "difficulty": "0x020000",
  "gasLimit": "0x2fefd8",
  "timestamp": "0x54c98c81",
  "extraData": "0x42",
  "mixHash": "0x2c85bcbce56429100b2108254bb56906257582aeafcbd682bc9af67a9f5aee46",
  "nonce": "0x78cc16f7b4f65485",
  "alloc": {
    "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
      "balance": "0x09184e72a000"
    }
  }
}

Backtrace

goroutine 89 [running]:
github.com/ethereum/go-ethereum/consensus/clique.(*Clique).snapshot(0xc0000c0620, 0x502dc20, 0xc00021c000, 0x0, 0x26d63f58213f0f8, 0xeb6f9a67ff7faced, 0xaada95a3372d577a, 0x7f21feb6fe3879b7, 0x0, 0x0, ...)
	/private/tmp/ethereum-20200204-95299-bttoer/consensus/clique/clique.go:377 +0x539
github.com/ethereum/go-ethereum/consensus/clique.(*Clique).Prepare(0xc0000c0620, 0x502dc20, 0xc00021c000, 0xc00028e480, 0x7f21feb6fe3879b7, 0x0)
	/private/tmp/ethereum-20200204-95299-bttoer/consensus/clique/clique.go:497 +0xec
github.com/ethereum/go-ethereum/miner.(*worker).commitNewWork(0xc00028e240, 0xc00019afb0, 0x0, 0x5e53bb4d)
	/private/tmp/ethereum-20200204-95299-bttoer/miner/worker.go:859 +0x39e
github.com/ethereum/go-ethereum/miner.(*worker).mainLoop(0xc00028e240)
	/private/tmp/ethereum-20200204-95299-bttoer/miner/worker.go:412 +0xcc8
created by github.com/ethereum/go-ethereum/miner.newWorker
	/private/tmp/ethereum-20200204-95299-bttoer/miner/worker.go:219 +0x525

Log

INFO [02-24|13:02:21.475] Maximum peer count                       ETH=50 LES=0 total=50
INFO [02-24|13:02:21.491] Allocated cache and file handles         database=/tmp/reproduce/geth/chaindata cache=16.00MiB handles=16
INFO [02-24|13:02:21.532] Writing custom genesis block
INFO [02-24|13:02:21.532] Persisted trie from memory database      nodes=1 size=145.00B time=409.581µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-24|13:02:21.533] Successfully wrote genesis state         database=chaindata               hash=f8f013…fe217f
INFO [02-24|13:02:21.533] Allocated cache and file handles         database=/tmp/reproduce/geth/lightchaindata cache=16.00MiB handles=16
INFO [02-24|13:02:21.556] Writing custom genesis block
INFO [02-24|13:02:21.557] Persisted trie from memory database      nodes=1 size=145.00B time=452.95µs  gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-24|13:02:21.558] Successfully wrote genesis state         database=lightchaindata               hash=f8f013…fe217f
INFO [02-24|13:02:21.610] Maximum peer count                       ETH=50 LES=0 total=50
INFO [02-24|13:02:21.632] Starting peer-to-peer node               instance=Geth/v1.9.11-unstable-33791dbe-20200204/darwin-amd64/go1.13.4
INFO [02-24|13:02:21.632] Allocated trie memory caches             clean=256.00MiB dirty=256.00MiB
INFO [02-24|13:02:21.632] Allocated cache and file handles         database=/tmp/reproduce/geth/chaindata cache=512.00MiB handles=5120
INFO [02-24|13:02:21.726] Opened ancient database                  database=/tmp/reproduce/geth/chaindata/ancient
INFO [02-24|13:02:21.727] Initialised chain configuration          config="{ChainID: 42 Homestead: <nil> DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil> Byzantium: <nil> Constantinople: <nil> Petersburg: <nil> Istanbul: <nil>, Muir Glacier: <nil>, Engine: clique}"
INFO [02-24|13:02:21.727] Initialising Ethereum protocol           versions="[64 63]" network=42 dbversion=<nil>
WARN [02-24|13:02:21.727] Upgrade blockchain database version      from=<nil> to=7
INFO [02-24|13:02:21.729] Loaded most recent local header          number=0 hash=f8f013…fe217f td=131072 age=5y1mo3w
INFO [02-24|13:02:21.729] Loaded most recent local full block      number=0 hash=f8f013…fe217f td=131072 age=5y1mo3w
INFO [02-24|13:02:21.729] Loaded most recent local fast block      number=0 hash=f8f013…fe217f td=131072 age=5y1mo3w
INFO [02-24|13:02:21.729] Regenerated local transaction journal    transactions=0 accounts=0
INFO [02-24|13:02:21.738] Allocated fast sync bloom                size=512.00MiB
@karalabe
Copy link
Member

The extradata section in clique has special meaning. Beside the vanity of ethash, it also contains a 65 byte signature for non-genesis blocks and an authorized signer list for the genesis. The vanity is also not optional, rather mandatory. Would be nicer to reject the genesis on geth init, that's for sure.

@karalabe karalabe changed the title Different networkid with clique results in a weird panic core: initializing a clique network with invalid genesis extradata is not rejected, crashes later Feb 27, 2020
@Neyromancer
Copy link

Hi, is help still needed? I can try it.

@hoangpham95
Copy link

Looking into this. Would love to take on as first issue.

@ligi
Copy link
Member

ligi commented Mar 20, 2021

YAY - PR's welcome!

@hoangpham95
Copy link

@ligi Does ETH have a discord/slack channel I can join?

@ligi
Copy link
Member

ligi commented Mar 20, 2021

https://discord.com/invite/nthXNEv

@hoangpham95
Copy link

Finally had the time to sit down to explore the code. Currently does genesis.go provide any mechanism to validate the genesis.json? I'm looking into chaincmd.go on the intiailization but looks like there's no verification step on the validity of genesis.json, e.g. extraData format, or the vanity of ethash.

@hoangpham95
Copy link

Creating a very minimal PR here for a start. This PR basically expose the two constant ExtraVanity and ExtraSeal in clique.go, and check the length of the genesis.Extradata. Not sure if it's neccessary to do other validation as described in here. Let me know what you think @ligi @karalabe.

@Kantitad
Copy link

Kantitad commented Mar 30, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
@ligi @karalabe @adamschmideg @Neyromancer @hoangpham95 @Kantitad and others