Skip to content

Commit

Permalink
fix: hash computation doesn't include proof elements
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Jan 4, 2023
1 parent eda12dc commit 64a7c0b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
32 changes: 17 additions & 15 deletions core/beacon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,23 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) {
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
}
header := &types.Header{
ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash,
Coinbase: params.FeeRecipient,
Root: params.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: common.Big0,
Number: new(big.Int).SetUint64(params.Number),
GasLimit: params.GasLimit,
GasUsed: params.GasUsed,
Time: params.Timestamp,
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash,
Coinbase: params.FeeRecipient,
Root: params.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: common.Big0,
Number: new(big.Int).SetUint64(params.Number),
GasLimit: params.GasLimit,
GasUsed: params.GasUsed,
Time: params.Timestamp,
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
VerkleKeyVals: params.VerkleKeyVals,
VerkleProof: params.VerkleProof,
}
block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */)
if block.Hash() != params.BlockHash {
Expand Down
12 changes: 12 additions & 0 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,20 @@ func (b *Block) Hash() common.Hash {
if hash := b.hash.Load(); hash != nil {
return hash.(common.Hash)
}

// Set the verkle stuff to `nil` when computing the block
// hash, as the proof elements are not included in the
// hash calculation for now.
vp := b.header.VerkleProof
kvs := b.header.VerkleKeyVals
b.header.VerkleKeyVals = nil
b.header.VerkleProof = nil

v := b.header.Hash()
b.hash.Store(v)

b.header.VerkleKeyVals = kvs
b.header.VerkleProof = vp
return v
}

Expand Down

0 comments on commit 64a7c0b

Please sign in to comment.