Skip to content

Commit

Permalink
Remove signature from Block Header (ethereum#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
nambrot authored Jun 17, 2019
1 parent 107bb48 commit 242e2cc
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 39 deletions.
7 changes: 2 additions & 5 deletions cmd/geth/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var daoOldGenesis = `{
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"signature" : "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {}
}`
Expand All @@ -54,7 +53,6 @@ var daoNoForkGenesis = `{
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"signature" : "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {
"daoForkBlock" : 314,
Expand All @@ -72,15 +70,14 @@ var daoProForkGenesis = `{
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"signature" : "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {
"daoForkBlock" : 314,
"daoForkSupport" : true
}
}`

var daoGenesisHash = common.HexToHash("6e535a8af35e1da477617a04db449f1167824a15b1f0bbced3591b37725f1b6d")
var daoGenesisHash = common.HexToHash("5e1fc79cb4ffa4739177b5408045cd5d51c6cf766133f23f7cd72ee1f8d790e0")
var daoGenesisForkBlock = big.NewInt(314)

// TestDAOForkBlockNewChain tests that the DAO hard-fork number and the nodes support/opposition is correctly
Expand Down Expand Up @@ -130,7 +127,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
}
defer db.Close()

genesisHash := common.HexToHash("0x755c328ecddd758876f9466c8f0b6b607688b658ff8f625f1acc3fcb31788429")
genesisHash := common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
if genesis != "" {
genesisHash = daoGenesisHash
}
Expand Down
6 changes: 1 addition & 5 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ func TestDefaultGenesisBlock(t *testing.T) {
if block.Hash() != params.TestnetGenesisHash {
t.Errorf("wrong testnet genesis hash, got %v, want %v", block.Hash().Hex(), params.TestnetGenesisHash.Hex())
}
block = DefaultRinkebyGenesisBlock().ToBlock(nil)
if block.Hash() != params.RinkebyGenesisHash {
t.Errorf("wrong testnet genesis hash, got %v, want %v", block.Hash().Hex(), params.RinkebyGenesisHash.Hex())
}
}

func TestSetupGenesis(t *testing.T) {
var (
customghash = common.HexToHash("0x12c995f892a22e8a2dcdfa53f8155c07679d104a979c8b047c8486232c966866")
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
customg = Genesis{
Config: &params.ChainConfig{HomesteadBlock: big.NewInt(3)},
Alloc: GenesisAlloc{
Expand Down
7 changes: 0 additions & 7 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ var (
// out on a block.
type BlockNonce [8]byte

// A BlockSignature is a 65-byte signature of the previous blockHash. This makes
// the public key available and verifies that the miner has access to the
// private key associated with the etherbase.
type BlockSignature [65]byte

// EncodeNonce converts the given integer to a block nonce.
func EncodeNonce(i uint64) BlockNonce {
var n BlockNonce
Expand Down Expand Up @@ -88,7 +83,6 @@ type Header struct {
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
Nonce BlockNonce `json:"nonce" gencodec:"required"`
Signature BlockSignature `json:"signature" gencodec:"required"`
}

// field type overrides for gencodec
Expand Down Expand Up @@ -313,7 +307,6 @@ func (b *Block) TxHash() common.Hash { return b.header.TxHash }
func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash }
func (b *Block) UncleHash() common.Hash { return b.header.UncleHash }
func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) }
func (b *Block) Signature() []byte { return common.CopyBytes(b.header.Signature[:]) }

func (b *Block) Header() *Header { return CopyHeader(b.header) }

Expand Down
7 changes: 3 additions & 4 deletions core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// from bcValidBlockTest.json, "SimpleTx"
func TestBlockEncoding(t *testing.T) {
blockEnc := common.FromHex("f90263f9023ca07285abd5b24742f184ad676e31f6054663b3529bc35ea2fcad8a3e0f642a46f7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ecc60e00b3fe5ce9f6e1a10e5469764daf51f1fe93c22ec3f9a7583a80357217a0d35d334d87c0cc0a202e3756bf81fae08b1575f286c7ee7a3f8df4f0f3afc55da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845c47775c80a00000000000000000000000000000000000000000000000000000000000000000880000000000000000b8413e835d97c294e9c5a24e072eb6cb07c91f562042c4dac5e67229b5cea30b35c73258e1a426173c4267c480a13d7c8c0c92ca70d55837b706194b763e0d57186a01e2e1800a82c350808094095e7baea6a6c7c4c2dfeb977efac326af552d870a80808080c0")
blockEnc := common.FromHex("f90234f901f9a07285abd5b24742f184ad676e31f6054663b3529bc35ea2fcad8a3e0f642a46f7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ecc60e00b3fe5ce9f6e1a10e5469764daf51f1fe93c22ec3f9a7583a80357217a086b17a8075a60641c549b89ca152915dadb70061fecaff43d6a03262b42152b3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845c47775c80a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f6f5800a82c3508094095e7baea6a6c7c4c2dfeb977efac326af552d8794095e7baea6a6c7c4c2dfeb977efac326af552d870a80808080c0")
var block Block
if err := rlp.DecodeBytes(blockEnc, &block); err != nil {
t.Fatal("decode error: ", err)
Expand All @@ -45,15 +45,14 @@ func TestBlockEncoding(t *testing.T) {
check("Coinbase", block.Coinbase(), common.HexToAddress("8888f1f195afa192cfee860698584c030f4c9db1"))
check("MixDigest", block.MixDigest(), common.HexToHash("0000000000000000000000000000000000000000000000000000000000000000"))
check("Root", block.Root(), common.HexToHash("ecc60e00b3fe5ce9f6e1a10e5469764daf51f1fe93c22ec3f9a7583a80357217"))
check("Hash", block.Hash(), common.HexToHash("9ddc8f73668b4a9cf6772715d1a28c59e352bdab6ac85a7dedef65f42755ec4f"))
check("Hash", block.Hash(), common.HexToHash("543f77909efcb1305bb8b8057403a7c6bac4b3df10f8270d56da95671d458cdb"))
check("Nonce", block.Nonce(), uint64(0x0))
check("Time", block.Time(), big.NewInt(1548187484))
check("Size", block.Size(), common.StorageSize(len(blockEnc)))
check("ParentHash", block.ParentHash(), common.HexToHash("7285abd5b24742f184ad676e31f6054663b3529bc35ea2fcad8a3e0f642a46f7"))
check("Signature", block.Signature(), common.FromHex("3e835d97c294e9c5a24e072eb6cb07c91f562042c4dac5e67229b5cea30b35c73258e1a426173c4267c480a13d7c8c0c92ca70d55837b706194b763e0d57186a01"))

check("len(Transactions)", len(block.Transactions()), 1)
check("Transactions[0].Hash", block.Transactions()[0].Hash(), common.HexToHash("613448c2afd5564da95787b6fc1c464f0ef90a63eb5d54eced83e16dbe7c2a1a"))
check("Transactions[0].Hash", block.Transactions()[0].Hash(), common.HexToHash("f2048da8ea5a864531bfe14280d9020e6f236f58c8a5ef376e039dbe2fdb70df"))

ourBlockEnc, err := rlp.EncodeToBytes(&block)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/types/istanbul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func TestHeaderHash(t *testing.T) {
// 0xaf194652cebbd181065203aded680c42d72eed7ae7d59d8e347b0bbb64ac5772
expectedExtra := common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000000f89af8549444add0ec310f115a0e603b2d7db9f067778eaf8a94294fc7e8f22b3bcdcf955dd7ff3ba2ed833f8212946beaaed781d2d2ab6350f5c4566a2c6eaac407a6948be76812f765c24641ec63dc2852b378aba2b440b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0")
expectedHash := common.HexToHash("0xaf194652cebbd181065203aded680c42d72eed7ae7d59d8e347b0bbb64ac5772")
expectedHash := common.HexToHash("0xcefefd3ade63a5955bca4562ed840b67f39e74df217f7e5f7241a6e9552cca70")

// for istanbul consensus
header := &Header{MixDigest: IstanbulDigest, Extra: expectedExtra}
Expand Down
1 change: 0 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,6 @@ func RPCMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]inter
"timestamp": (*hexutil.Big)(head.Time),
"transactionsRoot": head.TxHash,
"receiptsRoot": head.ReceiptHash,
"signature": hexutil.Bytes(common.CopyBytes(head.Signature[:])),
}

if inclTx {
Expand Down
14 changes: 0 additions & 14 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/abe"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
Expand Down Expand Up @@ -980,19 +979,6 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
return
}
header.Coinbase = w.coinbase
// TODO(asa): Set signature in the consensus engine, verify elsewhere
wallet, err := w.eth.AccountManager().Find(accounts.Account{Address: w.coinbase})
if err != nil {
log.Error("[Celo] Failed to get account for block signature", "err", err)
} else {
code, err := wallet.SignHash(accounts.Account{Address: w.coinbase}, header.ParentHash.Bytes())
if err != nil {
log.Error("[Celo] Failed to sign block hash", "err", err)
} else {
// TODO(asa): Verify the signature when doing block verification
copy(header.Signature[:], code[:])
}
}
}
if err := w.engine.Prepare(w.chain, header); err != nil {
log.Error("Failed to prepare header for mining", "err", err)
Expand Down
4 changes: 2 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

// Genesis hashes to enforce below configs on.
var (
MainnetGenesisHash = common.HexToHash("0x755c328ecddd758876f9466c8f0b6b607688b658ff8f625f1acc3fcb31788429")
TestnetGenesisHash = common.HexToHash("0x6d3f7cf1468c7f7a5fc47d788ebd8ea8491706bab1690c320818f1861236c001")
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
RinkebyGenesisHash = common.HexToHash("0x2cdb663cd9fc9d5cf03ec8dc2e3d25b9805a5ed88d6895fc2cb7b328737758f4")
)

Expand Down

0 comments on commit 242e2cc

Please sign in to comment.