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

consensus/clique: prevent 0 len extradata from panicing #23538

Merged
merged 5 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/genesis.go
Expand Up @@ -310,7 +310,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
block := g.ToBlock(db)
if block.Number().Sign() != 0 {
return nil, fmt.Errorf("can't commit genesis block with number > 0")
return nil, errors.New("can't commit genesis block with number > 0")
}
config := g.Config
if config == nil {
Expand All @@ -319,6 +319,9 @@ func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
if err := config.CheckConfigForkOrder(); err != nil {
return nil, err
}
if config.Clique != nil && len(block.Extra()) == 0 {
return nil, errors.New("can't start clique chain without signers")
}
rawdb.WriteTd(db, block.Hash(), block.NumberU64(), g.Difficulty)
rawdb.WriteBlock(db, block)
rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), nil)
Expand Down
16 changes: 16 additions & 0 deletions core/genesis_test.go
Expand Up @@ -39,6 +39,22 @@ func TestDefaultGenesisBlock(t *testing.T) {
if block.Hash() != params.RopstenGenesisHash {
t.Errorf("wrong ropsten genesis hash, got %v, want %v", block.Hash(), params.RopstenGenesisHash)
}
block = DefaultRinkebyGenesisBlock().ToBlock(nil)
if block.Hash() != params.RinkebyGenesisHash {
t.Errorf("wrong rinkeby genesis hash, got %v, want %v", block.Hash(), params.RinkebyGenesisHash)
}
block = DefaultGoerliGenesisBlock().ToBlock(nil)
if block.Hash() != params.GoerliGenesisHash {
t.Errorf("wrong goerli genesis hash, got %v, want %v", block.Hash(), params.GoerliGenesisHash)
}
}

func TestInvalidCliqueConfig(t *testing.T) {
block := DefaultGoerliGenesisBlock()
block.ExtraData = []byte{}
if _, err := block.Commit(nil); err == nil {
t.Fatal("Expected error on invalid clique config")
}
}

func TestSetupGenesis(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions miner/worker_test.go
Expand Up @@ -74,8 +74,10 @@ var (
func init() {
testTxPoolConfig = core.DefaultTxPoolConfig
testTxPoolConfig.Journal = ""
ethashChainConfig = params.TestChainConfig
cliqueChainConfig = params.TestChainConfig
ethashChainConfig = new(params.ChainConfig)
*ethashChainConfig = *params.TestChainConfig
cliqueChainConfig = new(params.ChainConfig)
*cliqueChainConfig = *params.TestChainConfig
cliqueChainConfig.Clique = &params.CliqueConfig{
Period: 10,
Epoch: 30000,
Expand Down