Skip to content

Commit 1ceb1ba

Browse files
authored
fix(system-contract): Ensure header.coinbase is not set (#1127)
1 parent 1dedddb commit 1ceb1ba

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

consensus/system_contract/consensus.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,16 @@ func (s *SystemContract) VerifyUncles(chain consensus.ChainReader, block *types.
219219
// Prepare initializes the consensus fields of a block header according to the
220220
// rules of a particular engine. Update only timestamp and prepare ExtraData for Signature
221221
func (s *SystemContract) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
222+
// Make sure unused fields are empty
223+
header.Coinbase = common.Address{}
224+
header.Nonce = types.BlockNonce{}
225+
header.MixDigest = common.Hash{}
226+
227+
// Prepare EuclidV2-related fields
222228
header.BlockSignature = make([]byte, extraSeal)
223229
header.IsEuclidV2 = true
224230
header.Extra = nil
231+
225232
// Ensure the timestamp has the correct delay
226233
parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
227234
if parent == nil {
@@ -233,14 +240,19 @@ func (s *SystemContract) Prepare(chain consensus.ChainHeaderReader, header *type
233240
if s.config.RelaxedPeriod || header.Time < uint64(time.Now().Unix()) {
234241
header.Time = uint64(time.Now().Unix())
235242
}
243+
244+
// Difficulty must be 1
236245
header.Difficulty = big.NewInt(1)
246+
237247
return nil
238248
}
239249

240250
// Finalize implements consensus.Engine. There is no post-transaction
241251
// No rules here
242252
func (s *SystemContract) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
243253
// No block rewards in PoA, so the state remains as is
254+
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
255+
header.UncleHash = types.CalcUncleHash(nil)
244256
}
245257

246258
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
@@ -249,9 +261,6 @@ func (s *SystemContract) FinalizeAndAssemble(chain consensus.ChainHeaderReader,
249261
// Finalize block
250262
s.Finalize(chain, header, state, txs, uncles)
251263

252-
// Assign the final state root to header.
253-
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
254-
255264
// Assemble and return the final block for sealing.
256265
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil)), nil
257266
}

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 15 // Patch version component of the current release
27+
VersionPatch = 16 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)